Add mentions

Signed-off-by: Emmy D'Anello <emmy.danello@animath.fr>
This commit is contained in:
Emmy D'Anello 2024-04-17 00:29:48 +02:00
parent 3a0a98a331
commit 49fda3df49
Signed by: ynerant
GPG Key ID: 3A75C55819C8CF85
3 changed files with 80 additions and 6 deletions

View File

@ -0,0 +1,27 @@
# Generated by Django 5.0.3 on 2024-04-16 22:17
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
("participation", "0011_remove_note_observer_oral_remove_passage_observer"),
]
operations = [
migrations.AddField(
model_name="participation",
name="mention",
field=models.CharField(
blank=True, default="", max_length=255, verbose_name="mention"
),
),
migrations.AddField(
model_name="participation",
name="mention_final",
field=models.CharField(
blank=True, default="", max_length=255, verbose_name="mention (final)"
),
),
]

View File

@ -474,21 +474,32 @@ class Tournament(models.Model):
line.append(f"=$B{i + 2} + $C{i + 2} + $D{i + 2} + E{i + 2}")
line.append(f"=RANG($F{i + 2}; $F$2:$F${participations.count() + 1})")
final_ranking = [["", "", ""], ["", "", ""], ["Équipe", "Score", "Rang"],
final_ranking = [["", "", "", ""], ["", "", "", ""], ["Équipe", "Score", "Rang", "Mention"],
[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)", ]]
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)
data = header + lines + final_ranking
worksheet.update(data, f"A1:G{participations.count() + 5}", raw=False)
worksheet.update(data, f"A1:G{2 * participations.count() + 4}", raw=False)
format_requests = []
# Set the width of the columns
column_widths = [("A", 300), ("B", 120), ("C", 120), ("D", 120), ("E", 120), ("F", 120), ("G", 120)]
column_widths = [("A", 300), ("B", 150), ("C", 150), ("D", 150), ("E", 150), ("F", 150), ("G", 150)]
for column, width in column_widths:
grid_range = a1_range_to_grid_range(column, worksheet.id)
format_requests.append({
@ -509,7 +520,7 @@ class Tournament(models.Model):
# Set borders
border_ranges = [("A1:AF", "0000"),
(f"A1:G{participations.count() + 1}", "1111"),
(f"A{participations.count() + 4}:C{2 * participations.count() + 4}", "1111")]
(f"A{participations.count() + 4}:D{2 * participations.count() + 4}", "1111")]
sides_names = ['top', 'bottom', 'left', 'right']
styles = ["NONE", "SOLID", "SOLID_MEDIUM", "SOLID_THICK", "DOUBLE"]
for border_range, sides in border_ranges:
@ -531,7 +542,7 @@ class Tournament(models.Model):
# Make titles bold
bold_ranges = [("A1:AF", False), ("A1:G1", True),
(f"A{participations.count() + 4}:C{participations.count() + 4}", True)]
(f"A{participations.count() + 4}:D{participations.count() + 4}", True)]
for bold_range, bold in bold_ranges:
format_requests.append({
"repeatCell": {
@ -549,7 +560,7 @@ class Tournament(models.Model):
(f"D2:D{participations.count() + 1}", (0.9, 0.9, 0.9)),
(f"E2:E{participations.count() + 1}", (1, 1, 1)),
(f"F2:G{participations.count() + 1}", (0.9, 0.9, 0.9)),
(f"A{participations.count() + 4}:C{participations.count() + 4}", (0.8, 0.8, 0.8)),
(f"A{participations.count() + 4}:D{participations.count() + 4}", (0.8, 0.8, 0.8)),
(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
@ -646,6 +657,22 @@ class Tournament(models.Model):
create_defaults={'diff': tweak2_nb, 'pool': pool2,
'participation': participation})
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):
mention = mentions[i][3]
if not self.final:
participation.mention = mention
else:
participation.mention_final = mention
participation.save()
def get_absolute_url(self):
return reverse_lazy("participation:tournament_detail", args=(self.pk,))
@ -693,6 +720,20 @@ class Participation(models.Model):
help_text=_("The team is selected for the final tournament."),
)
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="",
)
def get_absolute_url(self):
return reverse_lazy("participation:participation_detail", args=(self.pk,))

View File

@ -105,6 +105,12 @@
{% for participation, note in notes %}
<li>
<strong>{{ participation.team }} :</strong> {{ note|floatformat }}
{% if not tournament.final and participation.mention %}
— {{ participation.mention }}
{% endif %}
{% if tournament.final and participation.mention_final %}
— {{ participation.mention_final }}
{% endif %}
{% if participation.final %}
<span class="badge badge-sm text-bg-warning">
<i class="fas fa-medal"></i>