<commit_before>from __future__ import division
import csv

from django.core.management.base import BaseCommand, CommandError
from django.core.exceptions import ObjectDoesNotExist
from core.models import Subject, SubjectStats, DivisionSet, init_division_sets

class Command(BaseCommand):
    help = "Computes statistics for subjects and division sets"

    def handle(self, *args, **options):
        compute_div_stats(options['verbosity'])

def compute_div_stats(verbosity):
    """Computes statistics for all Subject, DivisionSet pairs.
    Verbosity ranges from
        0: no output to console
        1: prints division set and subject once completed
    """
    if DivisionSet.objects.count == 0:
        init_division_sets()
    for subject in Subject.objects.all():
        for division_set in DivisionSet.objects.all():
            stats = SubjectStats.objects.get_or_create(subject=subject,
                                                       division_set=division_set)[0]
            stats.compute()
            stats.save()
            if verbosity >= 1:
                print "compute_div_stats: processed subject {0} with division set {1}".\
                      format(subject, division_set)<commit_msg>ugh typo<commit_after>from __future__ import division
import csv

from django.core.management.base import BaseCommand, CommandError
from django.core.exceptions import ObjectDoesNotExist
from core.models import Subject, SubjectStats, DivisionSet, init_division_sets

class Command(BaseCommand):
    help = "Computes statistics for subjects and division sets"

    def handle(self, *args, **options):
        compute_div_stats(options['verbosity'])

def compute_div_stats(verbosity):
    """Computes statistics for all Subject, DivisionSet pairs.
    Verbosity ranges from
        0: no output to console
        1: prints division set and subject once completed
    """
    if DivisionSet.objects.count() == 0:
        init_division_sets()
    for subject in Subject.objects.all():
        for division_set in DivisionSet.objects.all():
            stats = SubjectStats.objects.get_or_create(subject=subject,
                                                       division_set=division_set)[0]
            stats.compute()
            stats.save()
            if verbosity >= 1:
                print "compute_div_stats: processed subject {0} with division set {1}".\
                      format(subject, division_set)
{'fraction_non_alphanumeric': 0.07796471070988921, 'fraction_numerical': 0.005744768157570784, 'mean_word_length': 2.693939393939394, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '1886962', 'n_tokens_mistral': 616, 'n_tokens_neox': 596, 'n_words': 186}