public function testCoderOfTheMonthCalc() { $user = UserFactory::createUser(); $contest = ContestsFactory::createContest(); $problem = ProblemsFactory::createProblem(); ContestsFactory::addProblemToContest($problem, $contest); ContestsFactory::addUser($contest, $user); // Creating 10 AC runs for our user in the last month $n = 10; $lastMonth = intval(date('m')) - 1; $runCreationDate = null; if ($lastMonth == 0) { $runCreationDate = date(intval(date('Y') - 1) . '-12-01'); } else { $runCreationDate = date('Y-' . $lastMonth . '-01'); } for ($i = 0; $i < $n; $i++) { $runData = RunsFactory::createRun($problem, $contest, $user); RunsFactory::gradeRun($runData); // Force the run to be in last month $run = RunsDAO::getByAlias($runData['response']['guid']); $run->setTime($runCreationDate); RunsDAO::save($run); } $response = UserController::apiCoderOfTheMonth(new Request()); $this->assertEquals($user->getUsername(), $response['userinfo']['username']); }
/** * Validate a run * * @param type $r * @param type $response */ private function assertRun($r, $response) { // Validate $this->assertEquals("ok", $response["status"]); $this->assertArrayHasKey("guid", $response); // Get run from DB $run = RunsDAO::getByAlias($response["guid"]); $this->assertNotNull($run); // Get contest from DB to check times with respect to contest start $contest = ContestsDAO::getByAlias($r["contest_alias"]); // Validate data $this->assertEquals($r["language"], $run->getLanguage()); $this->assertNotNull($run->getGuid()); // Validate file created $filename = RunController::getSubmissionPath($run); $this->assertFileExists($filename); $fileContent = file_get_contents($filename); $this->assertEquals($r["source"], $fileContent); // Validate defaults $this->assertEquals("new", $run->getStatus()); $this->assertEquals(0, $run->getRuntime()); $this->assertEquals(0, $run->getMemory()); $this->assertEquals(0, $run->getScore()); $this->assertEquals(0, $run->getContestScore()); $this->assertEquals("127.0.0.1", $run->getIp()); if (!is_null($contest)) { $this->assertEquals((time() - intval(strtotime($contest->getStartTime()))) / 60, $run->penalty, '', 0.5); } $this->assertEquals("JE", $run->getVerdict()); }
/** * Validate a run * * @param type $r * @param type $response */ private function assertRun($r, $response) { // Validate $this->assertEquals('ok', $response['status']); $this->assertArrayHasKey('guid', $response); // Get run from DB $run = RunsDAO::getByAlias($response['guid']); $this->assertNotNull($run); // Get contest from DB to check times with respect to contest start $contest = ContestsDAO::getByAlias($r['contest_alias']); // Validate data $this->assertEquals($r['language'], $run->getLanguage()); $this->assertNotNull($run->getGuid()); // Validate file created $filename = RunController::getSubmissionPath($run); $this->assertFileExists($filename); $fileContent = file_get_contents($filename); $this->assertEquals($r['source'], $fileContent); // Validate defaults $this->assertEquals('new', $run->getStatus()); $this->assertEquals(0, $run->getRuntime()); $this->assertEquals(0, $run->getMemory()); $this->assertEquals(0, $run->getScore()); $this->assertEquals(0, $run->getContestScore()); $logs = SubmissionLogDAO::search(array('run_id' => $run->run_id)); $this->assertEquals(1, count($logs)); $this->assertEquals(ip2long('127.0.0.1'), $logs[0]->ip); if (!is_null($contest)) { $this->assertEquals((time() - intval(strtotime($contest->getStartTime()))) / 60, $run->penalty, '', 0.5); } $this->assertEquals('JE', $run->getVerdict()); }
public function testRunTotals() { // Get a problem $problemData = ProblemsFactory::createProblem(); // Get a contest $contestData = ContestsFactory::createContest(); // Add the problem to the contest ContestsFactory::addProblemToContest($problemData, $contestData); // Create our contestant $contestant = UserFactory::createUser(); // Create a run $runData = RunsFactory::createRun($problemData, $contestData, $contestant); $runDataOld = RunsFactory::createRun($problemData, $contestData, $contestant); $run = RunsDAO::getByAlias($runDataOld['response']['guid']); $run->setTime(date('Y-m-d H:i:s', strtotime('-72 hours'))); RunsDAO::save($run); $response = RunController::apiCounts(new Request()); $this->assertGreaterThan(1, count($response)); }
/** * Given a run id, set a score to a given run * * @param type $runData * @param int $points * @param string $verdict */ public static function gradeRun($runData, $points = 1, $verdict = 'AC', $submitDelay = null) { $run = RunsDAO::getByAlias($runData['response']['guid']); $run->setVerdict($verdict); $run->setScore($points); $run->setContestScore($points * 100); $run->setStatus('ready'); $run->judged_by = 'J1'; if (!is_null($submitDelay)) { $run->submit_delay = $submitDelay; $run->penalty = $submitDelay; } RunsDAO::save($run); }
/** * Validate request of admin details * * @param Request $r * @throws InvalidDatabaseOperationException * @throws NotFoundException * @throws ForbiddenAccessException */ private static function validateAdminDetailsRequest(Request $r) { Validators::isStringNonEmpty($r['run_alias'], 'run_alias'); try { $r['run'] = RunsDAO::getByAlias($r['run_alias']); } catch (Exception $e) { throw new InvalidDatabaseOperationException($e); } if (is_null($r['run'])) { throw new NotFoundException('runNotFound'); } try { $r['problem'] = ProblemsDAO::getByPK($r['run']->problem_id); } catch (Exception $e) { throw new InvalidDatabaseOperationException($e); } if (is_null($r['problem'])) { throw new NotFoundException('problemNotFound'); } if (!Authorization::IsProblemAdmin($r['current_user_id'], $r['problem'])) { throw new ForbiddenAccessException('userNotAllowed'); } }
/** * Given a run id, set a score to a given run * * @param type $runData * @param int $points * @param string $verdict */ public static function gradeRun($runData, $points = 1, $verdict = "AC", $submitDelay = null) { $run = RunsDAO::getByAlias($runData["response"]["guid"]); $run->setVerdict($verdict); $run->setScore($points); $run->setContestScore($points * 100); $run->setStatus("ready"); $run->judged_by = "J1"; if (!is_null($submitDelay)) { $run->submit_delay = $submitDelay; $run->penalty = $submitDelay; } RunsDAO::save($run); }