<commit_before>import datetime
from urlparse import urljoin
from django.core.management.base import BaseCommand, CommandError
from django.conf import settings
from locksmith.common import apicall

class Command(BaseCommand):
    help = "Push a given day's logs up to the analytics hub"
    args = '[date:YYYY-MM-DD]'
    requires_model_validation = False

    def handle(self, date=None, *args, **options):
        if not date:
            # set date to yesterday if not passed in
            yesterday = datetime.datetime.now() - datetime.timedelta(days=1)
            date = yesterday.strftime('%Y-%m-%d')

        print 'pushing logs for %s' % date

        dt_begin = datetime.datetime.strptime(date, '%Y-%m-%d')
        dt_end = dt_begin + datetime.timedelta(days=1)

        # construct database query
        qs = LogModel.objects.extra(where=["date_trunc('day', {0}) = '{1}'".format(DATE_FIELD, date)]).order_by()
        results = qs.values(ENDPOINT_FIELD, USER_FIELD).annotate(calls=Count('id'))

        results = db.logs.group(['key', 'method'],
                               {"timestamp" {"$gte": dt_begin, "$lt": dt_end}},
                               {"count": 0},
                               "function (obj, prev) {prev.count += 1;}")

        endpoint = urljoin(settings.LOCKSMITH_HUB_URL, 'report_calls/')

        # report results
        for item in results:
            apicall(endpoint, settings.LOCKSMITH_SIGNING_KEY,
                    api=settings.LOCKSMITH_API_NAME, date=date,
                    endpoint=item['method'], key=item['key'],
                    calls=item['count'])<commit_msg>syntax is hard?<commit_after>import datetime
from urlparse import urljoin
from django.core.management.base import BaseCommand, CommandError
from django.conf import settings
from locksmith.common import apicall

class Command(BaseCommand):
    help = "Push a given day's logs up to the analytics hub"
    args = '[date:YYYY-MM-DD]'
    requires_model_validation = False

    def handle(self, date=None, *args, **options):
        if not date:
            # set date to yesterday if not passed in
            yesterday = datetime.datetime.now() - datetime.timedelta(days=1)
            date = yesterday.strftime('%Y-%m-%d')

        print 'pushing logs for %s' % date

        dt_begin = datetime.datetime.strptime(date, '%Y-%m-%d')
        dt_end = dt_begin + datetime.timedelta(days=1)

        # construct database query
        qs = LogModel.objects.extra(where=["date_trunc('day', {0}) = '{1}'".format(DATE_FIELD, date)]).order_by()
        results = qs.values(ENDPOINT_FIELD, USER_FIELD).annotate(calls=Count('id'))

        results = db.logs.group(['key', 'method'],
                               {"timestamp": {"$gte": dt_begin, "$lt": dt_end}},
                               {"count": 0},
                               "function (obj, prev) {prev.count += 1;}")

        endpoint = urljoin(settings.LOCKSMITH_HUB_URL, 'report_calls/')

        # report results
        for item in results:
            apicall(endpoint, settings.LOCKSMITH_SIGNING_KEY,
                    api=settings.LOCKSMITH_API_NAME, date=date,
                    endpoint=item['method'], key=item['key'],
                    calls=item['count'])
{'fraction_non_alphanumeric': 0.1278819551183523, 'fraction_numerical': 0.0036889025514909315, 'mean_word_length': 2.4216614090431126, 'pattern_counts': {'":': 7, '<': 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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4327754', 'n_tokens_mistral': 953, 'n_tokens_neox': 929, 'n_words': 223}