Skip to content

Commit 830d743

Browse files
committed
Move getVerdicts to ConfigurationService
Also add some documentation.
1 parent ebacfa6 commit 830d743

11 files changed

+45
-32
lines changed

webapp/src/Controller/API/JudgementController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public function __construct(
4444
) {
4545
parent::__construct($entityManager, $DOMJudgeService, $config, $eventLogService);
4646

47-
$this->verdicts = $this->dj->getVerdicts(['final', 'error']);
47+
$this->verdicts = $this->config->getVerdicts(['final', 'error']);
4848
}
4949

5050
/**

webapp/src/Controller/API/JudgementTypeController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ public function singleAction(Request $request, string $id): JudgementType
8585
*/
8686
protected function getJudgementTypes(?array $filteredOn = null): array
8787
{
88-
$verdicts = $this->dj->getVerdicts(['final', 'external']);
88+
$verdicts = $this->config->getVerdicts(['final', 'external']);
8989

9090
$result = [];
9191
foreach ($verdicts as $name => $label) {

webapp/src/Controller/API/RunController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public function __construct(
4646
parent::__construct($entityManager, $DOMJudgeService, $config,
4747
$eventLogService);
4848

49-
$this->verdicts = $this->dj->getVerdicts();
49+
$this->verdicts = $this->config->getVerdicts();
5050
}
5151

5252
/**

webapp/src/Controller/Jury/RejudgingController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ public function viewAction(
243243
$todo = $todoAndDone['todo'];
244244
$done = $todoAndDone['done'];
245245

246-
$verdicts = $this->dj->getVerdicts(['final', 'error']);
246+
$verdicts = $this->config->getVerdicts(['final', 'error']);
247247
$verdicts[''] = 'JE'; /* happens for aborted judgings */
248248

249249
$used = [];

webapp/src/Controller/Jury/ShadowDifferencesController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ public function indexAction(
8383
$this->requestStack->getSession()->save();
8484

8585
$contest = $this->dj->getCurrentContest();
86-
$verdicts = $this->dj->getVerdicts(['final', 'error', 'external', 'in_progress']);
86+
$verdicts = $this->config->getVerdicts(['final', 'error', 'external', 'in_progress']);
8787

8888
$used = [];
8989
$verdictTable = [];

webapp/src/Controller/Jury/SubmissionController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ public function indexAction(
138138
// Load preselected filters
139139
$filters = Utils::jsonDecode((string)$this->dj->getCookie('domjudge_submissionsfilter') ?: '[]');
140140

141-
$results = array_keys($this->dj->getVerdicts(['final', 'in_progress']));
141+
$results = array_keys($this->config->getVerdicts(['final', 'in_progress']));
142142

143143
$data = [
144144
'refresh' => $refresh,

webapp/src/Form/Type/RejudgingType.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
107107
->orderBy('j.hostname'),
108108
]);
109109

110-
$verdicts = array_keys($this->dj->getVerdicts());
110+
$verdicts = array_keys($this->config->getVerdicts());
111111
$builder->add('verdicts', ChoiceType::class, [
112112
'label' => 'Verdict',
113113
'multiple' => true,

webapp/src/Form/Type/SubmissionsFilterType.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
115115
"attr" => ["data-filter-field" => "team-id"],
116116
]);
117117

118-
$verdicts = array_keys($this->dj->getVerdicts(['final', 'error', 'in_progress']));
118+
$verdicts = array_keys($this->config->getVerdicts(['final', 'error', 'in_progress']));
119119
$builder->add("result", ChoiceType::class, [
120120
"label" => "Filter on result(s)",
121121
"multiple" => true,

webapp/src/Service/ConfigurationService.php

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,41 @@ public function addOptions(ConfigurationSpecification $item): ConfigurationSpeci
399399
return $item;
400400
}
401401

402+
/**
403+
* Returns all possible judgement (run) verdicts, both internally
404+
* hardcoded and from configured judgement types. Depending on the
405+
* requirements of the context, the following groups of verdicts can be
406+
* requests:
407+
* - final: final verdicts supported by the system
408+
* - error: error states that must be resolved by an admin
409+
* - in_progress: states reported when a judging is pending a final verdict
410+
* - external: configured verdicts when importing from an external system
411+
*
412+
* Verdicts are returned as an associative array of name/2-3 letter
413+
* identifier key/value pairs. The identifiers try to adhere to
414+
* https://ccs-specs.icpc.io/draft/contest_api#known-judgement-types
415+
*
416+
* @return array<string, string>
417+
*/
418+
public function getVerdicts(array $groups = ['final']): array
419+
{
420+
$verdictsConfig = $this->etcDir . '/verdicts.php';
421+
$verdictGroups = include $verdictsConfig;
422+
423+
$verdicts = [];
424+
foreach( $groups as $group ) {
425+
if ( $group === 'external' ) {
426+
foreach ($this->get('external_judgement_types') as $id => $name) {
427+
$verdicts[$name] = $id;
428+
}
429+
} else {
430+
$verdicts = array_merge($verdicts, $verdictGroups[$group]);
431+
}
432+
}
433+
434+
return $verdicts;
435+
}
436+
402437
public function getRunConfig(ContestProblem $problem, Submission $submission, int $overshoot = 0): string
403438
{
404439
$memoryLimit = $problem->getProblem()->getMemlimit();

webapp/src/Service/DOMJudgeService.php

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1425,28 +1425,6 @@ public function parseMetadata(string $raw_metadata): array
14251425
return $res;
14261426
}
14271427

1428-
/**
1429-
* @return array<string, string>
1430-
*/
1431-
public function getVerdicts(array $groups = ['final']): array
1432-
{
1433-
$verdictsConfig = $this->getDomjudgeEtcDir() . '/verdicts.php';
1434-
$verdictGroups = include $verdictsConfig;
1435-
1436-
$verdicts = [];
1437-
foreach( $groups as $group ) {
1438-
if ( $group === 'external' ) {
1439-
foreach ($this->config->get('external_judgement_types') as $id => $name) {
1440-
$verdicts[$name] = $id;
1441-
}
1442-
} else {
1443-
$verdicts = array_merge($verdicts, $verdictGroups[$group]);
1444-
}
1445-
}
1446-
1447-
return $verdicts;
1448-
}
1449-
14501428
public function getScoreboardZip(
14511429
Request $request,
14521430
RequestStack $requestStack,

0 commit comments

Comments
 (0)