1
0
mirror of https://gitlab.com/animath/si/plateforme.git synced 2024-12-25 05:02:23 +00:00

Jurys can note passages

This commit is contained in:
Yohann D'ANELLO 2021-01-14 17:54:47 +01:00
parent c8780a6d9d
commit be8904079d
Signed by: ynerant
GPG Key ID: 3A75C55819C8CF85
2 changed files with 138 additions and 0 deletions

View File

@ -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',
},
),
]

View File

@ -311,6 +311,9 @@ class Pool(models.Model):
def solutions(self): def solutions(self):
return Solution.objects.filter(participation__in=self.participations, final_solution=self.tournament.final) 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): def get_absolute_url(self):
return reverse_lazy("participation:pool_detail", args=(self.pk,)) return reverse_lazy("participation:pool_detail", args=(self.pk,))
@ -375,6 +378,49 @@ class Passage(models.Model):
problem=self.solution_number, problem=self.solution_number,
final_solution=self.pool.tournament.final) 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): def get_absolute_url(self):
return reverse_lazy("participation:passage_detail", args=(self.pk,)) return reverse_lazy("participation:passage_detail", args=(self.pk,))
@ -482,3 +528,62 @@ class Synthesis(models.Model):
verbose_name = _("synthesis") verbose_name = _("synthesis")
verbose_name_plural = _("syntheses") verbose_name_plural = _("syntheses")
unique_together = (('participation', 'passage', 'type', ), ) 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")