Fixes #3314, #3331: Various minor fixes.
[edumed.git] / wtem / models.py
index 4038485..4c3d0ee 100644 (file)
@@ -27,6 +27,7 @@ class Submission(models.Model):
     key_sent = models.BooleanField(default = False)
     marks = JSONField()
     examiners = models.ManyToManyField(User, null = True, blank = True)
+    end_time = models.CharField(max_length = 5, null = True, blank = True)
 
     def __unicode__(self):
         return ', '.join((self.last_name, self.first_name, self.email))
@@ -83,7 +84,7 @@ class Submission(models.Model):
         if exercise_checked_manually(exercise):
             marks_by_examiner = self.get_exercise_marks_by_examiner(exercise_id)
             if len(marks_by_examiner):
-                return max(map(int, marks_by_examiner.values()))
+                return sum(map(int, marks_by_examiner.values())) / float(len(marks_by_examiner))
             else:
                 return None
         else:
@@ -97,7 +98,12 @@ class Submission(models.Model):
                 toret = 0
                 for bucket_id, items in answer.items():
                     for item_id in items:
-                        if int(item_id) in exercise['answer'].get(bucket_id, []):
+                        is_corect = False
+                        if exercise.get('answer_mode', None) == 'possible_buckets_for_item':
+                            is_correct = int(bucket_id) in exercise['answer'].get(item_id)
+                        else:
+                            is_correct = int(item_id) in exercise['answer'].get(bucket_id, [])
+                        if is_correct:
                             toret += exercise['points_per_hit']
                 return toret
             if t == 'edumed_wybor':
@@ -108,9 +114,12 @@ class Submission(models.Model):
                         return 0
                 else:
                     toret = 0
-                    for id in map(int, answer):
-                        if id in exercise['answer']:
-                            toret += exercise['points_per_hit']
+                    if exercise.get('answer_mode', None) == 'all_or_nothing':
+                        toret = exercise['points'] if map(int, answer) == exercise['answer'] else 0
+                    else:
+                        for id in map(int, answer):
+                            if id in exercise['answer']:
+                                toret += exercise['points_per_hit']
                     return toret
             if t == 'edumed_prawdafalsz':
                 toret = 0