Esempio n. 1
0
 public function broadcastClarification(Request $r, $time)
 {
     try {
         $message = json_encode(array('message' => '/clarification/update/', 'clarification' => array('clarification_id' => $r['clarification']->clarification_id, 'problem_alias' => $r['problem']->alias, 'author' => $r['user']->username, 'message' => $r['clarification']->message, 'answer' => $r['clarification']->answer, 'time' => $time, 'public' => $r['clarification']->public != '0')));
         $grader = new Grader();
         $this->log->debug("Sending update {$message}");
         $grader->broadcast(is_null($r['contest']) ? null : $r['contest']->alias, $message, $r['clarification']->public != '0', $r['clarification']->author_id);
     } catch (Exception $e) {
         $this->log->error('Failed to send to broadcaster ' . $e->getMessage());
     }
     $this->sendClarificationEmail($r, $time);
 }
Esempio n. 2
0
 public static function RefreshScoreboardCache($contest_id)
 {
     try {
         $contest = ContestsDAO::getByPK($contest_id);
         $contest_runs = RunsDAO::GetContestRuns($contest_id);
         // Get all distinct contestants participating in the contest given contest_id
         $raw_contest_users = RunsDAO::GetAllRelevantUsers($contest_id, true, null);
         // Get all problems given contest_id
         $raw_contest_problems = ContestProblemsDAO::GetRelevantProblems($contest_id);
     } catch (Exception $e) {
         throw new InvalidDatabaseOperationException($e);
     }
     $problem_mapping = array();
     $order = 0;
     foreach ($raw_contest_problems as $problem) {
         $problem_mapping[$problem->problem_id] = array('order' => $order++, 'alias' => $problem->alias);
     }
     $scoreboardLimit = Scoreboard::getScoreboardTimeLimitUnixTimestamp($contest);
     // Cache scoreboard until the contest ends (or forever if it has already ended).
     $timeout = max(0, strtotime($contest->getFinishTime()) - time());
     $contestantScoreboardCache = new Cache(Cache::CONTESTANT_SCOREBOARD_PREFIX, $contest_id);
     $contestantScoreboard = Scoreboard::getScoreboardFromRuns($contest_runs, $raw_contest_users, $problem_mapping, $contest->getPenalty(), $scoreboardLimit, $contest, false, false);
     $contestantScoreboardCache->set($contestantScoreboard, $timeout);
     $adminScoreboardCache = new Cache(Cache::ADMIN_SCOREBOARD_PREFIX, $contest_id);
     $scoreboardLimit = Scoreboard::getScoreboardTimeLimitUnixTimestamp($contest, true);
     $adminScoreboard = Scoreboard::getScoreboardFromRuns($contest_runs, $raw_contest_users, $problem_mapping, $contest->getPenalty(), $scoreboardLimit, $contest, true, false);
     $adminScoreboardCache->set($adminScoreboard, $timeout);
     $contestantEventCache = new Cache(Cache::CONTESTANT_SCOREBOARD_EVENTS_PREFIX, $contest_id);
     $contestantEventCache->set(Scoreboard::calculateEvents($contest, $contest_runs, $raw_contest_users, $problem_mapping, false), $timeout);
     $adminEventCache = new Cache(Cache::ADMIN_SCOREBOARD_EVENTS_PREFIX, $contest_id);
     $adminEventCache->set(Scoreboard::calculateEvents($contest, $contest_runs, $raw_contest_users, $problem_mapping, true), $timeout);
     // Try to broadcast the updated scoreboards:
     $log = Logger::getLogger('Scoreboard');
     try {
         $grader = new Grader();
         $log->debug('Sending updated scoreboards');
         $grader->broadcast($contest->alias, json_encode(array('message' => '/scoreboard/update/', 'scoreboard' => $adminScoreboard)), false, -1, false);
         $grader->broadcast($contest->alias, json_encode(array('message' => '/scoreboard/update/', 'scoreboard' => $contestantScoreboard)), true, -1, true);
     } catch (Exception $e) {
         $log->error('Error broadcasting scoreboard: ' . $e);
     }
 }
 /**
  * Calls to /status grader
  *
  * @param Request $r
  * @return array
  */
 public static function apiStatus(Request $r)
 {
     self::validateRequest($r);
     $response = array();
     self::$log->debug('Getting grader /status');
     $grader = new Grader();
     $response['grader'] = $grader->status();
     // TODO(lhchavez): Re-enable when we use EC2 again.
     //self::$log->info("Getting EC2 status");
     //$response["cloud"] = self::getEc2Status();
     $response['status'] = 'ok';
     return $response;
 }