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 50f854b
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 62 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),

Check warning on line 578 in webapp/src/Controller/Jury/SubmissionController.php

View check run for this annotation

Codecov / codecov/patch

webapp/src/Controller/Jury/SubmissionController.php#L578

Added line #L578 was not covered by tests
$sampleJudgeTask->getCompileConfig(),
$errors);
$this->maybeGetErrors('Run config',
$this->dj->getRunConfig($contestProblem, $submission),
$this->config->getRunConfig($contestProblem, $submission),

Check warning on line 582 in webapp/src/Controller/Jury/SubmissionController.php

View check run for this annotation

Codecov / codecov/patch

webapp/src/Controller/Jury/SubmissionController.php#L582

Added line #L582 was not covered by tests
$sampleJudgeTask->getRunConfig(),
$errors);
$this->maybeGetErrors('Compare config',
$this->dj->getCompareConfig($contestProblem),
$this->config->getCompareConfig($contestProblem),

Check warning on line 586 in webapp/src/Controller/Jury/SubmissionController.php

View check run for this annotation

Codecov / codecov/patch

webapp/src/Controller/Jury/SubmissionController.php#L586

Added line #L586 was not covered by tests
$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

Check warning on line 401 in webapp/src/Service/ConfigurationService.php

View check run for this annotation

Codecov / codecov/patch

webapp/src/Service/ConfigurationService.php#L401

Added line #L401 was not covered by tests
{
$memoryLimit = $problem->getProblem()->getMemlimit();
$outputLimit = $problem->getProblem()->getOutputlimit();
if (empty($memoryLimit)) {
$memoryLimit = $this->config->get('memory_limit');

Check warning on line 406 in webapp/src/Service/ConfigurationService.php

View check run for this annotation

Codecov / codecov/patch

webapp/src/Service/ConfigurationService.php#L403-L406

Added lines #L403 - L406 were not covered by tests
}
if (empty($outputLimit)) {
$outputLimit = $this->config->get('output_limit');

Check warning on line 409 in webapp/src/Service/ConfigurationService.php

View check run for this annotation

Codecov / codecov/patch

webapp/src/Service/ConfigurationService.php#L408-L409

Added lines #L408 - L409 were not covered by tests
}
$runExecutable = $this->getImmutableRunExecutable($problem);

Check warning on line 411 in webapp/src/Service/ConfigurationService.php

View check run for this annotation

Codecov / codecov/patch

webapp/src/Service/ConfigurationService.php#L411

Added line #L411 was not covered by tests

return $this->jsonEncode(

Check warning on line 413 in webapp/src/Service/ConfigurationService.php

View check run for this annotation

Codecov / codecov/patch

webapp/src/Service/ConfigurationService.php#L413

Added line #L413 was not covered by tests
[
'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,

Check warning on line 422 in webapp/src/Service/ConfigurationService.php

View check run for this annotation

Codecov / codecov/patch

webapp/src/Service/ConfigurationService.php#L415-L422

Added lines #L415 - L422 were not covered by tests
]
);
}

public function getCompareConfig(ContestProblem $problem): string

Check warning on line 427 in webapp/src/Service/ConfigurationService.php

View check run for this annotation

Codecov / codecov/patch

webapp/src/Service/ConfigurationService.php#L427

Added line #L427 was not covered by tests
{
$compareExecutable = $this->getImmutableCompareExecutable($problem);
return $this->jsonEncode(

Check warning on line 430 in webapp/src/Service/ConfigurationService.php

View check run for this annotation

Codecov / codecov/patch

webapp/src/Service/ConfigurationService.php#L429-L430

Added lines #L429 - L430 were not covered by tests
[
'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(),

Check warning on line 437 in webapp/src/Service/ConfigurationService.php

View check run for this annotation

Codecov / codecov/patch

webapp/src/Service/ConfigurationService.php#L432-L437

Added lines #L432 - L437 were not covered by tests
]
);
}

public function getCompileConfig(Submission $submission): string

Check warning on line 442 in webapp/src/Service/ConfigurationService.php

View check run for this annotation

Codecov / codecov/patch

webapp/src/Service/ConfigurationService.php#L442

Added line #L442 was not covered by tests
{
$compileExecutable = $submission->getLanguage()->getCompileExecutable()->getImmutableExecutable();
return $this->jsonEncode(

Check warning on line 445 in webapp/src/Service/ConfigurationService.php

View check run for this annotation

Codecov / codecov/patch

webapp/src/Service/ConfigurationService.php#L444-L445

Added lines #L444 - L445 were not covered by tests
[
'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(),

Check warning on line 452 in webapp/src/Service/ConfigurationService.php

View check run for this annotation

Codecov / codecov/patch

webapp/src/Service/ConfigurationService.php#L447-L452

Added lines #L447 - L452 were not covered by tests
]
);
}
}
62 changes: 3 additions & 59 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 Expand Up @@ -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),

Check warning on line 1579 in webapp/src/Service/DOMJudgeService.php

View check run for this annotation

Codecov / codecov/patch

webapp/src/Service/DOMJudgeService.php#L1577-L1579

Added lines #L1577 - L1579 were not covered by tests
];

$judgetaskDefaultParamNames = array_keys($judgetaskInsertParams);
Expand Down

0 comments on commit 50f854b

Please sign in to comment.