Skip to content

Commit a2377dc

Browse files
committed
Add a basic visualization for the scoring scoreboard type.
This currently only works with integers, e.g. setting points per problem. Part of #2525
1 parent fc07d9d commit a2377dc

File tree

5 files changed

+52
-14
lines changed

5 files changed

+52
-14
lines changed

webapp/src/Service/ScoreboardService.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -554,7 +554,7 @@ public function updateRankCache(Contest $contest, Team $team): void
554554
}
555555
}
556556

557-
const SCALE = 9;
557+
public const SCALE = 9;
558558

559559
// Converts integer or bcmath floats to a string that can be used as a key in a score cache.
560560
// The resulting key will be a string with 33 characters, 23 before the decimal dot and 9 after.

webapp/src/Utils/Scoreboard/Scoreboard.php

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use App\Entity\Contest;
66
use App\Entity\ContestProblem;
77
use App\Entity\RankCache;
8+
use App\Entity\ScoreboardType;
89
use App\Entity\ScoreCache;
910
use App\Entity\Team;
1011
use App\Entity\TeamCategory;
@@ -152,22 +153,32 @@ protected function calculateScoreboard(): void
152153
!array_key_exists($probId, $this->problems)) {
153154
continue;
154155
}
156+
$isCorrect = $scoreCell->getIsCorrect($this->restricted);
155157

156158
$penalty = Utils::calcPenaltyTime(
157-
$scoreCell->getIsCorrect($this->restricted),
159+
$isCorrect,
158160
$scoreCell->getSubmissions($this->restricted),
159161
$this->penaltyTime, $this->scoreIsInSeconds
160162
);
161163

164+
$contestProblem = $scoreCell->getContest()->getContestProblem($scoreCell->getProblem());
165+
// TODO: For actual scoring problems, we need to calculate the score here and
166+
// output it with the correct precision. For now, this is always an integer.
167+
$points = strval(
168+
$isCorrect ?
169+
$contestProblem->getPoints() : 0
170+
);
171+
162172
$this->matrix[$teamId][$probId] = new ScoreboardMatrixItem(
163-
isCorrect: $scoreCell->getIsCorrect($this->restricted),
164-
isFirst: $scoreCell->getIsCorrect($this->restricted) && $scoreCell->getIsFirstToSolve(),
173+
isCorrect: $isCorrect,
174+
isFirst: $isCorrect && $scoreCell->getIsFirstToSolve(),
165175
numSubmissions: $scoreCell->getSubmissions($this->restricted),
166176
numSubmissionsPending: $scoreCell->getPending($this->restricted),
167177
time: $scoreCell->getSolveTime($this->restricted),
168178
penaltyTime: $penalty,
169179
runtime: $scoreCell->getRuntime($this->restricted),
170180
numSubmissionsInFreeze: $scoreCell->getPending(false),
181+
points: $points,
171182
);
172183
}
173184

@@ -257,6 +268,11 @@ public function showPoints(): bool
257268
return false;
258269
}
259270

271+
public function isScoring(): bool
272+
{
273+
return $this->contest->getScoreboardType() === ScoreboardType::SCORING;
274+
}
275+
260276
/**
261277
* Return the used team categories for this scoreboard.
262278
*

webapp/src/Utils/Scoreboard/ScoreboardMatrixItem.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,6 @@ public function __construct(
1313
public int $penaltyTime,
1414
public int $runtime,
1515
public ?int $numSubmissionsInFreeze = null,
16+
public string $points = "",
1617
) {}
1718
}

webapp/templates/partials/scoreboard_summary.html.twig

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@
2323
{{ scoreboard.summary.numberOfPoints(sortOrder) }}
2424
</td>
2525
{% endif %}
26-
<td></td>
26+
{% if not scoringScoreboard %}
27+
<td></td>
28+
{% endif %}
2729
{% endif %}
2830
{% for problem in scoreboard.problems %}
2931
{% set summary = scoreboard.summary.problem(problem.probid) %}

webapp/templates/partials/scoreboard_table.html.twig

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
{% set static = false %}
1515
{% endif %}
1616
{% set showPoints = scoreboard.showPoints %}
17+
{% set scoringScoreboard = scoreboard.isScoring %}
1718
{% set usedCategories = scoreboard.usedCategories(limitToTeamIds) %}
1819
{% set hasDifferentCategoryColors = scoreboard.categoryColors(limitToTeamIds) %}
1920
{% set scores = scoreboard.scores | filter(score => limitToTeams is null or score.team.teamid in limitToTeamIds) %}
@@ -62,7 +63,9 @@
6263
{% if enable_ranking %}
6364
<colgroup>
6465
<col id="scoresolv"/>
65-
<col id="scoretotal"/>
66+
{% if not scoringScoreboard %}
67+
<col id="scoretotal"/>
68+
{% endif %}
6669
</colgroup>
6770
{% endif %}
6871
<colgroup>
@@ -79,7 +82,11 @@
7982
{% endif %}
8083
<th title="team name" scope="col" colspan="{{ teamColspan }}">team</th>
8184
{% if enable_ranking %}
82-
<th title="# solved / penalty time" colspan="2" scope="col">score</th>
85+
{% if scoringScoreboard %}
86+
<th title="points" colspan="1" scope="col">score</th>
87+
{% else %}
88+
<th title="# solved / penalty time" colspan="2" scope="col">score</th>
89+
{% endif %}
8390
{% endif %}
8491
{% if showTeamSubmissions or jury %}
8592
{% for problem in problems %}
@@ -101,7 +108,8 @@
101108
<th title="problem {{ problem.problem.name }}" scope="col">
102109
<a {% if link %}href="{{ link }}"{% endif %} target="{{ target }}">
103110
{{ problem | problemBadge }}
104-
{% if showPoints %}
111+
{% if showPoints and not scoringScoreboard %}
112+
<br/>
105113
<span class='problempoints'>
106114
[{% if problem.points == 1 %}1 point{% else %}{{ problem.points }} points{% endif %}]
107115
</span>
@@ -248,10 +256,12 @@
248256
{% if enable_ranking %}
249257
{% set totalPoints = score.numPoints %}
250258
<td class="scorenc">{{ totalPoints }}</td>
251-
{% if scoreboard.getRuntimeAsScoreTiebreaker() %}
252-
<td class="scorett">{{ "%0.3f s" | format(score.totalRuntime/1000.0) }}</td>
253-
{% else %}
254-
<td class="scorett">{{ totalTime }}</td>
259+
{% if not scoringScoreboard %}
260+
{% if scoreboard.getRuntimeAsScoreTiebreaker() %}
261+
<td class="scorett">{{ "%0.3f s" | format(score.totalRuntime/1000.0) }}</td>
262+
{% else %}
263+
<td class="scorett">{{ totalTime }}</td>
264+
{% endif %}
255265
{% endif %}
256266
{% endif %}
257267
@@ -311,8 +321,17 @@
311321
<td class="score_cell">
312322
{% if numSubmissions != '0' %}
313323
<a {% if link %}href="{{ link }}"{% endif %}>
314-
<div class="{{ scoreCssClass }}">
315-
{% if matrixItem.isCorrect %}{{ time }}{% else %}&nbsp;{% endif %}
324+
<div
325+
class="{{ scoreCssClass }}"
326+
{% if scoringScoreboard %}
327+
title="{% if matrixItem.isCorrect %}{{ time }} mins{% endif %}"
328+
{% endif %}
329+
>
330+
{% if scoringScoreboard %}
331+
{% if matrixItem.isCorrect %}{{ matrixItem.points }}{% else %}&nbsp;{% endif %}
332+
{% else %}
333+
{% if matrixItem.isCorrect %}{{ time }}{% else %}&nbsp;{% endif %}
334+
{% endif %}
316335
<span>
317336
{% if numSubmissions is same as(1) %}
318337
1 try

0 commit comments

Comments
 (0)