Skip to content

Commit 597f71e

Browse files
committed
Merge remote-tracking branch 'nicky/phpstan-fixes' into vmcj-patch-2
2 parents 89054ef + da75a14 commit 597f71e

22 files changed

+158
-45
lines changed

webapp/src/Command/ScoreboardMergeCommand.php

Lines changed: 60 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use App\Entity\Contest;
66
use App\Entity\ContestProblem;
77
use App\Entity\Problem;
8+
use App\Entity\RankCache;
89
use App\Entity\ScoreCache;
910
use App\Entity\Team;
1011
use App\Entity\TeamAffiliation;
@@ -14,6 +15,7 @@
1415
use App\Service\ScoreboardService;
1516
use App\Utils\FreezeData;
1617
use App\Utils\Scoreboard\Scoreboard;
18+
use App\Utils\Utils;
1719
use Symfony\Component\Console\Attribute\AsCommand;
1820
use Symfony\Component\Console\Command\Command;
1921
use Symfony\Component\Console\Input\InputArgument;
@@ -131,6 +133,11 @@ protected function execute(InputInterface $input, OutputInterface $output): int
131133
$problems = [];
132134
$problemNameToIdMap = [];
133135
$scoreCache = [];
136+
/** @var RankCache[] $rankCache */
137+
$rankCache = [];
138+
$penaltyTime = (int)$this->config->get('penalty_time');
139+
$scoreIsInSeconds = (bool)$this->config->get('score_in_seconds');
140+
$timeOfLastCorrect = [];
134141
$affiliations = [];
135142
$firstSolve = [];
136143
$contest = (new Contest())
@@ -261,6 +268,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
261268
$id = count($problems);
262269
$problemObj = (new Problem())
263270
->setProbid($id)
271+
->setExternalid((string)$id)
264272
->setName($name);
265273
$contestProblemObj = (new ContestProblem())
266274
->setProblem($problemObj)
@@ -280,10 +288,8 @@ protected function execute(InputInterface $input, OutputInterface $output): int
280288
$scoreCacheObj
281289
->setSolveTimePublic($problem['time'] * 60)
282290
->setSolveTimeRestricted($problem['time'] * 60);
283-
if (
284-
$firstSolve[$name] === null or
285-
$problem['time'] * 60 < $firstSolve[$name]
286-
) {
291+
if ($firstSolve[$name] === null ||
292+
$problem['time'] * 60 < $firstSolve[$name]) {
287293
$firstSolve[$name] = $problem['time'] * 60;
288294
}
289295
}
@@ -302,14 +308,64 @@ protected function execute(InputInterface $input, OutputInterface $output): int
302308
if ($scoreCacheObj->getSolveTimeRestricted() == $firstSolve[$scoreCacheObj->getProblem()->getName()]) {
303309
$scoreCacheObj->setIsFirstToSolve(true);
304310
}
311+
312+
$teamId = $scoreCacheObj->getTeam()->getTeamid();
313+
if (isset($rankCache[$teamId])) {
314+
$rankCacheObj = $rankCache[$teamId];
315+
} else {
316+
$rankCacheObj = (new RankCache())
317+
->setTeam($scoreCacheObj->getTeam());
318+
$rankCache[$teamId] = $rankCacheObj;
319+
}
320+
321+
$problem = $problems[$scoreCacheObj->getProblem()->getProbid()];
322+
if ($scoreCacheObj->getIsCorrectRestricted()) {
323+
$rankCacheObj->setPointsRestricted($rankCacheObj->getPointsRestricted() + $problem->getPoints());
324+
$solveTime = Utils::scoretime(
325+
(float)$scoreCacheObj->getSolvetimeRestricted(),
326+
$scoreIsInSeconds
327+
);
328+
$penalty = Utils::calcPenaltyTime($scoreCacheObj->getIsCorrectRestricted(),
329+
$scoreCacheObj->getSubmissionsRestricted(),
330+
$penaltyTime, $scoreIsInSeconds);
331+
$rankCacheObj->setTotaltimeRestricted($rankCacheObj->getTotaltimeRestricted() + $solveTime + $penalty);
332+
$rankCacheObj->setTotalruntimeRestricted($rankCacheObj->getTotalruntimeRestricted() + $scoreCacheObj->getRuntimeRestricted());
333+
$timeOfLastCorrect[$teamId] = max(
334+
$timeOfLastCorrect[$teamId] ?? 0,
335+
Utils::scoretime(
336+
(float)$scoreCacheObj->getSolvetimeRestricted(),
337+
$scoreIsInSeconds
338+
),
339+
);
340+
}
305341
}
306342

343+
foreach ($rankCache as $rankCacheObj) {
344+
$teamId = $rankCacheObj->getTeam()->getTeamid();
345+
$rankCacheObj->setSortKeyRestricted(ScoreboardService::getICPCScoreKey(
346+
$rankCacheObj->getPointsRestricted(),
347+
$rankCacheObj->getTotaltimeRestricted(), $timeOfLastCorrect[$teamId] ?? 0
348+
));
349+
}
350+
351+
usort($teams, function (Team $a, Team $b) use ($rankCache) {
352+
$rankCacheA = $rankCache[$a->getTeamid()];
353+
$rankCacheB = $rankCache[$b->getTeamid()];
354+
$rankCacheSort = $rankCacheB->getSortKeyRestricted() <=> $rankCacheA->getSortKeyRestricted();
355+
if ($rankCacheSort === 0) {
356+
return $a->getEffectiveName() <=> $b->getEffectiveName();
357+
}
358+
359+
return $rankCacheSort;
360+
});
361+
307362
$scoreboard = new Scoreboard(
308363
$contest,
309364
$teams,
310365
[$category],
311366
$problems,
312367
$scoreCache,
368+
array_values($rankCache),
313369
$freezeData,
314370
false,
315371
(int)$this->config->get('penalty_time'),

webapp/src/Controller/API/JudgehostController.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1656,9 +1656,7 @@ public function getJudgeTasksAction(Request $request): array
16561656
$judgetasks = [['type' => 'try_again']];
16571657
}
16581658
}
1659-
if (!empty($judgetasks)) {
1660-
return $judgetasks;
1661-
}
1659+
return $judgetasks;
16621660
}
16631661

16641662
if ($this->config->get('enable_parallel_judging')) {

webapp/src/Controller/API/PrintController.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Symfony\Component\HttpFoundation\Request;
1616
use Symfony\Component\HttpFoundation\Response;
1717
use Symfony\Component\HttpKernel\Attribute\MapRequestPayload;
18+
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
1819
use Symfony\Component\HttpKernel\Exception\ServiceUnavailableHttpException;
1920
use Symfony\Component\Routing\Attribute\Route;
2021
use Symfony\Component\Security\Http\Attribute\IsGranted;

webapp/src/Controller/API/SubmissionController.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use App\Entity\Language;
1010
use App\Entity\Submission;
1111
use App\Entity\SubmissionFile;
12+
use App\Entity\SubmissionSource;
1213
use App\Entity\Team;
1314
use App\Entity\User;
1415
use App\Service\ConfigurationService;
@@ -331,7 +332,7 @@ public function addSubmissionAction(
331332
// Now submit the solution.
332333
$submission = $this->submissionService->submitSolution(
333334
$team, $user, $problem, $problem->getContest(), $language,
334-
$files, 'API', null, null, $entryPoint, $submissionId, $time, $message
335+
$files, SubmissionSource::API, null, null, $entryPoint, $submissionId, $time, $message
335336
);
336337

337338
// Clean up temporary if needed.

webapp/src/Controller/BaseController.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
use App\Entity\ExternalIdFromInternalIdInterface;
1111
use App\Entity\Problem;
1212
use App\Entity\RankCache;
13-
use App\Entity\ScoreboardType;
1413
use App\Entity\ScoreCache;
1514
use App\Entity\Team;
1615
use App\Entity\TeamCategory;
@@ -168,8 +167,9 @@ protected function getDatabaseRelations(array $files): array {
168167
$parts = explode('/', $file);
169168
$shortClass = str_replace('.php', '', $parts[count($parts) - 1]);
170169
$class = sprintf('App\\Entity\\%s', $shortClass);
171-
if (class_exists($class) && !in_array($class,
172-
[RankCache::class, ScoreCache::class, BaseApiEntity::class, ScoreboardType::class])) {
170+
if (class_exists($class) &&
171+
!in_array($class, [RankCache::class, ScoreCache::class, BaseApiEntity::class]) &&
172+
!enum_exists($class)) {
173173
$metadata = $this->em->getClassMetadata($class);
174174

175175
$tableRelations = [];

webapp/src/Controller/Jury/ProblemController.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -593,8 +593,10 @@ public function testcasesAction(Request $request, int $probId): Response
593593
$content = file_get_contents($file->getRealPath());
594594
if ($type === 'image') {
595595
if (mime_content_type($file->getRealPath()) === 'image/svg+xml') {
596+
$originalContent = $content;
596597
$content = Utils::sanitizeSvg($content);
597598
if ($content === false) {
599+
$imageType = Utils::getImageType($originalContent, $error);
598600
$this->addFlash('danger', sprintf('image: %s', $error));
599601
return $this->redirectToRoute('jury_problem_testcases', ['probId' => $probId]);
600602
}

webapp/src/Controller/Jury/SubmissionController.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use App\Entity\Problem;
1818
use App\Entity\Submission;
1919
use App\Entity\SubmissionFile;
20+
use App\Entity\SubmissionSource;
2021
use App\Entity\Team;
2122
use App\Entity\TeamAffiliation;
2223
use App\Entity\TeamCategory;
@@ -1014,7 +1015,7 @@ public function editSourceAction(Request $request, Submission $submission, #[Map
10141015
$submission->getContest(),
10151016
$language,
10161017
$filesToSubmit,
1017-
'edit/resubmit',
1018+
SubmissionSource::EDIT_RESUBMIT,
10181019
$this->getUser()->getUserIdentifier(),
10191020
$submission->getOriginalSubmission() ?? $submission,
10201021
$entryPoint,

webapp/src/Controller/Team/SubmissionController.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use App\Entity\Language;
88
use App\Entity\Problem;
99
use App\Entity\Submission;
10+
use App\Entity\SubmissionSource;
1011
use App\Entity\Testcase;
1112
use App\Form\Type\SubmitProblemType;
1213
use App\Service\ConfigurationService;
@@ -84,7 +85,7 @@ public function createAction(Request $request, ?Problem $problem = null): Respon
8485
}
8586
$entryPoint = $form->get('entry_point')->getData() ?: null;
8687
$submission = $this->submissionService->submitSolution(
87-
$team, $this->dj->getUser(), $problem->getProbid(), $contest, $language, $files, 'team page', null,
88+
$team, $this->dj->getUser(), $problem->getProbid(), $contest, $language, $files, SubmissionSource::TEAM_PAGE, null,
8889
null, $entryPoint, null, null, $message
8990
);
9091

webapp/src/Entity/Contest.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -936,6 +936,9 @@ public function removeLanguage(Language $language): void
936936
$this->languages->removeElement($language);
937937
}
938938

939+
/**
940+
* @return Collection<int, Language>
941+
*/
939942
public function getLanguages(): Collection
940943
{
941944
return $this->languages;
@@ -1191,7 +1194,8 @@ public function getDataForJuryInterface(): array
11911194
$showButton = $hasstarted && !$hasended && (empty($this->getFreezetime()) || $hasfrozen);
11921195
break;
11931196
case 'deactivate':
1194-
$showButton = $hasended && (empty($this->getUnfreezetime()) || $hasunfrozen);
1197+
$futureDeactivate = empty($this->getDeactivatetime()) || Utils::difftime((float)$this->getDeactivatetime(), $now) > 0;
1198+
$showButton = $hasended && (empty($this->getUnfreezetime()) || $hasunfrozen) && $futureDeactivate;
11951199
break;
11961200
case 'freeze':
11971201
$showButton = $hasstarted && !$hasended && !$hasfrozen;

webapp/src/Entity/Language.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -447,6 +447,9 @@ public function removeContest(Contest $contest): Language
447447
return $this;
448448
}
449449

450+
/**
451+
* @return Collection<int, Contest>
452+
*/
450453
public function getContests(): Collection
451454
{
452455
return $this->contests;
@@ -466,6 +469,9 @@ public function removeProblem(Problem $problem): Language
466469
return $this;
467470
}
468471

472+
/**
473+
* @return Collection<int, Problem>
474+
*/
469475
public function getProblems(): Collection
470476
{
471477
return $this->problems;

0 commit comments

Comments
 (0)