Skip to content

Commit 6147f8d

Browse files
Add memory/output/code limits to problem endpoint
1 parent 529760e commit 6147f8d

File tree

5 files changed

+23
-2
lines changed

5 files changed

+23
-2
lines changed

webapp/src/Controller/API/AccessController.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,9 @@ public function getStatusAction(Request $request): Access
165165
'rgb',
166166
'color',
167167
'time_limit',
168+
'memory_limit',
169+
'output_limit',
170+
'code_limit',
168171
'test_data_count',
169172
'statement',
170173
// DOMjudge specific properties:

webapp/src/Controller/API/ProblemController.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,13 @@ public function transformObject($object): ContestProblem|ContestProblemWrapper
476476
$problem = $object[0];
477477
$testDataCount = (int)$object['testdatacount'];
478478
if ($this->dj->checkrole('jury')) {
479-
return new ContestProblemWrapper($problem, $testDataCount);
479+
return new ContestProblemWrapper(
480+
$problem,
481+
(int)round(($problem->getProblem()->getMemlimit() === null ? $this->config->get('memory_limit') : $problem->getProblem()->getMemlimit()) / 1024),
482+
(int)round(($problem->getProblem()->getOutputlimit() === null ? $this->config->get('output_limit') : $problem->getProblem()->getOutputlimit()) / 1024),
483+
$this->config->get('sourcesize_limit'),
484+
$testDataCount,
485+
);
480486
} else {
481487
return $problem;
482488
}

webapp/src/DataTransferObject/ContestProblemWrapper.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace App\DataTransferObject;
44

5+
use App\Controller\API\AbstractRestController as ARC;
56
use App\Entity\ContestProblem;
67
use JMS\Serializer\Annotation as Serializer;
78

@@ -10,6 +11,12 @@ class ContestProblemWrapper
1011
public function __construct(
1112
#[Serializer\Inline]
1213
protected readonly ContestProblem $contestProblem,
14+
#[Serializer\Groups([ARC::GROUP_NONSTRICT, '2025-draft'])]
15+
protected readonly int $memoryLimit,
16+
#[Serializer\Groups([ARC::GROUP_NONSTRICT, '2025-draft'])]
17+
protected readonly int $outputLimit,
18+
#[Serializer\Groups([ARC::GROUP_NONSTRICT, '2025-draft'])]
19+
protected readonly int $codeLimit,
1320
#[Serializer\SerializedName('test_data_count')]
1421
protected readonly int $testDataCount
1522
) {}

webapp/tests/Unit/Controller/API/AccessControllerTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public function testAccessAsAdmin(): void
3232
'contest' => ['id', 'name', 'formal_name', 'start_time', 'duration', 'scoreboard_freeze_duration', 'penalty_time'],
3333
'judgement-types' => ['id', 'name', 'penalty', 'solved'],
3434
'languages' => ['id', 'name', 'entry_point_required', 'entry_point_name', 'extensions'],
35-
'problems' => ['id', 'label', 'name', 'ordinal', 'rgb', 'color', 'time_limit', 'test_data_count', 'statement'],
35+
'problems' => ['id', 'label', 'name', 'ordinal', 'rgb', 'color', 'time_limit', 'memory_limit', 'output_limit', 'code_limit', 'test_data_count', 'statement'],
3636
'groups' => ['id', 'icpc_id', 'name', 'hidden'],
3737
'organizations' => ['id', 'icpc_id', 'name', 'formal_name', 'country', 'country_flag'],
3838
'teams' => ['id', 'icpc_id', 'name', 'display_name', 'organization_id', 'group_ids'],

webapp/tests/Unit/Controller/API/ProblemControllerAdminTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ protected function setUp(): void
1818
$this->expectedObjects['boolfind']['test_data_count'] = 10;
1919
$this->expectedObjects['fltcmp']['test_data_count'] = 1+3; // 1 sample, 3 secret cases
2020
$this->expectedObjects['hello']['test_data_count'] = 1;
21+
foreach (array_keys($this->expectedObjects) as $problemId) {
22+
$this->expectedObjects[$problemId]['memory_limit'] = 2048;
23+
$this->expectedObjects[$problemId]['output_limit'] = 8;
24+
$this->expectedObjects[$problemId]['code_limit'] = 256;
25+
}
2126
parent::setUp();
2227
}
2328

0 commit comments

Comments
 (0)