Skip to content

Commit acb589a

Browse files
committed
display optscore on UI
1 parent 4ea9227 commit acb589a

File tree

4 files changed

+50
-4
lines changed

4 files changed

+50
-4
lines changed

webapp/src/Twig/TwigExtension.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ public function getFilters(): array
114114
new TwigFilter('entityIdBadge', $this->entityIdBadge(...), ['is_safe' => ['html']]),
115115
new TwigFilter('medalType', $this->awards->medalType(...)),
116116
new TwigFilter('numTableActions', $this->numTableActions(...)),
117+
new TwigFilter('formatOptScore', $this->formatOptScore(...)),
117118
];
118119
}
119120

@@ -1222,4 +1223,28 @@ protected function numTableActions(array $tableData): int
12221223
}
12231224
return $maxNumActions;
12241225
}
1226+
1227+
/**
1228+
* Format the given optScore:
1229+
* - If it's an integer, display without decimal places
1230+
* - Otherwise, display up to the specified number of decimal places
1231+
*
1232+
* @param float|null $optScore The value to format (nullable)
1233+
* @param int $maxDecimals Maximum number of decimal places to show (default = 3)
1234+
* @return string Formatted string representation of the score
1235+
*/
1236+
protected function formatOptScore(?float $optScore, int $maxDecimals = 3): string
1237+
{
1238+
if ($optScore === null) {
1239+
return '-';
1240+
}
1241+
1242+
// If the value is an integer, format without decimal places
1243+
if ($optScore == floor($optScore)) {
1244+
return number_format($optScore, 0, '.', '');
1245+
}
1246+
1247+
// Otherwise, format with specified decimal precision
1248+
return number_format($optScore, $maxDecimals, '.', '');
1249+
}
12251250
}

webapp/templates/jury/partials/submission_graph.html.twig

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@
66
<span id="graphs" style="font-weight: bold;">testcase CPU times
77
<span style="font-weight: normal;">
88
{%- if selectedJudging.result != 'compiler-error' -%}
9-
| max:
10-
{{ selectedJudging.maxRuntime | number_format(3, '.', '') }}s
11-
| sum: {{ selectedJudging.sumRuntime | number_format(3, '.', '') }}s
12-
{% endif %}
9+
| max: {{ selectedJudging.maxRuntime | number_format(3, '.', '') }}s
10+
| sum: {{ selectedJudging.sumRuntime | number_format(3, '.', '') }}s&nbsp
11+
{%- if selectedJudging.SumOptScore is not null -%}
12+
| <span>opt score:</span> {{ selectedJudging.SumOptScore | formatOptScore }}
13+
{%- endif %}
14+
{%- endif %}
1315
</span>
1416
</span>
1517
</div>

webapp/templates/team/partials/submission.html.twig

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@
4545
Max. Runtime: <b>{{ "%0.3f s" | format(judging.getMaxRuntime()) }}</b>
4646
</div>
4747
{% endif %}
48+
{% if judging.result == 'correct' and judging.submission.contest.getOptScoreAsScoreTiebreaker() %}
49+
<div class="p-2">
50+
Opt. Score: <b>{{ judging.SumOptScore | formatOptScore }}</b>
51+
</div>
52+
{% endif %}
4853
</div>
4954
{% endif %}
5055
</div>

webapp/templates/team/partials/submission_list.html.twig

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414
{% if contest.getRuntimeAsScoreTiebreaker() %}
1515
<th scope="col">runtime</th>
1616
{% endif %}
17+
{% if contest.getOptScoreAsScoreTiebreaker() %}
18+
<th scope="col">optscore</th>
19+
{% endif %}
1720
{% if allowDownload %}
1821
<th scope="col"></th>
1922
{% endif %}
@@ -79,6 +82,17 @@
7982
</a>
8083
</td>
8184
{% endif %}
85+
{% if contest.getOptScoreAsScoreTiebreaker() %}
86+
<td>
87+
<a data-ajax-modal data-ajax-modal-after="markSeen" {% if link %}href="{{ link }}"{% endif %}>
88+
{% if link and submission.getResult()=='correct' %}
89+
{{ submission.judgings.first.SumOptScore | formatOptScore }}
90+
{% else %}
91+
-
92+
{% endif %}
93+
</a>
94+
</td>
95+
{% endif %}
8296
{% if allowDownload %}
8397
<td>
8498
<a title="Download submission ZIP" aria-label="download submission zip" class="btn btn-light" href="{{ path('team_submission_download', {'submitId': submission.submitid}) }}">

0 commit comments

Comments
 (0)