Fix notation sheets when we change the order of pools

Signed-off-by: Emmy D'Anello <emmy.danello@animath.fr>
This commit is contained in:
Emmy D'Anello 2024-04-17 22:02:29 +02:00
parent 91a1837c99
commit 059cae75c5
Signed by: ynerant
GPG Key ID: 3A75C55819C8CF85
2 changed files with 13 additions and 57 deletions

View File

@ -1085,36 +1085,15 @@ class Pool(models.Model):
ranking = [
["Équipe", "", "Problème", "Total", "Rang"],
]
passage_matrix = []
match pool_size:
case 3:
passage_matrix = [
[0, 2, 1],
[1, 0, 2],
[2, 1, 0],
]
case 4:
passage_matrix = [
[0, 3, 2],
[1, 0, 3],
[2, 1, 0],
[3, 2, 1],
]
case 5:
passage_matrix = [
[0, 2, 3],
[1, 4, 2],
[2, 0, 4],
[3, 1, 0],
[4, 3, 1],
]
for passage in passages:
participation = passage.defender
passage_line = passage_matrix[passage.position - 1]
defender_pos = passage.position - 1
opponent_pos = passages.get(opponent=passage.defender).position - 1
reporter_pos = passages.get(reporter=passage.defender).position - 1
formula = "="
formula += getcol(min_column + passage_line[0] * passage_width) + str(max_row + 3) # Defender
formula += " + " + getcol(min_column + passage_line[1] * passage_width + 2) + str(max_row + 3) # Opponent
formula += " + " + getcol(min_column + passage_line[2] * passage_width + 4) + str(max_row + 3) # Reporter
formula += getcol(min_column + defender_pos * passage_width) + str(max_row + 3) # Defender
formula += " + " + getcol(min_column + opponent_pos * passage_width + 2) + str(max_row + 3) # Opponent
formula += " + " + getcol(min_column + reporter_pos * passage_width + 4) + str(max_row + 3) # Reporter
ranking.append([f"{participation.team.name} ({participation.team.trigram})", "",
f"=${getcol(3 + (passage.position - 1) * passage_width)}$1", formula,
f"=RANG(D{max_row + 5 + passage.position}; "

View File

@ -1675,32 +1675,6 @@ class PoolNotesTemplateView(VolunteerMixin, DetailView):
rank_tc.addElement(P(text="Rang"))
scores_header.addElement(rank_tc)
# For each line of the matrix P, the ith team is defender on the passage number Pi0,
# opponent on the passage number Pi1, reporter on the passage number Pi2
passage_matrix = []
match pool_size:
case 3:
passage_matrix = [
[0, 2, 1],
[1, 0, 2],
[2, 1, 0],
]
case 4:
passage_matrix = [
[0, 3, 2],
[1, 0, 3],
[2, 1, 0],
[3, 2, 1],
]
case 5:
passage_matrix = [
[0, 2, 3],
[1, 4, 2],
[2, 0, 4],
[3, 1, 0],
[4, 3, 1],
]
sorted_participations = sorted(self.object.participations.all(), key=lambda p: -self.object.average(p))
for passage in self.object.passages.all():
team_row = TableRow()
@ -1717,14 +1691,17 @@ class PoolNotesTemplateView(VolunteerMixin, DetailView):
problem_tc.addElement(P(text=f"Problème {passage.solution_number}"))
team_row.addElement(problem_tc)
passage_line = passage_matrix[passage.position - 1]
defender_pos = passage.position - 1
opponent_pos = self.object.passages.get(opponent=passage.defender).position - 1
reporter_pos = self.object.passages.get(reporter=passage.defender).position - 1
score_tc = TableCell(valuetype="float", value=self.object.average(passage.defender),
stylename=style_bot if passage.position == pool_size else style)
score_tc.addElement(P(text=self.object.average(passage.defender)))
formula = "of:="
formula += getcol(min_column + passage_line[0] * passage_width) + str(max_row + 3) # Defender
formula += " + " + getcol(min_column + passage_line[1] * passage_width + 2) + str(max_row + 3) # Opponent
formula += " + " + getcol(min_column + passage_line[2] * passage_width + 4) + str(max_row + 3) # Reporter
formula += getcol(min_column + defender_pos * passage_width) + str(max_row + 3) # Defender
formula += " + " + getcol(min_column + opponent_pos * passage_width + 2) + str(max_row + 3) # Opponent
formula += " + " + getcol(min_column + reporter_pos * passage_width + 4) + str(max_row + 3) # Reporter
score_tc.setAttribute("formula", formula)
team_row.addElement(score_tc)