<commit_before>from django.db import models
from django.conf import settings
from django.db.models.signals import post_save
from django.shortcuts import get_object_or_404

from ..professors.models import Professor


class Comment(models.Model):
    created_by = models.ForeignKey(settings.AUTH_USER_MODEL)
    professor = models.ForeignKey(Professor)

    body = models.TextField()
    created_at = models.DateField(auto_now=False, auto_now_add=False)
    is_anonymous = models.BooleanField()

    responsibility = models.IntegerField(null=True)
    personality = models.IntegerField(null=True)
    workload = models.IntegerField(null=True)
    difficulty = models.IntegerField(null=True)

    def __unicode__(self):
        return self.created_at


def recalculate_score(sender, **kwargs):
    c = kwargs['instance']

    if c.responsibility and c.personality and c.workload and c.difficulty:
        comments = Comment.objects.filter(
            professor=c.professor.id,
            responsibility__isnull=False,
            personality__isnull=False,
            workload__isnull=False,
            difficulty__isnull=False).exclude(responsibility=0, personality=0,
                                              workload=0, difficulty=0)

        comments_count = 0
        sum_responsibility = 0
        sum_personality = 0
        sum_workload = 0
        sum_difficulty = 0

        for c in comments:
            sum_responsibility += c.responsibility
            sum_personality += c.personality
            sum_workload += c.workload<commit_msg>fixed error with comment<commit_after>from django.db import models
from django.conf import settings
from django.db.models.signals import post_save
from django.shortcuts import get_object_or_404

from ..professors.models import Professor


class Comment(models.Model):
    created_by = models.ForeignKey(settings.AUTH_USER_MODEL)
    professor = models.ForeignKey(Professor)

    body = models.TextField()
    created_at = models.DateField(auto_now=False, auto_now_add=False)
    is_anonymous = models.BooleanField()

    responsibility = models.IntegerField(null=True)
    personality = models.IntegerField(null=True)
    workload = models.IntegerField(null=True)
    difficulty = models.IntegerField(null=True)

    def __unicode__(self):
        return self.body


def recalculate_score(sender, **kwargs):
    c = kwargs['instance']

    if c.responsibility and c.personality and c.workload and c.difficulty:
        comments = Comment.objects.filter(
            professor=c.professor.id,
            responsibility__isnull=False,
            personality__isnull=False,
            workload__isnull=False,
            difficulty__isnull=False).exclude(responsibility=0, personality=0,
                                              workload=0, difficulty=0)

        comments_count = 0
        sum_responsibility = 0
        sum_personality = 0
        sum_workload = 0
        sum_difficulty = 0

        for c in comments:
            sum_responsibility += c.responsibility
            sum_personality += c.personality
            sum_workload += c.workload
{'fraction_non_alphanumeric': 0.07763875521334616, 'fraction_numerical': 0.007699711260827719, 'mean_word_length': 2.8399014778325125, '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': '3917895', 'n_tokens_mistral': 884, 'n_tokens_neox': 849, 'n_words': 178}