* It is run every 15 minutes */ require_once dirname(__FILE__) . "/../system/backend_functions.php"; global $addon; $context = $addon->callHook('context'); require dirname(__FILE__) . "/../system/dbconnection.class.php"; if ($context == "") { $context = "staging"; } $dbc = new DBConnection(); $dbh = $dbc->connect(); # refresh the scoreboard -- not every 15 minutes! $forceRefresh = strcasecmp(getenv("FORCE_BABEL_REFRESH"), "true"); if (rand(1, 100) < 25 || $forceRefresh) { require_once dirname(__FILE__) . "/../system/scoreboard.class.php"; $sb = new Scoreboard(); $sb->refresh(); # Refresh file progress # This only needs to happen once in a while too. # See also: babel-setup.sql $sql = "select f.file_id, l.language_id, IF(COUNT(s.string_id) > 0, COUNT(t.string_id)/COUNT(s.string_id)*100,100) AS translate_percent\nFROM files AS f\n INNER JOIN languages as l ON l.is_active = 1\n LEFT JOIN strings as s ON (s.file_id = f.file_id AND s.is_active AND s.value <> '' AND s.non_translatable <> 1) \n LEFT JOIN translations AS t ON (s.string_id = t.string_id \n AND t.language_id = l.language_id AND t.is_active = 1)\nWHERE f.is_active = 1 \nGROUP BY f.file_id, l.language_id\nHAVING translate_percent > 0"; $rs = mysql_query($sql, $dbh); while ($myrow = mysql_fetch_assoc($rs)) { mysql_query("INSERT INTO file_progress (file_id, language_id, pct_complete)\n\t\t\tVALUES(" . $myrow['file_id'] . ", " . $myrow['language_id'] . ", " . $myrow['translate_percent'] . ")\n\t\t\tON DUPLICATE KEY UPDATE pct_complete=" . $myrow['translate_percent'], $dbh); } mysql_query("DELETE FROM file_progress WHERE pct_complete = 0", $dbh); } # Update project/version/language progress $sql = "SELECT * FROM project_progress WHERE is_stale"; $rs = mysql_query($sql, $dbh); while ($myrow = mysql_fetch_assoc($rs)) {
/** * Returns a detailed report of the contest * * @param Request $r * @return array */ public static function apiReport(Request $r) { self::authenticateRequest($r); self::validateStats($r); $scoreboard = new Scoreboard($r["contest"]->getContestId(), true, $r["auth_token"]); // Check the filter if we have one Validators::isStringNonEmpty($r["filterBy"], "filterBy", false); $contestReport = $scoreboard->generate(true, true, isset($r["filterBy"]) ? null : $r["filterBy"]); $contestReport["status"] = "ok"; return $contestReport; }
/** * Returns a detailed report of the contest * * @param Request $r * @return array */ public static function apiReport(Request $r) { self::authenticateRequest($r); self::validateStats($r); $scoreboard = new Scoreboard($r['contest']->getContestId(), true, $r['auth_token']); // Check the filter if we have one Validators::isStringNonEmpty($r['filterBy'], 'filterBy', false); $contestReport = $scoreboard->generate(true, true, isset($r['filterBy']) ? null : $r['filterBy']); $contestReport['status'] = 'ok'; return $contestReport; }
function do_post_testbasicphp_thing_v1($job, $resp) { $resp->status()->progress(10); $resp->status()->add_message("processing"); # test SWIG wapper for scoreboarding Scoreboard::initialize($resp->status()->component()); $sb = Scoreboard::get_scoreboard(); $sb->increment_counter("status", "testbasicphp"); $sw = new StopWatch(); $sw->start(); $sw->stop(); $sb->update_duration_hours("status", "testbasicphp", "duration_success", $sw); if ($job->operation() == "create") { // post-create where the resource id is created for user // (instead of a PUT where the user specifies the name) // get the generated id $in = json_decode($job->content(), true); $in["id"] = $job->resource_name(); file_put_contents(DBDIR . $job->resource_name(), json_encode($in)); } else { $args = $job->arguments(); // post update if (file_exists(DBDIR . $args[0])) { $in = json_decode($job->content(), true); $out = json_decode(file_get_contents(DBDIR . $args[0]), true); $out["stuff"] = $in["stuff"]; file_put_contents(DBDIR . $args[0], json_encode($out)); } else { throw new ERR_NOT_FOUND("thing \"" . $args[0] . "\" not found"); } } $resp->status()->add_message("done"); return Worker::WORKER_SUCCESS; }
/** * Returns a list of contests * * @param Request $r * @return array * @throws InvalidDatabaseOperationException */ public static function apiRefresh(Request $r) { // This is not supposed to be called by end-users, but by the // Grader service. Regular sessions cannot be used since they // expire, so use a pre-shared secret to authenticate that // grants admin-level privileges just for this call. if ($r['token'] !== OMEGAUP_GRADER_SECRET) { throw new ForbiddenAccessException(); } $contest = ContestsDAO::getByAlias($r['alias']); if ($contest === null) { throw new NotFoundException(); } $id = $contest->getContestId(); Scoreboard::RefreshScoreboardCache($id); return array('status' => 'ok'); }
private static function calculateEvents($contest, $contest_runs, $raw_contest_users, $problem_mapping, $showAllRuns) { $contest_users = array(); foreach ($raw_contest_users as $user) { $contest_users[$user->getUserId()] = $user; } $result = array(); $user_problems_score = array(); $contestStart = strtotime($contest->start_time); $scoreboardLimit = Scoreboard::getScoreboardTimeLimitUnixTimestamp($contest, $showAllRuns); // Calculate score for each contestant x problem x run foreach ($contest_runs as $run) { if (!$showAllRuns && $run->getTest() != 0) { continue; } $log = Logger::getLogger('Scoreboard'); $run_delay = strtotime($run->getTime()); $log->debug(">> run_delay : {$run_delay}"); $log->debug(">>scoreboardLimit : {$scoreboardLimit}"); $log->debug(''); if (!is_null($scoreboardLimit) && $run_delay >= $scoreboardLimit) { continue; } $user_id = $run->getUserId(); $problem_id = $run->getProblemId(); $contest_score = $run->getContestScore(); if (!isset($user_problems_score[$user_id])) { $user_problems_score[$user_id] = array($problem_id => array('points' => 0, 'penalty' => 0)); } elseif (!isset($user_problems_score[$user_id][$problem_id])) { $user_problems_score[$user_id][$problem_id] = array('points' => 0, 'penalty' => 0); } $problem_data =& $user_problems_score[$user_id][$problem_id]; if ($problem_data['points'] >= $contest_score) { continue; } $problem_data['points'] = round((double) $contest_score, 2); $problem_data['penalty'] = 0; $user =& $contest_users[$user_id]; if ($user == null) { continue; } $data = array('name' => $user->getName() ? $user->getName() : $user->getUsername(), 'username' => $user->getUsername(), 'delta' => max(0, ($run_delay - $contestStart) / 60), 'problem' => array('alias' => $problem_mapping[$problem_id]['alias'], 'points' => round($contest_score, 2), 'penalty' => 0), 'total' => array('points' => 0, 'penalty' => 0), 'country' => $user->getCountryId()); foreach ($user_problems_score[$user_id] as $problem) { $data['total']['points'] += $problem['points']; $data['total']['penalty'] += $problem['penalty']; } // Add contestant results to scoreboard data array_push($result, $data); } return $result; }