From 7591de5cbe2da270e49053eb0abbf9a573036caf 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 a20a3fd350..72affb88ae 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 f8e1e64128..a42b7695f6 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 d889ce3352..c4031e4b75 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 3d0212d523..507fcb2617 100644 --- a/webapp/src/Service/ExternalContestSourceService.php +++ b/webapp/src/Service/ExternalContestSourceService.php @@ -267,7 +267,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'); @@ -797,7 +797,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]);