From 50f854bb7e1b264b541be72fb2d2cfec80af87f3 Mon Sep 17 00:00:00 2001 From: Jaap Eldering Date: Tue, 3 Dec 2024 22:51:56 +0100 Subject: [PATCH] Move get{Run,Compare,Compile}Config methods to ConfigurationService Start disentangling the mess in DOMJudgeService and these methods don't depend on anything but config. --- .../Controller/Jury/SubmissionController.php | 6 +- webapp/src/Service/ConfigurationService.php | 58 +++++++++++++++++ webapp/src/Service/DOMJudgeService.php | 62 +------------------ 3 files changed, 64 insertions(+), 62 deletions(-) diff --git a/webapp/src/Controller/Jury/SubmissionController.php b/webapp/src/Controller/Jury/SubmissionController.php index 20f40e2168..7f45e99b5b 100644 --- a/webapp/src/Controller/Jury/SubmissionController.php +++ b/webapp/src/Controller/Jury/SubmissionController.php @@ -575,15 +575,15 @@ public function viewAction( if ($sampleJudgeTask !== null) { $errors = []; $this->maybeGetErrors('Compile config', - $this->dj->getCompileConfig($submission), + $this->config->getCompileConfig($submission), $sampleJudgeTask->getCompileConfig(), $errors); $this->maybeGetErrors('Run config', - $this->dj->getRunConfig($contestProblem, $submission), + $this->config->getRunConfig($contestProblem, $submission), $sampleJudgeTask->getRunConfig(), $errors); $this->maybeGetErrors('Compare config', - $this->dj->getCompareConfig($contestProblem), + $this->config->getCompareConfig($contestProblem), $sampleJudgeTask->getCompareConfig(), $errors); if (!empty($errors)) { diff --git a/webapp/src/Service/ConfigurationService.php b/webapp/src/Service/ConfigurationService.php index 6fe72c340f..dd7af91ab4 100644 --- a/webapp/src/Service/ConfigurationService.php +++ b/webapp/src/Service/ConfigurationService.php @@ -5,8 +5,10 @@ use App\Config\Loader\YamlConfigLoader; use App\DataTransferObject\ConfigurationSpecification; use App\Entity\Configuration; +use App\Entity\ContestProblem; use App\Entity\Executable; use App\Entity\Judging; +use App\Entity\Submission; use BackedEnum; use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\NonUniqueResultException; @@ -395,4 +397,60 @@ public function addOptions(ConfigurationSpecification $item): ConfigurationSpeci } return $item; } + + public function getRunConfig(ContestProblem $problem, Submission $submission, int $overshoot = 0): string + { + $memoryLimit = $problem->getProblem()->getMemlimit(); + $outputLimit = $problem->getProblem()->getOutputlimit(); + if (empty($memoryLimit)) { + $memoryLimit = $this->config->get('memory_limit'); + } + if (empty($outputLimit)) { + $outputLimit = $this->config->get('output_limit'); + } + $runExecutable = $this->getImmutableRunExecutable($problem); + + return $this->jsonEncode( + [ + 'time_limit' => $problem->getProblem()->getTimelimit() * $submission->getLanguage()->getTimeFactor(), + 'memory_limit' => $memoryLimit, + 'output_limit' => $outputLimit, + 'process_limit' => $this->config->get('process_limit'), + 'entry_point' => $submission->getEntryPoint(), + 'pass_limit' => $problem->getProblem()->getMultipassLimit(), + 'hash' => $runExecutable->getHash(), + 'overshoot' => $overshoot, + ] + ); + } + + public function getCompareConfig(ContestProblem $problem): string + { + $compareExecutable = $this->getImmutableCompareExecutable($problem); + return $this->jsonEncode( + [ + 'script_timelimit' => $this->config->get('script_timelimit'), + 'script_memory_limit' => $this->config->get('script_memory_limit'), + 'script_filesize_limit' => $this->config->get('script_filesize_limit'), + 'compare_args' => $problem->getProblem()->getSpecialCompareArgs(), + 'combined_run_compare' => $problem->getProblem()->getCombinedRunCompare(), + 'hash' => $compareExecutable->getHash(), + ] + ); + } + + public function getCompileConfig(Submission $submission): string + { + $compileExecutable = $submission->getLanguage()->getCompileExecutable()->getImmutableExecutable(); + return $this->jsonEncode( + [ + 'script_timelimit' => $this->config->get('script_timelimit'), + 'script_memory_limit' => $this->config->get('script_memory_limit'), + 'script_filesize_limit' => $this->config->get('script_filesize_limit'), + 'language_extensions' => $submission->getLanguage()->getExtensions(), + 'filter_compiler_files' => $submission->getLanguage()->getFilterCompilerFiles(), + 'hash' => $compileExecutable->getHash(), + ] + ); + } } diff --git a/webapp/src/Service/DOMJudgeService.php b/webapp/src/Service/DOMJudgeService.php index b2914afef2..07a6868bc0 100644 --- a/webapp/src/Service/DOMJudgeService.php +++ b/webapp/src/Service/DOMJudgeService.php @@ -1442,62 +1442,6 @@ public function parseMetadata(string $raw_metadata): array return $res; } - public function getRunConfig(ContestProblem $problem, Submission $submission, int $overshoot = 0): string - { - $memoryLimit = $problem->getProblem()->getMemlimit(); - $outputLimit = $problem->getProblem()->getOutputlimit(); - if (empty($memoryLimit)) { - $memoryLimit = $this->config->get('memory_limit'); - } - if (empty($outputLimit)) { - $outputLimit = $this->config->get('output_limit'); - } - $runExecutable = $this->getImmutableRunExecutable($problem); - - return $this->jsonEncode( - [ - 'time_limit' => $problem->getProblem()->getTimelimit() * $submission->getLanguage()->getTimeFactor(), - 'memory_limit' => $memoryLimit, - 'output_limit' => $outputLimit, - 'process_limit' => $this->config->get('process_limit'), - 'entry_point' => $submission->getEntryPoint(), - 'pass_limit' => $problem->getProblem()->getMultipassLimit(), - 'hash' => $runExecutable->getHash(), - 'overshoot' => $overshoot, - ] - ); - } - - public function getCompareConfig(ContestProblem $problem): string - { - $compareExecutable = $this->getImmutableCompareExecutable($problem); - return $this->jsonEncode( - [ - 'script_timelimit' => $this->config->get('script_timelimit'), - 'script_memory_limit' => $this->config->get('script_memory_limit'), - 'script_filesize_limit' => $this->config->get('script_filesize_limit'), - 'compare_args' => $problem->getProblem()->getSpecialCompareArgs(), - 'combined_run_compare' => $problem->getProblem()->getCombinedRunCompare(), - 'hash' => $compareExecutable->getHash(), - ] - ); - } - - public function getCompileConfig(Submission $submission): string - { - $compileExecutable = $submission->getLanguage()->getCompileExecutable()->getImmutableExecutable(); - return $this->jsonEncode( - [ - 'script_timelimit' => $this->config->get('script_timelimit'), - 'script_memory_limit' => $this->config->get('script_memory_limit'), - 'script_filesize_limit' => $this->config->get('script_filesize_limit'), - 'language_extensions' => $submission->getLanguage()->getExtensions(), - 'filter_compiler_files' => $submission->getLanguage()->getFilterCompilerFiles(), - 'hash' => $compileExecutable->getHash(), - ] - ); - } - /** * @return array */ @@ -1630,9 +1574,9 @@ private function actuallyCreateJudgetasks(int $priority, Judging $judging, int $ ':compile_script_id' => $compileExecutable->getImmutableExecId(), ':compare_script_id' => $this->getImmutableCompareExecutable($problem)->getImmutableExecId(), ':run_script_id' => $this->getImmutableRunExecutable($problem)->getImmutableExecId(), - ':compile_config' => $this->getCompileConfig($submission), - ':run_config' => $this->getRunConfig($problem, $submission, $overshoot), - ':compare_config' => $this->getCompareConfig($problem), + ':compile_config' => $this->config->getCompileConfig($submission), + ':run_config' => $this->config->getRunConfig($problem, $submission, $overshoot), + ':compare_config' => $this->config->getCompareConfig($problem), ]; $judgetaskDefaultParamNames = array_keys($judgetaskInsertParams);