Skip to content

Commit

Permalink
Create verdict groups that selectively can be used
Browse files Browse the repository at this point in the history
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'])`.
  • Loading branch information
eldering committed Nov 25, 2024
1 parent 34b1849 commit 754779b
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 31 deletions.
28 changes: 20 additions & 8 deletions etc/verdicts.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
];
4 changes: 1 addition & 3 deletions webapp/src/Controller/API/JudgementController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion webapp/src/Controller/API/JudgementTypeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
3 changes: 1 addition & 2 deletions webapp/src/Controller/Jury/RejudgingController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [];
Expand Down
4 changes: 1 addition & 3 deletions webapp/src/Controller/Jury/ShadowDifferencesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [];
Expand Down
4 changes: 1 addition & 3 deletions webapp/src/Controller/Jury/SubmissionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
5 changes: 1 addition & 4 deletions webapp/src/Form/Type/SubmissionsFilterType.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
15 changes: 10 additions & 5 deletions webapp/src/Service/DOMJudgeService.php
Original file line number Diff line number Diff line change
Expand Up @@ -1485,14 +1485,19 @@ public function getCompileConfig(Submission $submission): string
/**
* @return array<string, string>
*/
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]);
}
}

Expand Down
4 changes: 2 additions & 2 deletions webapp/src/Service/ExternalContestSourceService.php
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,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');
Expand Down Expand Up @@ -799,7 +799,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]);
Expand Down

0 comments on commit 754779b

Please sign in to comment.