Skip to content

Changes for the 2025 draft CCS spec #3041

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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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
8 changes: 4 additions & 4 deletions etc/db-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -349,12 +349,12 @@
public: true
description: If set, enable teams and jury to send source code to this command. See admin manual for allowed arguments.
docdescription: See :ref:`printing` for more information.
- name: event_feed_format
- name: ccs_api_version
type: enum
default_value: 2022-07
enum_class: App\Utils\EventFeedFormat
default_value: 2025-draft
enum_class: App\Utils\CcsApiVersion
public: false
description: Format of the event feed to use. See [current draft](https://ccs-specs.icpc.io/draft/contest_api#event-feed) and [versions available](https://ccs-specs.icpc.io/).
description: Version of the CCS API to use for the API and event feed. See [current draft](https://ccs-specs.icpc.io/draft/contest_api#event-feed) and [versions available](https://ccs-specs.icpc.io/).
- name: shadow_mode
type: bool
default_value: false
Expand Down
40 changes: 40 additions & 0 deletions webapp/migrations/Version20250706121413.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?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 Version20250706121413 extends AbstractMigration
{
public function getDescription(): string
{
return 'Update `event_feed_format` config to `ccs_api_version`';
}

public function up(Schema $schema): void
{
// Change key and values to the new format
$this->addSql('UPDATE configuration SET name = \'ccs_api_version\' WHERE name = \'event_feed_format\' AND value = \'"2020-03"\'');
$this->addSql('UPDATE configuration SET name = \'ccs_api_version\', value = \'"2023-06"\' WHERE name = \'event_feed_format\' AND value = \'"2022-07"\'');
}

public function down(Schema $schema): void
{
// Change key and values back to the old format
$this->addSql('UPDATE configuration SET name = \'event_feed_format\' WHERE name = \'ccs_api_version\' AND value = \'"2020-03"\'');
$this->addSql('UPDATE configuration SET name = \'event_feed_format\', value = \'"2022-07"\' WHERE name = \'ccs_api_version\' AND value = \'"2023-06"\'');
// Delete it if we have a non-supported version
$this->addSql('DELETE FROM configuration WHERE name = \'ccs_api_version\'');
}

public function isTransactional(): bool
{
return false;
}
}
2 changes: 0 additions & 2 deletions webapp/src/Command/ImportEventFeedCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace App\Command;

use App\Controller\API\GeneralInfoController as GI;
use App\Entity\Contest;
use App\Entity\ExternalContestSource;
use App\Entity\User;
Expand Down Expand Up @@ -53,7 +52,6 @@ protected function configure(): void
$this
->setHelp(
'Import contest data from an event feed following the Contest API specification:' . PHP_EOL .
GI::CCS_SPEC_API_URL . ' or any version starting from "2021-11"' . PHP_EOL . PHP_EOL .
'Note the following assumptions and caveats:' . PHP_EOL .
'- Configuration data will only be verified.' . PHP_EOL .
'- Team members will not be imported.' . PHP_EOL .
Expand Down
5 changes: 4 additions & 1 deletion webapp/src/Controller/API/AbstractRestController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace App\Controller\API;

use App\Entity\BaseApiEntity;
use App\Utils\CcsApiVersion;
use Doctrine\ORM\NonUniqueResultException;
use Doctrine\ORM\QueryBuilder;
use Symfony\Component\HttpFoundation\BinaryFileResponse;
Expand Down Expand Up @@ -73,7 +74,9 @@ protected function renderData(
$view->getContext()->setAttribute('domjudge_service', $this->dj);
$view->getContext()->setAttribute('config_service', $this->config);

$groups = [static::GROUP_DEFAULT];
/** @var CcsApiVersion $ccsApiVersion */
$ccsApiVersion = $this->config->get('ccs_api_version');
$groups = [static::GROUP_DEFAULT, $ccsApiVersion->value];
if (!$request->query->has('strict') || !$request->query->getBoolean('strict')) {
$groups[] = static::GROUP_NONSTRICT;
}
Expand Down
14 changes: 13 additions & 1 deletion webapp/src/Controller/API/AccessController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use App\DataTransferObject\Access;
use App\DataTransferObject\AccessEndpoint;
use App\Utils\CcsApiVersion;
use Doctrine\ORM\NonUniqueResultException;
use Doctrine\ORM\NoResultException;
use FOS\RestBundle\Controller\Annotations as Rest;
Expand Down Expand Up @@ -81,6 +82,9 @@ public function getStatusAction(Request $request): Access
$submissionsProperties[] = 'files';
}

/** @var CcsApiVersion $ccsApiVersion */
$ccsApiVersion = $this->config->get('ccs_api_version');

$capabilities = [];

// Add capabilities
Expand All @@ -90,7 +94,11 @@ public function getStatusAction(Request $request): Access
}
if ($this->dj->checkrole('team') && $this->dj->getUser()->getTeam()) {
$capabilities[] = 'team_submit';
$capabilities[] = 'team_clar';
if ($ccsApiVersion->usePostClar()) {
$capabilities[] = 'post_clar';
} else {
$capabilities[] = 'team_clar';
}
}
if ($this->dj->checkrole('api_writer')) {
$capabilities[] = 'proxy_submit';
Expand Down Expand Up @@ -161,6 +169,9 @@ public function getStatusAction(Request $request): Access
'rgb',
'color',
'time_limit',
'memory_limit',
'output_limit',
'code_limit',
'test_data_count',
'statement',
// DOMjudge specific properties:
Expand Down Expand Up @@ -252,6 +263,7 @@ public function getStatusAction(Request $request): Access
'end_time',
'end_contest_time',
'max_run_time',
'current',
// DOMjudge specific properties:
'valid',
],
Expand Down
27 changes: 18 additions & 9 deletions webapp/src/Controller/API/ContestController.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
use App\Service\DOMJudgeService;
use App\Service\EventLogService;
use App\Service\ImportExportService;
use App\Utils\EventFeedFormat;
use App\Utils\CcsApiVersion;
use App\Utils\Utils;
use BadMethodCallException;
use Doctrine\Inflector\InflectorFactory;
Expand Down Expand Up @@ -648,7 +648,8 @@ public function getEventFeedAction(
$since_id = -1;
}

$format = $this->config->get('event_feed_format');
/** @var CcsApiVersion $format */
$format = $this->config->get('ccs_api_version');

$response = new StreamedResponse();
$response->headers->set('X-Accel-Buffering', 'no');
Expand Down Expand Up @@ -696,12 +697,16 @@ public function getEventFeedAction(
unset($toCheck['teamaffiliations']);
unset($toCheck['contestproblems']);

/** @var CcsApiVersion $ccsApiVersion */
$ccsApiVersion = $this->config->get('ccs_api_version');

foreach ($toCheck as $plural => $class) {
$serializerMetadata = $metadataFactory->getMetadataForClass($class);
/** @var PropertyMetadata $propertyMetadata */
foreach ($serializerMetadata->propertyMetadata as $propertyMetadata) {
if (is_array($propertyMetadata->groups) &&
!in_array('Default', $propertyMetadata->groups)) {
!in_array('Default', $propertyMetadata->groups) &&
!in_array($ccsApiVersion->value, $propertyMetadata->groups)) {
$skippedProperties[$plural][] = $propertyMetadata->serializedName;
}
}
Expand Down Expand Up @@ -835,21 +840,25 @@ public function getEventFeedAction(
unset($data[$property]);
}
}

$data = $this->eventLogService->applyCcsVersionChanges($event->getEndpointtype(), $data);

switch ($format) {
case EventFeedFormat::Format_2020_03:
case CcsApiVersion::Format_2020_03:
$result = [
'id' => (string)$event->getEventid(),
'type' => (string)$event->getEndpointtype(),
'op' => (string)$event->getAction(),
'type' => $event->getEndpointtype(),
'op' => $event->getAction(),
'data' => $data,
];
break;
case EventFeedFormat::Format_2022_07:
case CcsApiVersion::Format_2023_06:
case CcsApiVersion::Format_2025_DRAFT:
if ($event->getAction() === EventLogService::ACTION_DELETE) {
$data = null;
}
$id = (string)$event->getEndpointid() ?: null;
$type = (string)$event->getEndpointtype();
$id = $event->getEndpointid() ?: null;
$type = $event->getEndpointtype();
if ($type === 'contests') {
// Special case: the type for a contest is singular and the ID must not be set
$id = null;
Expand Down
10 changes: 6 additions & 4 deletions webapp/src/Controller/API/GeneralInfoController.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use App\Service\DOMJudgeService;
use App\Service\EventLogService;
use App\Service\ImportProblemService;
use App\Utils\CcsApiVersion;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\NonUniqueResultException;
use Doctrine\ORM\NoResultException;
Expand Down Expand Up @@ -42,8 +43,6 @@ class GeneralInfoController extends AbstractFOSRestController
{
protected const API_VERSION = 4;

final public const CCS_SPEC_API_VERSION = '2023-06';
final public const CCS_SPEC_API_URL = 'https://ccs-specs.icpc.io/2023-06/contest_api';

public function __construct(
protected readonly EntityManagerInterface $em,
Expand Down Expand Up @@ -94,9 +93,12 @@ public function getInfoAction(
);
}

/** @var CcsApiVersion $ccsApiVersion */
$ccsApiVersion = $this->config->get('ccs_api_version');

return new ApiInfo(
version: self::CCS_SPEC_API_VERSION,
versionUrl: self::CCS_SPEC_API_URL,
version: $ccsApiVersion->value,
versionUrl: $ccsApiVersion->getCcsSpecsApiUrl(),
name: 'DOMjudge',
//TODO: Add DOMjudge logo
provider: new ApiInfoProvider(
Expand Down
8 changes: 7 additions & 1 deletion webapp/src/Controller/API/ProblemController.php
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,13 @@ public function transformObject($object): ContestProblem|ContestProblemWrapper
$problem = $object[0];
$testDataCount = (int)$object['testdatacount'];
if ($this->dj->checkrole('jury')) {
return new ContestProblemWrapper($problem, $testDataCount);
return new ContestProblemWrapper(
$problem,
(int)round(($problem->getProblem()->getMemlimit() === null ? $this->config->get('memory_limit') : $problem->getProblem()->getMemlimit()) / 1024),
(int)round(($problem->getProblem()->getOutputlimit() === null ? $this->config->get('output_limit') : $problem->getProblem()->getOutputlimit()) / 1024),
$this->config->get('sourcesize_limit'),
$testDataCount,
);
} else {
return $problem;
}
Expand Down
30 changes: 27 additions & 3 deletions webapp/src/Controller/API/ScoreboardController.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,15 @@
use App\Service\DOMJudgeService;
use App\Service\EventLogService;
use App\Service\ScoreboardService;
use App\Utils\CcsApiVersion;
use App\Utils\Scoreboard\Filter;
use App\Utils\Utils;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\NonUniqueResultException;
use FOS\RestBundle\Controller\Annotations as Rest;
use Nelmio\ApiDocBundle\Attribute\Model;
use OpenApi\Attributes as OA;
use Symfony\Component\Form\FormFactoryInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Attribute\MapQueryParameter;
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
Expand All @@ -39,7 +41,7 @@ public function __construct(
DOMJudgeService $DOMJudgeService,
ConfigurationService $config,
EventLogService $eventLogService,
protected readonly ScoreboardService $scoreboardService
protected readonly ScoreboardService $scoreboardService,
) {
parent::__construct($entityManager, $DOMJudgeService, $config, $eventLogService);
}
Expand Down Expand Up @@ -169,6 +171,8 @@ public function getScoreboardAction(
}

$scoreIsInSeconds = (bool)$this->config->get('score_in_seconds');
/** @var CcsApiVersion $ccsApiVersion */
$ccsApiVersion = $this->config->get('ccs_api_version');

foreach ($scoreboard->getScores() as $teamScore) {
if ($teamScore->team->getCategory()->getSortorder() !== $sortorder) {
Expand All @@ -183,10 +187,12 @@ public function getScoreboardAction(
} else {
$score = new Score(
numSolved: $teamScore->numPoints,
totalTime: $teamScore->totalTime,
totalTime: $this->formatTime($teamScore->totalTime, $ccsApiVersion, $scoreIsInSeconds),
);
}

$lastProblemTime = null;

$problems = [];
foreach ($scoreboard->getMatrix()[$teamScore->team->getTeamid()] as $problemId => $matrixItem) {
$contestProblem = $scoreboard->getProblems()[$problemId];
Expand All @@ -206,13 +212,19 @@ public function getScoreboardAction(
} else {
$problem->firstToSolve = $matrixItem->isCorrect && $scoreboard->solvedFirst($teamScore->team, $contestProblem);
if ($matrixItem->isCorrect) {
$problem->time = Utils::scoretime($matrixItem->time, $scoreIsInSeconds);
$problemTime = Utils::scoretime($matrixItem->time, $scoreIsInSeconds);
$problem->time = $this->formatTime($problemTime, $ccsApiVersion, $scoreIsInSeconds);
$lastProblemTime = max($lastProblemTime, $problemTime);
}
}

$problems[] = $problem;
}

if ($lastProblemTime !== null) {
$score->time = $this->formatTime($lastProblemTime, $ccsApiVersion, $scoreIsInSeconds);
}

usort($problems, fn(Problem $a, Problem $b) => $a->label <=> $b->label);

$row = new Row(
Expand All @@ -227,4 +239,16 @@ public function getScoreboardAction(

return $results;
}

protected function formatTime(
int $time,
CcsApiVersion $ccsApiVersion,
bool $scoreIsInSeconds
): int|string {
if ($ccsApiVersion->useRelTimes()) {
return $scoreIsInSeconds ? Utils::relTime($time) : Utils::relTime($time * 60);
} else {
return $time;
}
}
}
7 changes: 6 additions & 1 deletion webapp/src/Controller/Jury/JuryMiscController.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use App\Service\DOMJudgeService;
use App\Service\EventLogService;
use App\Service\ScoreboardService;
use App\Utils\CcsApiVersion;
use App\Utils\Utils;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\Query\Expr\Join;
Expand All @@ -39,6 +40,7 @@ class JuryMiscController extends BaseController
public function __construct(
EntityManagerInterface $em,
DOMJudgeService $dj,
protected readonly ConfigurationService $config,
protected readonly EventLogService $eventLogService,
protected readonly RequestStack $requestStack,
KernelInterface $kernel,
Expand All @@ -57,9 +59,12 @@ public function indexAction(ConfigurationService $config): Response
}
}

/** @var CcsApiVersion $ccsApiVersion */
$ccsApiVersion = $this->config->get('ccs_api_version');

return $this->render('jury/index.html.twig', [
'adminer_enabled' => $config->get('adminer_enabled'),
'CCS_SPEC_API_URL' => GI::CCS_SPEC_API_URL,
'CCS_SPEC_API_URL' => $ccsApiVersion->getCcsSpecsApiUrl(),
]);
}

Expand Down
7 changes: 7 additions & 0 deletions webapp/src/DataTransferObject/ContestProblemWrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App\DataTransferObject;

use App\Controller\API\AbstractRestController as ARC;
use App\Entity\ContestProblem;
use JMS\Serializer\Annotation as Serializer;

Expand All @@ -10,6 +11,12 @@ class ContestProblemWrapper
public function __construct(
#[Serializer\Inline]
protected readonly ContestProblem $contestProblem,
#[Serializer\Groups([ARC::GROUP_NONSTRICT, '2025-draft'])]
protected readonly int $memoryLimit,
#[Serializer\Groups([ARC::GROUP_NONSTRICT, '2025-draft'])]
protected readonly int $outputLimit,
#[Serializer\Groups([ARC::GROUP_NONSTRICT, '2025-draft'])]
protected readonly int $codeLimit,
#[Serializer\SerializedName('test_data_count')]
protected readonly int $testDataCount
) {}
Expand Down
Loading
Loading