<commit_before>from django.contrib.auth.decorators import login_required
from django.shortcuts import render_to_response, get_object_or_404
from django.http import HttpResponseRedirect, HttpResponseForbidden, \
        HttpResponseBadRequest
from django.core.urlresolvers import reverse
from django.template import RequestContext
from django.utils.translation import ugettext as _

from devilry.core.models import AssignmentGroup


@login_required
def userstats(request):
    #period = get_object_or_404(Period, pk=subject_id)
    #if not subject.can_save(request.user):
        #return HttpResponseForbidden("Forbidden")
    from devilry.core.gradeplugin import registry

    def iter():
        assignment_groups = AssignmentGroup.active_where_is_candidate(
                request.user)
        assignment_groups = assignment_groups.order_by(
                "parentnode__parentnode", "parentnode__grade_plugin")
        current_period = None
        plugins = None
        for group in assignment_groups:
            if current_period == None \
                    or current_period.id != group.parentnode.parentnode.id:
                if current_period != None:
                    yield current_period, plugins
                current_period = group.parentnode.parentnode
                current_gradeplugin = None
                plugins = []
            if current_gradeplugin != group.parentnode.grade_plugin:
                current_gradeplugin = group.parentnode.grade_plugin
                ri = registry.getitem(current_gradeplugin)
                final_grade = ri.model_cls.calc_final_grade(current_period,
                        current_gradeplugin, request.user)
                plugins.append((ri, final_grade, []))
            d = group.get_latest_delivery_with_published_feedback()

            value = None
            if d:
                value = d.feedback.get_grade_as_short_string()
            else:
                value = group.get_localized_status()
            plugins[-1][2].append((group, value))
        yield current_period, plugins

    return render_to_response(
        'devilry/gradestats/user.django.html', {
            'periods': iter(),
        }, context_instance=RequestContext(request))
<commit_msg>Minimal changes to gradestats.<commit_after>from django.contrib.auth.decorators import login_required
from django.shortcuts import render_to_response, get_object_or_404
from django.http import HttpResponseRedirect, HttpResponseForbidden, \
        HttpResponseBadRequest
from django.core.urlresolvers import reverse
from django.template import RequestContext
from django.utils.translation import ugettext as _

from devilry.core.models import AssignmentGroup, Period
from devilry.core.gradeplugin import registry


@login_required
def userstats(request):
    #period = get_object_or_404(Period, pk=subject_id)
    #if not subject.can_save(request.user):
        #return HttpResponseForbidden("Forbidden")

    def iter():
        assignment_groups = AssignmentGroup.active_where_is_candidate(
                request.user)
        assignment_groups = assignment_groups.order_by(
                "parentnode__parentnode", "parentnode__grade_plugin")
        current_period = None
        plugins = None
        for group in assignment_groups:
            if current_period == None \
                    or current_period.id != group.parentnode.parentnode.id:
                if current_period != None:
                    yield current_period, plugins
                current_period = group.parentnode.parentnode
                current_gradeplugin = None
                plugins = []
            if current_gradeplugin != group.parentnode.grade_plugin:
                current_gradeplugin = group.parentnode.grade_plugin
                ri = registry.getitem(current_gradeplugin)
                final_grade = ri.model_cls.calc_final_grade(current_period,
                        current_gradeplugin, request.user)
                plugins.append((ri, final_grade, []))
            d = group.get_latest_delivery_with_published_feedback()

            value = None
            if d:
                value = d.feedback.get_grade_as_short_string()
            else:
                value = group.get_localized_status()
            plugins[-1][2].append((group, value))
        yield current_period, plugins

    return render_to_response(
        'devilry/gradestats/user.django.html', {
            'periods': iter(),
        }, context_instance=RequestContext(request))


def adminstats(request, period_id):
    period = get_object_or_404(Period, id=period_id)
    for assignment in period.assignments.all():
        for group in assignment.assignment_groups.all():
            delivery = group.get_latest_delivery_with_published_feedback()
            if delivery:
                value = delivery.feedback.get_grade_as_short_string()
            else:
                value = group.get_localized_status()

{'fraction_non_alphanumeric': 0.07229402261712439, 'fraction_numerical': 0.003836833602584814, 'mean_word_length': 2.5003533568904595, '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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5880498', 'n_tokens_mistral': 1310, 'n_tokens_neox': 1259, 'n_words': 259}