<commit_before>from django.db import models

# Create your models here.<commit_msg>Added calibration history/calibration record model to store calibration data<commit_after>from django.db import models

CHARFIELD_LEN_SMALL = 128
class CalibrationHistory(models.Model):
    student_id=models.CharField(max_length=CHARFIELD_LEN_SMALL)

    #Have problem_id and location in order to allow for one to be user_defined, and one system defined
    #This allows for the same problem to be used across classes without re-calibration if needed.
    #Currently use location instead of problem_id
    problem_id=models.CharField(max_length=CHARFIELD_LEN_SMALL)
    location=models.CharField(max_length=CHARFIELD_LEN_SMALL)

    def __unicode__(self):
        history_row=("Calibration history for student {0} on problem {1} at location {2}").format(
            self.student_id,self.problem_id,self.location)
        return history_row

    def get_all_calibration_records(self):
        return self.calibrationrecord_set.all()

    def get_calibration_record_count(self):
        return self.get_all_calibration_records().count()

    def get_average_calibration_error(self):
        all_records=list(self.get_all_calibration_records())
        errors=[abs(all_records[i].actual_score-all_records[i].score) for i in xrange(0,len(all_records))]
        total_error=0
        for i in xrange(0,len(errors)):
            total_error+=errors[i]
        average_error=total_error/float(len(errors))
        return average_error

class CalibrationRecord(models.Model):
    calibration_history=models.ForeignKey("CalibrationHistory")
    score=models.IntegerField()
    actual_score=models.IntegerField()

    #This tracks whether the record was created from a calibration essay prior to the student starting grading,
    #Or from a calibration essay inserted into the peer grading
    is_pre_calibration=models.BooleanField(default=True)
{'fraction_non_alphanumeric': 0.075, 'fraction_numerical': 0.0046875, 'mean_word_length': 4.568115942028985, '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': '7211556', 'n_tokens_mistral': 553, 'n_tokens_neox': 533, 'n_words': 138}