Skip to content

Commit 68d4d7e

Browse files
committed
Move parseMetadata function to Utils
1 parent b03e8ac commit 68d4d7e

File tree

4 files changed

+20
-20
lines changed

4 files changed

+20
-20
lines changed

webapp/src/Controller/Jury/SubmissionController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@ public function viewAction(
397397
$runs[] = $runResult[0];
398398
unset($runResult[0]);
399399
if (!empty($runResult['metadata'])) {
400-
$metadata = $this->dj->parseMetadata($runResult['metadata']);
400+
$metadata = Utils::parseMetadata($runResult['metadata']);
401401
$runResult['output_limit'] = $metadata['output-truncated'] ?? 'n/a';
402402
}
403403
$runResult['terminated'] = preg_match('/timelimit exceeded.*hard (wall|cpu) time/',

webapp/src/Service/DOMJudgeService.php

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1407,24 +1407,6 @@ public function loadTeam(string $teamId, Contest $contest): Team
14071407
return $team;
14081408
}
14091409

1410-
/**
1411-
* @return array<string, string>
1412-
*/
1413-
public function parseMetadata(string $raw_metadata): array
1414-
{
1415-
// TODO: Reduce duplication with judgedaemon code.
1416-
$contents = explode("\n", $raw_metadata);
1417-
$res = [];
1418-
foreach ($contents as $line) {
1419-
if (str_contains($line, ":")) {
1420-
[$key, $value] = explode(":", $line, 2);
1421-
$res[$key] = trim($value);
1422-
}
1423-
}
1424-
1425-
return $res;
1426-
}
1427-
14281410
public function getRunConfig(ContestProblem $problem, Submission $submission, int $overshoot = 0): string
14291411
{
14301412
$memoryLimit = $problem->getProblem()->getMemlimit();

webapp/src/Twig/TwigExtension.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1209,7 +1209,7 @@ public function printMetadata(?string $metadata): string
12091209
if ($metadata === null) {
12101210
return '';
12111211
}
1212-
$metadata = $this->dj->parseMetadata($metadata);
1212+
$metadata = Utils::parseMetadata($metadata);
12131213
return '<span style="display:inline; margin-left: 5px;">'
12141214
. '<i class="fas fa-stopwatch" title="runtime"></i> '
12151215
. $metadata['cpu-time'] . 's CPU, '

webapp/src/Utils/Utils.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -966,4 +966,22 @@ public static function jsonEncode(mixed $data): string
966966
{
967967
return json_encode($data, JSON_PRESERVE_ZERO_FRACTION | JSON_UNESCAPED_SLASHES | JSON_THROW_ON_ERROR);
968968
}
969+
970+
/**
971+
* @return array<string, string>
972+
*/
973+
public static function parseMetadata(string $raw_metadata): array
974+
{
975+
// TODO: Reduce duplication with judgedaemon code.
976+
$contents = explode("\n", $raw_metadata);
977+
$res = [];
978+
foreach ($contents as $line) {
979+
if (str_contains($line, ":")) {
980+
[$key, $value] = explode(":", $line, 2);
981+
$res[$key] = trim($value);
982+
}
983+
}
984+
985+
return $res;
986+
}
969987
}

0 commit comments

Comments
 (0)