Skip to content

Commit adf02f8

Browse files
aguss787veluca93
authored andcommitted
Save the first time each submission is scored
1 parent 722ceab commit adf02f8

6 files changed

Lines changed: 37 additions & 7 deletions

File tree

cms/db/submission.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,11 @@ class SubmissionResult(Base):
364364
JSONB,
365365
nullable=True)
366366

367+
# Time when the submission is scored for the first time
368+
scored_at = Column(
369+
DateTime,
370+
nullable=True)
371+
367372
# The same as the last two fields, but only showing information
368373
# visible to the user (assuming they did not use a token on this
369374
# submission).

cms/server/admin/static/aws_style.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,10 @@ table td.partial::after {
394394
content: "*";
395395
}
396396

397+
table td#latency {
398+
text-align: right;
399+
}
400+
397401
table.sortable th {
398402
white-space: nowrap;
399403
}

cms/server/admin/templates/macro/submission.html

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
<th>User</th>
3131
<th>Task</th>
3232
<th>Status</th>
33+
<th>Latency</th>
3334
<th>Files</th>
3435
<th>Token</th>
3536
<th>Official</th>
@@ -145,6 +146,11 @@ <h3>Compilation output</h3>{# TODO: trim long outputs and add facility to see ra
145146

146147
{% endif %}
147148
</td>
149+
<td id="latency"">
150+
{% if sr is not none and sr.scored_at is not none %}
151+
{{ (sr.scored_at - s.timestamp).total_seconds()|format_duration }}
152+
{% endif %}
153+
</td>
148154
<td>
149155
{% for filename, sub_file in s.files|dictsort(by="key") %}
150156
{% set real_filename = filename if s.language is none else filename|replace(".%l", (s.language|to_language).source_extension) %}

cms/server/admin/templates/submission.html

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -105,22 +105,22 @@ <h2 id="title_details" class="toggling_on">Submission details</h2>
105105
<td>Status</td>
106106
<td id="submission_status">
107107
{% if status == SubmissionResult.COMPILING %}
108-
Compiling...
108+
Compiling...
109109
{% elif status == SubmissionResult.COMPILATION_FAILED %}
110-
Compilation failed
110+
Compilation failed
111111
{% elif status == SubmissionResult.EVALUATING %}
112-
Evaluating...
112+
Evaluating...
113113
{% elif status == SubmissionResult.SCORING %}
114-
Scoring...
114+
Scoring...
115115
{% elif status == SubmissionResult.SCORED %}
116116
{% if st is defined %}
117117
{% set max_score = st.max_score %}
118118
{% else %}
119119
{% set max_score = "[Cannot get score type - see logs]" %}
120120
{% endif %}
121-
Scored ({{ sr.score }} / {{ max_score }})
121+
Scored ({{ sr.score }} / {{ max_score }})
122122
{% else %}
123-
N/A
123+
N/A
124124
{% endif %}
125125
</td>
126126
</tr>
@@ -136,7 +136,13 @@ <h2 id="title_details" class="toggling_on">Submission details</h2>
136136
</td>
137137
</tr>
138138
{% endif %}
139-
{% if sr is not none %}
139+
{% if sr is not none and sr.scored_at is not none %}
140+
<tr>
141+
<td>Latency as seen by user</td>
142+
<td>
143+
{{ (sr.scored_at - s.timestamp).total_seconds()|format_duration }}
144+
</td>
145+
</tr>
140146
<tr>
141147
<td>Failures during compilation</td>
142148
<td>{{ sr.compilation_tries }}</td>

cms/service/ScoringService.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,9 @@ def execute(self, entry: QueueEntry[ScoringOperation]):
101101
submission_result.ranking_score_details = \
102102
score_type.compute_score(submission_result)
103103

104+
if submission_result.scored_at is None:
105+
submission_result.scored_at = make_datetime()
106+
104107
# Store it.
105108
session.commit()
106109

cmstestsuite/unit_tests/service/ScoringServiceTest.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
# We enable monkey patching to make many libraries gevent-friendly
2525
# (for instance, urllib3, used by requests)
2626
import gevent.monkey
27+
2728
gevent.monkey.patch_all() # noqa
2829

2930
import unittest
@@ -35,6 +36,7 @@
3536
from cmstestsuite.unit_tests.databasemixin import DatabaseMixin
3637

3738
from cms.service.ScoringService import ScoringService
39+
from cmscommon.datetime import make_datetime
3840
from cmstestsuite.unit_tests.testidgenerator import unique_long_id, \
3941
unique_unicode_id
4042

@@ -101,6 +103,7 @@ def test_new_evaluation(self):
101103
sr.public_score, sr.public_score_details,
102104
sr.ranking_score_details),
103105
self.score_info)
106+
self.assertIsNotNone(sr.scored_at)
104107

105108
def test_new_evaluation_two(self):
106109
"""More than one submissions in the queue.
@@ -126,6 +129,8 @@ def test_new_evaluation_already_scored(self):
126129
127130
"""
128131
sr = self.new_sr_scored()
132+
current_time = make_datetime()
133+
sr.scored_at = current_time
129134
self.session.commit()
130135

131136
service = ScoringService(0)
@@ -135,6 +140,7 @@ def test_new_evaluation_already_scored(self):
135140

136141
# Asserts that compute_score was called.
137142
self.score_type.compute_score.assert_not_called()
143+
self.assertEqual(current_time, sr.scored_at)
138144

139145

140146
if __name__ == "__main__":

0 commit comments

Comments
 (0)