Skip to content

Commit

Permalink
Move getVerdicts to ConfigurationService
Browse files Browse the repository at this point in the history
Also add some documentation.
  • Loading branch information
eldering committed Dec 3, 2024
1 parent ebacfa6 commit 830d743
Show file tree
Hide file tree
Showing 11 changed files with 45 additions and 32 deletions.
2 changes: 1 addition & 1 deletion webapp/src/Controller/API/JudgementController.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function __construct(
) {
parent::__construct($entityManager, $DOMJudgeService, $config, $eventLogService);

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

/**
Expand Down
2 changes: 1 addition & 1 deletion webapp/src/Controller/API/JudgementTypeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public function singleAction(Request $request, string $id): JudgementType
*/
protected function getJudgementTypes(?array $filteredOn = null): array
{
$verdicts = $this->dj->getVerdicts(['final', 'external']);
$verdicts = $this->config->getVerdicts(['final', 'external']);

$result = [];
foreach ($verdicts as $name => $label) {
Expand Down
2 changes: 1 addition & 1 deletion webapp/src/Controller/API/RunController.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public function __construct(
parent::__construct($entityManager, $DOMJudgeService, $config,
$eventLogService);

$this->verdicts = $this->dj->getVerdicts();
$this->verdicts = $this->config->getVerdicts();
}

/**
Expand Down
2 changes: 1 addition & 1 deletion webapp/src/Controller/Jury/RejudgingController.php
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ public function viewAction(
$todo = $todoAndDone['todo'];
$done = $todoAndDone['done'];

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

$used = [];
Expand Down
2 changes: 1 addition & 1 deletion webapp/src/Controller/Jury/ShadowDifferencesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public function indexAction(
$this->requestStack->getSession()->save();

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

$used = [];
$verdictTable = [];
Expand Down
2 changes: 1 addition & 1 deletion webapp/src/Controller/Jury/SubmissionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ public function indexAction(
// Load preselected filters
$filters = Utils::jsonDecode((string)$this->dj->getCookie('domjudge_submissionsfilter') ?: '[]');

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

$data = [
'refresh' => $refresh,
Expand Down
2 changes: 1 addition & 1 deletion webapp/src/Form/Type/RejudgingType.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
->orderBy('j.hostname'),
]);

$verdicts = array_keys($this->dj->getVerdicts());
$verdicts = array_keys($this->config->getVerdicts());
$builder->add('verdicts', ChoiceType::class, [
'label' => 'Verdict',
'multiple' => true,
Expand Down
2 changes: 1 addition & 1 deletion webapp/src/Form/Type/SubmissionsFilterType.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
"attr" => ["data-filter-field" => "team-id"],
]);

$verdicts = array_keys($this->dj->getVerdicts(['final', 'error', 'in_progress']));
$verdicts = array_keys($this->config->getVerdicts(['final', 'error', 'in_progress']));
$builder->add("result", ChoiceType::class, [
"label" => "Filter on result(s)",
"multiple" => true,
Expand Down
35 changes: 35 additions & 0 deletions webapp/src/Service/ConfigurationService.php
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,41 @@ public function addOptions(ConfigurationSpecification $item): ConfigurationSpeci
return $item;
}

/**
* Returns all possible judgement (run) verdicts, both internally
* hardcoded and from configured judgement types. Depending on the
* requirements of the context, the following groups of verdicts can be
* requests:
* - final: final verdicts supported by the system
* - error: error states that must be resolved by an admin
* - in_progress: states reported when a judging is pending a final verdict
* - external: configured verdicts when importing from an external system
*
* Verdicts are returned as an associative array of name/2-3 letter
* identifier key/value pairs. The identifiers try to adhere to
* https://ccs-specs.icpc.io/draft/contest_api#known-judgement-types
*
* @return array<string, string>
*/
public function getVerdicts(array $groups = ['final']): array
{
$verdictsConfig = $this->etcDir . '/verdicts.php';
$verdictGroups = include $verdictsConfig;

$verdicts = [];
foreach( $groups as $group ) {

Check failure on line 424 in webapp/src/Service/ConfigurationService.php

View workflow job for this annotation

GitHub Actions / phpcs

Expected 1 space(s) after FOREACH keyword; 0 found

Check failure on line 424 in webapp/src/Service/ConfigurationService.php

View workflow job for this annotation

GitHub Actions / phpcs

Expected 0 spaces after opening bracket; 1 found

Check failure on line 424 in webapp/src/Service/ConfigurationService.php

View workflow job for this annotation

GitHub Actions / phpcs

Expected 0 spaces before closing bracket; 1 found
if ( $group === 'external' ) {

Check failure on line 425 in webapp/src/Service/ConfigurationService.php

View workflow job for this annotation

GitHub Actions / phpcs

Expected 0 spaces after opening bracket; 1 found

Check failure on line 425 in webapp/src/Service/ConfigurationService.php

View workflow job for this annotation

GitHub Actions / phpcs

Expected 0 spaces before closing bracket; 1 found
foreach ($this->get('external_judgement_types') as $id => $name) {
$verdicts[$name] = $id;
}
} else {
$verdicts = array_merge($verdicts, $verdictGroups[$group]);
}
}

return $verdicts;
}

public function getRunConfig(ContestProblem $problem, Submission $submission, int $overshoot = 0): string
{
$memoryLimit = $problem->getProblem()->getMemlimit();
Expand Down
22 changes: 0 additions & 22 deletions webapp/src/Service/DOMJudgeService.php
Original file line number Diff line number Diff line change
Expand Up @@ -1425,28 +1425,6 @@ public function parseMetadata(string $raw_metadata): array
return $res;
}

/**
* @return array<string, string>
*/
public function getVerdicts(array $groups = ['final']): array
{
$verdictsConfig = $this->getDomjudgeEtcDir() . '/verdicts.php';
$verdictGroups = include $verdictsConfig;

$verdicts = [];
foreach( $groups as $group ) {
if ( $group === 'external' ) {
foreach ($this->config->get('external_judgement_types') as $id => $name) {
$verdicts[$name] = $id;
}
} else {
$verdicts = array_merge($verdicts, $verdictGroups[$group]);
}
}

return $verdicts;
}

public function getScoreboardZip(
Request $request,
RequestStack $requestStack,
Expand Down
4 changes: 2 additions & 2 deletions webapp/src/Service/ExternalContestSourceService.php
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ public function getLastReadEventId(): ?string
public function import(bool $fromStart, array $eventsToSkip, ?callable $progressReporter = null): bool
{
// We need the verdicts to validate judgement-types.
$this->verdicts = $this->dj->getVerdicts(['final', 'external']);
$this->verdicts = $this->config->getVerdicts(['final', 'external']);

if (!$this->isValidContestSource()) {
throw new LogicException('The contest source is not valid');
Expand Down Expand Up @@ -799,7 +799,7 @@ protected function importJudgementType(Event $event, EventData $data): void
$customVerdicts = $this->config->get('external_judgement_types');
$customVerdicts[$verdict] = str_replace(' ', '-', $data->name);
$this->config->saveChanges(['external_judgement_types' => $customVerdicts], $this->eventLog, $this->dj);
$this->verdicts = $this->dj->getVerdicts(['final', 'external']);
$this->verdicts = $this->config->getVerdicts(['final', 'external']);
$penalty = true;
$solved = false;
$this->logger->warning('Judgement type %s not found locally, importing as external verdict', [$verdict]);
Expand Down

0 comments on commit 830d743

Please sign in to comment.