diff --git a/apps/participation/migrations/0011_note.py b/apps/participation/migrations/0011_note.py new file mode 100644 index 0000000..74d308a --- /dev/null +++ b/apps/participation/migrations/0011_note.py @@ -0,0 +1,33 @@ +# Generated by Django 3.0.11 on 2021-01-14 16:59 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('registration', '0001_initial'), + ('participation', '0010_passage_solution_number'), + ] + + operations = [ + migrations.CreateModel( + name='Note', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('defender_writing', models.PositiveSmallIntegerField(choices=[(0, 0), (1, 1), (2, 2), (3, 3), (4, 4), (5, 5), (6, 6), (7, 7), (8, 8), (9, 9), (10, 10), (11, 11), (12, 12), (13, 13), (14, 14), (15, 15), (16, 16), (17, 17), (18, 18), (19, 19), (20, 20)], default=0, verbose_name='defender writing note')), + ('defender_oral', models.PositiveSmallIntegerField(choices=[(0, 0), (1, 1), (2, 2), (3, 3), (4, 4), (5, 5), (6, 6), (7, 7), (8, 8), (9, 9), (10, 10), (11, 11), (12, 12), (13, 13), (14, 14), (15, 15), (16, 16)], default=0, verbose_name='defender oral note')), + ('opponent_writing', models.PositiveSmallIntegerField(choices=[(0, 0), (1, 1), (2, 2), (3, 3), (4, 4), (5, 5), (6, 6), (7, 7), (8, 8), (9, 9)], default=0, verbose_name='opponent writing note')), + ('opponent_oral', models.PositiveSmallIntegerField(choices=[(0, 0), (1, 1), (2, 2), (3, 3), (4, 4), (5, 5), (6, 6), (7, 7), (8, 8), (9, 9), (10, 10)], default=0, verbose_name='opponent oral note')), + ('reporter_writing', models.PositiveSmallIntegerField(choices=[(0, 0), (1, 1), (2, 2), (3, 3), (4, 4), (5, 5), (6, 6), (7, 7), (8, 8), (9, 9)], default=0, verbose_name='reporter writing note')), + ('reporter_oral', models.PositiveSmallIntegerField(choices=[(0, 0), (1, 1), (2, 2), (3, 3), (4, 4), (5, 5), (6, 6), (7, 7), (8, 8), (9, 9), (10, 10)], default=0, verbose_name='reporter oral note')), + ('jury', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='notes', to='registration.VolunteerRegistration', verbose_name='jury')), + ('passage', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='notes', to='participation.Passage', verbose_name='passage')), + ], + options={ + 'verbose_name': 'note', + 'verbose_name_plural': 'notes', + }, + ), + ] diff --git a/apps/participation/models.py b/apps/participation/models.py index 8635651..6b18e1a 100644 --- a/apps/participation/models.py +++ b/apps/participation/models.py @@ -311,6 +311,9 @@ class Pool(models.Model): def solutions(self): return Solution.objects.filter(participation__in=self.participations, final_solution=self.tournament.final) + def average(self, participation): + return sum(passage.average(participation) for passage in self.passages.all()) + def get_absolute_url(self): return reverse_lazy("participation:pool_detail", args=(self.pk,)) @@ -375,6 +378,49 @@ class Passage(models.Model): problem=self.solution_number, final_solution=self.pool.tournament.final) + def avg(self, iterator) -> int: + return sum(iterator) / len(list(iterator)) + + @property + def average_defender_writing(self): + return self.avg(note.defender_writing for note in self.notes.all()) + + @property + def average_defender_oral(self): + return self.avg(note.defender_oral for note in self.notes.all()) + + @property + def average_defender(self): + return 2 * self.average_defender_writing + self.average_defender_oral + + @property + def average_opponent_writing(self): + return self.avg(note.opponent_writing for note in self.notes.all()) + + @property + def average_opponent_oral(self): + return self.avg(note.opponent_oral for note in self.notes.all()) + + @property + def average_opponent(self): + return 2 * self.average_opponent_writing + self.average_opponent_oral + + @property + def average_reporter_writing(self): + return self.avg(note.reporter_writing for note in self.notes.all()) + + @property + def average_reporter_oral(self): + return self.avg(note.reporter_oral for note in self.notes.all()) + + @property + def average_reporter(self): + return self.average_reporter_writing + self.average_reporter_oral + + def average(self, participation): + return self.average_defender if participation == self.defender else self.average_opponent \ + if participation == self.opponent else self.average_reporter if participation == self.reporter else 0 + def get_absolute_url(self): return reverse_lazy("participation:passage_detail", args=(self.pk,)) @@ -482,3 +528,62 @@ class Synthesis(models.Model): verbose_name = _("synthesis") verbose_name_plural = _("syntheses") unique_together = (('participation', 'passage', 'type', ), ) + + +class Note(models.Model): + jury = models.ForeignKey( + VolunteerRegistration, + on_delete=models.CASCADE, + verbose_name=_("jury"), + related_name="notes", + ) + + passage = models.ForeignKey( + Passage, + on_delete=models.CASCADE, + verbose_name=_("passage"), + related_name="notes", + ) + + defender_writing = models.PositiveSmallIntegerField( + verbose_name=_("defender writing note"), + choices=[(i, i) for i in range(0, 21)], + default=0, + ) + + defender_oral = models.PositiveSmallIntegerField( + verbose_name=_("defender oral note"), + choices=[(i, i) for i in range(0, 17)], + default=0, + ) + + opponent_writing = models.PositiveSmallIntegerField( + verbose_name=_("opponent writing note"), + choices=[(i, i) for i in range(0, 10)], + default=0, + ) + + opponent_oral = models.PositiveSmallIntegerField( + verbose_name=_("opponent oral note"), + choices=[(i, i) for i in range(0, 11)], + default=0, + ) + + reporter_writing = models.PositiveSmallIntegerField( + verbose_name=_("reporter writing note"), + choices=[(i, i) for i in range(0, 10)], + default=0, + ) + + reporter_oral = models.PositiveSmallIntegerField( + verbose_name=_("reporter oral note"), + choices=[(i, i) for i in range(0, 11)], + default=0, + ) + + def __str__(self): + return _("Notes of {jury} for {passage}").format(jury=self.jury, passage=self.passage) + + class Meta: + verbose_name = _("note") + verbose_name_plural = _("notes")