Skip to content

Commit

Permalink
Move parseMetadata function to Utils
Browse files Browse the repository at this point in the history
  • Loading branch information
eldering committed Dec 4, 2024
1 parent c802b1b commit f3ec76d
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 20 deletions.
2 changes: 1 addition & 1 deletion webapp/src/Controller/Jury/SubmissionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ public function viewAction(
$runs[] = $runResult[0];
unset($runResult[0]);
if (!empty($runResult['metadata'])) {
$metadata = $this->dj->parseMetadata($runResult['metadata']);
$metadata = Utils::parseMetadata($runResult['metadata']);
$runResult['output_limit'] = $metadata['output-truncated'] ?? 'n/a';
}
$runResult['terminated'] = preg_match('/timelimit exceeded.*hard (wall|cpu) time/',
Expand Down
18 changes: 0 additions & 18 deletions webapp/src/Service/DOMJudgeService.php
Original file line number Diff line number Diff line change
Expand Up @@ -1407,24 +1407,6 @@ public function loadTeam(string $teamId, Contest $contest): Team
return $team;
}

/**
* @return array<string, string>
*/
public function parseMetadata(string $raw_metadata): array
{
// TODO: Reduce duplication with judgedaemon code.
$contents = explode("\n", $raw_metadata);
$res = [];
foreach ($contents as $line) {
if (str_contains($line, ":")) {
[$key, $value] = explode(":", $line, 2);
$res[$key] = trim($value);
}
}

return $res;
}

public function getRunConfig(ContestProblem $problem, Submission $submission, int $overshoot = 0): string
{
$memoryLimit = $problem->getProblem()->getMemlimit();
Expand Down
2 changes: 1 addition & 1 deletion webapp/src/Twig/TwigExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -1209,7 +1209,7 @@ public function printMetadata(?string $metadata): string
if ($metadata === null) {
return '';
}
$metadata = $this->dj->parseMetadata($metadata);
$metadata = Utils::parseMetadata($metadata);
return '<span style="display:inline; margin-left: 5px;">'
. '<i class="fas fa-stopwatch" title="runtime"></i> '
. $metadata['cpu-time'] . 's CPU, '
Expand Down
18 changes: 18 additions & 0 deletions webapp/src/Utils/Utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -966,4 +966,22 @@ public static function jsonEncode(mixed $data): string
{
return json_encode($data, JSON_PRESERVE_ZERO_FRACTION | JSON_UNESCAPED_SLASHES | JSON_THROW_ON_ERROR);
}

/**
* @return array<string, string>
*/
public static function parseMetadata(string $raw_metadata): array
{
// TODO: Reduce duplication with judgedaemon code.
$contents = explode("\n", $raw_metadata);
$res = [];
foreach ($contents as $line) {
if (str_contains($line, ":")) {
[$key, $value] = explode(":", $line, 2);
$res[$key] = trim($value);
}
}

return $res;
}
}

0 comments on commit f3ec76d

Please sign in to comment.