/** * 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()); }
/** * Given the run alias, returns the source code and any compile errors if any * Used in the arena, any contestant can view its own codes and compile errors * * @param Request $r * @throws ForbiddenAccessException */ public static function apiSource(Request $r) { // Get the user who is calling this API self::authenticateRequest($r); self::validateDetailsRequest($r); if (!Authorization::CanViewRun($r['current_user_id'], $r['run'])) { throw new ForbiddenAccessException('userNotAllowed'); } $response = array(); if (OMEGAUP_LOCKDOWN) { // OMI hotfix // @TODO @joemmanuel, hay que localizar este msg :P $response['source'] = 'Ver el código ha sido temporalmente desactivado.'; } else { // Get the source $response['source'] = file_get_contents(RunController::getSubmissionPath($r['run'])); } // Get the error $grade_dir = RunController::getGradePath($r['run']); if (file_exists("{$grade_dir}/compile_error.log")) { $response['compile_error'] = file_get_contents("{$grade_dir}/compile_error.log"); } $response['status'] = 'ok'; return $response; }
public static function apiDownload(Request $r) { self::authenticateRequest($r); self::validateStats($r); // Get our runs $relevant_columns = array("run_id", "guid", "language", "status", "verdict", "runtime", "penalty", "memory", "score", "contest_score", "time", "submit_delay", "Users.username", "Problems.alias"); try { $runs = RunsDAO::search(new Runs(array("contest_id" => $r["contest"]->getContestId())), "time", "DESC", $relevant_columns); } catch (Exception $e) { // Operation failed in the data layer throw new InvalidDatabaseOperationException($e); } $zip = new ZipStream($r["contest_alias"] . '.zip'); // Add runs to zip $table = "guid,user,problem,verdict,points\n"; foreach ($runs as $run) { $zip->add_file_from_path("runs/" . $run->getGuid(), RunController::getSubmissionPath($run)); $columns[0] = 'username'; $columns[1] = 'alias'; $usernameProblemData = $run->asFilteredArray($columns); $table .= $run->getGuid() . "," . $usernameProblemData['username'] . "," . $usernameProblemData['alias'] . "," . $run->getVerdict() . "," . $run->getContestScore(); $table .= "\n"; } $zip->add_file("summary.csv", $table); // Add problem cases to zip $contest_problems = ContestProblemsDAO::GetRelevantProblems($r["contest"]->getContestId()); foreach ($contest_problems as $problem) { $zip->add_file_from_path($problem->getAlias() . "_cases.zip", PROBLEMS_PATH . "/" . $problem->getAlias() . "/cases.zip"); } // Return zip $zip->finish(); die; }
public static function apiDownload(Request $r) { self::authenticateRequest($r); self::validateStats($r); // Get our runs $relevant_columns = array('run_id', 'guid', 'language', 'status', 'verdict', 'runtime', 'penalty', 'memory', 'score', 'contest_score', 'time', 'submit_delay', 'Users.username', 'Problems.alias'); try { $runs = RunsDAO::search(new Runs(array('contest_id' => $r['contest']->getContestId())), 'time', 'DESC', $relevant_columns); } catch (Exception $e) { // Operation failed in the data layer throw new InvalidDatabaseOperationException($e); } $zip = new ZipStream($r['contest_alias'] . '.zip'); // Add runs to zip $table = "guid,user,problem,verdict,points\n"; foreach ($runs as $run) { $zip->add_file_from_path('runs/' . $run->getGuid(), RunController::getSubmissionPath($run)); $columns[0] = 'username'; $columns[1] = 'alias'; $usernameProblemData = $run->asFilteredArray($columns); $table .= $run->getGuid() . ',' . $usernameProblemData['username'] . ',' . $usernameProblemData['alias'] . ',' . $run->getVerdict() . ',' . $run->getContestScore(); $table .= "\n"; } $zip->add_file('summary.csv', $table); // Add problem cases to zip $contest_problems = ContestProblemsDAO::GetRelevantProblems($r['contest']->getContestId()); foreach ($contest_problems as $problem) { $zip->add_file_from_path($problem->getAlias() . '_cases.zip', PROBLEMS_PATH . '/' . $problem->getAlias() . '/cases.zip'); } // Return zip $zip->finish(); die; }