<commit_before>import datetime

from django.db import connection, transaction
from django.db.models import Sum, Max

import commonware.log
from celery.decorators import task

import amo
from addons.models import Addon
from bandwagon.models import Collection, CollectionAddon
from stats.models import Contribution
from reviews.models import Review
from users.models import UserProfile
from versions.models import Version
from .models import UpdateCount, DownloadCount, AddonCollectionCount

log = commonware.log.getLogger('z.task')


@task
def addon_total_contributions(*addons):
    "Updates the total contributions for a given addon."

    log.info('[%s@%s] Updating total contributions.' %
             (len(addons), addon_total_contributions.rate_limit))
    stats = (Contribution.objects.filter(addon__in=addons).values_list('addon')
             .annotate(Sum('amount')))

    for addon, total in stats:
        Addon.objects.filter(id=addon).update(total_contributions=total)


@task(rate_limit='10/m')
def cron_total_contributions(*addons):
    "Rate limited version of `addon_total_contributions` suitable for cron."
    addon_total_contributions(*addons)


@task(rate_limit='10/m')
def update_addons_collections_downloads(data, **kw):
    log.info("[%s@%s] Updating addons+collections download totals." %
                  (len(data), update_addons_collections_downloads.rate_limit))
    for var in data:
        (CollectionAddon.objects.filter(addon=var['addon'],
                                        collection=var['collection'])
                                .update(downloads=var['sum']))


@task(rate_limit='15/m')
def update_collections_total(data, **kw):<commit_msg>only count uuid=None; those are verified transactions<commit_after>import datetime

from django.db import connection, transaction
from django.db.models import Sum, Max

import commonware.log
from celery.decorators import task

import amo
from addons.models import Addon
from bandwagon.models import Collection, CollectionAddon
from stats.models import Contribution
from reviews.models import Review
from users.models import UserProfile
from versions.models import Version
from .models import UpdateCount, DownloadCount, AddonCollectionCount

log = commonware.log.getLogger('z.task')


@task
def addon_total_contributions(*addons):
    "Updates the total contributions for a given addon."

    log.info('[%s@%s] Updating total contributions.' %
             (len(addons), addon_total_contributions.rate_limit))
    # Only count uuid=None; those are verified transactions.
    stats = (Contribution.objects.filter(addon__in=addons, uuid=None)
             .values_list('addon').annotate(Sum('amount')))

    for addon, total in stats:
        Addon.objects.filter(id=addon).update(total_contributions=total)


@task(rate_limit='10/m')
def cron_total_contributions(*addons):
    "Rate limited version of `addon_total_contributions` suitable for cron."
    addon_total_contributions(*addons)


@task(rate_limit='10/m')
def update_addons_collections_downloads(data, **kw):
    log.info("[%s@%s] Updating addons+collections download totals." %
                  (len(data), update_addons_collections_downloads.rate_limit))
    for var in data:
        (CollectionAddon.objects.filter(addon=var['addon'],
                                        collection=var['collection'])
                                .update(downloads=var['sum']))


@task(rate_limit='15/m')
def update_collections_total(data, **kw):
{'fraction_non_alphanumeric': 0.10269650028686174, 'fraction_numerical': 0.0034423407917383822, 'mean_word_length': 4.120411160058737, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4780613', 'n_tokens_mistral': 1036, 'n_tokens_neox': 998, 'n_words': 239}