<commit_before>"""Views for remotes app."""
import logging

from braces.views import GroupRequiredMixin

from django.db.models.aggregates import Count
from django.db.models.functions.datetime import TruncDate
from django.views.generic import ListView

from .models import Source

logger = logging.getLogger(__name__)


class SourceListView(GroupRequiredMixin, ListView):
    """List all Sources."""

    model = Source
    group_required = u'Debuggers'
    template_name = "remotes/source_list.html"

    def _get_harvest_history(self):
        """Get a history of harvests executed."""
        harvest_table = []
        code_position = {}
        header = [(0, 'Harvest Date')]

        all_sources = Source.objects.all().values_list('code', 'name').order_by('name')
        for position, (code, name) in enumerate(all_sources, 1):
            code_position[code] = position
            header.append((position, name))

        history = Source.objects.all().values('code', harvest_date=TruncDate('posts__created')).annotate(post_count=Count('posts')).order_by('-harvest_date')
        current_date = None
        this_row = header
        for row in history:
            logger.info("Processing source history row: %s", row)
            if row['harvest_date'] != current_date:
                if len(this_row) < len(code_position) + 1:<commit_msg>order by date asc<commit_after>"""Views for remotes app."""
import logging

from braces.views import GroupRequiredMixin

from django.db.models.aggregates import Count
from django.db.models.functions.datetime import TruncDate
from django.views.generic import ListView

from .models import Source

logger = logging.getLogger(__name__)


class SourceListView(GroupRequiredMixin, ListView):
    """List all Sources."""

    model = Source
    group_required = u'Debuggers'
    template_name = "remotes/source_list.html"

    def _get_harvest_history(self):
        """Get a history of harvests executed."""
        harvest_table = []
        code_position = {}
        header = [(0, 'Harvest Date')]

        all_sources = Source.objects.all().values_list('code', 'name').order_by('name')
        for position, (code, name) in enumerate(all_sources, 1):
            code_position[code] = position
            header.append((position, name))

        history = Source.objects.all().values('code', harvest_date=TruncDate('posts__created')).annotate(post_count=Count('posts')).order_by('harvest_date')
        current_date = None
        this_row = header
        for row in history:
            logger.info("Processing source history row: %s", row)
            if row['harvest_date'] != current_date:
                if len(this_row) < len(code_position) + 1:
{'fraction_non_alphanumeric': 0.11727709951905291, 'fraction_numerical': 0.0022197558268590455, 'mean_word_length': 3.3264, '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': '3691379', 'n_tokens_mistral': 779, 'n_tokens_neox': 756, 'n_words': 186}