22
33namespace App \Controller \API ;
44
5+ use App \Entity \Visualization ;
6+ use App \Entity \Testcase ;
7+
58use App \DataTransferObject \JudgehostFile ;
69use App \Doctrine \DBAL \Types \JudgeTaskType ;
710use App \Entity \Contest ;
@@ -550,6 +553,60 @@ public function addDebugInfo(
550553 $ this ->em ->flush ();
551554 }
552555
556+ /**
557+ * Add visual team output.
558+ */
559+ #[IsGranted('ROLE_JUDGEHOST ' )]
560+ #[Rest \Post('/add-visual/{hostname}/{judgeTaskId<\d+>} ' )]
561+ #[OA \Response(response: 200 , description: 'When the visual output has been added ' )]
562+ public function addVisualization (
563+ Request $ request ,
564+ #[OA \PathParameter(description: 'The hostname of the judgehost that wants to add the debug info ' )]
565+ string $ hostname ,
566+ #[OA \PathParameter(description: 'The ID of the judgetask to add ' , schema: new OA \Schema (type: 'integer ' ))]
567+ int $ judgeTaskId
568+ ): void {
569+ $ judgeTask = $ this ->em ->getRepository (JudgeTask::class)->find ($ judgeTaskId );
570+ if ($ judgeTask === null ) {
571+ throw new BadRequestHttpException (
572+ 'Inconsistent data, no judgetask known with judgetaskid = ' . $ judgeTaskId . '. ' );
573+ }
574+
575+ foreach (['visual_output ' , 'testcase_id ' ] as $ argument ) {
576+ if (!$ request ->request ->has ($ argument )) {
577+ throw new BadRequestHttpException (
578+ sprintf ("Argument '%s' is mandatory " , $ argument ));
579+ }
580+ }
581+
582+ $ judgehost = $ this ->em ->getRepository (Judgehost::class)->findOneBy (['hostname ' => $ hostname ]);
583+ if (!$ judgehost ) {
584+ throw new BadRequestHttpException ("Who are you and why are you sending us any data? " );
585+ }
586+
587+ $ judging = $ this ->em ->getRepository (Judging::class)->find ($ judgeTask ->getJobId ());
588+ if ($ judging === null ) {
589+ throw new BadRequestHttpException (
590+ 'Inconsistent data, no judging known with judgingid = ' . $ judgeTask ->getJobId () . '. ' );
591+ }
592+ if ($ tempFilename = tempnam ($ this ->dj ->getDomjudgeTmpDir (), "visual- " )) {
593+ $ debug_package = base64_decode ($ request ->request ->get ('visual_output ' ));
594+ file_put_contents ($ tempFilename , $ debug_package );
595+ var_dump ($ debug_package );
596+ }
597+ // FIXME: error checking
598+ var_dump ("Received " , $ request ->request ->get ('testcase_id ' ), "Processed " );
599+ $ testcase = $ this ->em ->getRepository (Testcase::class)->findOneBy (['testcaseid ' => $ request ->request ->get ('testcase_id ' )]);
600+ $ visualization = new Visualization ();
601+ $ visualization
602+ ->setJudgehost ($ judgehost )
603+ ->setJudging ($ judging )
604+ ->setTestcase ($ testcase )
605+ ->setFilename ($ tempFilename );
606+ $ this ->em ->persist ($ visualization );
607+ $ this ->em ->flush ();
608+ }
609+
553610 /**
554611 * Add one JudgingRun. When relevant, finalize the judging.
555612 * @throws DBALException
@@ -1186,7 +1243,7 @@ public function getFilesAction(
11861243 return match ($ type ) {
11871244 'source ' => $ this ->getSourceFiles ($ id ),
11881245 'testcase ' => $ this ->getTestcaseFiles ($ id ),
1189- 'compare ' , 'compile ' , 'debug ' , 'run ' => $ this ->getExecutableFiles ($ id ),
1246+ 'compare ' , 'compile ' , 'debug ' , 'run ' , ' output_visualization ' => $ this ->getExecutableFiles ($ id ),
11901247 default => throw new BadRequestHttpException ('Unknown type requested. ' ),
11911248 };
11921249 }
@@ -1656,7 +1713,7 @@ public function getJudgeTasksAction(Request $request): array
16561713 ->createQueryBuilder ()
16571714 ->from (JudgeTask::class, 'jt ' )
16581715 ->select ('jt ' )
1659- ->andWhere ('jt.judgehost = :judgehost ' )
1716+ ->andWhere ('jt.judgehost = :judgehost OR jt.judgehost IS NULL ' )
16601717 //->andWhere('jt.starttime IS NULL')
16611718 ->andWhere ('jt.valid = 1 ' )
16621719 ->andWhere ('jt.type = :type ' )
@@ -1703,7 +1760,7 @@ private function serializeJudgeTasks(array $judgeTasks, Judgehost $judgehost): a
17031760 }
17041761
17051762 $ now = Utils::now ();
1706- $ numUpdated = $ this ->em ->getConnection ()->executeStatement (
1763+ $ numUpdated = sizeof ( $ judgeTasks ); /* $this->em->getConnection()->executeStatement(
17071764 'UPDATE judgetask SET judgehostid = :judgehostid, starttime = :starttime WHERE starttime IS NULL AND valid = 1 AND judgetaskid IN (:ids)',
17081765 [
17091766 'judgehostid' => $judgehost->getJudgehostid(),
@@ -1718,7 +1775,7 @@ private function serializeJudgeTasks(array $judgeTasks, Judgehost $judgehost): a
17181775 if ($numUpdated == 0) {
17191776 // Bad luck, some other judgehost beat us to it.
17201777 return [];
1721- }
1778+ }*/
17221779
17231780 // We got at least one, let's update the starttime of the corresponding judging if haven't done so in the past.
17241781 $ starttime_set = $ this ->em ->getConnection ()->executeStatement (
0 commit comments