2020-12-27 10:49:54 +00:00
|
|
|
# Copyright (C) 2020 by Animath
|
|
|
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
2024-06-07 22:19:33 +00:00
|
|
|
|
2024-03-30 21:23:34 +00:00
|
|
|
from datetime import date, timedelta
|
2024-06-07 22:19:33 +00:00
|
|
|
import math
|
2020-12-27 10:49:54 +00:00
|
|
|
import os
|
|
|
|
|
2021-01-12 17:02:00 +00:00
|
|
|
from django.conf import settings
|
2021-01-14 13:22:45 +00:00
|
|
|
from django.core.exceptions import ValidationError
|
2023-04-06 22:05:56 +00:00
|
|
|
from django.core.validators import MaxValueValidator, MinValueValidator, RegexValidator
|
2020-12-27 10:49:54 +00:00
|
|
|
from django.db import models
|
2024-03-26 20:18:03 +00:00
|
|
|
from django.db.models import Index
|
2020-12-27 10:49:54 +00:00
|
|
|
from django.urls import reverse_lazy
|
2024-04-18 12:53:58 +00:00
|
|
|
from django.utils import timezone, translation
|
2020-12-27 10:49:54 +00:00
|
|
|
from django.utils.crypto import get_random_string
|
2021-01-12 17:02:00 +00:00
|
|
|
from django.utils.text import format_lazy
|
2024-03-31 20:46:40 +00:00
|
|
|
from django.utils.timezone import localtime
|
2020-12-27 10:49:54 +00:00
|
|
|
from django.utils.translation import gettext_lazy as _
|
2024-03-30 12:41:46 +00:00
|
|
|
import gspread
|
|
|
|
from gspread.utils import a1_range_to_grid_range, MergeType
|
2024-02-12 21:30:27 +00:00
|
|
|
from registration.models import Payment, VolunteerRegistration
|
2020-12-28 18:19:01 +00:00
|
|
|
from tfjm.lists import get_sympa_client
|
2020-12-27 10:49:54 +00:00
|
|
|
|
2024-01-13 18:37:54 +00:00
|
|
|
|
2021-01-22 08:40:28 +00:00
|
|
|
def get_motivation_letter_filename(instance, filename):
|
|
|
|
return f"authorization/motivation_letters/motivation_letter_{instance.trigram}"
|
|
|
|
|
|
|
|
|
2020-12-27 10:49:54 +00:00
|
|
|
class Team(models.Model):
|
|
|
|
"""
|
2024-06-07 22:19:33 +00:00
|
|
|
The Team model represents a real team that participates to the tournament.
|
2020-12-27 10:49:54 +00:00
|
|
|
This only includes the registration detail.
|
|
|
|
"""
|
|
|
|
name = models.CharField(
|
|
|
|
max_length=255,
|
|
|
|
verbose_name=_("name"),
|
|
|
|
unique=True,
|
|
|
|
)
|
|
|
|
|
|
|
|
trigram = models.CharField(
|
2024-06-13 08:57:51 +00:00
|
|
|
max_length=4,
|
2024-06-07 12:18:25 +00:00
|
|
|
verbose_name=_("code"),
|
|
|
|
help_text=format_lazy(_("The code must be composed of {nb_letters} uppercase letters."),
|
|
|
|
nb_letters=settings.TEAM_CODE_LENGTH),
|
2020-12-27 10:49:54 +00:00
|
|
|
unique=True,
|
2023-02-19 18:49:03 +00:00
|
|
|
validators=[
|
2024-06-13 08:57:51 +00:00
|
|
|
RegexValidator("^[A-Z]{3}[A-Z]*$"),
|
2023-02-19 18:49:03 +00:00
|
|
|
RegexValidator(fr"^(?!{'|'.join(f'{t}$' for t in settings.FORBIDDEN_TRIGRAMS)})",
|
2024-06-07 12:52:09 +00:00
|
|
|
message=_("This team code is forbidden.")),
|
2023-02-19 18:49:03 +00:00
|
|
|
],
|
2020-12-27 10:49:54 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
access_code = models.CharField(
|
|
|
|
max_length=6,
|
|
|
|
verbose_name=_("access code"),
|
|
|
|
help_text=_("The access code let other people to join the team."),
|
|
|
|
)
|
|
|
|
|
2021-01-22 08:40:28 +00:00
|
|
|
motivation_letter = models.FileField(
|
|
|
|
verbose_name=_("motivation letter"),
|
|
|
|
upload_to=get_motivation_letter_filename,
|
|
|
|
blank=True,
|
|
|
|
default="",
|
|
|
|
)
|
|
|
|
|
2020-12-28 17:52:50 +00:00
|
|
|
@property
|
|
|
|
def students(self):
|
|
|
|
return self.participants.filter(studentregistration__isnull=False)
|
|
|
|
|
|
|
|
@property
|
2021-01-18 20:30:26 +00:00
|
|
|
def coaches(self):
|
2020-12-28 17:52:50 +00:00
|
|
|
return self.participants.filter(coachregistration__isnull=False)
|
|
|
|
|
2024-02-11 19:20:28 +00:00
|
|
|
def can_validate(self):
|
2024-02-11 21:24:22 +00:00
|
|
|
if any(not r.email_confirmed for r in self.participants.all()):
|
|
|
|
return False
|
2024-02-11 19:20:28 +00:00
|
|
|
if self.students.count() < 4:
|
|
|
|
return False
|
|
|
|
if not self.coaches.exists():
|
|
|
|
return False
|
|
|
|
if not self.participation.tournament:
|
|
|
|
return False
|
|
|
|
if any(not r.photo_authorization for r in self.participants.all()):
|
|
|
|
return False
|
2024-06-07 15:20:06 +00:00
|
|
|
if settings.MOTIVATION_LETTER_REQUIRED and not self.motivation_letter:
|
2024-02-11 19:20:28 +00:00
|
|
|
return False
|
|
|
|
if not self.participation.tournament.remote:
|
2024-06-07 15:20:06 +00:00
|
|
|
if settings.HEALTH_SHEET_REQUIRED and any(r.under_18 and not r.health_sheet for r in self.students.all()):
|
2024-02-11 19:20:28 +00:00
|
|
|
return False
|
2024-06-07 15:20:06 +00:00
|
|
|
if settings.VACCINE_SHEET_REQUIRED and any(r.under_18 and not r.vaccine_sheet for r in self.students.all()):
|
2024-02-11 19:20:28 +00:00
|
|
|
return False
|
|
|
|
if any(r.under_18 and not r.parental_authorization for r in self.students.all()):
|
|
|
|
return False
|
|
|
|
return True
|
|
|
|
|
|
|
|
def important_informations(self):
|
|
|
|
informations = []
|
|
|
|
|
|
|
|
if self.participation.valid is None:
|
|
|
|
if not self.participation.tournament:
|
2024-02-11 21:24:22 +00:00
|
|
|
text = _("The team {trigram} is not registered to any tournament. "
|
2024-02-11 19:20:28 +00:00
|
|
|
"You can register the team to a tournament using <a href='{url}'>this link</a>.")
|
|
|
|
url = reverse_lazy("participation:update_team", args=(self.pk,))
|
2024-02-11 21:24:22 +00:00
|
|
|
content = format_lazy(text, trigram=self.trigram, url=url)
|
2024-02-11 19:20:28 +00:00
|
|
|
informations.append({
|
|
|
|
'title': _("No tournament"),
|
|
|
|
'type': "danger",
|
|
|
|
'priority': 4,
|
|
|
|
'content': content,
|
|
|
|
})
|
2024-02-11 21:24:22 +00:00
|
|
|
else:
|
|
|
|
text = _("Registrations for the tournament of {tournament} are ending on the {date:%Y-%m-%d %H:%M}.")
|
|
|
|
content = format_lazy(text,
|
|
|
|
tournament=self.participation.tournament.name,
|
2024-03-31 20:46:40 +00:00
|
|
|
date=localtime(self.participation.tournament.inscription_limit))
|
2024-02-11 19:20:28 +00:00
|
|
|
informations.append({
|
2024-02-11 21:24:22 +00:00
|
|
|
'title': _("Registrations closure"),
|
|
|
|
'type': "info",
|
|
|
|
'priority': 1,
|
2024-02-11 19:20:28 +00:00
|
|
|
'content': content,
|
|
|
|
})
|
|
|
|
|
2024-06-07 15:20:06 +00:00
|
|
|
if settings.MOTIVATION_LETTER_REQUIRED and not self.motivation_letter:
|
2024-02-11 21:24:22 +00:00
|
|
|
text = _("The team {trigram} has not uploaded a motivation letter. "
|
|
|
|
"You can upload your motivation letter using <a href='{url}'>this link</a>.")
|
|
|
|
url = reverse_lazy("participation:upload_team_motivation_letter", args=(self.pk,))
|
|
|
|
content = format_lazy(text, trigram=self.trigram, url=url)
|
|
|
|
informations.append({
|
|
|
|
'title': _("No motivation letter"),
|
|
|
|
'type': "danger",
|
|
|
|
'priority': 10,
|
|
|
|
'content': content,
|
|
|
|
})
|
|
|
|
|
|
|
|
nb_students = self.students.count()
|
|
|
|
nb_coaches = self.coaches.count()
|
|
|
|
if nb_students < 4:
|
|
|
|
text = _("The team {trigram} has less than 4 students ({nb_students}). "
|
|
|
|
"You can invite more students to join the team using "
|
|
|
|
"the invite code <strong>{code}</strong>.")
|
|
|
|
content = format_lazy(text, trigram=self.trigram, nb_students=nb_students, code=self.access_code)
|
|
|
|
informations.append({
|
|
|
|
'title': _("Not enough students"),
|
|
|
|
'type': "warning",
|
|
|
|
'priority': 7,
|
|
|
|
'content': content,
|
|
|
|
})
|
|
|
|
|
|
|
|
if not nb_coaches:
|
|
|
|
text = _("The team {trigram} has no coach. "
|
|
|
|
"You can invite a coach to join the team using the invite code <strong>{code}</strong>.")
|
|
|
|
content = format_lazy(text, trigram=self.trigram, nb_students=nb_students, code=self.access_code)
|
|
|
|
informations.append({
|
|
|
|
'title': _("No coach"),
|
|
|
|
'type': "warning",
|
|
|
|
'priority': 8,
|
|
|
|
'content': content,
|
|
|
|
})
|
|
|
|
|
|
|
|
if nb_students > 6 or nb_coaches > 2:
|
|
|
|
text = _("The team {trigram} has more than 6 students ({nb_students}) "
|
|
|
|
"or more than 2 coaches ({nb_coaches})."
|
|
|
|
"You have to restrict the number of students and coaches to 6 and 2, respectively.")
|
|
|
|
content = format_lazy(text, trigram=self.trigram, nb_students=nb_students, nb_coaches=nb_coaches)
|
|
|
|
informations.append({
|
|
|
|
'title': _("Too many members"),
|
|
|
|
'type': "warning",
|
|
|
|
'priority': 7,
|
|
|
|
'content': content,
|
|
|
|
})
|
|
|
|
elif nb_students >= 4 and nb_coaches >= 1:
|
|
|
|
if self.can_validate():
|
|
|
|
text = _("The team {trigram} is ready to be validated. "
|
|
|
|
"You can request validation on <a href='{url}'>the page of your team</a>.")
|
|
|
|
url = reverse_lazy("participation:team_detail", args=(self.pk,))
|
|
|
|
content = format_lazy(text, trigram=self.trigram, url=url)
|
|
|
|
informations.append({
|
|
|
|
'title': _("Validate team"),
|
|
|
|
'type': "success",
|
|
|
|
'priority': 2,
|
|
|
|
'content': content,
|
|
|
|
})
|
|
|
|
else:
|
|
|
|
text = _("The team {trigram} has enough participants, but is not ready to be validated. "
|
|
|
|
"Please make sure that all the participants have uploaded the required documents. "
|
|
|
|
"To invite more participants, use the invite code <strong>{code}</strong>.")
|
|
|
|
content = format_lazy(text, trigram=self.trigram, code=self.access_code)
|
|
|
|
informations.append({
|
|
|
|
'title': _("Validate team"),
|
|
|
|
'type': "warning",
|
|
|
|
'priority': 10,
|
|
|
|
'content': content,
|
|
|
|
})
|
|
|
|
elif self.participation.valid is False:
|
|
|
|
text = _("The team {trigram} has not been validated by the organizers yet. Please be patient.")
|
|
|
|
content = format_lazy(text, trigram=self.trigram)
|
|
|
|
informations.append({
|
|
|
|
'title': _("Pending validation"),
|
|
|
|
'type': "warning",
|
|
|
|
'priority': 2,
|
|
|
|
'content': content,
|
|
|
|
})
|
2024-02-11 22:31:24 +00:00
|
|
|
else:
|
|
|
|
informations.extend(self.participation.important_informations())
|
2024-02-11 19:20:28 +00:00
|
|
|
|
|
|
|
return informations
|
|
|
|
|
2020-12-27 10:49:54 +00:00
|
|
|
@property
|
|
|
|
def email(self):
|
|
|
|
"""
|
|
|
|
:return: The mailing list to contact the team members.
|
|
|
|
"""
|
|
|
|
return f"equipe-{self.trigram.lower()}@{os.getenv('SYMPA_HOST', 'localhost')}"
|
|
|
|
|
|
|
|
def create_mailing_list(self):
|
|
|
|
"""
|
|
|
|
Create a new Sympa mailing list to contact the team.
|
|
|
|
"""
|
|
|
|
get_sympa_client().create_list(
|
|
|
|
f"equipe-{self.trigram.lower()}",
|
2021-01-16 21:29:10 +00:00
|
|
|
f"Equipe {self.name} ({self.trigram})",
|
2020-12-27 10:49:54 +00:00
|
|
|
"hotline", # TODO Use a custom sympa template
|
2021-01-16 21:29:10 +00:00
|
|
|
f"Liste de diffusion pour contacter l'equipe {self.name} du TFJM2",
|
2020-12-27 10:49:54 +00:00
|
|
|
"education",
|
|
|
|
raise_error=False,
|
|
|
|
)
|
|
|
|
|
|
|
|
def delete_mailing_list(self):
|
|
|
|
"""
|
|
|
|
Drop the Sympa mailing list, if the team is empty or if the trigram changed.
|
|
|
|
"""
|
|
|
|
if self.participation.valid: # pragma: no cover
|
2021-01-16 21:29:10 +00:00
|
|
|
get_sympa_client().unsubscribe(
|
|
|
|
self.email, f"equipes-{self.participation.tournament.name.lower().replace(' ', '-')}", False)
|
2020-12-27 10:49:54 +00:00
|
|
|
else:
|
|
|
|
get_sympa_client().unsubscribe(self.email, "equipes-non-valides", False)
|
|
|
|
get_sympa_client().delete_list(f"equipe-{self.trigram}")
|
|
|
|
|
2024-06-13 08:57:51 +00:00
|
|
|
def clean(self):
|
2024-06-13 09:03:10 +00:00
|
|
|
if self.trigram and len(self.trigram) != settings.TEAM_CODE_LENGTH:
|
2024-06-13 08:57:51 +00:00
|
|
|
raise ValidationError({'trigram': _("The team code must be composed of {nb_letters} uppercase letters.")},
|
|
|
|
params={'nb_letters': settings.TEAM_CODE_LENGTH})
|
|
|
|
return super().clean()
|
|
|
|
|
2020-12-27 10:49:54 +00:00
|
|
|
def save(self, *args, **kwargs):
|
|
|
|
if not self.access_code:
|
|
|
|
# if the team got created, generate the access code, create the contact mailing list
|
|
|
|
self.access_code = get_random_string(6)
|
2024-06-07 14:35:08 +00:00
|
|
|
if settings.ML_MANAGEMENT:
|
|
|
|
self.create_mailing_list()
|
2020-12-27 10:49:54 +00:00
|
|
|
|
|
|
|
return super().save(*args, **kwargs)
|
|
|
|
|
|
|
|
def get_absolute_url(self):
|
|
|
|
return reverse_lazy("participation:team_detail", args=(self.pk,))
|
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return _("Team {name} ({trigram})").format(name=self.name, trigram=self.trigram)
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
verbose_name = _("team")
|
|
|
|
verbose_name_plural = _("teams")
|
2023-04-03 17:13:15 +00:00
|
|
|
ordering = ('trigram',)
|
2020-12-27 10:49:54 +00:00
|
|
|
indexes = [
|
|
|
|
Index(fields=("trigram", )),
|
|
|
|
]
|
|
|
|
|
|
|
|
|
2020-12-28 12:47:05 +00:00
|
|
|
class Tournament(models.Model):
|
|
|
|
name = models.CharField(
|
|
|
|
max_length=255,
|
|
|
|
verbose_name=_("name"),
|
|
|
|
unique=True,
|
|
|
|
)
|
|
|
|
|
|
|
|
date_start = models.DateField(
|
|
|
|
verbose_name=_("start"),
|
2021-01-18 21:28:43 +00:00
|
|
|
default=date.today,
|
2020-12-28 12:47:05 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
date_end = models.DateField(
|
2020-12-30 11:13:05 +00:00
|
|
|
verbose_name=_("end"),
|
2021-01-18 21:28:43 +00:00
|
|
|
default=date.today,
|
2020-12-28 12:47:05 +00:00
|
|
|
)
|
|
|
|
|
2023-01-10 19:24:06 +00:00
|
|
|
place = models.CharField(
|
|
|
|
max_length=255,
|
2020-12-31 11:13:42 +00:00
|
|
|
verbose_name=_("place"),
|
|
|
|
)
|
|
|
|
|
2020-12-31 11:26:49 +00:00
|
|
|
max_teams = models.PositiveSmallIntegerField(
|
|
|
|
verbose_name=_("max team count"),
|
|
|
|
default=9,
|
|
|
|
)
|
|
|
|
|
2021-01-01 11:11:09 +00:00
|
|
|
price = models.PositiveSmallIntegerField(
|
|
|
|
verbose_name=_("price"),
|
|
|
|
default=21,
|
|
|
|
)
|
|
|
|
|
2021-01-23 18:57:25 +00:00
|
|
|
remote = models.BooleanField(
|
|
|
|
verbose_name=_("remote"),
|
|
|
|
default=False,
|
|
|
|
)
|
|
|
|
|
2020-12-28 12:47:05 +00:00
|
|
|
inscription_limit = models.DateTimeField(
|
|
|
|
verbose_name=_("limit date for registrations"),
|
|
|
|
default=timezone.now,
|
|
|
|
)
|
|
|
|
|
|
|
|
solution_limit = models.DateTimeField(
|
|
|
|
verbose_name=_("limit date to upload solutions"),
|
|
|
|
default=timezone.now,
|
|
|
|
)
|
|
|
|
|
2021-01-01 11:11:09 +00:00
|
|
|
solutions_draw = models.DateTimeField(
|
|
|
|
verbose_name=_("random draw for solutions"),
|
|
|
|
default=timezone.now,
|
|
|
|
)
|
|
|
|
|
2024-06-07 14:03:42 +00:00
|
|
|
date_first_phase = models.DateField(
|
|
|
|
verbose_name=_("first phase date"),
|
|
|
|
default=date.today,
|
|
|
|
)
|
|
|
|
|
2020-12-28 12:47:05 +00:00
|
|
|
syntheses_first_phase_limit = models.DateTimeField(
|
|
|
|
verbose_name=_("limit date to upload the syntheses for the first phase"),
|
|
|
|
default=timezone.now,
|
|
|
|
)
|
|
|
|
|
2024-06-07 14:03:42 +00:00
|
|
|
date_second_phase = models.DateField(
|
|
|
|
verbose_name=_("first second date"),
|
|
|
|
default=date.today,
|
|
|
|
)
|
|
|
|
|
2024-06-07 13:48:52 +00:00
|
|
|
solutions_available_second_phase = models.BooleanField(
|
|
|
|
verbose_name=_("check this case when solutions for the second round become available"),
|
|
|
|
default=False,
|
2021-01-01 11:11:09 +00:00
|
|
|
)
|
|
|
|
|
2020-12-28 12:47:05 +00:00
|
|
|
syntheses_second_phase_limit = models.DateTimeField(
|
|
|
|
verbose_name=_("limit date to upload the syntheses for the second phase"),
|
|
|
|
default=timezone.now,
|
|
|
|
)
|
|
|
|
|
2024-06-07 14:03:42 +00:00
|
|
|
date_third_phase = models.DateField(
|
|
|
|
verbose_name=_("third phase date"),
|
|
|
|
default=date.today,
|
|
|
|
)
|
|
|
|
|
2024-06-07 13:48:52 +00:00
|
|
|
solutions_available_third_phase = models.BooleanField(
|
|
|
|
verbose_name=_("check this case when solutions for the third round become available"),
|
|
|
|
default=False,
|
|
|
|
)
|
|
|
|
|
|
|
|
syntheses_third_phase_limit = models.DateTimeField(
|
|
|
|
verbose_name=_("limit date to upload the syntheses for the third phase"),
|
|
|
|
default=timezone.now,
|
|
|
|
)
|
|
|
|
|
2020-12-28 12:47:05 +00:00
|
|
|
description = models.TextField(
|
|
|
|
verbose_name=_("description"),
|
|
|
|
blank=True,
|
|
|
|
)
|
|
|
|
|
|
|
|
organizers = models.ManyToManyField(
|
|
|
|
VolunteerRegistration,
|
|
|
|
verbose_name=_("organizers"),
|
|
|
|
related_name="organized_tournaments",
|
|
|
|
)
|
|
|
|
|
|
|
|
final = models.BooleanField(
|
|
|
|
verbose_name=_("final"),
|
|
|
|
default=False,
|
|
|
|
)
|
|
|
|
|
2024-03-30 12:41:46 +00:00
|
|
|
notes_sheet_id = models.CharField(
|
|
|
|
max_length=64,
|
|
|
|
blank=True,
|
|
|
|
default="",
|
|
|
|
verbose_name=_("Google Sheet ID"),
|
|
|
|
)
|
|
|
|
|
2021-01-16 21:29:10 +00:00
|
|
|
@property
|
|
|
|
def teams_email(self):
|
|
|
|
"""
|
|
|
|
:return: The mailing list to contact the team members.
|
|
|
|
"""
|
|
|
|
return f"equipes-{self.name.lower().replace(' ', '-')}@{os.getenv('SYMPA_HOST', 'localhost')}"
|
|
|
|
|
|
|
|
@property
|
|
|
|
def organizers_email(self):
|
|
|
|
"""
|
|
|
|
:return: The mailing list to contact the team members.
|
|
|
|
"""
|
|
|
|
return f"organisateurs-{self.name.lower().replace(' ', '-')}@{os.getenv('SYMPA_HOST', 'localhost')}"
|
|
|
|
|
|
|
|
@property
|
|
|
|
def jurys_email(self):
|
|
|
|
"""
|
|
|
|
:return: The mailing list to contact the team members.
|
|
|
|
"""
|
2021-01-18 01:07:31 +00:00
|
|
|
return f"jurys-{self.name.lower().replace(' ', '-')}@{os.getenv('SYMPA_HOST', 'localhost')}"
|
2021-01-16 21:29:10 +00:00
|
|
|
|
|
|
|
def create_mailing_lists(self):
|
|
|
|
"""
|
|
|
|
Create a new Sympa mailing list to contact the team.
|
|
|
|
"""
|
|
|
|
get_sympa_client().create_list(
|
|
|
|
f"equipes-{self.name.lower().replace(' ', '-')}",
|
|
|
|
f"Equipes du tournoi de {self.name}",
|
|
|
|
"hotline", # TODO Use a custom sympa template
|
|
|
|
f"Liste de diffusion pour contacter les equipes du tournoi {self.name} du TFJM²",
|
|
|
|
"education",
|
|
|
|
raise_error=False,
|
|
|
|
)
|
|
|
|
get_sympa_client().create_list(
|
|
|
|
f"organisateurs-{self.name.lower().replace(' ', '-')}",
|
|
|
|
f"Organisateurs du tournoi de {self.name}",
|
|
|
|
"hotline", # TODO Use a custom sympa template
|
|
|
|
f"Liste de diffusion pour contacter les equipes du tournoi {self.name} du TFJM²",
|
|
|
|
"education",
|
|
|
|
raise_error=False,
|
|
|
|
)
|
|
|
|
|
2020-12-28 12:47:05 +00:00
|
|
|
@staticmethod
|
|
|
|
def final_tournament():
|
|
|
|
qs = Tournament.objects.filter(final=True)
|
|
|
|
if qs.exists():
|
|
|
|
return qs.get()
|
|
|
|
|
2020-12-28 16:49:59 +00:00
|
|
|
@property
|
|
|
|
def participations(self):
|
|
|
|
if self.final:
|
|
|
|
return Participation.objects.filter(final=True)
|
|
|
|
return self.participation_set
|
|
|
|
|
|
|
|
@property
|
|
|
|
def solutions(self):
|
|
|
|
if self.final:
|
|
|
|
return Solution.objects.filter(final_solution=True)
|
|
|
|
return Solution.objects.filter(participation__tournament=self)
|
|
|
|
|
|
|
|
@property
|
|
|
|
def syntheses(self):
|
|
|
|
if self.final:
|
|
|
|
return Synthesis.objects.filter(final_solution=True)
|
|
|
|
return Synthesis.objects.filter(participation__tournament=self)
|
|
|
|
|
2023-03-22 17:44:49 +00:00
|
|
|
@property
|
|
|
|
def best_format(self):
|
|
|
|
n = len(self.participations.filter(valid=True).all())
|
|
|
|
fmt = [n] if n <= 5 else [3] * (n // 3 - 1) + [3 + n % 3]
|
2024-03-24 20:37:37 +00:00
|
|
|
return '+'.join(map(str, sorted(fmt)))
|
2023-03-22 17:44:49 +00:00
|
|
|
|
2024-03-30 12:41:46 +00:00
|
|
|
def create_spreadsheet(self):
|
|
|
|
if self.notes_sheet_id:
|
|
|
|
return self.notes_sheet_id
|
|
|
|
|
|
|
|
gc = gspread.service_account_from_dict(settings.GOOGLE_SERVICE_CLIENT)
|
|
|
|
spreadsheet = gc.create(f"Feuille de notes - {self.name}", folder_id=settings.NOTES_DRIVE_FOLDER_ID)
|
2024-03-30 14:55:28 +00:00
|
|
|
spreadsheet.update_locale("fr_FR")
|
2024-03-30 19:49:56 +00:00
|
|
|
spreadsheet.share(None, "anyone", "writer", with_link=True)
|
2024-03-30 12:41:46 +00:00
|
|
|
self.notes_sheet_id = spreadsheet.id
|
|
|
|
self.save()
|
|
|
|
|
2024-04-18 12:53:58 +00:00
|
|
|
def update_ranking_spreadsheet(self): # noqa: C901
|
2024-06-07 15:20:06 +00:00
|
|
|
translation.activate(settings.PREFERRED_LANGUAGE_CODE)
|
2024-04-18 12:53:58 +00:00
|
|
|
|
2024-03-30 17:28:54 +00:00
|
|
|
gc = gspread.service_account_from_dict(settings.GOOGLE_SERVICE_CLIENT)
|
|
|
|
spreadsheet = gc.open_by_key(self.notes_sheet_id)
|
|
|
|
worksheets = spreadsheet.worksheets()
|
2024-03-30 19:43:04 +00:00
|
|
|
if "Classement final" not in [ws.title for ws in worksheets]:
|
2024-03-30 17:28:54 +00:00
|
|
|
worksheet = spreadsheet.add_worksheet("Classement final", 100, 26)
|
|
|
|
else:
|
|
|
|
worksheet = spreadsheet.worksheet("Classement final")
|
|
|
|
|
2024-03-30 17:57:05 +00:00
|
|
|
if worksheet.index != self.pools.count():
|
|
|
|
worksheet.update_index(self.pools.count())
|
2024-03-30 17:28:54 +00:00
|
|
|
|
2024-03-30 17:57:05 +00:00
|
|
|
header = [["Équipe", "Score jour 1", "Harmonisation 1", "Score jour 2", "Harmonisation 2", "Total", "Rang"]]
|
2024-03-30 17:28:54 +00:00
|
|
|
lines = []
|
2024-04-18 12:53:58 +00:00
|
|
|
participations = self.participations.filter(pools__round=1, pools__tournament=self).distinct().all()
|
2024-03-30 17:28:54 +00:00
|
|
|
for i, participation in enumerate(participations):
|
|
|
|
line = [f"{participation.team.name} ({participation.team.trigram})"]
|
|
|
|
lines.append(line)
|
|
|
|
|
2024-04-18 12:53:58 +00:00
|
|
|
passage1 = Passage.objects.get(pool__tournament=self, pool__round=1, defender=participation)
|
|
|
|
pool1 = passage1.pool
|
|
|
|
if pool1.participations.count() != 5:
|
|
|
|
position1 = passage1.position
|
|
|
|
else:
|
|
|
|
position1 = (passage1.position - 1) * 2 + pool1.room
|
2024-03-30 17:57:05 +00:00
|
|
|
tweak1_qs = Tweak.objects.filter(pool=pool1, participation=participation)
|
|
|
|
tweak1 = tweak1_qs.get() if tweak1_qs.exists() else None
|
|
|
|
|
2024-04-18 12:53:58 +00:00
|
|
|
line.append(f"=SIERREUR('Poule {pool1.short_name}'!$D{pool1.juries.count() + 10 + position1}; 0)")
|
2024-03-30 17:57:05 +00:00
|
|
|
line.append(tweak1.diff if tweak1 else 0)
|
2024-03-31 11:42:34 +00:00
|
|
|
|
2024-04-18 12:53:58 +00:00
|
|
|
if Passage.objects.filter(pool__tournament=self, pool__round=2, defender=participation).exists():
|
|
|
|
passage2 = Passage.objects.get(pool__tournament=self, pool__round=2, defender=participation)
|
|
|
|
pool2 = passage2.pool
|
|
|
|
if pool2.participations.count() != 5:
|
|
|
|
position2 = passage2.position
|
|
|
|
else:
|
|
|
|
position2 = (passage2.position - 1) * 2 + pool2.room
|
2024-03-31 11:42:34 +00:00
|
|
|
tweak2_qs = Tweak.objects.filter(pool=pool2, participation=participation)
|
|
|
|
tweak2 = tweak2_qs.get() if tweak2_qs.exists() else None
|
|
|
|
|
|
|
|
line.append(
|
2024-04-18 12:53:58 +00:00
|
|
|
f"=SIERREUR('Poule {pool2.short_name}'!$D{pool2.juries.count() + 10 + position2}; 0)")
|
2024-03-31 11:42:34 +00:00
|
|
|
line.append(tweak2.diff if tweak2 else 0)
|
|
|
|
else:
|
|
|
|
# User has no second pool yet
|
|
|
|
line.append(0)
|
|
|
|
line.append(0)
|
|
|
|
|
2024-03-30 17:57:05 +00:00
|
|
|
line.append(f"=$B{i + 2} + $C{i + 2} + $D{i + 2} + E{i + 2}")
|
2024-03-30 17:28:54 +00:00
|
|
|
line.append(f"=RANG($F{i + 2}; $F$2:$F${participations.count() + 1})")
|
|
|
|
|
2024-04-16 22:29:48 +00:00
|
|
|
final_ranking = [["", "", "", ""], ["", "", "", ""], ["Équipe", "Score", "Rang", "Mention"],
|
2024-03-30 17:28:54 +00:00
|
|
|
[f"=SORT($A$2:$A${participations.count() + 1}; "
|
|
|
|
f"$F$2:$F${participations.count() + 1}; FALSE)",
|
|
|
|
f"=SORT($F$2:$F${participations.count() + 1}; "
|
|
|
|
f"$F$2:$F${participations.count() + 1}; FALSE)",
|
|
|
|
f"=SORT($G$2:$G${participations.count() + 1}; "
|
|
|
|
f"$F$2:$F${participations.count() + 1}; FALSE)", ]]
|
2024-04-16 22:29:48 +00:00
|
|
|
final_ranking += [["", "", ""] for _i in range(participations.count() - 1)]
|
|
|
|
|
|
|
|
notes = dict()
|
|
|
|
for participation in self.participations.filter(valid=True).all():
|
|
|
|
note = sum(pool.average(participation) for pool in self.pools.filter(participations=participation).all())
|
|
|
|
if note:
|
|
|
|
notes[participation] = note
|
|
|
|
sorted_notes = sorted(notes.items(), key=lambda x: x[1], reverse=True)
|
|
|
|
|
|
|
|
for i, (participation, _note) in enumerate(sorted_notes):
|
|
|
|
final_ranking[i + 3].append(participation.mention if not self.final else participation.mention_final)
|
2024-03-30 17:28:54 +00:00
|
|
|
|
|
|
|
data = header + lines + final_ranking
|
2024-04-16 22:29:48 +00:00
|
|
|
worksheet.update(data, f"A1:G{2 * participations.count() + 4}", raw=False)
|
2024-03-30 17:28:54 +00:00
|
|
|
|
|
|
|
format_requests = []
|
|
|
|
|
|
|
|
# Set the width of the columns
|
2024-04-16 22:29:48 +00:00
|
|
|
column_widths = [("A", 300), ("B", 150), ("C", 150), ("D", 150), ("E", 150), ("F", 150), ("G", 150)]
|
2024-03-30 17:28:54 +00:00
|
|
|
for column, width in column_widths:
|
|
|
|
grid_range = a1_range_to_grid_range(column, worksheet.id)
|
|
|
|
format_requests.append({
|
|
|
|
"updateDimensionProperties": {
|
|
|
|
"range": {
|
|
|
|
"sheetId": worksheet.id,
|
|
|
|
"dimension": "COLUMNS",
|
|
|
|
"startIndex": grid_range['startColumnIndex'],
|
|
|
|
"endIndex": grid_range['endColumnIndex'],
|
|
|
|
},
|
|
|
|
"properties": {
|
|
|
|
"pixelSize": width,
|
|
|
|
},
|
|
|
|
"fields": "pixelSize",
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
# Set borders
|
2024-04-18 13:41:27 +00:00
|
|
|
border_ranges = [("A1:Z", "0000"),
|
2024-03-30 17:28:54 +00:00
|
|
|
(f"A1:G{participations.count() + 1}", "1111"),
|
2024-04-16 22:29:48 +00:00
|
|
|
(f"A{participations.count() + 4}:D{2 * participations.count() + 4}", "1111")]
|
2024-03-30 17:28:54 +00:00
|
|
|
sides_names = ['top', 'bottom', 'left', 'right']
|
|
|
|
styles = ["NONE", "SOLID", "SOLID_MEDIUM", "SOLID_THICK", "DOUBLE"]
|
|
|
|
for border_range, sides in border_ranges:
|
|
|
|
borders = {}
|
|
|
|
for side_name, side in zip(sides_names, sides):
|
|
|
|
borders[side_name] = {"style": styles[int(side)]}
|
|
|
|
format_requests.append({
|
|
|
|
"repeatCell": {
|
|
|
|
"range": a1_range_to_grid_range(border_range, worksheet.id),
|
|
|
|
"cell": {
|
|
|
|
"userEnteredFormat": {
|
|
|
|
"borders": borders,
|
|
|
|
"horizontalAlignment": "CENTER",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
"fields": "userEnteredFormat(borders,horizontalAlignment)",
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
# Make titles bold
|
2024-04-18 13:41:27 +00:00
|
|
|
bold_ranges = [("A1:Z", False), ("A1:G1", True),
|
2024-04-16 22:29:48 +00:00
|
|
|
(f"A{participations.count() + 4}:D{participations.count() + 4}", True)]
|
2024-03-30 17:28:54 +00:00
|
|
|
for bold_range, bold in bold_ranges:
|
|
|
|
format_requests.append({
|
|
|
|
"repeatCell": {
|
|
|
|
"range": a1_range_to_grid_range(bold_range, worksheet.id),
|
|
|
|
"cell": {"userEnteredFormat": {"textFormat": {"bold": bold}}},
|
|
|
|
"fields": "userEnteredFormat(textFormat)",
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
# Set background color for headers and footers
|
2024-04-18 13:41:27 +00:00
|
|
|
bg_colors = [("A1:Z", (1, 1, 1)),
|
2024-03-30 19:43:04 +00:00
|
|
|
("A1:G1", (0.8, 0.8, 0.8)),
|
2024-03-30 17:57:05 +00:00
|
|
|
(f"A2:B{participations.count() + 1}", (0.9, 0.9, 0.9)),
|
|
|
|
(f"C2:C{participations.count() + 1}", (1, 1, 1)),
|
|
|
|
(f"D2:D{participations.count() + 1}", (0.9, 0.9, 0.9)),
|
2024-03-30 17:28:54 +00:00
|
|
|
(f"E2:E{participations.count() + 1}", (1, 1, 1)),
|
|
|
|
(f"F2:G{participations.count() + 1}", (0.9, 0.9, 0.9)),
|
2024-04-16 22:29:48 +00:00
|
|
|
(f"A{participations.count() + 4}:D{participations.count() + 4}", (0.8, 0.8, 0.8)),
|
2024-03-30 17:28:54 +00:00
|
|
|
(f"A{participations.count() + 5}:C{2 * participations.count() + 4}", (0.9, 0.9, 0.9)),]
|
|
|
|
for bg_range, bg_color in bg_colors:
|
|
|
|
r, g, b = bg_color
|
|
|
|
format_requests.append({
|
|
|
|
"repeatCell": {
|
|
|
|
"range": a1_range_to_grid_range(bg_range, worksheet.id),
|
|
|
|
"cell": {"userEnteredFormat": {"backgroundColor": {"red": r, "green": g, "blue": b}}},
|
|
|
|
"fields": "userEnteredFormat(backgroundColor)",
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
# Set number format, display only one decimal
|
2024-03-30 17:57:05 +00:00
|
|
|
number_format_ranges = [(f"B2:B{participations.count() + 1}", "0.0"),
|
|
|
|
(f"C2:C{participations.count() + 1}", "0"),
|
|
|
|
(f"D2:D{participations.count() + 1}", "0.0"),
|
|
|
|
(f"E2:E{participations.count() + 1}", "0"),
|
|
|
|
(f"F2:F{participations.count() + 1}", "0.0"),
|
|
|
|
(f"G2:G{participations.count() + 1}", "0"),
|
|
|
|
(f"B{participations.count() + 5}:B{2 * participations.count() + 5}", "0.0"),
|
|
|
|
(f"C{participations.count() + 5}:C{2 * participations.count() + 5}", "0"), ]
|
|
|
|
for number_format_range, pattern in number_format_ranges:
|
2024-03-30 17:28:54 +00:00
|
|
|
format_requests.append({
|
|
|
|
"repeatCell": {
|
|
|
|
"range": a1_range_to_grid_range(number_format_range, worksheet.id),
|
2024-03-30 17:57:05 +00:00
|
|
|
"cell": {"userEnteredFormat": {"numberFormat": {"type": "NUMBER", "pattern": pattern}}},
|
2024-03-30 17:28:54 +00:00
|
|
|
"fields": "userEnteredFormat.numberFormat",
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
# Remove old protected ranges
|
|
|
|
for protected_range in spreadsheet.list_protected_ranges(worksheet.id):
|
|
|
|
format_requests.append({
|
|
|
|
"deleteProtectedRange": {
|
|
|
|
"protectedRangeId": protected_range["protectedRangeId"],
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
# Protect the header, the juries list, the footer and the ranking
|
2024-03-30 19:43:04 +00:00
|
|
|
protected_ranges = ["A1:G1", f"A2:B{participations.count() + 1}",
|
2024-03-30 17:57:05 +00:00
|
|
|
f"D2:D{participations.count() + 1}", f"F2:G{participations.count() + 1}",
|
2024-03-30 17:28:54 +00:00
|
|
|
f"A{participations.count() + 4}:C{2 * participations.count() + 4}", ]
|
|
|
|
for protected_range in protected_ranges:
|
|
|
|
format_requests.append({
|
|
|
|
"addProtectedRange": {
|
|
|
|
"protectedRange": {
|
|
|
|
"range": a1_range_to_grid_range(protected_range, worksheet.id),
|
|
|
|
"description": "Structure du tableur à ne pas modifier "
|
|
|
|
"pour une meilleure prise en charge automatisée",
|
|
|
|
"warningOnly": True,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
body = {"requests": format_requests}
|
|
|
|
worksheet.client.batch_update(spreadsheet.id, body)
|
|
|
|
|
2024-04-06 19:55:46 +00:00
|
|
|
def parse_tweaks_spreadsheets(self):
|
2024-04-06 17:16:32 +00:00
|
|
|
if not self.pools.exists():
|
|
|
|
# Draw has not been done yet
|
|
|
|
return
|
|
|
|
|
2024-03-30 17:57:05 +00:00
|
|
|
gc = gspread.service_account_from_dict(settings.GOOGLE_SERVICE_CLIENT)
|
|
|
|
spreadsheet = gc.open_by_key(self.notes_sheet_id)
|
|
|
|
worksheet = spreadsheet.worksheet("Classement final")
|
|
|
|
|
|
|
|
score_cell = worksheet.find("Score")
|
|
|
|
max_row = score_cell.row - 3
|
2024-04-06 17:16:32 +00:00
|
|
|
if max_row == 1:
|
|
|
|
# There is no team
|
|
|
|
return
|
|
|
|
|
2024-03-30 17:57:05 +00:00
|
|
|
data = worksheet.get_values(f"A2:E{max_row}")
|
|
|
|
for line in data:
|
|
|
|
trigram = line[0][-4:-1]
|
|
|
|
participation = self.participations.get(team__trigram=trigram)
|
2024-04-20 19:37:37 +00:00
|
|
|
pool1 = self.pools.get(round=1, participations=participation, room=1)
|
2024-03-30 17:57:05 +00:00
|
|
|
tweak1_qs = Tweak.objects.filter(pool=pool1, participation=participation)
|
2024-03-31 11:42:34 +00:00
|
|
|
tweak1_nb = int(line[2])
|
2024-03-30 17:57:05 +00:00
|
|
|
if not tweak1_nb:
|
|
|
|
tweak1_qs.delete()
|
|
|
|
else:
|
|
|
|
tweak1_qs.update_or_create(defaults={'diff': tweak1_nb},
|
|
|
|
create_defaults={'diff': tweak1_nb, 'pool': pool1,
|
|
|
|
'participation': participation})
|
2024-03-31 11:42:34 +00:00
|
|
|
|
|
|
|
if self.pools.filter(round=2, participations=participation).exists():
|
2024-04-20 19:37:37 +00:00
|
|
|
pool2 = self.pools.get(round=2, participations=participation, room=1)
|
2024-03-31 11:42:34 +00:00
|
|
|
tweak2_qs = Tweak.objects.filter(pool=pool2, participation=participation)
|
|
|
|
tweak2_nb = int(line[4])
|
|
|
|
if not tweak2_nb:
|
|
|
|
tweak2_qs.delete()
|
|
|
|
else:
|
|
|
|
tweak2_qs.update_or_create(defaults={'diff': tweak2_nb},
|
|
|
|
create_defaults={'diff': tweak2_nb, 'pool': pool2,
|
2024-03-31 13:30:17 +00:00
|
|
|
'participation': participation})
|
2024-03-30 17:57:05 +00:00
|
|
|
|
2024-04-16 22:29:48 +00:00
|
|
|
nb_participations = self.participations.filter(valid=True).count()
|
|
|
|
mentions = worksheet.get_values(f"A{score_cell.row + 1}:D{score_cell.row + nb_participations}")
|
|
|
|
notes = dict()
|
|
|
|
for participation in self.participations.filter(valid=True).all():
|
|
|
|
note = sum(pool.average(participation) for pool in self.pools.filter(participations=participation).all())
|
|
|
|
if note:
|
|
|
|
notes[participation] = note
|
|
|
|
sorted_notes = sorted(notes.items(), key=lambda x: x[1], reverse=True)
|
|
|
|
for i, (participation, _note) in enumerate(sorted_notes):
|
2024-04-20 19:43:37 +00:00
|
|
|
mention = mentions[i][3] if len(mentions[i]) >= 4 else ""
|
2024-04-16 22:29:48 +00:00
|
|
|
if not self.final:
|
|
|
|
participation.mention = mention
|
|
|
|
else:
|
|
|
|
participation.mention_final = mention
|
|
|
|
participation.save()
|
|
|
|
|
2020-12-31 11:23:09 +00:00
|
|
|
def get_absolute_url(self):
|
|
|
|
return reverse_lazy("participation:tournament_detail", args=(self.pk,))
|
|
|
|
|
2020-12-28 18:19:01 +00:00
|
|
|
def __str__(self):
|
2021-01-01 23:06:58 +00:00
|
|
|
return self.name
|
2020-12-28 18:19:01 +00:00
|
|
|
|
2020-12-28 12:47:05 +00:00
|
|
|
class Meta:
|
|
|
|
verbose_name = _("tournament")
|
|
|
|
verbose_name_plural = _("tournaments")
|
|
|
|
indexes = [
|
|
|
|
Index(fields=("name", "date_start", "date_end", )),
|
|
|
|
]
|
|
|
|
|
|
|
|
|
2020-12-27 10:49:54 +00:00
|
|
|
class Participation(models.Model):
|
|
|
|
"""
|
|
|
|
The Participation model contains all data that are related to the participation:
|
2021-01-12 14:42:32 +00:00
|
|
|
chosen problem, validity status, solutions,...
|
2020-12-27 10:49:54 +00:00
|
|
|
"""
|
|
|
|
team = models.OneToOneField(
|
|
|
|
Team,
|
|
|
|
on_delete=models.CASCADE,
|
|
|
|
verbose_name=_("team"),
|
|
|
|
)
|
|
|
|
|
2020-12-28 12:47:05 +00:00
|
|
|
tournament = models.ForeignKey(
|
|
|
|
Tournament,
|
|
|
|
on_delete=models.SET_NULL,
|
2020-12-27 10:49:54 +00:00
|
|
|
null=True,
|
2020-12-28 12:47:05 +00:00
|
|
|
blank=True,
|
2020-12-27 10:49:54 +00:00
|
|
|
default=None,
|
2020-12-28 12:47:05 +00:00
|
|
|
verbose_name=_("tournament"),
|
2020-12-27 10:49:54 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
valid = models.BooleanField(
|
|
|
|
null=True,
|
|
|
|
default=None,
|
2023-04-05 08:44:27 +00:00
|
|
|
verbose_name=_("valid team"),
|
2021-01-01 16:07:28 +00:00
|
|
|
help_text=_("The participation got the validation of the organizers."),
|
2020-12-27 10:49:54 +00:00
|
|
|
)
|
|
|
|
|
2021-01-12 16:24:46 +00:00
|
|
|
final = models.BooleanField(
|
|
|
|
default=False,
|
|
|
|
verbose_name=_("selected for final"),
|
|
|
|
help_text=_("The team is selected for the final tournament."),
|
|
|
|
)
|
|
|
|
|
2024-04-16 22:29:48 +00:00
|
|
|
mention = models.CharField(
|
|
|
|
verbose_name=_("mention"),
|
|
|
|
max_length=255,
|
|
|
|
blank=True,
|
|
|
|
default="",
|
|
|
|
)
|
|
|
|
|
|
|
|
mention_final = models.CharField(
|
|
|
|
verbose_name=_("mention (final)"),
|
|
|
|
max_length=255,
|
|
|
|
blank=True,
|
|
|
|
default="",
|
|
|
|
)
|
|
|
|
|
2020-12-27 10:49:54 +00:00
|
|
|
def get_absolute_url(self):
|
|
|
|
return reverse_lazy("participation:participation_detail", args=(self.pk,))
|
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return _("Participation of the team {name} ({trigram})").format(name=self.team.name, trigram=self.team.trigram)
|
|
|
|
|
2024-02-11 22:31:24 +00:00
|
|
|
def important_informations(self):
|
|
|
|
informations = []
|
|
|
|
|
2024-02-12 21:30:27 +00:00
|
|
|
missing_payments = Payment.objects.filter(registrations__in=self.team.participants.all(), valid=False)
|
2024-02-11 22:31:24 +00:00
|
|
|
if missing_payments.exists():
|
|
|
|
text = _("<p>The team {trigram} has {nb_missing_payments} missing payments. Each member of the team "
|
|
|
|
"must have a valid payment (or send a scholarship notification) "
|
|
|
|
"to participate to the tournament.</p>"
|
|
|
|
"<p>Participants that have not paid yet are: {participants}.</p>")
|
|
|
|
content = format_lazy(text, trigram=self.team.trigram, nb_missing_payments=missing_payments.count(),
|
2024-02-12 21:30:27 +00:00
|
|
|
participants=", ".join(", ".join(str(r) for r in p.registrations.all())
|
|
|
|
for p in missing_payments.all()))
|
2024-02-11 22:31:24 +00:00
|
|
|
informations.append({
|
|
|
|
'title': _("Missing payments"),
|
|
|
|
'type': "danger",
|
|
|
|
'priority': 10,
|
|
|
|
'content': content,
|
|
|
|
})
|
|
|
|
|
2024-04-07 10:38:41 +00:00
|
|
|
if self.tournament:
|
|
|
|
informations.extend(self.informations_for_tournament(self.tournament))
|
|
|
|
if self.final:
|
|
|
|
informations.extend(self.informations_for_tournament(Tournament.final_tournament()))
|
|
|
|
|
|
|
|
return informations
|
|
|
|
|
|
|
|
def informations_for_tournament(self, tournament) -> list[dict]:
|
|
|
|
informations = []
|
|
|
|
if timezone.now() <= tournament.solution_limit + timedelta(hours=2):
|
|
|
|
if not tournament.final:
|
|
|
|
text = _("<p>The solutions for the tournament of {tournament} are due on the {date:%Y-%m-%d %H:%M}.</p>"
|
|
|
|
"<p>You have currently sent <strong>{nb_solutions}</strong> solutions. "
|
|
|
|
"We suggest to send at least <strong>{min_solutions}</strong> different solutions.</p>"
|
|
|
|
"<p>You can upload your solutions on <a href='{url}'>your participation page</a>.</p>")
|
|
|
|
url = reverse_lazy("participation:participation_detail", args=(self.pk,))
|
|
|
|
content = format_lazy(text, tournament=tournament.name, date=localtime(tournament.solution_limit),
|
|
|
|
nb_solutions=self.solutions.filter(final_solution=False).count(),
|
|
|
|
min_solutions=len(settings.PROBLEMS) - 3,
|
|
|
|
url=url)
|
|
|
|
informations.append({
|
|
|
|
'title': _("Solutions due"),
|
|
|
|
'type': "info",
|
|
|
|
'priority': 1,
|
|
|
|
'content': content,
|
|
|
|
})
|
|
|
|
else:
|
|
|
|
text = _("<p>The solutions for the tournament of {tournament} are due on the {date:%Y-%m-%d %H:%M}.</p>"
|
|
|
|
"<p>Remember that you can only fix minor changes to your solutions "
|
|
|
|
"without adding new parts.</p>"
|
|
|
|
"<p>You can upload your solutions on <a href='{url}'>your participation page</a>.</p>")
|
|
|
|
url = reverse_lazy("participation:participation_detail", args=(self.pk,))
|
|
|
|
content = format_lazy(text, tournament=tournament.name, date=localtime(tournament.solution_limit),
|
|
|
|
url=url)
|
|
|
|
informations.append({
|
|
|
|
'title': _("Solutions due"),
|
|
|
|
'type': "info",
|
|
|
|
'priority': 1,
|
|
|
|
'content': content,
|
|
|
|
})
|
|
|
|
elif timezone.now() <= tournament.solutions_draw + timedelta(hours=2):
|
2024-03-30 21:23:34 +00:00
|
|
|
text = _("<p>The draw of the solutions for the tournament {tournament} is planned on the "
|
|
|
|
"{date:%Y-%m-%d %H:%M}. You can join it on <a href='{url}'>this link</a>.</p>")
|
|
|
|
url = reverse_lazy("draw:index")
|
2024-04-07 10:38:41 +00:00
|
|
|
content = format_lazy(text, tournament=tournament.name,
|
|
|
|
date=localtime(tournament.solutions_draw), url=url)
|
2024-03-30 21:23:34 +00:00
|
|
|
informations.append({
|
|
|
|
'title': _("Draw of solutions"),
|
|
|
|
'type': "info",
|
|
|
|
'priority': 1,
|
|
|
|
'content': content,
|
|
|
|
})
|
2024-04-07 10:38:41 +00:00
|
|
|
elif timezone.now() <= tournament.syntheses_first_phase_limit + timedelta(hours=2):
|
2024-04-18 13:07:15 +00:00
|
|
|
defender_passage = Passage.objects.get(pool__tournament=self.tournament, pool__round=1, defender=self)
|
|
|
|
opponent_passage = Passage.objects.get(pool__tournament=self.tournament, pool__round=1, opponent=self)
|
2024-07-05 09:00:11 +00:00
|
|
|
reviewer_passage = Passage.objects.get(pool__tournament=self.tournament, pool__round=1, reviewer=self)
|
2024-07-05 09:47:19 +00:00
|
|
|
observer_passage = Passage.objects.filter(pool__tournament=self.tournament, pool__round=1, observer=self)
|
|
|
|
observer_passage = observer_passage.get() if observer_passage.exists() else None
|
2024-03-30 21:23:34 +00:00
|
|
|
|
|
|
|
defender_text = _("<p>The solutions draw is ended. You can check the result on "
|
2024-04-03 21:06:11 +00:00
|
|
|
"<a href='{draw_url}'>this page</a>.</p>"
|
2024-03-30 21:23:34 +00:00
|
|
|
"<p>For the first round, you will defend "
|
|
|
|
"<a href='{solution_url}'>your solution of the problem {problem}</a>.</p>")
|
|
|
|
draw_url = reverse_lazy("draw:index")
|
2024-04-03 21:21:23 +00:00
|
|
|
solution_url = defender_passage.defended_solution.file.url
|
2024-03-30 21:23:34 +00:00
|
|
|
defender_content = format_lazy(defender_text, draw_url=draw_url,
|
2024-04-03 20:19:09 +00:00
|
|
|
solution_url=solution_url, problem=defender_passage.solution_number)
|
2024-03-30 21:23:34 +00:00
|
|
|
|
2024-04-03 21:14:59 +00:00
|
|
|
opponent_text = _("<p>You will oppose the solution of the team {opponent} on the "
|
|
|
|
"<a href='{solution_url}'>problem {problem}</a>. "
|
2024-03-30 21:23:34 +00:00
|
|
|
"You can upload your synthesis sheet on <a href='{passage_url}'>this page</a>.</p>")
|
2024-04-03 21:21:23 +00:00
|
|
|
solution_url = opponent_passage.defended_solution.file.url
|
2024-03-30 21:23:34 +00:00
|
|
|
passage_url = reverse_lazy("participation:passage_detail", args=(opponent_passage.pk,))
|
|
|
|
opponent_content = format_lazy(opponent_text, opponent=opponent_passage.defender.team.trigram,
|
2024-04-03 21:14:59 +00:00
|
|
|
solution_url=solution_url,
|
2024-04-03 20:19:09 +00:00
|
|
|
problem=opponent_passage.solution_number, passage_url=passage_url)
|
2024-03-30 21:23:34 +00:00
|
|
|
|
2024-07-05 09:00:11 +00:00
|
|
|
reviewer_text = _("<p>You will report the solution of the team {reviewer} on the "
|
2024-04-03 21:14:59 +00:00
|
|
|
"<a href='{solution_url}'>problem {problem}. "
|
2024-03-30 21:23:34 +00:00
|
|
|
"You can upload your synthesis sheet on <a href='{passage_url}'>this page</a>.</p>")
|
2024-07-05 09:00:11 +00:00
|
|
|
solution_url = reviewer_passage.defended_solution.file.url
|
|
|
|
passage_url = reverse_lazy("participation:passage_detail", args=(reviewer_passage.pk,))
|
|
|
|
reviewer_content = format_lazy(reviewer_text, reviewer=reviewer_passage.defender.team.trigram,
|
2024-04-03 21:14:59 +00:00
|
|
|
solution_url=solution_url,
|
2024-07-05 09:00:11 +00:00
|
|
|
problem=reviewer_passage.solution_number, passage_url=passage_url)
|
2024-03-30 21:23:34 +00:00
|
|
|
|
2024-07-05 09:47:19 +00:00
|
|
|
if observer_passage:
|
|
|
|
observer_text = _("<p>You will observe the solution of the team {observer} on the "
|
|
|
|
"<a href='{solution_url}'>problem {problem}. "
|
|
|
|
"You can upload your synthesis sheet on <a href='{passage_url}'>this page</a>.</p>")
|
|
|
|
solution_url = observer_passage.defended_solution.file.url
|
|
|
|
passage_url = reverse_lazy("participation:passage_detail", args=(observer_passage.pk,))
|
|
|
|
observer_content = format_lazy(observer_text,
|
|
|
|
observer=observer_passage.defender.team.trigram,
|
|
|
|
solution_url=solution_url,
|
|
|
|
problem=observer_passage.solution_number, passage_url=passage_url)
|
|
|
|
else:
|
|
|
|
observer_content = ""
|
|
|
|
|
2024-04-03 21:30:31 +00:00
|
|
|
syntheses_template_begin = f"{settings.STATIC_URL}Fiche_synthèse."
|
|
|
|
syntheses_templates = " — ".join(f"<a href='{syntheses_template_begin}{ext}'>{ext.upper()}</a>"
|
|
|
|
for ext in ["pdf", "tex", "odt", "docx"])
|
|
|
|
syntheses_templates_content = f"<p>{_('Templates:')} {syntheses_templates}</p>"
|
|
|
|
|
2024-07-05 09:47:19 +00:00
|
|
|
content = defender_content + opponent_content + reviewer_content + observer_content \
|
|
|
|
+ syntheses_templates_content
|
2024-03-30 21:23:34 +00:00
|
|
|
informations.append({
|
|
|
|
'title': _("First round"),
|
|
|
|
'type': "info",
|
|
|
|
'priority': 1,
|
|
|
|
'content': content,
|
|
|
|
})
|
2024-04-07 10:38:41 +00:00
|
|
|
elif timezone.now() <= tournament.syntheses_second_phase_limit + timedelta(hours=2):
|
2024-04-18 13:07:15 +00:00
|
|
|
defender_passage = Passage.objects.get(pool__tournament=self.tournament, pool__round=2, defender=self)
|
|
|
|
opponent_passage = Passage.objects.get(pool__tournament=self.tournament, pool__round=2, opponent=self)
|
2024-07-05 09:00:11 +00:00
|
|
|
reviewer_passage = Passage.objects.get(pool__tournament=self.tournament, pool__round=2, reviewer=self)
|
2024-07-05 09:47:19 +00:00
|
|
|
observer_passage = Passage.objects.filter(pool__tournament=self.tournament, pool__round=2, observer=self)
|
|
|
|
observer_passage = observer_passage.get() if observer_passage.exists() else None
|
2024-03-30 21:23:34 +00:00
|
|
|
|
|
|
|
defender_text = _("<p>For the second round, you will defend "
|
|
|
|
"<a href='{solution_url}'>your solution of the problem {problem}</a>.</p>")
|
|
|
|
draw_url = reverse_lazy("draw:index")
|
2024-04-03 21:21:23 +00:00
|
|
|
solution_url = defender_passage.defended_solution.file.url
|
2024-06-07 13:48:52 +00:00
|
|
|
defender_content = format_lazy(defender_text, draw_url=draw_url,
|
|
|
|
solution_url=solution_url, problem=defender_passage.solution_number)
|
|
|
|
|
|
|
|
opponent_text = _("<p>You will oppose the solution of the team {opponent} on the "
|
|
|
|
"<a href='{solution_url}'>problem {problem}</a>. "
|
|
|
|
"You can upload your synthesis sheet on <a href='{passage_url}'>this page</a>.</p>")
|
|
|
|
solution_url = opponent_passage.defended_solution.file.url
|
|
|
|
passage_url = reverse_lazy("participation:passage_detail", args=(opponent_passage.pk,))
|
|
|
|
opponent_content = format_lazy(opponent_text, opponent=opponent_passage.defender.team.trigram,
|
|
|
|
solution_url=solution_url,
|
|
|
|
problem=opponent_passage.solution_number, passage_url=passage_url)
|
|
|
|
|
2024-07-05 09:00:11 +00:00
|
|
|
reviewer_text = _("<p>You will report the solution of the team {reviewer} on the "
|
2024-06-07 13:48:52 +00:00
|
|
|
"<a href='{solution_url}'>problem {problem}. "
|
|
|
|
"You can upload your synthesis sheet on <a href='{passage_url}'>this page</a>.</p>")
|
2024-07-05 09:00:11 +00:00
|
|
|
solution_url = reviewer_passage.defended_solution.file.url
|
|
|
|
passage_url = reverse_lazy("participation:passage_detail", args=(reviewer_passage.pk,))
|
|
|
|
reviewer_content = format_lazy(reviewer_text, reviewer=reviewer_passage.defender.team.trigram,
|
2024-06-07 13:48:52 +00:00
|
|
|
solution_url=solution_url,
|
2024-07-05 09:00:11 +00:00
|
|
|
problem=reviewer_passage.solution_number, passage_url=passage_url)
|
2024-06-07 13:48:52 +00:00
|
|
|
|
2024-07-05 09:47:19 +00:00
|
|
|
if observer_passage:
|
|
|
|
observer_text = _("<p>You will observe the solution of the team {observer} on the "
|
|
|
|
"<a href='{solution_url}'>problem {problem}. "
|
|
|
|
"You can upload your synthesis sheet on <a href='{passage_url}'>this page</a>.</p>")
|
|
|
|
solution_url = observer_passage.defended_solution.file.url
|
|
|
|
passage_url = reverse_lazy("participation:passage_detail", args=(observer_passage.pk,))
|
|
|
|
observer_content = format_lazy(observer_text,
|
|
|
|
observer=observer_passage.defender.team.trigram,
|
|
|
|
solution_url=solution_url,
|
|
|
|
problem=observer_passage.solution_number, passage_url=passage_url)
|
|
|
|
else:
|
|
|
|
observer_content = ""
|
|
|
|
|
2024-06-07 13:48:52 +00:00
|
|
|
syntheses_template_begin = f"{settings.STATIC_URL}Fiche_synthèse."
|
|
|
|
syntheses_templates = " — ".join(f"<a href='{syntheses_template_begin}{ext}'>{ext.upper()}</a>"
|
|
|
|
for ext in ["pdf", "tex", "odt", "docx"])
|
|
|
|
syntheses_templates_content = f"<p>{_('Templates:')} {syntheses_templates}</p>"
|
|
|
|
|
2024-07-05 09:47:19 +00:00
|
|
|
content = defender_content + opponent_content + reviewer_content + observer_content \
|
|
|
|
+ syntheses_templates_content
|
2024-06-07 13:48:52 +00:00
|
|
|
informations.append({
|
|
|
|
'title': _("Second round"),
|
|
|
|
'type': "info",
|
|
|
|
'priority': 1,
|
|
|
|
'content': content,
|
|
|
|
})
|
|
|
|
elif settings.TFJM_APP == "ETEAM" \
|
|
|
|
and timezone.now() <= tournament.syntheses_third_phase_limit + timedelta(hours=2):
|
|
|
|
defender_passage = Passage.objects.get(pool__tournament=self.tournament, pool__round=3, defender=self)
|
|
|
|
opponent_passage = Passage.objects.get(pool__tournament=self.tournament, pool__round=3, opponent=self)
|
2024-07-05 09:00:11 +00:00
|
|
|
reviewer_passage = Passage.objects.get(pool__tournament=self.tournament, pool__round=3, reviewer=self)
|
2024-07-05 09:47:19 +00:00
|
|
|
observer_passage = Passage.objects.filter(pool__tournament=self.tournament, pool__round=3, observer=self)
|
|
|
|
observer_passage = observer_passage.get() if observer_passage.exists() else None
|
2024-06-07 13:48:52 +00:00
|
|
|
|
|
|
|
defender_text = _("<p>For the third round, you will defend "
|
|
|
|
"<a href='{solution_url}'>your solution of the problem {problem}</a>.</p>")
|
|
|
|
draw_url = reverse_lazy("draw:index")
|
|
|
|
solution_url = defender_passage.defended_solution.file.url
|
2024-03-30 21:23:34 +00:00
|
|
|
defender_content = format_lazy(defender_text, draw_url=draw_url,
|
2024-04-03 20:19:09 +00:00
|
|
|
solution_url=solution_url, problem=defender_passage.solution_number)
|
2024-03-30 21:23:34 +00:00
|
|
|
|
2024-04-03 21:21:23 +00:00
|
|
|
opponent_text = _("<p>You will oppose the solution of the team {opponent} on the "
|
|
|
|
"<a href='{solution_url}'>problem {problem}</a>. "
|
2024-03-30 21:23:34 +00:00
|
|
|
"You can upload your synthesis sheet on <a href='{passage_url}'>this page</a>.</p>")
|
2024-04-03 21:21:23 +00:00
|
|
|
solution_url = opponent_passage.defended_solution.file.url
|
2024-03-30 21:23:34 +00:00
|
|
|
passage_url = reverse_lazy("participation:passage_detail", args=(opponent_passage.pk,))
|
|
|
|
opponent_content = format_lazy(opponent_text, opponent=opponent_passage.defender.team.trigram,
|
2024-04-03 21:30:31 +00:00
|
|
|
solution_url=solution_url,
|
2024-04-03 20:19:09 +00:00
|
|
|
problem=opponent_passage.solution_number, passage_url=passage_url)
|
2024-03-30 21:23:34 +00:00
|
|
|
|
2024-07-05 09:00:11 +00:00
|
|
|
reviewer_text = _("<p>You will report the solution of the team {reviewer} on the "
|
2024-04-03 21:21:23 +00:00
|
|
|
"<a href='{solution_url}'>problem {problem}. "
|
2024-03-30 21:23:34 +00:00
|
|
|
"You can upload your synthesis sheet on <a href='{passage_url}'>this page</a>.</p>")
|
2024-07-05 09:00:11 +00:00
|
|
|
solution_url = reviewer_passage.defended_solution.file.url
|
|
|
|
passage_url = reverse_lazy("participation:passage_detail", args=(reviewer_passage.pk,))
|
|
|
|
reviewer_content = format_lazy(reviewer_text, reviewer=reviewer_passage.defender.team.trigram,
|
2024-04-03 21:30:31 +00:00
|
|
|
solution_url=solution_url,
|
2024-07-05 09:00:11 +00:00
|
|
|
problem=reviewer_passage.solution_number, passage_url=passage_url)
|
2024-03-30 21:23:34 +00:00
|
|
|
|
2024-07-05 09:47:19 +00:00
|
|
|
if observer_passage:
|
|
|
|
observer_text = _("<p>You will observe the solution of the team {observer} on the "
|
|
|
|
"<a href='{solution_url}'>problem {problem}. "
|
|
|
|
"You can upload your synthesis sheet on <a href='{passage_url}'>this page</a>.</p>")
|
|
|
|
solution_url = observer_passage.defended_solution.file.url
|
|
|
|
passage_url = reverse_lazy("participation:passage_detail", args=(observer_passage.pk,))
|
|
|
|
observer_content = format_lazy(observer_text,
|
|
|
|
observer=observer_passage.defender.team.trigram,
|
|
|
|
solution_url=solution_url,
|
|
|
|
problem=observer_passage.solution_number, passage_url=passage_url)
|
|
|
|
else:
|
|
|
|
observer_content = ""
|
|
|
|
|
2024-04-03 21:30:31 +00:00
|
|
|
syntheses_template_begin = f"{settings.STATIC_URL}Fiche_synthèse."
|
|
|
|
syntheses_templates = " — ".join(f"<a href='{syntheses_template_begin}{ext}'>{ext.upper()}</a>"
|
|
|
|
for ext in ["pdf", "tex", "odt", "docx"])
|
|
|
|
syntheses_templates_content = f"<p>{_('Templates:')} {syntheses_templates}</p>"
|
|
|
|
|
2024-07-05 09:47:19 +00:00
|
|
|
content = defender_content + opponent_content + reviewer_content + observer_content \
|
|
|
|
+ syntheses_templates_content
|
2024-03-30 21:23:34 +00:00
|
|
|
informations.append({
|
|
|
|
'title': _("Second round"),
|
|
|
|
'type': "info",
|
|
|
|
'priority': 1,
|
|
|
|
'content': content,
|
|
|
|
})
|
2024-04-07 10:38:41 +00:00
|
|
|
elif not self.final or tournament.final:
|
2024-03-30 21:23:34 +00:00
|
|
|
text = _("<p>The tournament {tournament} is ended. You can check the results on the "
|
|
|
|
"<a href='{url}'>tournament page</a>.</p>")
|
2024-04-07 10:38:41 +00:00
|
|
|
url = reverse_lazy("participation:tournament_detail", args=(tournament.pk,))
|
|
|
|
content = format_lazy(text, tournament=tournament.name, url=url)
|
2024-03-30 21:23:34 +00:00
|
|
|
informations.append({
|
|
|
|
'title': _("Tournament ended"),
|
|
|
|
'type': "info",
|
|
|
|
'priority': 1,
|
|
|
|
'content': content,
|
|
|
|
})
|
2024-02-11 22:31:24 +00:00
|
|
|
|
|
|
|
return informations
|
|
|
|
|
2020-12-27 10:49:54 +00:00
|
|
|
class Meta:
|
|
|
|
verbose_name = _("participation")
|
|
|
|
verbose_name_plural = _("participations")
|
2023-04-11 20:41:52 +00:00
|
|
|
ordering = ('valid', 'team__trigram',)
|
2020-12-27 10:49:54 +00:00
|
|
|
|
|
|
|
|
2020-12-28 16:49:59 +00:00
|
|
|
class Pool(models.Model):
|
|
|
|
tournament = models.ForeignKey(
|
|
|
|
Tournament,
|
|
|
|
on_delete=models.CASCADE,
|
|
|
|
related_name="pools",
|
|
|
|
verbose_name=_("tournament"),
|
|
|
|
)
|
|
|
|
|
|
|
|
round = models.PositiveSmallIntegerField(
|
|
|
|
verbose_name=_("round"),
|
2021-01-13 16:00:50 +00:00
|
|
|
choices=[
|
|
|
|
(1, format_lazy(_("Round {round}"), round=1)),
|
|
|
|
(2, format_lazy(_("Round {round}"), round=2)),
|
2024-06-07 12:18:25 +00:00
|
|
|
] + ([] if settings.NB_ROUNDS == 2 else [(3, format_lazy(_("Round {round}"), round=3))]),
|
2020-12-28 16:49:59 +00:00
|
|
|
)
|
|
|
|
|
2023-03-31 15:23:40 +00:00
|
|
|
letter = models.PositiveSmallIntegerField(
|
2024-04-18 12:53:58 +00:00
|
|
|
verbose_name=_('letter'),
|
2023-03-31 15:23:40 +00:00
|
|
|
choices=[
|
|
|
|
(1, 'A'),
|
|
|
|
(2, 'B'),
|
|
|
|
(3, 'C'),
|
|
|
|
(4, 'D'),
|
|
|
|
],
|
2024-04-18 12:53:58 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
room = models.PositiveSmallIntegerField(
|
|
|
|
verbose_name=_("room"),
|
|
|
|
choices=[
|
|
|
|
(1, _("Room 1")),
|
|
|
|
(2, _("Room 2")),
|
|
|
|
],
|
|
|
|
default=1,
|
|
|
|
help_text=_("For 5-teams pools only"),
|
2023-03-31 15:23:40 +00:00
|
|
|
)
|
|
|
|
|
2020-12-28 16:49:59 +00:00
|
|
|
participations = models.ManyToManyField(
|
|
|
|
Participation,
|
|
|
|
related_name="pools",
|
|
|
|
verbose_name=_("participations"),
|
|
|
|
)
|
|
|
|
|
|
|
|
juries = models.ManyToManyField(
|
|
|
|
VolunteerRegistration,
|
|
|
|
related_name="jury_in",
|
|
|
|
verbose_name=_("juries"),
|
|
|
|
)
|
|
|
|
|
2024-03-24 14:36:51 +00:00
|
|
|
jury_president = models.ForeignKey(
|
|
|
|
VolunteerRegistration,
|
|
|
|
on_delete=models.SET_NULL,
|
|
|
|
null=True,
|
|
|
|
default=None,
|
|
|
|
related_name="pools_presided",
|
|
|
|
verbose_name=_("president of the jury"),
|
|
|
|
)
|
|
|
|
|
2021-01-22 17:25:37 +00:00
|
|
|
bbb_url = models.CharField(
|
|
|
|
max_length=255,
|
2021-01-21 16:55:20 +00:00
|
|
|
blank=True,
|
|
|
|
default="",
|
2021-01-22 17:25:37 +00:00
|
|
|
verbose_name=_("BigBlueButton URL"),
|
|
|
|
help_text=_("The link of the BBB visio for this pool."),
|
2021-01-21 16:55:20 +00:00
|
|
|
)
|
|
|
|
|
2021-04-10 07:59:04 +00:00
|
|
|
results_available = models.BooleanField(
|
|
|
|
default=False,
|
|
|
|
verbose_name=_("results available"),
|
|
|
|
help_text=_("Check this case when results become accessible to teams. "
|
|
|
|
"They stay accessible to you. Only averages are given."),
|
|
|
|
)
|
|
|
|
|
2024-03-29 17:59:37 +00:00
|
|
|
@property
|
|
|
|
def short_name(self):
|
2024-04-18 12:53:58 +00:00
|
|
|
short_name = f"{self.get_letter_display()}{self.round}"
|
|
|
|
if self.participations.count() == 5:
|
|
|
|
short_name += f" — {self.get_room_display()}"
|
|
|
|
return short_name
|
2024-03-29 17:59:37 +00:00
|
|
|
|
2020-12-28 16:49:59 +00:00
|
|
|
@property
|
|
|
|
def solutions(self):
|
2023-05-19 12:44:31 +00:00
|
|
|
return [passage.defended_solution for passage in self.passages.all()]
|
2020-12-28 16:49:59 +00:00
|
|
|
|
2024-06-07 12:18:25 +00:00
|
|
|
@property
|
|
|
|
def coeff(self):
|
|
|
|
return 1 if self.round <= 2 else math.pi - 2
|
|
|
|
|
2021-01-14 16:54:47 +00:00
|
|
|
def average(self, participation):
|
2024-06-07 12:18:25 +00:00
|
|
|
return self.coeff * sum(passage.average(participation) for passage in self.passages.all()) \
|
2022-05-15 14:43:07 +00:00
|
|
|
+ sum(tweak.diff for tweak in participation.tweaks.filter(pool=self).all())
|
2021-01-14 16:54:47 +00:00
|
|
|
|
2023-04-04 13:10:28 +00:00
|
|
|
async def aaverage(self, participation):
|
2024-06-07 12:18:25 +00:00
|
|
|
return self.coeff * sum([passage.average(participation) async for passage in self.passages.all()]) \
|
2023-04-04 13:10:28 +00:00
|
|
|
+ sum([tweak.diff async for tweak in participation.tweaks.filter(pool=self).all()])
|
|
|
|
|
2021-01-13 16:00:50 +00:00
|
|
|
def get_absolute_url(self):
|
|
|
|
return reverse_lazy("participation:pool_detail", args=(self.pk,))
|
|
|
|
|
2024-03-24 14:36:51 +00:00
|
|
|
def validate_constraints(self, exclude=None):
|
|
|
|
if self.jury_president not in self.juries.all():
|
|
|
|
raise ValidationError({'jury_president': _("The president of the jury must be part of the jury.")})
|
|
|
|
return super().validate_constraints()
|
|
|
|
|
2024-03-30 12:41:46 +00:00
|
|
|
def update_spreadsheet(self): # noqa: C901
|
2024-06-07 15:20:06 +00:00
|
|
|
translation.activate(settings.PREFERRED_LANGUAGE_CODE)
|
2024-04-18 12:53:58 +00:00
|
|
|
|
2024-03-30 15:02:12 +00:00
|
|
|
# Create tournament sheet if it does not exist
|
|
|
|
self.tournament.create_spreadsheet()
|
|
|
|
|
2024-03-30 12:41:46 +00:00
|
|
|
gc = gspread.service_account_from_dict(settings.GOOGLE_SERVICE_CLIENT)
|
|
|
|
spreadsheet = gc.open_by_key(self.tournament.notes_sheet_id)
|
|
|
|
worksheets = spreadsheet.worksheets()
|
|
|
|
if f"Poule {self.short_name}" not in [ws.title for ws in worksheets]:
|
2024-04-18 13:41:27 +00:00
|
|
|
worksheet = spreadsheet.add_worksheet(f"Poule {self.short_name}", 100, 26)
|
2024-03-30 12:41:46 +00:00
|
|
|
else:
|
|
|
|
worksheet = spreadsheet.worksheet(f"Poule {self.short_name}")
|
|
|
|
if any(ws.title == "Sheet1" for ws in worksheets):
|
|
|
|
spreadsheet.del_worksheet(spreadsheet.worksheet("Sheet1"))
|
|
|
|
|
|
|
|
pool_size = self.participations.count()
|
2024-04-16 21:58:42 +00:00
|
|
|
passage_width = 6
|
2024-03-30 12:41:46 +00:00
|
|
|
passages = self.passages.all()
|
|
|
|
|
|
|
|
header = [
|
|
|
|
sum(([f"Problème {passage.solution_number}"] + (passage_width - 1) * [""]
|
|
|
|
for passage in passages), start=["Problème", ""]),
|
2024-04-13 18:15:07 +00:00
|
|
|
sum(([f"Défenseur⋅se ({passage.defender.team.trigram})", "",
|
|
|
|
f"Opposant⋅e ({passage.opponent.team.trigram})", "",
|
2024-07-05 09:00:11 +00:00
|
|
|
f"Rapporteur⋅rice ({passage.reviewer.team.trigram})", ""]
|
2024-04-13 18:15:07 +00:00
|
|
|
for passage in passages), start=["Rôle", ""]),
|
2024-03-30 12:41:46 +00:00
|
|
|
sum((["Écrit (/20)", "Oral (/20)", "Écrit (/10)", "Oral (/10)", "Écrit (/10)", "Oral (/10)"]
|
|
|
|
for _passage in passages), start=["Juré⋅e", ""]),
|
|
|
|
]
|
|
|
|
|
2024-03-30 14:55:28 +00:00
|
|
|
notes = [[]] # Begin with empty hidden line to ensure pretty design
|
2024-03-30 12:41:46 +00:00
|
|
|
for jury in self.juries.all():
|
|
|
|
line = [str(jury), jury.id]
|
|
|
|
for passage in passages:
|
|
|
|
note = passage.notes.filter(jury=jury).first()
|
|
|
|
line.extend([note.defender_writing, note.defender_oral, note.opponent_writing, note.opponent_oral,
|
2024-07-05 09:00:11 +00:00
|
|
|
note.reviewer_writing, note.reviewer_oral])
|
2024-03-30 12:41:46 +00:00
|
|
|
notes.append(line)
|
2024-03-30 14:55:28 +00:00
|
|
|
notes.append([]) # Add empty line to ensure pretty design
|
2024-03-30 12:41:46 +00:00
|
|
|
|
|
|
|
def getcol(number: int) -> str:
|
|
|
|
"""
|
|
|
|
Translates the given number to the nth column name
|
|
|
|
"""
|
|
|
|
if number == 0:
|
|
|
|
return ''
|
|
|
|
return getcol((number - 1) // 26) + chr(65 + (number - 1) % 26)
|
|
|
|
|
|
|
|
average = ["Moyenne", ""]
|
2024-04-16 21:58:42 +00:00
|
|
|
coeffs = sum(([1, 1.6 - 0.4 * passage.defender_penalties, 0.9, 2, 0.9, 1] for passage in passages),
|
|
|
|
start=["Coefficient", ""])
|
2024-03-30 12:41:46 +00:00
|
|
|
subtotal = ["Sous-total", ""]
|
2024-04-19 16:30:59 +00:00
|
|
|
footer = [average, coeffs, subtotal, 26 * [""]]
|
2024-03-30 12:41:46 +00:00
|
|
|
|
2024-03-30 14:55:28 +00:00
|
|
|
min_row = 5
|
|
|
|
max_row = min_row + self.juries.count()
|
2024-03-30 12:41:46 +00:00
|
|
|
min_column = 3
|
|
|
|
for i, passage in enumerate(passages):
|
|
|
|
for j, note in enumerate(passage.averages):
|
|
|
|
column = getcol(min_column + i * passage_width + j)
|
2024-03-30 17:28:54 +00:00
|
|
|
average.append(f"=SIERREUR(MOYENNE.SI(${getcol(min_column + i * passage_width)}${min_row - 1}"
|
2024-03-30 12:41:46 +00:00
|
|
|
f":${getcol(min_column + i * passage_width)}{max_row}; \">0\"; "
|
2024-03-30 17:28:54 +00:00
|
|
|
f"{column}${min_row - 1}:{column}{max_row});0)")
|
2024-03-30 12:41:46 +00:00
|
|
|
def_w_col = getcol(min_column + passage_width * i)
|
|
|
|
def_o_col = getcol(min_column + passage_width * i + 1)
|
|
|
|
subtotal.extend([f"={def_w_col}{max_row + 1} * {def_w_col}{max_row + 2}"
|
|
|
|
f" + {def_o_col}{max_row + 1} * {def_o_col}{max_row + 2}", ""])
|
|
|
|
|
|
|
|
opp_w_col = getcol(min_column + passage_width * i + 2)
|
|
|
|
opp_o_col = getcol(min_column + passage_width * i + 3)
|
|
|
|
subtotal.extend([f"={opp_w_col}{max_row + 1} * {opp_w_col}{max_row + 2}"
|
|
|
|
f" + {opp_o_col}{max_row + 1} * {opp_o_col}{max_row + 2}", ""])
|
|
|
|
|
|
|
|
rep_w_col = getcol(min_column + passage_width * i + 4)
|
|
|
|
rep_o_col = getcol(min_column + passage_width * i + 5)
|
|
|
|
subtotal.extend([f"={rep_w_col}{max_row + 1} * {rep_w_col}{max_row + 2}"
|
|
|
|
f" + {rep_o_col}{max_row + 1} * {rep_o_col}{max_row + 2}", ""])
|
|
|
|
|
|
|
|
ranking = [
|
|
|
|
["Équipe", "", "Problème", "Total", "Rang"],
|
|
|
|
]
|
2024-04-18 12:53:58 +00:00
|
|
|
all_passages = Passage.objects.filter(pool__tournament=self.tournament,
|
|
|
|
pool__round=self.round,
|
|
|
|
pool__letter=self.letter).order_by('position', 'pool__room')
|
|
|
|
for i, passage in enumerate(all_passages):
|
2024-03-30 12:41:46 +00:00
|
|
|
participation = passage.defender
|
2024-04-18 12:53:58 +00:00
|
|
|
defender_passage = Passage.objects.get(defender=participation,
|
|
|
|
pool__tournament=self.tournament, pool__round=self.round)
|
|
|
|
defender_row = 5 + defender_passage.pool.juries.count()
|
|
|
|
defender_col = defender_passage.position - 1
|
|
|
|
|
|
|
|
opponent_passage = Passage.objects.get(opponent=participation,
|
|
|
|
pool__tournament=self.tournament, pool__round=self.round)
|
|
|
|
opponent_row = 5 + opponent_passage.pool.juries.count()
|
|
|
|
opponent_col = opponent_passage.position - 1
|
|
|
|
|
2024-07-05 09:00:11 +00:00
|
|
|
reviewer_passage = Passage.objects.get(reviewer=participation,
|
2024-04-18 12:53:58 +00:00
|
|
|
pool__tournament=self.tournament, pool__round=self.round)
|
2024-07-05 09:00:11 +00:00
|
|
|
reviewer_row = 5 + reviewer_passage.pool.juries.count()
|
|
|
|
reviewer_col = reviewer_passage.position - 1
|
2024-04-18 12:53:58 +00:00
|
|
|
|
2024-03-30 12:41:46 +00:00
|
|
|
formula = "="
|
2024-04-18 12:53:58 +00:00
|
|
|
formula += (f"'Poule {defender_passage.pool.short_name}'"
|
|
|
|
f"!{getcol(min_column + defender_col * passage_width)}{defender_row + 3}") # Defender
|
|
|
|
formula += (f" + 'Poule {opponent_passage.pool.short_name}'"
|
|
|
|
f"!{getcol(min_column + opponent_col * passage_width + 2)}{opponent_row + 3}") # Opponent
|
2024-07-05 09:00:11 +00:00
|
|
|
formula += (f" + 'Poule {reviewer_passage.pool.short_name}'"
|
|
|
|
f"!{getcol(min_column + reviewer_col * passage_width + 4)}{reviewer_row + 3}") # reviewer
|
2024-03-30 12:41:46 +00:00
|
|
|
ranking.append([f"{participation.team.name} ({participation.team.trigram})", "",
|
2024-04-18 12:53:58 +00:00
|
|
|
f"='Poule {defender_passage.pool.short_name}'"
|
|
|
|
f"!${getcol(3 + defender_col * passage_width)}$1",
|
|
|
|
formula,
|
|
|
|
f"=RANG(D{max_row + 6 + i}; "
|
2024-03-30 12:41:46 +00:00
|
|
|
f"D${max_row + 6}:D${max_row + 5 + pool_size})"])
|
|
|
|
|
|
|
|
all_values = header + notes + footer + ranking
|
|
|
|
|
2024-04-18 13:41:27 +00:00
|
|
|
worksheet.batch_clear([f"A1:Z{max_row + 5 + pool_size}"])
|
|
|
|
worksheet.update("A1:Z", all_values, raw=False)
|
2024-03-30 12:41:46 +00:00
|
|
|
|
|
|
|
format_requests = []
|
|
|
|
|
|
|
|
# Merge cells
|
2024-03-30 13:21:28 +00:00
|
|
|
merge_cells = ["A1:B1", "A2:B2", "A3:B3"]
|
2024-03-30 12:41:46 +00:00
|
|
|
for i, passage in enumerate(passages):
|
|
|
|
merge_cells.append(f"{getcol(3 + i * passage_width)}1:{getcol(2 + passage_width + i * passage_width)}1")
|
|
|
|
|
|
|
|
merge_cells.append(f"{getcol(3 + i * passage_width)}2:{getcol(4 + i * passage_width)}2")
|
|
|
|
merge_cells.append(f"{getcol(5 + i * passage_width)}2:{getcol(6 + i * passage_width)}2")
|
|
|
|
merge_cells.append(f"{getcol(7 + i * passage_width)}2:{getcol(8 + i * passage_width)}2")
|
|
|
|
|
|
|
|
merge_cells.append(f"{getcol(3 + i * passage_width)}{max_row + 3}"
|
|
|
|
f":{getcol(4 + i * passage_width)}{max_row + 3}")
|
|
|
|
merge_cells.append(f"{getcol(5 + i * passage_width)}{max_row + 3}"
|
|
|
|
f":{getcol(6 + i * passage_width)}{max_row + 3}")
|
|
|
|
merge_cells.append(f"{getcol(7 + i * passage_width)}{max_row + 3}"
|
|
|
|
f":{getcol(8 + i * passage_width)}{max_row + 3}")
|
|
|
|
merge_cells.append(f"A{max_row + 1}:B{max_row + 1}")
|
|
|
|
merge_cells.append(f"A{max_row + 2}:B{max_row + 2}")
|
|
|
|
merge_cells.append(f"A{max_row + 3}:B{max_row + 3}")
|
|
|
|
|
|
|
|
for i in range(pool_size + 1):
|
|
|
|
merge_cells.append(f"A{max_row + 5 + i}:B{max_row + 5 + i}")
|
|
|
|
|
2024-04-18 13:41:27 +00:00
|
|
|
format_requests.append({"unmergeCells": {"range": a1_range_to_grid_range("A1:Z", worksheet.id)}})
|
2024-03-30 12:41:46 +00:00
|
|
|
for name in merge_cells:
|
|
|
|
grid_range = a1_range_to_grid_range(name, worksheet.id)
|
|
|
|
format_requests.append({"mergeCells": {"mergeType": MergeType.merge_all, "range": grid_range}})
|
|
|
|
|
|
|
|
# Make titles bold
|
2024-04-18 13:41:27 +00:00
|
|
|
bold_ranges = [("A1:Z", False), ("A1:Z3", True),
|
2024-03-30 14:55:28 +00:00
|
|
|
(f"A{max_row + 1}:B{max_row + 3}", True), (f"A{max_row + 5}:E{max_row + 5}", True)]
|
|
|
|
for bold_range, bold in bold_ranges:
|
2024-03-30 12:41:46 +00:00
|
|
|
format_requests.append({
|
|
|
|
"repeatCell": {
|
|
|
|
"range": a1_range_to_grid_range(bold_range, worksheet.id),
|
2024-03-30 14:55:28 +00:00
|
|
|
"cell": {"userEnteredFormat": {"textFormat": {"bold": bold}}},
|
2024-03-30 12:41:46 +00:00
|
|
|
"fields": "userEnteredFormat(textFormat)",
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
# Set background color for headers and footers
|
2024-04-18 13:41:27 +00:00
|
|
|
bg_colors = [("A1:Z", (1, 1, 1)),
|
2024-04-18 12:53:58 +00:00
|
|
|
(f"A1:{getcol(2 + passages.count() * passage_width)}3", (0.8, 0.8, 0.8)),
|
2024-03-30 14:55:28 +00:00
|
|
|
(f"A{min_row - 1}:B{max_row}", (0.95, 0.95, 0.95)),
|
2024-03-30 12:41:46 +00:00
|
|
|
(f"A{max_row + 1}:B{max_row + 3}", (0.8, 0.8, 0.8)),
|
2024-04-18 12:53:58 +00:00
|
|
|
(f"C{max_row + 1}:{getcol(2 + passages.count() * passage_width)}{max_row + 3}", (0.9, 0.9, 0.9)),
|
2024-03-30 12:41:46 +00:00
|
|
|
(f"A{max_row + 5}:E{max_row + 5}", (0.8, 0.8, 0.8)),
|
|
|
|
(f"A{max_row + 6}:E{max_row + 5 + pool_size}", (0.9, 0.9, 0.9)),]
|
2024-04-19 16:51:13 +00:00
|
|
|
# Display penalties in red
|
|
|
|
bg_colors += [(f"{getcol(2 + (passage.position - 1) * passage_width + 2)}{max_row + 2}", (1.0, 0.7, 0.7))
|
|
|
|
for passage in self.passages.filter(defender_penalties__gte=1).all()]
|
2024-03-30 12:41:46 +00:00
|
|
|
for bg_range, bg_color in bg_colors:
|
|
|
|
r, g, b = bg_color
|
|
|
|
format_requests.append({
|
|
|
|
"repeatCell": {
|
|
|
|
"range": a1_range_to_grid_range(bg_range, worksheet.id),
|
|
|
|
"cell": {"userEnteredFormat": {"backgroundColor": {"red": r, "green": g, "blue": b}}},
|
|
|
|
"fields": "userEnteredFormat(backgroundColor)",
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
# Freeze 2 first columns
|
|
|
|
format_requests.append({
|
|
|
|
"updateSheetProperties": {
|
|
|
|
"properties": {
|
|
|
|
"sheetId": worksheet.id,
|
|
|
|
"gridProperties": {
|
|
|
|
"frozenRowCount": 0,
|
|
|
|
"frozenColumnCount": 2,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
"fields": "gridProperties/frozenRowCount,gridProperties/frozenColumnCount",
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
# Set the width of the columns
|
2024-03-30 18:15:21 +00:00
|
|
|
column_widths = [("A", 300), ("B", 30)]
|
2024-03-30 12:41:46 +00:00
|
|
|
for passage in passages:
|
|
|
|
column_widths.append((f"{getcol(3 + passage_width * (passage.position - 1))}"
|
|
|
|
f":{getcol(8 + passage_width * (passage.position - 1))}", 75))
|
|
|
|
for column, width in column_widths:
|
|
|
|
grid_range = a1_range_to_grid_range(column, worksheet.id)
|
|
|
|
format_requests.append({
|
|
|
|
"updateDimensionProperties": {
|
|
|
|
"range": {
|
|
|
|
"sheetId": worksheet.id,
|
|
|
|
"dimension": "COLUMNS",
|
|
|
|
"startIndex": grid_range['startColumnIndex'],
|
|
|
|
"endIndex": grid_range['endColumnIndex'],
|
|
|
|
},
|
|
|
|
"properties": {
|
|
|
|
"pixelSize": width,
|
|
|
|
},
|
|
|
|
"fields": "pixelSize",
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2024-03-30 14:55:28 +00:00
|
|
|
# Hide second column (Jury ID) and first and last jury rows
|
|
|
|
hidden_dimensions = [(1, "COLUMNS"), (3, "ROWS"), (max_row - 1, "ROWS")]
|
2024-03-30 12:41:46 +00:00
|
|
|
format_requests.append({
|
|
|
|
"updateDimensionProperties": {
|
|
|
|
"range": {
|
|
|
|
"sheetId": worksheet.id,
|
2024-03-30 14:55:28 +00:00
|
|
|
"dimension": "ROWS",
|
|
|
|
"startIndex": 0,
|
|
|
|
"endIndex": 1000,
|
2024-03-30 12:41:46 +00:00
|
|
|
},
|
|
|
|
"properties": {
|
2024-03-30 14:55:28 +00:00
|
|
|
"hiddenByUser": False,
|
2024-03-30 12:41:46 +00:00
|
|
|
},
|
|
|
|
"fields": "hiddenByUser",
|
|
|
|
}
|
|
|
|
})
|
2024-03-30 14:55:28 +00:00
|
|
|
for dimension_id, dimension_type in hidden_dimensions:
|
|
|
|
format_requests.append({
|
|
|
|
"updateDimensionProperties": {
|
|
|
|
"range": {
|
|
|
|
"sheetId": worksheet.id,
|
|
|
|
"dimension": dimension_type,
|
|
|
|
"startIndex": dimension_id,
|
|
|
|
"endIndex": dimension_id + 1,
|
|
|
|
},
|
|
|
|
"properties": {
|
|
|
|
"hiddenByUser": True,
|
|
|
|
},
|
|
|
|
"fields": "hiddenByUser",
|
|
|
|
}
|
|
|
|
})
|
2024-03-30 12:41:46 +00:00
|
|
|
|
|
|
|
# Define borders
|
2024-04-18 13:41:27 +00:00
|
|
|
border_ranges = [("A1:Z", "0000"),
|
2024-04-18 12:53:58 +00:00
|
|
|
(f"A1:{getcol(2 + passages.count() * passage_width)}{max_row + 3}", "1111"),
|
2024-03-30 12:41:46 +00:00
|
|
|
(f"A{max_row + 5}:E{max_row + pool_size + 5}", "1111"),
|
|
|
|
(f"A1:B{max_row + 3}", "1113"),
|
2024-04-18 12:53:58 +00:00
|
|
|
(f"C1:{getcol(2 + (passages.count() - 1) * passage_width)}1", "1113")]
|
|
|
|
for i in range(passages.count() - 1):
|
2024-03-30 14:55:28 +00:00
|
|
|
border_ranges.append((f"{getcol(1 + (i + 1) * passage_width)}2"
|
|
|
|
f":{getcol(2 + (i + 1) * passage_width)}2", "1113"))
|
|
|
|
border_ranges.append((f"{getcol(2 + (i + 1) * passage_width)}3"
|
|
|
|
f":{getcol(2 + (i + 1) * passage_width)}{max_row + 2}", "1113"))
|
|
|
|
border_ranges.append((f"{getcol(1 + (i + 1) * passage_width)}{max_row + 3}"
|
2024-03-30 12:41:46 +00:00
|
|
|
f":{getcol(2 + (i + 1) * passage_width)}{max_row + 3}", "1113"))
|
|
|
|
sides_names = ['top', 'bottom', 'left', 'right']
|
|
|
|
styles = ["NONE", "SOLID", "SOLID_MEDIUM", "SOLID_THICK", "DOUBLE"]
|
|
|
|
for border_range, sides in border_ranges:
|
|
|
|
borders = {}
|
|
|
|
for side_name, side in zip(sides_names, sides):
|
|
|
|
borders[side_name] = {"style": styles[int(side)]}
|
|
|
|
format_requests.append({
|
|
|
|
"repeatCell": {
|
|
|
|
"range": a1_range_to_grid_range(border_range, worksheet.id),
|
|
|
|
"cell": {
|
|
|
|
"userEnteredFormat": {
|
|
|
|
"borders": borders,
|
|
|
|
"horizontalAlignment": "CENTER",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
"fields": "userEnteredFormat(borders,horizontalAlignment)",
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2024-03-30 16:07:53 +00:00
|
|
|
# Add range conditions
|
2024-04-18 12:53:58 +00:00
|
|
|
for i in range(passages.count()):
|
2024-03-30 16:07:53 +00:00
|
|
|
for j in range(passage_width):
|
|
|
|
column = getcol(min_column + i * passage_width + j)
|
2024-04-16 21:58:42 +00:00
|
|
|
min_note = 0
|
|
|
|
max_note = 20 if j < 2 else 10
|
2024-03-30 16:07:53 +00:00
|
|
|
format_requests.append({
|
|
|
|
"setDataValidation": {
|
|
|
|
"range": a1_range_to_grid_range(f"{column}{min_row - 1}:{column}{max_row}", worksheet.id),
|
|
|
|
"rule": {
|
|
|
|
"condition": {
|
|
|
|
"type": "CUSTOM_FORMULA",
|
|
|
|
"values": [{"userEnteredValue": f'=ET(REGEXMATCH(TO_TEXT({column}4); "^-?[0-9]+$"); '
|
|
|
|
f'{column}4>={min_note}; {column}4<={max_note})'},],
|
|
|
|
},
|
|
|
|
"inputMessage": f"La saisie doit être un entier valide "
|
|
|
|
f"compris entre {min_note} et {max_note}.",
|
|
|
|
"strict": True,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2024-03-30 16:23:31 +00:00
|
|
|
# Set number format, display only one decimal
|
2024-04-18 12:53:58 +00:00
|
|
|
number_format_ranges = [f"C{max_row + 1}:{getcol(2 + passage_width * passages.count())}{max_row + 1}",
|
|
|
|
f"C{max_row + 3}:{getcol(2 + passage_width * passages.count())}{max_row + 3}",
|
|
|
|
f"D{max_row + 6}:D{max_row + 5 + passages.count()}",]
|
2024-03-30 16:23:31 +00:00
|
|
|
for number_format_range in number_format_ranges:
|
|
|
|
format_requests.append({
|
|
|
|
"repeatCell": {
|
|
|
|
"range": a1_range_to_grid_range(number_format_range, worksheet.id),
|
|
|
|
"cell": {"userEnteredFormat": {"numberFormat": {"type": "NUMBER", "pattern": "0.0"}}},
|
|
|
|
"fields": "userEnteredFormat.numberFormat",
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2024-03-30 12:41:46 +00:00
|
|
|
# Remove old protected ranges
|
|
|
|
for protected_range in spreadsheet.list_protected_ranges(worksheet.id):
|
|
|
|
format_requests.append({
|
|
|
|
"deleteProtectedRange": {
|
|
|
|
"protectedRangeId": protected_range["protectedRangeId"],
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
# Protect the header, the juries list, the footer and the ranking
|
2024-04-18 13:41:27 +00:00
|
|
|
protected_ranges = ["A1:Z4",
|
2024-03-30 12:41:46 +00:00
|
|
|
f"A{min_row}:B{max_row}",
|
2024-04-18 13:41:27 +00:00
|
|
|
f"A{max_row}:Z{max_row + 5 + pool_size}"]
|
2024-03-30 12:41:46 +00:00
|
|
|
for protected_range in protected_ranges:
|
|
|
|
format_requests.append({
|
|
|
|
"addProtectedRange": {
|
|
|
|
"protectedRange": {
|
|
|
|
"range": a1_range_to_grid_range(protected_range, worksheet.id),
|
|
|
|
"description": "Structure du tableur à ne pas modifier "
|
|
|
|
"pour une meilleure prise en charge automatisée",
|
|
|
|
"warningOnly": True,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
body = {"requests": format_requests}
|
|
|
|
worksheet.client.batch_update(spreadsheet.id, body)
|
|
|
|
|
2024-03-30 14:55:28 +00:00
|
|
|
def update_juries_lines_spreadsheet(self):
|
2024-06-07 15:20:06 +00:00
|
|
|
translation.activate(settings.PREFERRED_LANGUAGE_CODE)
|
2024-04-20 14:16:50 +00:00
|
|
|
|
2024-03-30 14:55:28 +00:00
|
|
|
gc = gspread.service_account_from_dict(settings.GOOGLE_SERVICE_CLIENT)
|
|
|
|
spreadsheet = gc.open_by_key(self.tournament.notes_sheet_id)
|
|
|
|
worksheet = spreadsheet.worksheet(f"Poule {self.short_name}")
|
|
|
|
|
|
|
|
average_cell = worksheet.find("Moyenne")
|
|
|
|
min_row = 5
|
|
|
|
max_row = average_cell.row - 1
|
|
|
|
juries_visible = worksheet.get(f"A{min_row}:B{max_row}")
|
|
|
|
juries_visible = [t for t in juries_visible if t and len(t) == 2]
|
2024-03-31 13:34:21 +00:00
|
|
|
for i, (jury_name, jury_id) in enumerate(juries_visible):
|
2024-03-30 14:55:28 +00:00
|
|
|
if not jury_id.isnumeric() or int(jury_id) not in self.juries.values_list("id", flat=True):
|
2024-03-31 13:34:21 +00:00
|
|
|
print(f"Warning: {jury_name} ({jury_id}) appears on the sheet but is not part of the jury.")
|
2024-03-30 14:55:28 +00:00
|
|
|
|
|
|
|
for jury in self.juries.all():
|
|
|
|
if str(jury.id) not in list(map(lambda x: x[1], juries_visible)):
|
|
|
|
worksheet.insert_row([str(jury), jury.id], max_row)
|
|
|
|
max_row += 1
|
|
|
|
|
2024-03-30 15:36:57 +00:00
|
|
|
def parse_spreadsheet(self):
|
2024-06-07 15:20:06 +00:00
|
|
|
translation.activate(settings.PREFERRED_LANGUAGE_CODE)
|
2024-04-20 19:38:33 +00:00
|
|
|
|
2024-03-30 15:36:57 +00:00
|
|
|
gc = gspread.service_account_from_dict(settings.GOOGLE_SERVICE_CLIENT)
|
|
|
|
self.tournament.create_spreadsheet()
|
|
|
|
spreadsheet = gc.open_by_key(self.tournament.notes_sheet_id)
|
|
|
|
worksheet = spreadsheet.worksheet(f"Poule {self.short_name}")
|
|
|
|
|
|
|
|
average_cell = worksheet.find("Moyenne")
|
|
|
|
min_row = 5
|
|
|
|
max_row = average_cell.row - 2
|
2024-04-18 13:41:27 +00:00
|
|
|
data = worksheet.get_values(f"A{min_row}:Z{max_row}")
|
2024-03-30 15:36:57 +00:00
|
|
|
if not data or not data[0]:
|
|
|
|
return
|
|
|
|
|
2024-04-16 21:58:42 +00:00
|
|
|
passage_width = 6
|
2024-03-30 15:36:57 +00:00
|
|
|
for line in data:
|
|
|
|
jury_name = line[0]
|
|
|
|
jury_id = line[1]
|
|
|
|
if not jury_id.isnumeric() or int(jury_id) not in self.juries.values_list("id", flat=True):
|
|
|
|
print(format_lazy(_("The jury {jury} is not part of the jury for this pool."), jury=jury_name))
|
|
|
|
continue
|
|
|
|
|
|
|
|
jury = self.juries.get(id=jury_id)
|
|
|
|
for i, passage in enumerate(self.passages.all()):
|
|
|
|
note = passage.notes.get(jury=jury)
|
|
|
|
note_line = line[2 + i * passage_width:2 + (i + 1) * passage_width]
|
2024-04-06 08:42:55 +00:00
|
|
|
if not note_line: # There is no note
|
|
|
|
continue
|
2024-03-30 15:36:57 +00:00
|
|
|
note.set_all(*note_line)
|
|
|
|
note.save()
|
|
|
|
|
2020-12-28 18:19:01 +00:00
|
|
|
def __str__(self):
|
2024-04-18 13:05:10 +00:00
|
|
|
return _("Pool {code} for tournament {tournament} with teams {teams}")\
|
|
|
|
.format(code=self.short_name,
|
2021-01-13 15:22:26 +00:00
|
|
|
tournament=str(self.tournament),
|
|
|
|
teams=", ".join(participation.team.trigram for participation in self.participations.all()))
|
2020-12-28 18:19:01 +00:00
|
|
|
|
2020-12-28 16:49:59 +00:00
|
|
|
class Meta:
|
|
|
|
verbose_name = _("pool")
|
|
|
|
verbose_name_plural = _("pools")
|
2024-04-18 12:53:58 +00:00
|
|
|
ordering = ('round', 'letter', 'room',)
|
2020-12-28 16:49:59 +00:00
|
|
|
|
|
|
|
|
2021-01-14 13:22:45 +00:00
|
|
|
class Passage(models.Model):
|
|
|
|
pool = models.ForeignKey(
|
|
|
|
Pool,
|
|
|
|
on_delete=models.CASCADE,
|
|
|
|
verbose_name=_("pool"),
|
|
|
|
related_name="passages",
|
|
|
|
)
|
|
|
|
|
2023-04-06 22:05:56 +00:00
|
|
|
position = models.PositiveSmallIntegerField(
|
|
|
|
verbose_name=_("position"),
|
|
|
|
choices=zip(range(1, 6), range(1, 6)),
|
|
|
|
default=1,
|
|
|
|
validators=[MinValueValidator(1), MaxValueValidator(5)],
|
|
|
|
)
|
|
|
|
|
2021-01-14 14:59:11 +00:00
|
|
|
solution_number = models.PositiveSmallIntegerField(
|
|
|
|
verbose_name=_("defended solution"),
|
|
|
|
choices=[
|
2023-04-04 09:56:13 +00:00
|
|
|
(i, format_lazy(_("Problem #{problem}"), problem=i)) for i in range(1, len(settings.PROBLEMS) + 1)
|
2021-01-14 14:59:11 +00:00
|
|
|
],
|
|
|
|
)
|
|
|
|
|
2021-01-14 13:22:45 +00:00
|
|
|
defender = models.ForeignKey(
|
|
|
|
Participation,
|
|
|
|
on_delete=models.PROTECT,
|
|
|
|
verbose_name=_("defender"),
|
|
|
|
related_name="+",
|
|
|
|
)
|
|
|
|
|
|
|
|
opponent = models.ForeignKey(
|
|
|
|
Participation,
|
|
|
|
on_delete=models.PROTECT,
|
|
|
|
verbose_name=_("opponent"),
|
|
|
|
related_name="+",
|
|
|
|
)
|
|
|
|
|
2024-07-05 09:00:11 +00:00
|
|
|
reviewer = models.ForeignKey(
|
2021-01-14 13:22:45 +00:00
|
|
|
Participation,
|
|
|
|
on_delete=models.PROTECT,
|
2024-07-05 09:00:11 +00:00
|
|
|
verbose_name=_("reviewer"),
|
2021-01-14 13:22:45 +00:00
|
|
|
related_name="+",
|
|
|
|
)
|
|
|
|
|
2024-07-05 09:47:19 +00:00
|
|
|
observer = models.ForeignKey(
|
|
|
|
Participation,
|
|
|
|
on_delete=models.SET_NULL,
|
|
|
|
verbose_name=_("observer"),
|
|
|
|
related_name="+",
|
|
|
|
null=True,
|
|
|
|
blank=True,
|
|
|
|
default=None,
|
|
|
|
)
|
|
|
|
|
2021-04-03 19:59:06 +00:00
|
|
|
defender_penalties = models.PositiveSmallIntegerField(
|
|
|
|
verbose_name=_("penalties"),
|
|
|
|
default=0,
|
|
|
|
help_text=_("Number of penalties for the defender. "
|
|
|
|
"The defender will loose a 0.5 coefficient per penalty."),
|
|
|
|
)
|
|
|
|
|
2021-01-14 14:59:11 +00:00
|
|
|
@property
|
|
|
|
def defended_solution(self) -> "Solution":
|
|
|
|
return Solution.objects.get(
|
|
|
|
participation=self.defender,
|
|
|
|
problem=self.solution_number,
|
|
|
|
final_solution=self.pool.tournament.final)
|
|
|
|
|
2021-04-03 19:59:06 +00:00
|
|
|
def avg(self, iterator) -> float:
|
2021-01-14 17:21:22 +00:00
|
|
|
items = [i for i in iterator if i]
|
|
|
|
return sum(items) / len(items) if items else 0
|
2021-01-14 16:54:47 +00:00
|
|
|
|
|
|
|
@property
|
2021-04-03 19:59:06 +00:00
|
|
|
def average_defender_writing(self) -> float:
|
2021-01-14 16:54:47 +00:00
|
|
|
return self.avg(note.defender_writing for note in self.notes.all())
|
|
|
|
|
|
|
|
@property
|
2021-04-03 19:59:06 +00:00
|
|
|
def average_defender_oral(self) -> float:
|
2021-01-14 16:54:47 +00:00
|
|
|
return self.avg(note.defender_oral for note in self.notes.all())
|
|
|
|
|
|
|
|
@property
|
2021-04-03 19:59:06 +00:00
|
|
|
def average_defender(self) -> float:
|
2024-07-05 09:47:19 +00:00
|
|
|
writing_coeff = 1 if settings.TFJM_APP == "TFJM" else 2
|
|
|
|
oral_coeff = 1.6 if settings.TFJM_APP == "TFJM" else 3
|
|
|
|
oral_coeff *= 1 - 0.25 * self.defender_penalties
|
|
|
|
return writing_coeff * self.average_defender_writing + oral_coeff * self.average_defender_oral
|
2021-01-14 16:54:47 +00:00
|
|
|
|
|
|
|
@property
|
2021-04-03 19:59:06 +00:00
|
|
|
def average_opponent_writing(self) -> float:
|
2021-01-14 16:54:47 +00:00
|
|
|
return self.avg(note.opponent_writing for note in self.notes.all())
|
|
|
|
|
|
|
|
@property
|
2021-04-03 19:59:06 +00:00
|
|
|
def average_opponent_oral(self) -> float:
|
2021-01-14 16:54:47 +00:00
|
|
|
return self.avg(note.opponent_oral for note in self.notes.all())
|
|
|
|
|
|
|
|
@property
|
2021-04-03 19:59:06 +00:00
|
|
|
def average_opponent(self) -> float:
|
2024-07-05 09:47:19 +00:00
|
|
|
writing_coeff = 0.9 if not self.observer else 0.6
|
|
|
|
oral_coeff = 2
|
|
|
|
return writing_coeff * self.average_opponent_writing + oral_coeff * self.average_opponent_oral
|
2021-01-14 16:54:47 +00:00
|
|
|
|
|
|
|
@property
|
2024-07-05 09:00:11 +00:00
|
|
|
def average_reviewer_writing(self) -> float:
|
|
|
|
return self.avg(note.reviewer_writing for note in self.notes.all())
|
2021-01-14 16:54:47 +00:00
|
|
|
|
|
|
|
@property
|
2024-07-05 09:00:11 +00:00
|
|
|
def average_reviewer_oral(self) -> float:
|
|
|
|
return self.avg(note.reviewer_oral for note in self.notes.all())
|
2021-01-14 16:54:47 +00:00
|
|
|
|
|
|
|
@property
|
2024-07-05 09:00:11 +00:00
|
|
|
def average_reviewer(self) -> float:
|
2024-07-05 09:47:19 +00:00
|
|
|
writing_coeff = 0.9 if not self.observer else 0.6
|
|
|
|
oral_coeff = 1 if settings.TFJM_APP == "TFJM" else 1.2
|
|
|
|
return writing_coeff * self.average_reviewer_writing + oral_coeff * self.average_reviewer_oral
|
|
|
|
|
|
|
|
@property
|
|
|
|
def average_observer_writing(self) -> float:
|
|
|
|
return self.avg(note.observer_writing for note in self.notes.all())
|
|
|
|
|
|
|
|
@property
|
|
|
|
def average_observer_oral(self) -> float:
|
|
|
|
return self.avg(note.observer_oral for note in self.notes.all())
|
|
|
|
|
|
|
|
@property
|
|
|
|
def average_observer(self) -> float:
|
|
|
|
return 0.6 * self.average_observer_writing + 0.5 * self.average_observer_oral
|
2021-01-14 16:54:47 +00:00
|
|
|
|
2023-04-07 19:47:06 +00:00
|
|
|
@property
|
|
|
|
def averages(self):
|
|
|
|
yield self.average_defender_writing
|
|
|
|
yield self.average_defender_oral
|
|
|
|
yield self.average_opponent_writing
|
|
|
|
yield self.average_opponent_oral
|
2024-07-05 09:00:11 +00:00
|
|
|
yield self.average_reviewer_writing
|
|
|
|
yield self.average_reviewer_oral
|
2024-07-05 09:47:19 +00:00
|
|
|
if self.observer:
|
|
|
|
yield self.average_observer_writing
|
|
|
|
yield self.average_observer_oral
|
2023-04-07 19:47:06 +00:00
|
|
|
|
2021-01-14 16:54:47 +00:00
|
|
|
def average(self, participation):
|
2024-07-05 09:47:19 +00:00
|
|
|
avg = self.average_defender if participation == self.defender else self.average_opponent \
|
|
|
|
if participation == self.opponent else self.average_reviewer if participation == self.reviewer \
|
|
|
|
else self.average_observer if participation == self.observer else 0
|
|
|
|
|
|
|
|
if self.pool.round == 3 and settings.TFJM_APP == "ETEAM":
|
|
|
|
avg *= math.pi - 2
|
|
|
|
|
|
|
|
return avg
|
2021-01-14 16:54:47 +00:00
|
|
|
|
2021-01-14 14:59:11 +00:00
|
|
|
def get_absolute_url(self):
|
|
|
|
return reverse_lazy("participation:passage_detail", args=(self.pk,))
|
|
|
|
|
2021-01-14 13:22:45 +00:00
|
|
|
def clean(self):
|
|
|
|
if self.defender not in self.pool.participations.all():
|
|
|
|
raise ValidationError(_("Team {trigram} is not registered in the pool.")
|
|
|
|
.format(trigram=self.defender.team.trigram))
|
|
|
|
if self.opponent not in self.pool.participations.all():
|
|
|
|
raise ValidationError(_("Team {trigram} is not registered in the pool.")
|
|
|
|
.format(trigram=self.opponent.team.trigram))
|
2024-07-05 09:00:11 +00:00
|
|
|
if self.reviewer not in self.pool.participations.all():
|
2021-01-14 13:22:45 +00:00
|
|
|
raise ValidationError(_("Team {trigram} is not registered in the pool.")
|
2024-07-05 09:00:11 +00:00
|
|
|
.format(trigram=self.reviewer.team.trigram))
|
2024-07-05 09:47:19 +00:00
|
|
|
if self.observer and self.observer not in self.pool.participations.all():
|
|
|
|
raise ValidationError(_("Team {trigram} is not registered in the pool.")
|
|
|
|
.format(trigram=self.observer.team.trigram))
|
2021-01-14 13:22:45 +00:00
|
|
|
return super().clean()
|
|
|
|
|
2021-01-14 14:59:11 +00:00
|
|
|
def __str__(self):
|
|
|
|
return _("Passage of {defender} for problem {problem}")\
|
|
|
|
.format(defender=self.defender.team, problem=self.solution_number)
|
|
|
|
|
2021-01-14 13:22:45 +00:00
|
|
|
class Meta:
|
|
|
|
verbose_name = _("passage")
|
|
|
|
verbose_name_plural = _("passages")
|
2023-04-06 22:05:56 +00:00
|
|
|
ordering = ('pool', 'position',)
|
2021-01-14 13:22:45 +00:00
|
|
|
|
|
|
|
|
2022-05-15 14:43:07 +00:00
|
|
|
class Tweak(models.Model):
|
|
|
|
pool = models.ForeignKey(
|
|
|
|
Pool,
|
|
|
|
on_delete=models.CASCADE,
|
|
|
|
verbose_name=_("passage"),
|
|
|
|
)
|
|
|
|
|
|
|
|
participation = models.ForeignKey(
|
|
|
|
Participation,
|
|
|
|
on_delete=models.CASCADE,
|
|
|
|
verbose_name=_("participation"),
|
|
|
|
related_name='tweaks',
|
|
|
|
)
|
|
|
|
|
|
|
|
diff = models.IntegerField(
|
|
|
|
verbose_name=_("difference"),
|
|
|
|
help_text=_("Score to add/remove on the final score"),
|
|
|
|
)
|
|
|
|
|
2022-11-08 14:52:44 +00:00
|
|
|
def __str__(self):
|
|
|
|
return f"Tweak for {self.participation.team} of {self.diff} points"
|
|
|
|
|
2022-05-15 14:43:07 +00:00
|
|
|
class Meta:
|
|
|
|
verbose_name = _("tweak")
|
|
|
|
verbose_name_plural = _("tweaks")
|
|
|
|
|
|
|
|
|
2021-01-12 16:51:55 +00:00
|
|
|
def get_solution_filename(instance, filename):
|
|
|
|
return f"solutions/{instance.participation.team.trigram}_{instance.problem}" \
|
2024-04-07 10:54:16 +00:00
|
|
|
+ ("_final" if instance.final_solution else "")
|
2021-01-12 16:51:55 +00:00
|
|
|
|
|
|
|
|
2021-01-14 16:26:08 +00:00
|
|
|
def get_synthesis_filename(instance, filename):
|
|
|
|
return f"syntheses/{instance.participation.team.trigram}_{instance.type}_{instance.passage.pk}"
|
2021-01-12 16:51:55 +00:00
|
|
|
|
|
|
|
|
2020-12-28 12:47:05 +00:00
|
|
|
class Solution(models.Model):
|
|
|
|
participation = models.ForeignKey(
|
|
|
|
Participation,
|
|
|
|
on_delete=models.CASCADE,
|
|
|
|
verbose_name=_("participation"),
|
|
|
|
related_name="solutions",
|
2020-12-27 10:49:54 +00:00
|
|
|
)
|
|
|
|
|
2020-12-28 12:47:05 +00:00
|
|
|
problem = models.PositiveSmallIntegerField(
|
|
|
|
verbose_name=_("problem"),
|
2021-01-12 17:02:00 +00:00
|
|
|
choices=[
|
2023-04-04 09:56:13 +00:00
|
|
|
(i, format_lazy(_("Problem #{problem}"), problem=i)) for i in range(1, len(settings.PROBLEMS) + 1)
|
2021-01-12 17:02:00 +00:00
|
|
|
],
|
2020-12-27 10:49:54 +00:00
|
|
|
)
|
|
|
|
|
2020-12-28 12:47:05 +00:00
|
|
|
final_solution = models.BooleanField(
|
|
|
|
verbose_name=_("solution for the final tournament"),
|
|
|
|
default=False,
|
|
|
|
)
|
2020-12-27 10:49:54 +00:00
|
|
|
|
2020-12-28 12:47:05 +00:00
|
|
|
file = models.FileField(
|
|
|
|
verbose_name=_("file"),
|
2021-01-12 16:51:55 +00:00
|
|
|
upload_to=get_solution_filename,
|
2020-12-28 12:47:05 +00:00
|
|
|
unique=True,
|
|
|
|
)
|
2020-12-27 10:49:54 +00:00
|
|
|
|
2024-03-24 16:42:09 +00:00
|
|
|
@property
|
|
|
|
def tournament(self):
|
|
|
|
return Tournament.final_tournament() if self.final_solution else self.participation.tournament
|
|
|
|
|
2020-12-28 18:19:01 +00:00
|
|
|
def __str__(self):
|
2021-01-12 16:51:55 +00:00
|
|
|
return _("Solution of team {team} for problem {problem}")\
|
2021-04-29 13:46:38 +00:00
|
|
|
.format(team=self.participation.team.name, problem=self.problem)\
|
2021-05-11 14:56:44 +00:00
|
|
|
+ (" " + str(_("for final")) if self.final_solution else "")
|
2020-12-28 18:19:01 +00:00
|
|
|
|
2020-12-27 10:49:54 +00:00
|
|
|
class Meta:
|
2020-12-28 12:47:05 +00:00
|
|
|
verbose_name = _("solution")
|
|
|
|
verbose_name_plural = _("solutions")
|
2020-12-28 17:52:50 +00:00
|
|
|
unique_together = (('participation', 'problem', 'final_solution', ), )
|
2021-04-29 13:46:38 +00:00
|
|
|
ordering = ('participation__team__trigram', 'final_solution', 'problem',)
|
2020-12-27 10:49:54 +00:00
|
|
|
|
|
|
|
|
2020-12-28 12:47:05 +00:00
|
|
|
class Synthesis(models.Model):
|
2020-12-27 10:49:54 +00:00
|
|
|
participation = models.ForeignKey(
|
|
|
|
Participation,
|
|
|
|
on_delete=models.CASCADE,
|
|
|
|
verbose_name=_("participation"),
|
|
|
|
)
|
|
|
|
|
2021-01-14 13:22:45 +00:00
|
|
|
passage = models.ForeignKey(
|
|
|
|
Passage,
|
2020-12-28 12:47:05 +00:00
|
|
|
on_delete=models.CASCADE,
|
2020-12-28 16:49:59 +00:00
|
|
|
related_name="syntheses",
|
2021-01-14 13:22:45 +00:00
|
|
|
verbose_name=_("passage"),
|
2020-12-27 10:49:54 +00:00
|
|
|
)
|
|
|
|
|
2020-12-28 12:47:05 +00:00
|
|
|
type = models.PositiveSmallIntegerField(
|
|
|
|
choices=[
|
|
|
|
(1, _("opponent"), ),
|
2024-07-05 09:00:11 +00:00
|
|
|
(2, _("reviewer"), ),
|
2024-07-05 09:47:19 +00:00
|
|
|
(3, _("observer"), ),
|
2020-12-28 12:47:05 +00:00
|
|
|
]
|
2020-12-27 10:49:54 +00:00
|
|
|
)
|
|
|
|
|
2020-12-28 12:47:05 +00:00
|
|
|
file = models.FileField(
|
|
|
|
verbose_name=_("file"),
|
2021-01-14 16:26:08 +00:00
|
|
|
upload_to=get_synthesis_filename,
|
2020-12-28 12:47:05 +00:00
|
|
|
unique=True,
|
2020-12-27 10:49:54 +00:00
|
|
|
)
|
|
|
|
|
2021-01-14 16:26:08 +00:00
|
|
|
def __str__(self):
|
2021-04-10 08:02:49 +00:00
|
|
|
return _("Synthesis of {team} as {type} for problem {problem} of {defender}").format(
|
|
|
|
team=self.participation.team.trigram,
|
|
|
|
type=self.get_type_display(),
|
|
|
|
problem=self.passage.solution_number,
|
|
|
|
defender=self.passage.defender.team.trigram,
|
|
|
|
)
|
2021-01-14 16:26:08 +00:00
|
|
|
|
2020-12-27 10:49:54 +00:00
|
|
|
class Meta:
|
2020-12-28 12:47:05 +00:00
|
|
|
verbose_name = _("synthesis")
|
|
|
|
verbose_name_plural = _("syntheses")
|
2021-01-14 13:22:45 +00:00
|
|
|
unique_together = (('participation', 'passage', 'type', ), )
|
2021-04-13 08:05:00 +00:00
|
|
|
ordering = ('passage__pool__round', 'type',)
|
2021-01-14 16:54:47 +00:00
|
|
|
|
|
|
|
|
|
|
|
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"),
|
2024-03-24 18:19:55 +00:00
|
|
|
choices=[(i, i) for i in range(0, 21)],
|
2021-01-14 16:54:47 +00:00
|
|
|
default=0,
|
|
|
|
)
|
|
|
|
|
|
|
|
opponent_writing = models.PositiveSmallIntegerField(
|
|
|
|
verbose_name=_("opponent writing note"),
|
2024-03-24 18:19:55 +00:00
|
|
|
choices=[(i, i) for i in range(0, 11)],
|
2021-01-14 16:54:47 +00:00
|
|
|
default=0,
|
|
|
|
)
|
|
|
|
|
|
|
|
opponent_oral = models.PositiveSmallIntegerField(
|
|
|
|
verbose_name=_("opponent oral note"),
|
|
|
|
choices=[(i, i) for i in range(0, 11)],
|
|
|
|
default=0,
|
|
|
|
)
|
|
|
|
|
2024-07-05 09:00:11 +00:00
|
|
|
reviewer_writing = models.PositiveSmallIntegerField(
|
|
|
|
verbose_name=_("reviewer writing note"),
|
2024-03-24 18:19:55 +00:00
|
|
|
choices=[(i, i) for i in range(0, 11)],
|
2021-01-14 16:54:47 +00:00
|
|
|
default=0,
|
|
|
|
)
|
|
|
|
|
2024-07-05 09:00:11 +00:00
|
|
|
reviewer_oral = models.PositiveSmallIntegerField(
|
|
|
|
verbose_name=_("reviewer oral note"),
|
2021-01-14 16:54:47 +00:00
|
|
|
choices=[(i, i) for i in range(0, 11)],
|
|
|
|
default=0,
|
|
|
|
)
|
|
|
|
|
2024-07-05 09:47:19 +00:00
|
|
|
observer_writing = models.PositiveSmallIntegerField(
|
|
|
|
verbose_name=_("observer writing note"),
|
|
|
|
choices=[(i, i) for i in range(0, 11)],
|
|
|
|
default=0,
|
|
|
|
)
|
|
|
|
|
|
|
|
observer_oral = models.PositiveSmallIntegerField(
|
|
|
|
verbose_name=_("observer oral note"),
|
|
|
|
choices=[(i, i) for i in range(-10, 11)],
|
|
|
|
default=0,
|
|
|
|
)
|
|
|
|
|
2023-04-07 19:47:06 +00:00
|
|
|
def get_all(self):
|
|
|
|
yield self.defender_writing
|
|
|
|
yield self.defender_oral
|
|
|
|
yield self.opponent_writing
|
|
|
|
yield self.opponent_oral
|
2024-07-05 09:00:11 +00:00
|
|
|
yield self.reviewer_writing
|
|
|
|
yield self.reviewer_oral
|
2024-07-05 09:47:19 +00:00
|
|
|
if self.passage.observer:
|
|
|
|
yield self.observer_writing
|
|
|
|
yield self.observer_oral
|
2023-04-07 19:47:06 +00:00
|
|
|
|
2022-05-15 10:23:17 +00:00
|
|
|
def set_all(self, defender_writing: int, defender_oral: int, opponent_writing: int, opponent_oral: int,
|
2024-07-05 09:47:19 +00:00
|
|
|
reviewer_writing: int, reviewer_oral: int, observer_writing: int = 0, observer_oral: int = 0):
|
2022-05-15 10:23:17 +00:00
|
|
|
self.defender_writing = defender_writing
|
|
|
|
self.defender_oral = defender_oral
|
|
|
|
self.opponent_writing = opponent_writing
|
|
|
|
self.opponent_oral = opponent_oral
|
2024-07-05 09:00:11 +00:00
|
|
|
self.reviewer_writing = reviewer_writing
|
|
|
|
self.reviewer_oral = reviewer_oral
|
2024-07-05 09:47:19 +00:00
|
|
|
self.observer_writing = observer_writing
|
|
|
|
self.observer_oral = observer_oral
|
2022-05-15 10:23:17 +00:00
|
|
|
|
2024-03-30 13:21:28 +00:00
|
|
|
def update_spreadsheet(self):
|
2024-03-30 14:55:28 +00:00
|
|
|
if not self.has_any_note():
|
|
|
|
return
|
|
|
|
|
2024-06-07 15:20:06 +00:00
|
|
|
translation.activate(settings.PREFERRED_LANGUAGE_CODE)
|
2024-04-20 14:16:50 +00:00
|
|
|
|
2024-03-30 13:21:28 +00:00
|
|
|
gc = gspread.service_account_from_dict(settings.GOOGLE_SERVICE_CLIENT)
|
|
|
|
passage = Passage.objects.prefetch_related('pool__tournament', 'pool__participations').get(pk=self.passage.pk)
|
|
|
|
spreadsheet_id = passage.pool.tournament.notes_sheet_id
|
|
|
|
spreadsheet = gc.open_by_key(spreadsheet_id)
|
|
|
|
worksheet = spreadsheet.worksheet(f"Poule {passage.pool.short_name}")
|
|
|
|
jury_id_cell = worksheet.find(str(self.jury_id), in_column=2)
|
|
|
|
if not jury_id_cell:
|
|
|
|
raise ValueError("The jury ID cell was not found in the spreadsheet.")
|
|
|
|
jury_row = jury_id_cell.row
|
2024-04-16 21:58:42 +00:00
|
|
|
passage_width = 6
|
2024-03-30 13:21:28 +00:00
|
|
|
|
|
|
|
def getcol(number: int) -> str:
|
|
|
|
if number == 0:
|
|
|
|
return ''
|
|
|
|
return getcol((number - 1) // 26) + chr(65 + (number - 1) % 26)
|
|
|
|
|
|
|
|
min_col = getcol(3 + (self.passage.position - 1) * passage_width)
|
|
|
|
max_col = getcol(3 + self.passage.position * passage_width - 1)
|
|
|
|
|
|
|
|
worksheet.update([list(self.get_all())], f"{min_col}{jury_row}:{max_col}{jury_row}")
|
|
|
|
|
2021-01-14 17:21:22 +00:00
|
|
|
def get_absolute_url(self):
|
|
|
|
return reverse_lazy("participation:passage_detail", args=(self.passage.pk,))
|
|
|
|
|
2024-03-24 10:28:41 +00:00
|
|
|
@property
|
|
|
|
def modal_name(self):
|
|
|
|
return f"updateNotes{self.pk}"
|
|
|
|
|
2024-03-24 16:42:09 +00:00
|
|
|
def has_any_note(self):
|
|
|
|
return any(self.get_all())
|
|
|
|
|
2021-01-14 16:54:47 +00:00
|
|
|
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")
|