Skip to content

Commit

Permalink
Move get{Run,Compare,Compile}Config methods to ConfigurationService
Browse files Browse the repository at this point in the history
Start disentangling the mess in DOMJudgeService and these
methods don't depend on anything but config.
  • Loading branch information
eldering committed Dec 3, 2024
1 parent 0ac65d7 commit 5c150ab
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 59 deletions.
6 changes: 3 additions & 3 deletions webapp/src/Controller/Jury/SubmissionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
58 changes: 58 additions & 0 deletions webapp/src/Service/ConfigurationService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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(),
]
);
}
}
56 changes: 0 additions & 56 deletions webapp/src/Service/DOMJudgeService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, string>
*/
Expand Down

0 comments on commit 5c150ab

Please sign in to comment.