当前位置: 首页>>代码示例>>Python>>正文


Python Contribution._get_index方法代码示例

本文整理汇总了Python中stats.models.Contribution._get_index方法的典型用法代码示例。如果您正苦于以下问题:Python Contribution._get_index方法的具体用法?Python Contribution._get_index怎么用?Python Contribution._get_index使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在stats.models.Contribution的用法示例。


在下文中一共展示了Contribution._get_index方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: index_finance_total_by_currency

# 需要导入模块: from stats.models import Contribution [as 别名]
# 或者: from stats.models.Contribution import _get_index [as 别名]
def index_finance_total_by_currency(addons, **kw):
    """
    Bug 757581
    Total finance stats, currency breakdown.
    """
    index = kw.get('index', Contribution._get_index())
    es = amo.search.get_es()
    log.info('Indexing total financial stats by currency for %s apps.' %
              len(addons))

    for addon in addons:
        # Get all contributions for given add-on.
        qs = Contribution.objects.filter(addon=addon, uuid=None)
        if not qs.exists():
            continue

        # Get list of distinct currencies.
        currencies = set(qs.values_list('currency', flat=True))

        for currency in currencies:
            try:
                key = ord_word('cur' + str(addon) + currency.lower())
                data = search.get_finance_total(
                    qs, addon, 'currency', currency=currency)
                for index in get_indices(index):
                    if not already_indexed(Contribution, data, index):
                        Contribution.index(data, bulk=True, id=key,
                                           index=index)
                es.flush_bulk(forced=True)
            except Exception, exc:
                index_finance_total_by_currency.retry(args=[addons], exc=exc, **kw)
                raise
开发者ID:KryDos,项目名称:zamboni,代码行数:34,代码来源:tasks.py

示例2: index_finance_total_by_src

# 需要导入模块: from stats.models import Contribution [as 别名]
# 或者: from stats.models.Contribution import _get_index [as 别名]
def index_finance_total_by_src(addons, **kw):
    """
    Bug 758059
    Total finance stats, source breakdown.
    """
    index = kw.get('index', Contribution._get_index())
    es = elasticutils.get_es()
    log.info('Indexing total financial stats by source for %s apps.' %
              len(addons))

    for addon in addons:
        # Get all contributions for given add-on.
        qs = Contribution.objects.filter(addon=addon, uuid=None)
        if not qs.exists():
            continue

        # Get list of distinct sources.
        sources = set(qs.values_list('source', flat=True))

        for source in sources:
            try:
                key = ord_word('src' + str(addon) + str(source))
                data = search.get_finance_total(qs, addon, 'source',
                                                source=source)
                for index in get_indices(index):
                    if not already_indexed(Contribution, data, index):
                        Contribution.index(data, bulk=True, id=key,
                                           index=index)
                es.flush_bulk(forced=True)
            except Exception, exc:
                index_finance_total_by_src.retry(args=[addons], exc=exc, **kw)
                raise
开发者ID:MaxDumont,项目名称:zamboni,代码行数:34,代码来源:tasks.py

示例3: index_finance_daily

# 需要导入模块: from stats.models import Contribution [as 别名]
# 或者: from stats.models.Contribution import _get_index [as 别名]
def index_finance_daily(ids, **kw):
    """
    Bug 748015
    Takes a list of Contribution ids and uses its addon and date fields to
    index stats for that day.

    Contribution stats by addon-date unique pair. Uses a nested
    dictionary to not index duplicate contribution with same addon/date
    pairs. For each addon-date, it stores the addon in the dict as a top
    level key with a dict as its value. And it stores the date in the
    add-on's dict as a second level key. To check if an addon-date pair has
    been already index, it looks up the dict[addon][date] to see if the
    key exists. This adds some speed up when batch processing.

    ids -- ids of apps.stats.Contribution objects
    """
    index = kw.get('index', Contribution._get_index())
    es = amo.search.get_es()

    # Get contributions.
    qs = (Contribution.objects.filter(id__in=ids)
          .order_by('created').values('addon', 'created'))
    log.info('[%s] Indexing %s contributions for daily stats.' %
             (qs[0]['created'], len(ids)))

    addons_dates = defaultdict(lambda: defaultdict(dict))
    for contribution in qs:
        addon = contribution['addon']
        date = contribution['created'].strftime('%Y%m%d')

        try:
            # Date for add-on not processed, index it and give it key.
            if not date in addons_dates[addon]:
                key = ord_word('fin' + str(addon) + str(date))
                data = search.get_finance_daily(contribution)
                for index in get_indices(index):
                    if not already_indexed(Contribution, data, index):
                        Contribution.index(data, bulk=True, id=key,
                                           index=index)
                addons_dates[addon][date] = 0
            es.flush_bulk(forced=True)
        except Exception, exc:
            index_finance_daily.retry(args=[ids], exc=exc, **kw)
            raise
开发者ID:KryDos,项目名称:zamboni,代码行数:46,代码来源:tasks.py

示例4: index_finance_total

# 需要导入模块: from stats.models import Contribution [as 别名]
# 或者: from stats.models.Contribution import _get_index [as 别名]
def index_finance_total(addons, **kw):
    """
    Aggregates financial stats from all of the contributions for a given app.
    """
    index = kw.get('index', Contribution._get_index())
    es = amo.search.get_es()
    log.info('Indexing total financial stats for %s apps.' %
              len(addons))

    for addon in addons:
        # Get all contributions for given add-on.
        qs = Contribution.objects.filter(addon=addon, uuid=None)
        if not qs.exists():
            continue
        try:
            key = ord_word('tot' + str(addon))
            data = search.get_finance_total(qs, addon)
            for index in get_indices(index):
                if not already_indexed(Contribution, data, index):
                    Contribution.index(data, bulk=True, id=key, index=index)
            es.flush_bulk(forced=True)
        except Exception, exc:
            index_finance_total.retry(args=[addons], exc=exc, **kw)
            raise
开发者ID:KryDos,项目名称:zamboni,代码行数:26,代码来源:tasks.py


注:本文中的stats.models.Contribution._get_index方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。