From 754779b4408de2beb6a1b9a4b6d6bf50012cc4d8 Mon Sep 17 00:00:00 2001 From: Jaap Eldering Date: Sun, 24 Nov 2024 14:49:37 +0100 Subject: [PATCH] Create verdict groups that selectively can be used Instead of manually adding various verdicts to the list in different places. This is not completely equivalent to before, but the changes should be fine. The original behaviour of calling `getVerdicts` without arguments is unchanged and `getVerdicts(mergeExternal: true)` maps to `getVerdicts(['final', 'external'])`. --- etc/verdicts.php | 28 +++++++++++++------ .../Controller/API/JudgementController.php | 4 +-- .../API/JudgementTypeController.php | 2 +- .../Controller/Jury/RejudgingController.php | 3 +- .../Jury/ShadowDifferencesController.php | 4 +-- .../Controller/Jury/SubmissionController.php | 4 +-- .../src/Form/Type/SubmissionsFilterType.php | 5 +--- webapp/src/Service/DOMJudgeService.php | 15 ++++++---- .../Service/ExternalContestSourceService.php | 4 +-- 9 files changed, 38 insertions(+), 31 deletions(-) diff --git a/etc/verdicts.php b/etc/verdicts.php index a489479591..0f6f3b0aed 100644 --- a/etc/verdicts.php +++ b/etc/verdicts.php @@ -4,12 +4,24 @@ // CCS specification (and a few more common ones) at: // https://ccs-specs.icpc.io/2021-11/ccs_system_requirements#judge-responses return [ - 'compiler-error' => 'CE', - 'memory-limit' => 'MLE', - 'output-limit' => 'OLE', - 'run-error' => 'RTE', - 'timelimit' => 'TLE', - 'wrong-answer' => 'WA', - 'no-output' => 'NO', - 'correct' => 'AC', + 'final' => [ + 'compiler-error' => 'CE', + 'memory-limit' => 'MLE', + 'output-limit' => 'OLE', + 'run-error' => 'RTE', + 'timelimit' => 'TLE', + 'wrong-answer' => 'WA', + 'no-output' => 'NO', + 'correct' => 'AC', + ], + 'error' => [ + 'aborted' => 'JE', + 'import-error' => 'IE', + ], + 'in_progress' => [ + 'judging' => 'JU', + 'pending' => 'JU', + 'queued' => 'JU', + ], + // The 'external' group is defined in configuration. ]; diff --git a/webapp/src/Controller/API/JudgementController.php b/webapp/src/Controller/API/JudgementController.php index 2b9d089d29..ec252ed09e 100644 --- a/webapp/src/Controller/API/JudgementController.php +++ b/webapp/src/Controller/API/JudgementController.php @@ -44,9 +44,7 @@ public function __construct( ) { parent::__construct($entityManager, $DOMJudgeService, $config, $eventLogService); - $verdicts = $this->dj->getVerdicts(); - $verdicts['aborted'] = 'JE'; /* happens for aborted judgings */ - $this->verdicts = $verdicts; + $this->verdicts = $this->dj->getVerdicts(['final', 'error']); } /** diff --git a/webapp/src/Controller/API/JudgementTypeController.php b/webapp/src/Controller/API/JudgementTypeController.php index fe4bb3ae81..52aa5cf934 100644 --- a/webapp/src/Controller/API/JudgementTypeController.php +++ b/webapp/src/Controller/API/JudgementTypeController.php @@ -85,7 +85,7 @@ public function singleAction(Request $request, string $id): JudgementType */ protected function getJudgementTypes(?array $filteredOn = null): array { - $verdicts = $this->dj->getVerdicts(mergeExternal: true); + $verdicts = $this->dj->getVerdicts(['final', 'external']); $result = []; foreach ($verdicts as $name => $label) { diff --git a/webapp/src/Controller/Jury/RejudgingController.php b/webapp/src/Controller/Jury/RejudgingController.php index 73f47292d4..14289b6f5a 100644 --- a/webapp/src/Controller/Jury/RejudgingController.php +++ b/webapp/src/Controller/Jury/RejudgingController.php @@ -241,9 +241,8 @@ public function viewAction( } $todo = $this->rejudgingService->calculateTodo($rejudging)['todo']; - $verdicts = $this->dj->getVerdicts(); + $verdicts = $this->dj->getVerdicts(['final', 'error']); $verdicts[''] = 'JE'; /* happens for aborted judgings */ - $verdicts['aborted'] = 'JE'; /* happens for aborted judgings */ $used = []; $verdictTable = []; diff --git a/webapp/src/Controller/Jury/ShadowDifferencesController.php b/webapp/src/Controller/Jury/ShadowDifferencesController.php index 576c4cbfb3..f1f5b7a40e 100644 --- a/webapp/src/Controller/Jury/ShadowDifferencesController.php +++ b/webapp/src/Controller/Jury/ShadowDifferencesController.php @@ -83,9 +83,7 @@ public function indexAction( $this->requestStack->getSession()->save(); $contest = $this->dj->getCurrentContest(); - $verdicts = array_merge(['judging' => 'JU'], $this->dj->getVerdicts(mergeExternal: true)); - - $verdicts['import-error'] = 'IE'; + $verdicts = $this->dj->getVerdicts(['final', 'error', 'external', 'in_progress']); $used = []; $verdictTable = []; diff --git a/webapp/src/Controller/Jury/SubmissionController.php b/webapp/src/Controller/Jury/SubmissionController.php index 6c13465112..20f40e2168 100644 --- a/webapp/src/Controller/Jury/SubmissionController.php +++ b/webapp/src/Controller/Jury/SubmissionController.php @@ -138,9 +138,7 @@ public function indexAction( // Load preselected filters $filters = $this->dj->jsonDecode((string)$this->dj->getCookie('domjudge_submissionsfilter') ?: '[]'); - $results = array_keys($this->dj->getVerdicts()); - $results[] = 'judging'; - $results[] = 'queued'; + $results = array_keys($this->dj->getVerdicts(['final', 'in_progress'])); $data = [ 'refresh' => $refresh, diff --git a/webapp/src/Form/Type/SubmissionsFilterType.php b/webapp/src/Form/Type/SubmissionsFilterType.php index 3e93340729..9629cbf861 100644 --- a/webapp/src/Form/Type/SubmissionsFilterType.php +++ b/webapp/src/Form/Type/SubmissionsFilterType.php @@ -115,10 +115,7 @@ public function buildForm(FormBuilderInterface $builder, array $options): void "attr" => ["data-filter-field" => "team-id"], ]); - $verdicts = array_keys($this->dj->getVerdicts()); - $verdicts[] = "judging"; - $verdicts[] = "queued"; - $verdicts[] = "import-error"; + $verdicts = array_keys($this->dj->getVerdicts(['final', 'error', 'in_progress'])); $builder->add("result", ChoiceType::class, [ "label" => "Filter on result(s)", "multiple" => true, diff --git a/webapp/src/Service/DOMJudgeService.php b/webapp/src/Service/DOMJudgeService.php index 6e9cda2392..bdcb4cb263 100644 --- a/webapp/src/Service/DOMJudgeService.php +++ b/webapp/src/Service/DOMJudgeService.php @@ -1485,14 +1485,19 @@ public function getCompileConfig(Submission $submission): string /** * @return array */ - public function getVerdicts(bool $mergeExternal = false): array + public function getVerdicts(array $groups = ['final']): array { $verdictsConfig = $this->getDomjudgeEtcDir() . '/verdicts.php'; - $verdicts = include $verdictsConfig; + $verdictGroups = include $verdictsConfig; - if ($mergeExternal) { - foreach ($this->config->get('external_judgement_types') as $id => $name) { - $verdicts[$name] = $id; + $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]); } } diff --git a/webapp/src/Service/ExternalContestSourceService.php b/webapp/src/Service/ExternalContestSourceService.php index bad3824ab9..3c525ffb6c 100644 --- a/webapp/src/Service/ExternalContestSourceService.php +++ b/webapp/src/Service/ExternalContestSourceService.php @@ -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(mergeExternal: true); + $this->verdicts = $this->dj->getVerdicts(['final', 'external']); if (!$this->isValidContestSource()) { throw new LogicException('The contest source is not valid'); @@ -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(mergeExternal: true); + $this->verdicts = $this->dj->getVerdicts(['final', 'external']); $penalty = true; $solved = false; $this->logger->warning('Judgement type %s not found locally, importing as external verdict', [$verdict]);