Skip to content

Commit bb3baaa

Browse files
authored
Round (sub)task scores to correct precision when displaying (#1398)
1 parent e66ef9f commit bb3baaa

File tree

5 files changed

+13
-8
lines changed

5 files changed

+13
-8
lines changed

cms/grading/scoretypes/abc.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -238,10 +238,9 @@ class ScoreTypeGroup(ScoreTypeAlone):
238238
<span class="title">
239239
{% trans index=st["idx"] %}Subtask {{ index }}{% endtrans %}
240240
</span>
241-
{% if "score_fraction" in st and "max_score" in st %}
242-
{% set score = st["score_fraction"] * st["max_score"] %}
241+
{% if "score" in st and "max_score" in st %}
243242
<span class="score">
244-
({{ score|round(2)|format_decimal }}
243+
({{ st["score"]|format_decimal }}
245244
/ {{ st["max_score"]|format_decimal }})
246245
</span>
247246
{% else %}
@@ -416,6 +415,8 @@ def compute_score(self, submission_result):
416415
targets = self.retrieve_target_testcases()
417416
evaluations = {ev.codename: ev for ev in submission_result.evaluations}
418417

418+
score_precision = submission_result.submission.task.score_precision
419+
419420
for st_idx, parameter in enumerate(self.parameters):
420421
target = targets[st_idx]
421422

@@ -461,6 +462,7 @@ def compute_score(self, submission_result):
461462
[float(evaluations[tc_idx].outcome) for tc_idx in target],
462463
parameter)
463464
st_score = st_score_fraction * parameter[0]
465+
rounded_score = round(st_score, score_precision)
464466

465467
if tc_first_lowest_idx is not None and st_score_fraction < 1.0:
466468
for tc in testcases:
@@ -478,6 +480,8 @@ def compute_score(self, submission_result):
478480
# with a max score of zero is still properly rendered as
479481
# correct or incorrect.
480482
"score_fraction": st_score_fraction,
483+
# But we also want the properly rounded score for display.
484+
"score": rounded_score,
481485
"max_score": parameter[0],
482486
"testcases": testcases})
483487
if all(self.public_testcases[tc_idx] for tc_idx in target):
@@ -486,7 +490,7 @@ def compute_score(self, submission_result):
486490
else:
487491
public_subtasks.append({"idx": st_idx,
488492
"testcases": public_testcases})
489-
ranking_details.append("%g" % round(st_score, 2))
493+
ranking_details.append("%g" % rounded_score)
490494

491495
return score, subtasks, public_score, public_subtasks, ranking_details
492496

cms/grading/scoring.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ def _task_score_max_subtask(
251251
try:
252252
subtask_scores = dict(
253253
(subtask["idx"],
254-
subtask["score_fraction"] * subtask["max_score"])
254+
subtask["score"])
255255
for subtask in details)
256256
except Exception:
257257
subtask_scores = None

cmsranking/RankingWebServer.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -280,8 +280,7 @@ def callback(self, entity: str, event: str, key: str, *args):
280280
self.send(entity, "%s %s" % (event, key))
281281

282282
def score_callback(self, user: str, task: str, score: float):
283-
# FIXME Use score_precision.
284-
self.send("score", "%s %s %0.2f" % (user, task, score))
283+
self.send("score", "%s %s %s" % (user, task, str(score)))
285284

286285

287286
class SubListHandler:

cmstestsuite/unit_tests/grading/scoretypes/scoretypetestutils.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ def get_submission_result(testcases):
3939
sr.evaluations = [
4040
ScoreTypeTestMixin.get_evaluation(codename, 1.0)
4141
for codename in reversed(sorted(testcases.keys()))]
42+
sr.submission.task.score_precision = 4
4243
return sr
4344

4445
@staticmethod

cmstestsuite/unit_tests/grading/scoring_test.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,8 @@ def subtask(idx, max_score, score_fraction):
176176
return {
177177
"idx": idx,
178178
"max_score": max_score,
179-
"score_fraction": score_fraction
179+
"score_fraction": score_fraction,
180+
"score": round(max_score * score_fraction, 4) # assume a score_precision of 4 for these tests.
180181
}
181182

182183
def test_no_submissions(self):

0 commit comments

Comments
 (0)