Skip to content

Record validator metadata. #2936

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions judge/judgedaemon.main.php
Original file line number Diff line number Diff line change
Expand Up @@ -1489,6 +1489,7 @@ function judge(array $judgeTask): bool
'output_diff' => rest_encode_file($passdir . '/feedback/judgemessage.txt', $output_storage_limit),
'hostname' => $myhost,
'testcasedir' => $testcasedir,
'compare_metadata' => rest_encode_file($passdir . '/compare.meta', false),
];

if (file_exists($passdir . '/feedback/teammessage.txt')) {
Expand Down
36 changes: 36 additions & 0 deletions webapp/migrations/Version20250302070928.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

declare(strict_types=1);

namespace DoctrineMigrations;

use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;

/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20250302070928 extends AbstractMigration
{
public function getDescription(): string
{
return 'Add metadata for the validator.';
}

public function up(Schema $schema): void
{
// this up() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE judging_run_output ADD validator_metadata LONGBLOB DEFAULT NULL COMMENT \'Judging metadata of the validator(DC2Type:blobtext)\', CHANGE metadata metadata LONGBLOB DEFAULT NULL COMMENT \'Judging metadata of the run(DC2Type:blobtext)\'');
}

public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE judging_run_output DROP validator_metadata, CHANGE metadata metadata LONGBLOB DEFAULT NULL COMMENT \'Judging metadata(DC2Type:blobtext)\'');
}

public function isTransactional(): bool
{
return false;
}
}
36 changes: 24 additions & 12 deletions webapp/src/Controller/API/JudgehostController.php
Original file line number Diff line number Diff line change
Expand Up @@ -608,7 +608,12 @@ public function addDebugInfo(
),
new OA\Property(
property: 'metadata',
description: 'The (base64-encoded) metadata',
description: 'The (base64-encoded) metadata of the run',
type: 'string'
),
new OA\Property(
property: 'compare_metadata',
description: 'The (base64-encoded) metadata of the validator',
type: 'string'
),
]
Expand Down Expand Up @@ -647,14 +652,15 @@ public function addJudgingRunAction(
$teamMessage = $request->request->get('team_message');
$metadata = $request->request->get('metadata');
$testcasedir = $request->request->get('testcasedir');
$compareMeta = $request->request->get('compare_metadata');

$judgehost = $this->em->getRepository(Judgehost::class)->findOneBy(['hostname' => $hostname]);
if (!$judgehost) {
throw new BadRequestHttpException("Who are you and why are you sending us any data?");
}

$hasFinalResult = $this->addSingleJudgingRun($judgeTaskId, $hostname, $runResult, $runTime,
$outputSystem, $outputError, $outputDiff, $outputRun, $teamMessage, $metadata, $testcasedir);
$outputSystem, $outputError, $outputDiff, $outputRun, $teamMessage, $metadata, $testcasedir, $compareMeta);
$judgehost = $this->em->getRepository(Judgehost::class)->findOneBy(['hostname' => $hostname]);
$judgehost->setPolltime(Utils::now());
$this->em->flush();
Expand Down Expand Up @@ -910,16 +916,17 @@ protected function giveBackJudging(int $judgingId, ?Judgehost $judgehost): void
*/
private function addSingleJudgingRun(
int $judgeTaskId,
string $hostname,
string $runResult,
string $runTime,
string $outputSystem,
string $outputError,
string $outputDiff,
string $outputRun,
string $hostname,
string $runResult,
string $runTime,
string $outputSystem,
string $outputError,
string $outputDiff,
string $outputRun,
?string $teamMessage,
string $metadata,
?string $testcasedir
string $metadata,
?string $testcasedir,
?string $compareMeta,
): bool {
$resultsRemap = $this->config->get('results_remap');
$resultsPrio = $this->config->get('results_prio');
Expand All @@ -940,7 +947,8 @@ private function addSingleJudgingRun(
$outputRun,
$teamMessage,
$metadata,
$testcasedir
$testcasedir,
$compareMeta
) {
$judgingRun = $this->em->getRepository(JudgingRun::class)->findOneBy(
['judgetaskid' => $judgeTaskId]);
Expand All @@ -962,6 +970,10 @@ private function addSingleJudgingRun(
->setOutputSystem(base64_decode($outputSystem))
->setMetadata(base64_decode($metadata));

if ($compareMeta) {
$judgingRunOutput->setValidatorMetadata(base64_decode($compareMeta));
}

if ($teamMessage) {
$judgingRunOutput->setTeamMessage(base64_decode($teamMessage));
}
Expand Down
2 changes: 1 addition & 1 deletion webapp/src/Controller/Jury/SubmissionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ public function viewAction(
->join('t.content', 'tc')
->leftJoin('t.judging_runs', 'jr', Join::WITH, 'jr.judging = :judging')
->leftJoin('jr.output', 'jro')
->select('t', 'jr', 'tc.image_thumb AS image_thumb', 'jro.metadata')
->select('t', 'jr', 'tc.image_thumb AS image_thumb', 'jro.metadata', 'jro.validatorMetadata')
->andWhere('t.problem = :problem')
->setParameter('judging', $selectedJudging)
->setParameter('problem', $submission->getProblem())
Expand Down
20 changes: 19 additions & 1 deletion webapp/src/Entity/JudgingRunOutput.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,17 @@ class JudgingRunOutput
#[ORM\Column(
type: 'blobtext',
nullable: true,
options: ['comment' => 'Judging metadata']
options: ['comment' => 'Judging metadata of the run']
)]
private ?string $metadata = null;

#[ORM\Column(
type: 'blobtext',
nullable: true,
options: ['comment' => 'Judging metadata of the validator']
)]
private ?string $validatorMetadata = null;

public function setRun(JudgingRun $run): JudgingRunOutput
{
$this->run = $run;
Expand Down Expand Up @@ -144,4 +151,15 @@ public function setMetadata(?string $metadata): self
$this->metadata = $metadata;
return $this;
}

public function getValidatorMetadata(): string
{
return $this->validatorMetadata;
}

public function setValidatorMetadata(?string $validatorMetadata): self
{
$this->validatorMetadata = $validatorMetadata;
return $this;
}
}
35 changes: 25 additions & 10 deletions webapp/src/Twig/TwigExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -1228,16 +1228,31 @@ public function printMetadata(?string $metadata): string
return '';
}
$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, '
. $metadata['wall-time'] . 's wall, '
. '<i class="fas fa-memory" title="RAM"></i> '
. Utils::printsize((int)($metadata['memory-bytes'])) . ', '
. '<i class="far fa-question-circle" title="exit-status"></i> '
. 'exit-code: ' . $metadata['exitcode']
. (($metadata['signal'] ?? -1) > 0 ? ' signal: ' . $metadata['signal'] : '')
. '</span>';
$result = '<span style="display:inline; margin-left: 5px;">';

if (isset($metadata['cpu-time']) || isset($metadata['wall-time'])) {
$result .= '<i class="fas fa-stopwatch" title="runtime"></i> ';
}

if (isset($metadata['cpu-time'])) {
$result .= $metadata['cpu-time'] . 's CPU, ';
}
if (isset($metadata['wall-time'])) {
$result .= $metadata['wall-time'] . 's wall, ';
}
if (isset($metadata['memory-bytes'])) {
$result .= '<i class="fas fa-memory" title="RAM"></i> '
. Utils::printsize((int)($metadata['memory-bytes'])) . ', ';
}
if (isset($metadata['exitcode'])) {
$result .= '<i class="far fa-question-circle" title="exit-status"></i> '
. 'exit-code: ' . $metadata['exitcode'];
}
if (isset($metadata['signal'])) {
$result .= ' signal: ' . $metadata['signal'];
}
$result .= '</span>';
return $result;
}

public function printWarningContent(ExternalSourceWarning $warning): string
Expand Down
15 changes: 15 additions & 0 deletions webapp/templates/jury/submission.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -822,6 +822,21 @@
{{ runsOutput[runIdx].team_message }}</pre>
{% endif %}
{% endif %}
{% if runsOutput[runIdx].validatorMetadata is not empty %}
<hr/>
<h5>Validator metadata</h5>
{{ runsOutput[runIdx].validatorMetadata | printMetadata }}
<button class="btn btn-sm btn-outline-secondary" data-bs-toggle="collapse"
data-bs-target="#collapseValMeta-{{ runIdx }}"
aria-expanded="false">
show complete validator metadata
</button>
<div class="collapse" id="collapseValMeta-{{ runIdx }}">
<div class="card card-body output_text">{{ runsOutput[runIdx].validatorMetadata }}</div>
</div>
{% endif %}
{% endif %}
</div>
Expand Down
Loading