Skip to content

Commit 7271662

Browse files
committed
Show full scores in analysis mode and minor fixes
When the contest is in analysis mode (actual_phase == 3) total/task tokened scores are now shown as full scores instead of being limited to tokened submissions. Added joinedload(Participation.user) to the contest handler to eager-load users and avoid extra queries, and replaced per-task any(...) scans with a tokened_task_ids set for efficiency. The task submission handler now checks actual_phase to decide whether to restrict to tokened submissions. The template always renders a task score badge placeholder when sidebar scores are enabled so layout remains consistent. Also clarified related docstrings/comments.
1 parent b2e8b21 commit 7271662

3 files changed

Lines changed: 29 additions & 12 deletions

File tree

cms/server/contest/handlers/contest.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,7 @@ def _load_participation_for_scores(
203203
self.sql_session.query(Participation)
204204
.filter(Participation.id == participation.id)
205205
.options(
206+
joinedload(Participation.user),
206207
joinedload(Participation.contest)
207208
.joinedload(Contest.tasks)
208209
.joinedload(Task.active_dataset),
@@ -226,23 +227,28 @@ def _compute_task_scores(
226227
that task instead.
227228
"""
228229
task_scores: dict[int, tuple[float, float, str]] = {}
230+
tokened_task_ids = {
231+
s.task_id for s in participation.submissions if s.official and s.tokened()
232+
}
229233

230234
for task in participation.contest.tasks:
231235
score_type = task.active_dataset.score_type_object
232236

233-
has_tokened_submission = any(
234-
s.official and s.task_id == task.id and s.tokened()
235-
for s in participation.submissions
236-
)
237+
has_tokened_submission = task.id in tokened_task_ids
237238
show_tokened_total = (
238239
score_type.max_public_score < score_type.max_score
239240
and (has_tokened_submission or actual_phase == 3)
240241
)
241242

242243
if show_tokened_total:
243-
score_value, _ = task_score(
244-
participation, task, only_tokened=True, rounded=True
245-
)
244+
if actual_phase == 3:
245+
# In analysis mode users can see full scores, so do not
246+
# restrict to tokened submissions.
247+
score_value, _ = task_score(participation, task, rounded=True)
248+
else:
249+
score_value, _ = task_score(
250+
participation, task, only_tokened=True, rounded=True
251+
)
246252
max_score_value = round(score_type.max_score, task.score_precision)
247253
score_message = score_type.format_score(
248254
score_value,

cms/server/contest/handlers/tasksubmission.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -207,8 +207,9 @@ def add_task_score(self, participation: Participation, task: Task, data: dict):
207207
task: task for which we want the score.
208208
data: where to put the data; all fields will start with "task",
209209
followed by "public" if referring to the public scores, or
210-
"tokened" if referring to the total score (always limited to
211-
tokened submissions); for both public and tokened, the fields are:
210+
"tokened" if referring to the total score (limited to tokened
211+
submissions during contest, full score in analysis mode); for both
212+
public and tokened, the fields are:
212213
"score" and "score_message"; in addition we have
213214
"task_is_score_partial" as partial info is the same for both.
214215
@@ -222,8 +223,14 @@ def add_task_score(self, participation: Participation, task: Task, data: dict):
222223
.all()
223224
data["task_public_score"], public_score_is_partial = \
224225
task_score(participation, task, public=True, rounded=True)
225-
data["task_tokened_score"], tokened_score_is_partial = \
226-
task_score(participation, task, only_tokened=True, rounded=True)
226+
if self.r_params["actual_phase"] == 3:
227+
data["task_tokened_score"], tokened_score_is_partial = task_score(
228+
participation, task, rounded=True
229+
)
230+
else:
231+
data["task_tokened_score"], tokened_score_is_partial = task_score(
232+
participation, task, only_tokened=True, rounded=True
233+
)
227234
# These two should be the same, anyway.
228235
data["task_score_is_partial"] = \
229236
public_score_is_partial or tokened_score_is_partial

cms/server/contest/templates/contest.html

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,10 +181,14 @@ <h3 id="countdown_box">
181181
{% for t_iter in contest.tasks %}
182182
<li class="nav-header" data-task-name="{{ t_iter.name }}">
183183
<span>{{ t_iter.name }}</span>
184-
{% if contest.show_task_scores_in_sidebar and sidebar_task_scores is defined and t_iter.id in sidebar_task_scores %}
184+
{% if contest.show_task_scores_in_sidebar %}
185+
{% if sidebar_task_scores is defined and t_iter.id in sidebar_task_scores %}
185186
<span class="task_score_badge task_score {{ get_score_class(sidebar_task_scores[t_iter.id][0], sidebar_task_scores[t_iter.id][1], t_iter.score_precision) }}">
186187
{{ sidebar_task_scores[t_iter.id][2] }}
187188
</span>
189+
{% else %}
190+
<span class="task_score_badge task_score undefined"></span>
191+
{% endif %}
188192
{% endif %}
189193
</li>
190194
<li{% if page == "task_description" and task == t_iter %} class="active"{% endif %}>

0 commit comments

Comments
 (0)