From 059cae75c5940ad1addd87750d3f67c0bb26cd25 Mon Sep 17 00:00:00 2001 From: Emmy D'Anello Date: Wed, 17 Apr 2024 22:02:29 +0200 Subject: [PATCH] Fix notation sheets when we change the order of pools Signed-off-by: Emmy D'Anello --- participation/models.py | 33 ++++++--------------------------- participation/views.py | 37 +++++++------------------------------ 2 files changed, 13 insertions(+), 57 deletions(-) diff --git a/participation/models.py b/participation/models.py index b97b83b..e0d748e 100644 --- a/participation/models.py +++ b/participation/models.py @@ -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}; " diff --git a/participation/views.py b/participation/views.py index 1a8d437..d75a77d 100644 --- a/participation/views.py +++ b/participation/views.py @@ -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)