Skip to content

Add a basic visualization for the scoring scoreboard type. #3010

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion webapp/src/Service/ScoreboardService.php
Original file line number Diff line number Diff line change
Expand Up @@ -554,7 +554,7 @@ public function updateRankCache(Contest $contest, Team $team): void
}
}

const SCALE = 9;
public const SCALE = 9;

// Converts integer or bcmath floats to a string that can be used as a key in a score cache.
// The resulting key will be a string with 33 characters, 23 before the decimal dot and 9 after.
Expand Down
22 changes: 19 additions & 3 deletions webapp/src/Utils/Scoreboard/Scoreboard.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use App\Entity\Contest;
use App\Entity\ContestProblem;
use App\Entity\RankCache;
use App\Entity\ScoreboardType;
use App\Entity\ScoreCache;
use App\Entity\Team;
use App\Entity\TeamCategory;
Expand Down Expand Up @@ -152,22 +153,32 @@ protected function calculateScoreboard(): void
!array_key_exists($probId, $this->problems)) {
continue;
}
$isCorrect = $scoreCell->getIsCorrect($this->restricted);

$penalty = Utils::calcPenaltyTime(
$scoreCell->getIsCorrect($this->restricted),
$isCorrect,
$scoreCell->getSubmissions($this->restricted),
$this->penaltyTime, $this->scoreIsInSeconds
);

$contestProblem = $scoreCell->getContest()->getContestProblem($scoreCell->getProblem());
// TODO: For actual scoring problems, we need to calculate the score here and
// output it with the correct precision. For now, this is always an integer.
$points = strval(
$isCorrect ?
$contestProblem->getPoints() : 0
);

$this->matrix[$teamId][$probId] = new ScoreboardMatrixItem(
isCorrect: $scoreCell->getIsCorrect($this->restricted),
isFirst: $scoreCell->getIsCorrect($this->restricted) && $scoreCell->getIsFirstToSolve(),
isCorrect: $isCorrect,
isFirst: $isCorrect && $scoreCell->getIsFirstToSolve(),
numSubmissions: $scoreCell->getSubmissions($this->restricted),
numSubmissionsPending: $scoreCell->getPending($this->restricted),
time: $scoreCell->getSolveTime($this->restricted),
penaltyTime: $penalty,
runtime: $scoreCell->getRuntime($this->restricted),
numSubmissionsInFreeze: $scoreCell->getPending(false),
points: $points,
);
}

Expand Down Expand Up @@ -257,6 +268,11 @@ public function showPoints(): bool
return false;
}

public function isScoring(): bool
{
return $this->contest->getScoreboardType() === ScoreboardType::SCORING;
}

/**
* Return the used team categories for this scoreboard.
*
Expand Down
1 change: 1 addition & 0 deletions webapp/src/Utils/Scoreboard/ScoreboardMatrixItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@ public function __construct(
public int $penaltyTime,
public int $runtime,
public ?int $numSubmissionsInFreeze = null,
public string $points = "",
) {}
}
4 changes: 3 additions & 1 deletion webapp/templates/partials/scoreboard_summary.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@
{{ scoreboard.summary.numberOfPoints(sortOrder) }}
</td>
{% endif %}
<td></td>
{% if not scoringScoreboard %}
<td></td>
{% endif %}
{% endif %}
{% for problem in scoreboard.problems %}
{% set summary = scoreboard.summary.problem(problem.probid) %}
Expand Down
37 changes: 28 additions & 9 deletions webapp/templates/partials/scoreboard_table.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
{% set static = false %}
{% endif %}
{% set showPoints = scoreboard.showPoints %}
{% set scoringScoreboard = scoreboard.isScoring %}
{% set usedCategories = scoreboard.usedCategories(limitToTeamIds) %}
{% set hasDifferentCategoryColors = scoreboard.categoryColors(limitToTeamIds) %}
{% set scores = scoreboard.scores | filter(score => limitToTeams is null or score.team.teamid in limitToTeamIds) %}
Expand Down Expand Up @@ -62,7 +63,9 @@
{% if enable_ranking %}
<colgroup>
<col id="scoresolv"/>
<col id="scoretotal"/>
{% if not scoringScoreboard %}
<col id="scoretotal"/>
{% endif %}
</colgroup>
{% endif %}
<colgroup>
Expand All @@ -79,7 +82,11 @@
{% endif %}
<th title="team name" scope="col" colspan="{{ teamColspan }}">team</th>
{% if enable_ranking %}
<th title="# solved / penalty time" colspan="2" scope="col">score</th>
{% if scoringScoreboard %}
<th title="points" colspan="1" scope="col">score</th>
{% else %}
<th title="# solved / penalty time" colspan="2" scope="col">score</th>
{% endif %}
{% endif %}
{% if showTeamSubmissions or jury %}
{% for problem in problems %}
Expand All @@ -101,7 +108,8 @@
<th title="problem {{ problem.problem.name }}" scope="col">
<a {% if link %}href="{{ link }}"{% endif %} target="{{ target }}">
{{ problem | problemBadge }}
{% if showPoints %}
{% if showPoints and not scoringScoreboard %}
<br/>
<span class='problempoints'>
[{% if problem.points == 1 %}1 point{% else %}{{ problem.points }} points{% endif %}]
</span>
Expand Down Expand Up @@ -248,10 +256,12 @@
{% if enable_ranking %}
{% set totalPoints = score.numPoints %}
<td class="scorenc">{{ totalPoints }}</td>
{% if scoreboard.getRuntimeAsScoreTiebreaker() %}
<td class="scorett">{{ "%0.3f s" | format(score.totalRuntime/1000.0) }}</td>
{% else %}
<td class="scorett">{{ totalTime }}</td>
{% if not scoringScoreboard %}
{% if scoreboard.getRuntimeAsScoreTiebreaker() %}
<td class="scorett">{{ "%0.3f s" | format(score.totalRuntime/1000.0) }}</td>
{% else %}
<td class="scorett">{{ totalTime }}</td>
{% endif %}
{% endif %}
{% endif %}

Expand Down Expand Up @@ -311,8 +321,17 @@
<td class="score_cell">
{% if numSubmissions != '0' %}
<a {% if link %}href="{{ link }}"{% endif %}>
<div class="{{ scoreCssClass }}">
{% if matrixItem.isCorrect %}{{ time }}{% else %}&nbsp;{% endif %}
<div
class="{{ scoreCssClass }}"
{% if scoringScoreboard %}
title="{% if matrixItem.isCorrect %}{{ time }} mins{% endif %}"
{% endif %}
>
{% if scoringScoreboard %}
{% if matrixItem.isCorrect %}{{ matrixItem.points }}{% else %}&nbsp;{% endif %}
{% else %}
{% if matrixItem.isCorrect %}{{ time }}{% else %}&nbsp;{% endif %}
{% endif %}
<span>
{% if numSubmissions is same as(1) %}
1 try
Expand Down
1 change: 1 addition & 0 deletions webapp/tests/Unit/Service/AwardServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ protected function setUp(): void
)
->setContest($this->contest)
->setShortname($problemLabel);
$this->contest->addProblem($problem);
$reflectedProblem = new ReflectionClass(Problem::class);
$probIdProperty = $reflectedProblem->getProperty('probid');
$probIdProperty->setAccessible(true);
Expand Down
1 change: 1 addition & 0 deletions webapp/tests/Unit/Service/ImportExportServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1252,6 +1252,7 @@ public function testGetResultsData(bool $full, bool $honors, string $dataSet, st
->setShortname($problemData['label']);
$em->persist($problem);
$em->persist($contestProblem);
$contest->addProblem($contestProblem);
$em->flush();
$contestProblemsById[$contestProblem->getExternalid()] = $contestProblem;
}
Expand Down
Loading