<commit_before># This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
from __future__ import absolute_import

from django.db import models

import datetime


class DatedManager(models.Manager):
    def for_date(self, date):
        return (self.filter(models.Q(start__lte=date) |
                            models.Q(start__isnull=True))
                .filter(models.Q(end__gt=date) |
                        models.Q(end__isnull=True)))

    def current(self):
        return self.for_date(datetime.datetime.utcnow())


class DurationThrough(models.Model):
    start = models.DateTimeField(default=datetime.datetime.utcnow,
                                 blank=True,
                                 null=True)
    end = models.DateTimeField(blank=True, null=True)
    objects = DatedManager()
    unique = ('start', 'end')

    class Meta:
        abstract = True

    class DurationMeta:
        get_latest_by = 'start'
        ordering = ['-start', '-end']<commit_msg>Custom query set for dated queries.<commit_after># This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
from __future__ import absolute_import

from django.db import models

import datetime


class DatedQuerySet(models.QuerySet):
    def for_date(self, date):
        return (self.filter(models.Q(start__lte=date) |
                            models.Q(start__isnull=True))
                .filter(models.Q(end__gt=date) |
                        models.Q(end__isnull=True)))

    def current(self):
        return self.for_date(datetime.datetime.utcnow())


class DurationThrough(models.Model):
    start = models.DateTimeField(default=datetime.datetime.utcnow,
                                 blank=True,
                                 null=True)
    end = models.DateTimeField(blank=True, null=True)
    objects = DatedQuerySet.as_manager()
    unique = ('start', 'end')

    class Meta:
        abstract = True

    class DurationMeta:
        get_latest_by = 'start'
        ordering = ['-start', '-end']
{'fraction_non_alphanumeric': 0.10105448154657294, 'fraction_numerical': 0.0035149384885764497, 'mean_word_length': 2.3289473684210527, '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': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6171419', 'n_tokens_mistral': 661, 'n_tokens_neox': 634, 'n_words': 172}