Skip to content

Commit b2e8b21

Browse files
committed
Unify task score computation into _compute_task_scores
Replace separate _compute_public_task_scores and sidebar-specific logic with a single _compute_task_scores method that handles both public and tokened/total scores. The new method accepts actual_phase and a hide_zero_max_public flag (default true) to control whether tasks with zero public max score are shown. Update callers in contest/handlers/contest.py and contest/handlers/main.py to use the unified method and pass appropriate hide_zero_max_public values, preserving previous visibility behavior.
1 parent 7760b48 commit b2e8b21

2 files changed

Lines changed: 12 additions & 42 deletions

File tree

cms/server/contest/handlers/contest.py

Lines changed: 10 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -212,50 +212,18 @@ def _load_participation_for_scores(
212212
.first()
213213
)
214214

215-
def _compute_public_task_scores(
216-
self,
217-
participation: Participation,
218-
*,
219-
hide_zero_max_public: bool,
220-
) -> dict[int, tuple[float, float, str]]:
221-
"""Compute per-task public scores for the given participation."""
222-
task_scores: dict[int, tuple[float, float, str]] = {}
223-
for task in participation.contest.tasks:
224-
score_type = task.active_dataset.score_type_object
225-
max_public_score = round(
226-
score_type.max_public_score, task.score_precision
227-
)
228-
229-
if hide_zero_max_public and max_public_score <= 0:
230-
continue
231-
232-
public_score, _ = task_score(
233-
participation, task, public=True, rounded=True
234-
)
235-
task_scores[task.id] = (
236-
public_score,
237-
max_public_score,
238-
score_type.format_score(
239-
public_score,
240-
score_type.max_public_score,
241-
None,
242-
task.score_precision,
243-
translation=self.translation,
244-
),
245-
)
246-
return task_scores
247-
248-
def _compute_sidebar_task_scores(
215+
def _compute_task_scores(
249216
self,
250217
participation: Participation,
251218
*,
252219
actual_phase: int,
220+
hide_zero_max_public: bool = True,
253221
) -> dict[int, tuple[float, float, str]]:
254-
"""Compute per-task scores for the sidebar.
222+
"""Compute per-task scores for UI task lists.
255223
256-
By default the sidebar shows public scores. If a token has been played
257-
on a task (or we're in analysis mode), it shows the tokened/total score
258-
for that task instead.
224+
By default, this shows public scores. If a token has been played on a
225+
task (or we're in analysis mode), it shows the tokened/total score for
226+
that task instead.
259227
"""
260228
task_scores: dict[int, tuple[float, float, str]] = {}
261229

@@ -288,8 +256,8 @@ def _compute_sidebar_task_scores(
288256
score_type.max_public_score, task.score_precision
289257
)
290258

291-
# Do not show a sidebar score if there is no public score.
292-
if max_public_score <= 0:
259+
# Optionally hide entries with no public score.
260+
if hide_zero_max_public and max_public_score <= 0:
293261
continue
294262

295263
score_value, _ = task_score(
@@ -356,9 +324,10 @@ def render_params(self):
356324
ret["contest"] = self.contest
357325
ret["participation"] = participation
358326
ret["user"] = participation.user
359-
ret["sidebar_task_scores"] = self._compute_sidebar_task_scores(
327+
ret["sidebar_task_scores"] = self._compute_task_scores(
360328
participation,
361329
actual_phase=ret["actual_phase"],
330+
hide_zero_max_public=True,
362331
)
363332

364333
# some information about token configuration

cms/server/contest/handlers/main.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,9 @@ def render_params(self):
9494

9595
# Compute public scores for all tasks only if they will be shown
9696
if self.contest.show_task_scores_in_overview:
97-
ret["task_scores"] = self._compute_public_task_scores(
97+
ret["task_scores"] = self._compute_task_scores(
9898
participation,
99+
actual_phase=ret["actual_phase"],
99100
hide_zero_max_public=False,
100101
)
101102

0 commit comments

Comments
 (0)