<commit_before>from django.db import models
from detectors.models import Detector


class Performance(models.Model):
    """
    Stores performance metrics for the detector.
    Calculated outside with a test set.
    """
    created_at = models.DateTimeField(auto_now=True)
    detector = models.ForeignKey(Detector)
    average_precision = models.FloatField()
    precision = models.TextField(blank=True, null=True)
    recall = models.TextField(blank=True, null=True)
    test_set = models.TextField(blank=True, null=True)

    def save(self, *args, **kwargs):
        # creates the UserScore entry
        super(Performance, self).save(*args, **kwargs)
        name = self.detector.name
        try:
            category = Category.object.get(name=name.split("_")[0])
        except Category.DoesNotExist:
            category = Category.object.get(name="NA")
        user_score = UserScore(user=self.detector.author, category=category)
        user_score.save()
    
    def __unicode__(self):
        return u'Performance of %s - %s by %s is %s' % (self.detector.name,
                                                        self.detector.pk,
                                                        self.detector.author.username,
                                                        self.average_precision)
<commit_msg>solved bug with objects<commit_after>from django.db import models
from detectors.models import Detector


class Performance(models.Model):
    """
    Stores performance metrics for the detector.
    Calculated outside with a test set.
    """
    created_at = models.DateTimeField(auto_now=True)
    detector = models.ForeignKey(Detector)
    average_precision = models.FloatField()
    precision = models.TextField(blank=True, null=True)
    recall = models.TextField(blank=True, null=True)
    test_set = models.TextField(blank=True, null=True)

    def save(self, *args, **kwargs):
        # creates the UserScore entry
        super(Performance, self).save(*args, **kwargs)
        name = self.detector.name
        try:
            category = Category.objects.get(name=name.split("_")[0])
        except Category.DoesNotExist:
            category = Category.objects.get(name="NA")
        user_score = UserScore(user=self.detector.author, category=category)
        user_score.save()
    
    def __unicode__(self):
        return u'Performance of %s - %s by %s is %s' % (self.detector.name,
                                                        self.detector.pk,
                                                        self.detector.author.username,
                                                        self.average_precision)

{'fraction_non_alphanumeric': 0.09895052473763119, 'fraction_numerical': 0.0007496251874062968, 'mean_word_length': 2.053775743707094, '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': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '497655', 'n_tokens_mistral': 697, 'n_tokens_neox': 680, 'n_words': 155}