Ejemplo n.º 1
0
 /**
  * Returns all runs for a contest
  *
  * @param Request $r
  * @return array
  * @throws InvalidDatabaseOperationException
  */
 public static function apiRuns(Request $r)
 {
     // Authenticate request
     self::authenticateRequest($r);
     // Validate request
     self::validateRuns($r);
     // Get our runs
     try {
         $runs = RunsDAO::GetAllRuns($r["contest"]->getContestId(), $r["status"], $r["verdict"], !is_null($r["problem"]) ? $r["problem"]->getProblemId() : null, $r["language"], !is_null($r["user"]) ? $r["user"]->getUserId() : null, $r["offset"], $r["rowcount"]);
     } catch (Exception $e) {
         // Operation failed in the data layer
         throw new InvalidDatabaseOperationException($e);
     }
     $result = array();
     foreach ($runs as $run) {
         $run['time'] = (int) $run['time'];
         $run['score'] = round((double) $run['score'], 4);
         $run['contest_score'] = round((double) $run['contest_score'], 2);
         array_push($result, $run);
     }
     $response = array();
     $response["runs"] = $result;
     $response["status"] = "ok";
     return $response;
 }
Ejemplo n.º 2
0
 /**
  * Gets a list of latest runs overall
  *
  * @param Request $r
  * @return string
  * @throws InvalidDatabaseOperationException
  */
 public static function apiList(Request $r)
 {
     // Authenticate request
     self::authenticateRequest($r);
     self::validateList($r);
     try {
         $runs = RunsDAO::GetAllRuns(null, $r['status'], $r['verdict'], !is_null($r['problem']) ? $r['problem']->getProblemId() : null, $r['language'], !is_null($r['user']) ? $r['user']->getUserId() : null, $r['offset'], $r['rowcount']);
     } catch (Exception $e) {
         // Operation failed in the data layer
         throw new InvalidDatabaseOperationException($e);
     }
     $result = array();
     foreach ($runs as $run) {
         $run['time'] = (int) $run['time'];
         $run['score'] = round((double) $run['score'], 4);
         if ($run['contest_score'] != null) {
             $run['contest_score'] = round((double) $run['contest_score'], 2);
         }
         array_push($result, $run);
     }
     $response = array();
     $response['runs'] = $result;
     $response['status'] = 'ok';
     return $response;
 }
Ejemplo n.º 3
0
 /**
  * Entry point for Problem runs API
  *
  * @param Request $r
  * @throws InvalidFilesystemOperationException
  * @throws InvalidDatabaseOperationException
  */
 public static function apiRuns(Request $r)
 {
     // Get user
     self::authenticateRequest($r);
     // Validate request
     self::validateRuns($r);
     $response = array();
     if ($r['show_all']) {
         if (!Authorization::CanEditProblem($r['current_user_id'], $r['problem'])) {
             throw new ForbiddenAccessException();
         }
         if (!is_null($r['username'])) {
             try {
                 $r['user'] = UsersDAO::FindByUsername($r['username']);
             } catch (Exception $e) {
                 throw new NotFoundException('userNotFound');
             }
         }
         try {
             $runs = RunsDAO::GetAllRuns(null, $r['status'], $r['verdict'], $r['problem']->problem_id, $r['language'], !is_null($r['user']) ? $r['user']->user_id : null, $r['offset'], $r['rowcount']);
             $result = array();
             foreach ($runs as $run) {
                 $run['time'] = (int) $run['time'];
                 $run['score'] = round((double) $run['score'], 4);
                 if ($run['contest_score'] != null) {
                     $run['contest_score'] = round((double) $run['contest_score'], 2);
                 }
                 array_push($result, $run);
             }
             $response['runs'] = $result;
         } catch (Exception $e) {
             // Operation failed in the data layer
             throw new InvalidDatabaseOperationException($e);
         }
     } else {
         $keyrun = new Runs(array('user_id' => $r['current_user_id'], 'problem_id' => $r['problem']->getProblemId()));
         // Get all the available runs
         try {
             $runs_array = RunsDAO::search($keyrun);
             // Create array of relevant columns for list of runs
             $relevant_columns = array('guid', 'language', 'status', 'verdict', 'runtime', 'penalty', 'memory', 'score', 'contest_score', 'time', 'submit_delay');
             // Add each filtered run to an array
             $response['runs'] = array();
             if (count($runs_array) >= 0) {
                 $runs_filtered_array = array();
                 foreach ($runs_array as $run) {
                     $filtered = $run->asFilteredArray($relevant_columns);
                     $filtered['time'] = strtotime($filtered['time']);
                     $filtered['username'] = $r['current_user']->username;
                     $filtered['alias'] = $r['problem']->alias;
                     array_push($response['runs'], $filtered);
                 }
             }
         } catch (Exception $e) {
             // Operation failed in the data layer
             throw new InvalidDatabaseOperationException($e);
         }
     }
     $response['status'] = 'ok';
     return $response;
 }