Skip to content

Commit 50f854b

Browse files
committed
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.
1 parent 0ac65d7 commit 50f854b

File tree

3 files changed

+64
-62
lines changed

3 files changed

+64
-62
lines changed

webapp/src/Controller/Jury/SubmissionController.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -575,15 +575,15 @@ public function viewAction(
575575
if ($sampleJudgeTask !== null) {
576576
$errors = [];
577577
$this->maybeGetErrors('Compile config',
578-
$this->dj->getCompileConfig($submission),
578+
$this->config->getCompileConfig($submission),
579579
$sampleJudgeTask->getCompileConfig(),
580580
$errors);
581581
$this->maybeGetErrors('Run config',
582-
$this->dj->getRunConfig($contestProblem, $submission),
582+
$this->config->getRunConfig($contestProblem, $submission),
583583
$sampleJudgeTask->getRunConfig(),
584584
$errors);
585585
$this->maybeGetErrors('Compare config',
586-
$this->dj->getCompareConfig($contestProblem),
586+
$this->config->getCompareConfig($contestProblem),
587587
$sampleJudgeTask->getCompareConfig(),
588588
$errors);
589589
if (!empty($errors)) {

webapp/src/Service/ConfigurationService.php

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@
55
use App\Config\Loader\YamlConfigLoader;
66
use App\DataTransferObject\ConfigurationSpecification;
77
use App\Entity\Configuration;
8+
use App\Entity\ContestProblem;
89
use App\Entity\Executable;
910
use App\Entity\Judging;
11+
use App\Entity\Submission;
1012
use BackedEnum;
1113
use Doctrine\ORM\EntityManagerInterface;
1214
use Doctrine\ORM\NonUniqueResultException;
@@ -395,4 +397,60 @@ public function addOptions(ConfigurationSpecification $item): ConfigurationSpeci
395397
}
396398
return $item;
397399
}
400+
401+
public function getRunConfig(ContestProblem $problem, Submission $submission, int $overshoot = 0): string
402+
{
403+
$memoryLimit = $problem->getProblem()->getMemlimit();
404+
$outputLimit = $problem->getProblem()->getOutputlimit();
405+
if (empty($memoryLimit)) {
406+
$memoryLimit = $this->config->get('memory_limit');
407+
}
408+
if (empty($outputLimit)) {
409+
$outputLimit = $this->config->get('output_limit');
410+
}
411+
$runExecutable = $this->getImmutableRunExecutable($problem);
412+
413+
return $this->jsonEncode(
414+
[
415+
'time_limit' => $problem->getProblem()->getTimelimit() * $submission->getLanguage()->getTimeFactor(),
416+
'memory_limit' => $memoryLimit,
417+
'output_limit' => $outputLimit,
418+
'process_limit' => $this->config->get('process_limit'),
419+
'entry_point' => $submission->getEntryPoint(),
420+
'pass_limit' => $problem->getProblem()->getMultipassLimit(),
421+
'hash' => $runExecutable->getHash(),
422+
'overshoot' => $overshoot,
423+
]
424+
);
425+
}
426+
427+
public function getCompareConfig(ContestProblem $problem): string
428+
{
429+
$compareExecutable = $this->getImmutableCompareExecutable($problem);
430+
return $this->jsonEncode(
431+
[
432+
'script_timelimit' => $this->config->get('script_timelimit'),
433+
'script_memory_limit' => $this->config->get('script_memory_limit'),
434+
'script_filesize_limit' => $this->config->get('script_filesize_limit'),
435+
'compare_args' => $problem->getProblem()->getSpecialCompareArgs(),
436+
'combined_run_compare' => $problem->getProblem()->getCombinedRunCompare(),
437+
'hash' => $compareExecutable->getHash(),
438+
]
439+
);
440+
}
441+
442+
public function getCompileConfig(Submission $submission): string
443+
{
444+
$compileExecutable = $submission->getLanguage()->getCompileExecutable()->getImmutableExecutable();
445+
return $this->jsonEncode(
446+
[
447+
'script_timelimit' => $this->config->get('script_timelimit'),
448+
'script_memory_limit' => $this->config->get('script_memory_limit'),
449+
'script_filesize_limit' => $this->config->get('script_filesize_limit'),
450+
'language_extensions' => $submission->getLanguage()->getExtensions(),
451+
'filter_compiler_files' => $submission->getLanguage()->getFilterCompilerFiles(),
452+
'hash' => $compileExecutable->getHash(),
453+
]
454+
);
455+
}
398456
}

webapp/src/Service/DOMJudgeService.php

Lines changed: 3 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1442,62 +1442,6 @@ public function parseMetadata(string $raw_metadata): array
14421442
return $res;
14431443
}
14441444

1445-
public function getRunConfig(ContestProblem $problem, Submission $submission, int $overshoot = 0): string
1446-
{
1447-
$memoryLimit = $problem->getProblem()->getMemlimit();
1448-
$outputLimit = $problem->getProblem()->getOutputlimit();
1449-
if (empty($memoryLimit)) {
1450-
$memoryLimit = $this->config->get('memory_limit');
1451-
}
1452-
if (empty($outputLimit)) {
1453-
$outputLimit = $this->config->get('output_limit');
1454-
}
1455-
$runExecutable = $this->getImmutableRunExecutable($problem);
1456-
1457-
return $this->jsonEncode(
1458-
[
1459-
'time_limit' => $problem->getProblem()->getTimelimit() * $submission->getLanguage()->getTimeFactor(),
1460-
'memory_limit' => $memoryLimit,
1461-
'output_limit' => $outputLimit,
1462-
'process_limit' => $this->config->get('process_limit'),
1463-
'entry_point' => $submission->getEntryPoint(),
1464-
'pass_limit' => $problem->getProblem()->getMultipassLimit(),
1465-
'hash' => $runExecutable->getHash(),
1466-
'overshoot' => $overshoot,
1467-
]
1468-
);
1469-
}
1470-
1471-
public function getCompareConfig(ContestProblem $problem): string
1472-
{
1473-
$compareExecutable = $this->getImmutableCompareExecutable($problem);
1474-
return $this->jsonEncode(
1475-
[
1476-
'script_timelimit' => $this->config->get('script_timelimit'),
1477-
'script_memory_limit' => $this->config->get('script_memory_limit'),
1478-
'script_filesize_limit' => $this->config->get('script_filesize_limit'),
1479-
'compare_args' => $problem->getProblem()->getSpecialCompareArgs(),
1480-
'combined_run_compare' => $problem->getProblem()->getCombinedRunCompare(),
1481-
'hash' => $compareExecutable->getHash(),
1482-
]
1483-
);
1484-
}
1485-
1486-
public function getCompileConfig(Submission $submission): string
1487-
{
1488-
$compileExecutable = $submission->getLanguage()->getCompileExecutable()->getImmutableExecutable();
1489-
return $this->jsonEncode(
1490-
[
1491-
'script_timelimit' => $this->config->get('script_timelimit'),
1492-
'script_memory_limit' => $this->config->get('script_memory_limit'),
1493-
'script_filesize_limit' => $this->config->get('script_filesize_limit'),
1494-
'language_extensions' => $submission->getLanguage()->getExtensions(),
1495-
'filter_compiler_files' => $submission->getLanguage()->getFilterCompilerFiles(),
1496-
'hash' => $compileExecutable->getHash(),
1497-
]
1498-
);
1499-
}
1500-
15011445
/**
15021446
* @return array<string, string>
15031447
*/
@@ -1630,9 +1574,9 @@ private function actuallyCreateJudgetasks(int $priority, Judging $judging, int $
16301574
':compile_script_id' => $compileExecutable->getImmutableExecId(),
16311575
':compare_script_id' => $this->getImmutableCompareExecutable($problem)->getImmutableExecId(),
16321576
':run_script_id' => $this->getImmutableRunExecutable($problem)->getImmutableExecId(),
1633-
':compile_config' => $this->getCompileConfig($submission),
1634-
':run_config' => $this->getRunConfig($problem, $submission, $overshoot),
1635-
':compare_config' => $this->getCompareConfig($problem),
1577+
':compile_config' => $this->config->getCompileConfig($submission),
1578+
':run_config' => $this->config->getRunConfig($problem, $submission, $overshoot),
1579+
':compare_config' => $this->config->getCompareConfig($problem),
16361580
];
16371581

16381582
$judgetaskDefaultParamNames = array_keys($judgetaskInsertParams);

0 commit comments

Comments
 (0)