Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion cms/grading/scoring.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ def task_score(
task: Task,
public: bool = False,
only_tokened: bool = False,
submissions: list[Submission] | None = None,
) -> tuple[float, bool]:
"""Return the score of a contest's user on a task.

Expand All @@ -121,6 +122,7 @@ def task_score(
at the results of tokened submissions (that is, the score that the user
would obtain if all non-tokened submissions scored 0.0, or equivalently
had not been scored yet).
submissions: optional preloaded list of submissions for participation.

return: the score of user on task, and True if not
all submissions of the participation in the task have been scored.
Expand All @@ -140,7 +142,9 @@ def task_score(
"This is a programming error: users have access to all public "
"scores regardless of token status.")

submissions = [s for s in participation.submissions
if submissions is None:
submissions = participation.submissions
submissions = [s for s in submissions
if s.task is task and s.official]
if len(submissions) == 0:
return 0.0, False
Expand Down
10 changes: 5 additions & 5 deletions cms/server/contest/handlers/tasksubmission.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,9 @@ def get(self, task_name):
)

public_score, is_public_score_partial = task_score(
participation, task, public=True)
participation, task, public=True, submissions=submissions)
tokened_score, is_tokened_score_partial = task_score(
participation, task, only_tokened=True)
participation, task, only_tokened=True, submissions=submissions)
# These two should be the same, anyway.
is_score_partial = is_public_score_partial or is_tokened_score_partial

Expand Down Expand Up @@ -214,16 +214,16 @@ def add_task_score(self, participation: Participation, task: Task, data: dict):

"""
# Just to preload all information required to compute the task score.
self.sql_session.query(Submission)\
submissions = self.sql_session.query(Submission)\
.filter(Submission.participation == participation)\
.filter(Submission.task == task)\
.options(joinedload(Submission.token))\
.options(joinedload(Submission.results))\
.all()
data["task_public_score"], public_score_is_partial = \
task_score(participation, task, public=True)
task_score(participation, task, public=True, submissions=submissions)
data["task_tokened_score"], tokened_score_is_partial = \
task_score(participation, task, only_tokened=True)
task_score(participation, task, only_tokened=True, submissions=submissions)
# These two should be the same, anyway.
data["task_score_is_partial"] = \
public_score_is_partial or tokened_score_is_partial
Expand Down
Loading