<commit_before>from datetime import datetime, timedelta
import logging
from urllib import urlencode

from django.conf.urls.defaults import patterns, url
from django.utils.translation import ugettext_lazy as _
from django.forms import models as modelforms
from django import forms
from django.forms.fields import DateTimeField, IntegerField, HiddenInput
from django.core import signals as core_signals
from django.conf import settings
from django.http import HttpResponse
from django.shortcuts import render_to_response

from ella.exports import models
from ella.exports.managers import ExportItemizer
from ella.utils import remove_diacritical
from ella.newman import utils

DATETIME_FORMAT = models.DATETIME_FORMAT
TIME_FORMAT = models.TIME_FORMAT
TIMELINE_STEP = timedelta(hours=2)  # two hours
EMPTY_TIMELINE_CELL = None
log = logging.getLogger('ella.exports')

def get_timerange(year=datetime.now().year, month=datetime.now().month, day=datetime.now().day):
    now = datetime.now()
    out = list()
    for d in range(-14, 14):
        dt = timedelta(days=d)
        for h in [h for h in range(23) if h % 2 == 0]:
            t = datetime(year, month, day, h, 0) + dt
            str_t = t.strftime(DATETIME_FORMAT)
            out.append( (str_t, str_t) )
    return out

def get_export_choice_form():
    export_qs = models.Export.objects.all()
    exports = list()
    for e in export_qs:
        exports.append((e.slug, u'%s' % e,))

    timerange = get_timerange()

    class ExportChoiceForm(forms.Form):
        export_slug = forms.ChoiceField(choices=exports)
        range_from = forms.ChoiceField(choices=timerange)
        range_to = forms.ChoiceField(choices=timerange)
    log.debug('Form generated')
    return ExportChoiceForm

def get_timelined_items(slug, range_from, range_to, step=TIMELINE_STEP):
    itemizer = ExportItemizer(slug=slug)
    itemizer.datetime_from = range_from
    datetime_to = datetime.strptime(range_to, DATETIME_FORMAT)
    out = list()
    while itemizer.datetime_from <= datetime_to:
        column = list()
        column.append(itemizer.datetime_from.strftime(DATETIME_FORMAT))<commit_msg>Constants renamed to named constants.<commit_after>from datetime import datetime, timedelta
import logging
from urllib import urlencode

from django.conf.urls.defaults import patterns, url
from django.utils.translation import ugettext_lazy as _
from django.forms import models as modelforms
from django import forms
from django.forms.fields import DateTimeField, IntegerField, HiddenInput
from django.core import signals as core_signals
from django.conf import settings
from django.http import HttpResponse
from django.shortcuts import render_to_response

from ella.exports import models
from ella.exports.managers import ExportItemizer
from ella.utils import remove_diacritical
from ella.newman import utils

DATETIME_FORMAT = models.DATETIME_FORMAT
TIME_FORMAT = models.TIME_FORMAT
TIMELINE_STEP = timedelta(hours=2)  # two hours
EMPTY_TIMELINE_CELL = None
DAY_MAX_HOUR = 23
RANGE_DAYS = 14
RANGE_WIDTH_HOURS = 2
log = logging.getLogger('ella.exports')

def get_timerange(year=datetime.now().year, month=datetime.now().month, day=datetime.now().day):
    now = datetime.now()
    out = list()
    for d in range(-RANGE_DAYS, RANGE_DAYS):
        dt = timedelta(days=d)
        for h in [h for h in range(DAY_MAX_HOUR) if h % RANGE_WIDTH_HOURS == 0]:
            t = datetime(year, month, day, h, 0) + dt
            str_t = t.strftime(DATETIME_FORMAT)
            out.append( (str_t, str_t) )
    return out

def get_export_choice_form():
    export_qs = models.Export.objects.all()
    exports = list()
    for e in export_qs:
        exports.append((e.slug, u'%s' % e,))

    timerange = get_timerange()

    class ExportChoiceForm(forms.Form):
        export_slug = forms.ChoiceField(choices=exports)
        range_from = forms.ChoiceField(choices=timerange)
        range_to = forms.ChoiceField(choices=timerange)
    log.debug('Form generated')
    return ExportChoiceForm

def get_timelined_items(slug, range_from, range_to, step=TIMELINE_STEP):
    itemizer = ExportItemizer(slug=slug)
    itemizer.datetime_from = range_from
    datetime_to = datetime.strptime(range_to, DATETIME_FORMAT)
    out = list()
    while itemizer.datetime_from <= datetime_to:
        column = list()
        column.append(itemizer.datetime_from.strftime(DATETIME_FORMAT))
{'fraction_non_alphanumeric': 0.08735213830755233, 'fraction_numerical': 0.004094631483166515, 'mean_word_length': 4.15474794841735, 'pattern_counts': {'":': 0, '<': 5, '<?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': '2325572', 'n_tokens_mistral': 1388, 'n_tokens_neox': 1358, 'n_words': 351}