Skip to content

Commit a97d654

Browse files
Add test for results generation based on WF 47
1 parent ab267ec commit a97d654

File tree

10 files changed

+16283
-184
lines changed

10 files changed

+16283
-184
lines changed

webapp/src/Controller/Jury/ImportExportController.php

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace App\Controller\Jury;
44

55
use App\Controller\BaseController;
6+
use App\DataTransferObject\ResultRow;
67
use App\Entity\Clarification;
78
use App\Entity\Contest;
89
use App\Entity\ContestProblem;
@@ -321,6 +322,9 @@ public function exportTsvAction(
321322
echo sprintf("%s\t%s\n", $tsvType, $version);
322323
foreach ($data as $row) {
323324
// Utils::toTsvFields handles escaping of reserved characters.
325+
if ($row instanceof ResultRow) {
326+
$row = $row->toArray();
327+
}
324328
echo implode("\t", array_map(fn($field) => Utils::toTsvField((string)$field), $row)) . "\n";
325329
}
326330
});
@@ -391,31 +395,31 @@ protected function getResultsHtml(Request $request, bool $full = false): Respons
391395
$sortOrder = $request->query->getInt('sort_order');
392396

393397
foreach ($this->importExportService->getResultsData($sortOrder, full: $full) as $row) {
394-
$team = $teamNames[$row[0]];
395-
$rankPerTeam[$row[0]] = $row[1];
398+
$team = $teamNames[$row->teamId];
399+
$rankPerTeam[$row->teamId] = $row->rank;
396400

397-
if ($row[6] !== '') {
401+
if ($row->groupWinner) {
398402
$regionWinners[] = [
399-
'group' => $row[6],
403+
'group' => $row->groupWinner,
400404
'team' => $team,
401-
'rank' => $row[1] ?: '-',
405+
'rank' => $row->rank ?? '-',
402406
];
403407
}
404408

405409
$row = [
406410
'team' => $team,
407-
'rank' => $row[1],
408-
'award' => $row[2],
409-
'solved' => $row[3],
410-
'total_time' => $row[4],
411-
'max_time' => $row[5],
411+
'rank' => $row->rank,
412+
'award' => $row->award,
413+
'solved' => $row->numSolved,
414+
'total_time' => $row->totalTime,
415+
'max_time' => $row->timeOfLastSubmission,
412416
];
413417
if (preg_match('/^(.*) Medal$/', $row['award'], $matches)) {
414418
$row['class'] = strtolower($matches[1]);
415419
} else {
416420
$row['class'] = '';
417421
}
418-
if ($row['rank'] === '') {
422+
if ($row['rank'] === null) {
419423
$honorable[] = $row['team'];
420424
} elseif ($row['award'] === 'Ranked') {
421425
$ranked[] = $row;
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace App\DataTransferObject;
4+
5+
class ResultRow
6+
{
7+
public function __construct(
8+
public readonly string $teamId,
9+
public readonly ?int $rank,
10+
public readonly string $award,
11+
public readonly int $numSolved,
12+
public readonly int $totalTime,
13+
public readonly int $timeOfLastSubmission,
14+
public readonly ?string $groupWinner = null,
15+
) {}
16+
17+
public function toArray(): array
18+
{
19+
return [
20+
'team_id' => $this->teamId,
21+
'rank' => $this->rank,
22+
'award' => $this->award,
23+
'num_solved' => $this->numSolved,
24+
'total_time' => $this->totalTime,
25+
'time_of_last_submission' => $this->timeOfLastSubmission,
26+
'group_winner' => $this->groupWinner,
27+
];
28+
}
29+
}

webapp/src/Service/ImportExportService.php

Lines changed: 17 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace App\Service;
44

5+
use App\DataTransferObject\ResultRow;
56
use App\Entity\Configuration;
67
use App\Entity\Contest;
78
use App\Entity\ContestProblem;
@@ -456,16 +457,7 @@ public function getTeamData(): array
456457
/**
457458
* Get results data for the given sortorder.
458459
*
459-
* We'll here assume that the requested file will be of the current contest,
460-
* as all our scoreboard interfaces do:
461-
* 0 ICPC ID 24314 string
462-
* 1 Rank in contest 1 integer|''
463-
* 2 Award Gold Medal string
464-
* 3 Number of problems the team has solved 4 integer
465-
* 4 Total Time 534 integer
466-
* 5 Time of the last submission 233 integer
467-
* 6 Group Winner North American string
468-
* @return array<array{0: string, 1: integer|string, 2: string, 3: integer, 4: integer, 5: integer, 6: string}>
460+
* @return ResultRow[]
469461
*/
470462
public function getResultsData(int $sortOrder, bool $full = false): array
471463
{
@@ -545,55 +537,47 @@ public function getResultsData(int $sortOrder, bool $full = false): array
545537
$awardString = 'Ranked';
546538
} else {
547539
$awardString = 'Honorable';
548-
$rank = '';
540+
$rank = null;
549541
}
550542

551-
$groupWinner = "";
543+
$groupWinner = null;
552544
$categoryId = $teamScore->team->getCategory()->getCategoryid();
553545
if (!isset($groupWinners[$categoryId])) {
554546
$groupWinners[$categoryId] = true;
555547
$groupWinner = $teamScore->team->getCategory()->getName();
556548
}
557549

558-
$data[] = [
550+
$data[] = new ResultRow(
559551
$teamScore->team->getIcpcId(),
560552
$rank,
561553
$awardString,
562554
$teamScore->numPoints,
563555
$teamScore->totalTime,
564556
$maxTime,
565-
$groupWinner
566-
];
557+
$groupWinner,
558+
);
567559
}
568560

569561
// Sort by rank/name.
570-
uasort($data, function ($a, $b) use ($teams) {
571-
if ($a[1] != $b[1]) {
562+
uasort($data, function (ResultRow $a, ResultRow $b) use ($teams) {
563+
if ($a->rank !== $b->rank) {
572564
// Honorable mention has no rank.
573-
if ($a[1] === '') {
565+
if ($a->rank === null) {
574566
return 1;
575-
} elseif ($b[1] === '') {
567+
} elseif ($b->rank === null) {
576568
return -11;
577569
}
578-
return $a[1] - $b[1];
579-
}
580-
$teamA = $teams[$a[0]] ?? null;
581-
$teamB = $teams[$b[0]] ?? null;
582-
if ($teamA) {
583-
$nameA = $teamA->getEffectiveName();
584-
} else {
585-
$nameA = '';
586-
}
587-
if ($teamB) {
588-
$nameB = $teamB->getEffectiveName();
589-
} else {
590-
$nameB = '';
570+
return $a->rank <=> $b->rank;
591571
}
572+
$teamA = $teams[$a->teamId] ?? null;
573+
$teamB = $teams[$b->teamId] ?? null;
574+
$nameA = $teamA?->getEffectiveName();
575+
$nameB = $teamB?->getEffectiveName();
592576
$collator = new Collator('en');
593577
return $collator->compare($nameA, $nameB);
594578
});
595579

596-
return $data;
580+
return array_values($data);
597581
}
598582

599583
/**

webapp/src/Service/ScoreboardService.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -931,7 +931,7 @@ public function getScoreboardTwigData(
931931
$data['showFlags'] = $this->config->get('show_flags');
932932
$data['showAffiliationLogos'] = $this->config->get('show_affiliation_logos');
933933
$data['showAffiliations'] = $this->config->get('show_affiliations');
934-
$data['showPending'] = empty($scoreboard) || $scoreboard->getFreezeData()->showFrozen() ? $this->config->get('show_pending') : 0;
934+
$data['showPending'] = $this->config->get('show_pending');
935935
$data['showTeamSubmissions'] = $this->config->get('show_teams_submissions');
936936
$data['scoreInSeconds'] = $this->config->get('score_in_seconds');
937937
$data['maxWidth'] = $this->config->get('team_column_width');

webapp/src/Utils/Scoreboard/Scoreboard.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -154,9 +154,8 @@ protected function calculateScoreboard(): void
154154
$this->matrix[$teamId][$probId] = new ScoreboardMatrixItem(
155155
$scoreRow->getIsCorrect($this->restricted),
156156
$scoreRow->getIsCorrect($this->restricted) && $scoreRow->getIsFirstToSolve(),
157-
// When public scoreboard is frozen, also show "x + y tries" for jury
158-
$scoreRow->getSubmissions($this->freezeData->showFrozen() ? false : $this->restricted),
159-
$scoreRow->getPending($this->freezeData->showFrozen() ? false : $this->restricted),
157+
$scoreRow->getSubmissions($this->restricted),
158+
$scoreRow->getPending($this->restricted),
160159
$scoreRow->getSolveTime($this->restricted),
161160
$penalty,
162161
$scoreRow->getRuntime($this->restricted)
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
[
2+
{
3+
"hidden": false,
4+
"categoryid": 5,
5+
"id": "21495",
6+
"icpc_id": "21495",
7+
"name": "South Pacific",
8+
"sortorder": 0,
9+
"color": null,
10+
"allow_self_registration": false
11+
},
12+
{
13+
"hidden": false,
14+
"categoryid": 6,
15+
"id": "21496",
16+
"icpc_id": "21496",
17+
"name": "Europe",
18+
"sortorder": 0,
19+
"color": null,
20+
"allow_self_registration": false
21+
},
22+
{
23+
"hidden": false,
24+
"categoryid": 7,
25+
"id": "21497",
26+
"icpc_id": "21497",
27+
"name": "North America",
28+
"sortorder": 0,
29+
"color": null,
30+
"allow_self_registration": false
31+
},
32+
{
33+
"hidden": false,
34+
"categoryid": 10,
35+
"id": "21500",
36+
"icpc_id": "21500",
37+
"name": "Asia Pacific",
38+
"sortorder": 0,
39+
"color": null,
40+
"allow_self_registration": false
41+
},
42+
{
43+
"hidden": false,
44+
"categoryid": 11,
45+
"id": "21501",
46+
"icpc_id": "21501",
47+
"name": "Asia West",
48+
"sortorder": 0,
49+
"color": null,
50+
"allow_self_registration": false
51+
},
52+
{
53+
"hidden": false,
54+
"categoryid": 12,
55+
"id": "21502",
56+
"icpc_id": "21502",
57+
"name": "Northern Eurasia",
58+
"sortorder": 0,
59+
"color": null,
60+
"allow_self_registration": false
61+
},
62+
{
63+
"hidden": false,
64+
"categoryid": 23,
65+
"id": "21513",
66+
"icpc_id": "21513",
67+
"name": "Africa and Arab",
68+
"sortorder": 0,
69+
"color": null,
70+
"allow_self_registration": false
71+
},
72+
{
73+
"hidden": false,
74+
"categoryid": 24,
75+
"id": "21514",
76+
"icpc_id": "21514",
77+
"name": "Latin America",
78+
"sortorder": 0,
79+
"color": null,
80+
"allow_self_registration": false
81+
},
82+
{
83+
"hidden": false,
84+
"categoryid": 25,
85+
"id": "21515",
86+
"icpc_id": "21515",
87+
"name": "Asia",
88+
"sortorder": 0,
89+
"color": null,
90+
"allow_self_registration": false
91+
},
92+
{
93+
"hidden": false,
94+
"categoryid": 27,
95+
"id": "21517",
96+
"icpc_id": "21517",
97+
"name": "Asia East",
98+
"sortorder": 0,
99+
"color": null,
100+
"allow_self_registration": false
101+
}
102+
]

0 commit comments

Comments
 (0)