Beispiel #1
0
/**
 * Output a team row from the scoreboard based on the cached data in
 * table 'scoreboard'.
 */
function putTeamRow($cdata, $teamids)
{
    global $DB;
    if (empty($cdata)) {
        return;
    }
    $fdata = calcFreezeData($cdata);
    $displayrank = IS_JURY || !$fdata['showfrozen'];
    $cid = $cdata['cid'];
    if (!$fdata['cstarted']) {
        if (!IS_JURY) {
            global $teamdata;
            echo "<h2 id=\"teamwelcome\">welcome team <span id=\"teamwelcometeam\">" . htmlspecialchars($teamdata['name']) . "</span>!</h2>\n\n";
            echo "<h3 id=\"contestnotstarted\">contest is " . printContestStart($cdata) . "</h3>\n\n";
        }
        return;
    }
    // For computing team row, use smart trick when only a single team is requested such
    // that we don't need to compute the whole scoreboard.
    // This does not fully populate the summary, so the first correct problem per problem
    // is not computed and hence not shown in the individual team row.
    if (count($teamids) == 1) {
        $teams = getTeams(array("teams" => $teamids), true, $cdata);
        $probs = getProblems($cdata);
        $SCORES = initScores($teams);
        $SUMMARY = initSummary($probs);
        // Calculate rank, num points and total time from rank cache
        foreach ($teams as $teamid => $team) {
            $totals = $DB->q("MAYBETUPLE SELECT points, totaltime\n\t\t\t                  FROM rankcache_jury\n\t\t\t                  WHERE cid = %i\n\t\t\t                  AND teamid = %i", $cid, $teamid);
            if ($totals != null) {
                $SCORES[$teamid]['num_points'] = $totals['points'];
                $SCORES[$teamid]['total_time'] = $totals['totaltime'];
            }
            if ($displayrank) {
                $SCORES[$teamid]['rank'] = calcTeamRank($cdata, $teamid, $totals, true);
            }
        }
        // Get values for this team about problems from scoreboard cache
        $MATRIX = array();
        $scoredata = $DB->q("SELECT * FROM scorecache_jury WHERE cid = %i AND teamid = %i", $cid, current($teamids));
        // loop all info the scoreboard cache and put it in our own datastructure
        while ($srow = $scoredata->next()) {
            // skip this row if the problem is not known by us
            if (!array_key_exists($srow['probid'], $probs)) {
                continue;
            }
            $penalty = calcPenaltyTime($srow['is_correct'], $srow['submissions']);
            // fill our matrix with the scores from the database
            $MATRIX[$srow['teamid']][$srow['probid']] = array('is_correct' => (bool) $srow['is_correct'], 'num_submissions' => $srow['submissions'], 'num_pending' => $srow['pending'], 'time' => $srow['totaltime'], 'penalty' => $penalty);
        }
        // Fill in empty places in the matrix
        foreach (array_keys($teams) as $team) {
            foreach (array_keys($probs) as $prob) {
                // provide default scores when nothing submitted for this team,problem yet
                if (!isset($MATRIX[$team][$prob])) {
                    $MATRIX[$team][$prob] = array('is_correct' => FALSE, 'num_submissions' => 0, 'num_pending' => 0, 'time' => 0, 'penalty' => 0);
                }
            }
        }
        // Combine into data as genScoreBoard returns it
        $sdata = array('matrix' => $MATRIX, 'scores' => $SCORES, 'summary' => $SUMMARY, 'teams' => $teams, 'problems' => $probs, 'categories' => null);
    } else {
        // Otherwise, calculate scoreboard as jury to display non-visible teams
        $sdata = genScoreBoard($cdata, TRUE);
    }
    // Render the row based on this info
    $myteamid = null;
    $static = FALSE;
    if (!IS_JURY) {
        echo "<div id=\"teamscoresummary\">\n";
    }
    renderScoreBoardTable($sdata, $myteamid, $static, $teamids, $displayrank, TRUE, FALSE);
    if (!IS_JURY) {
        echo "</div>\n\n";
    }
    return;
}
Beispiel #2
0
<?php

require_once dirname(__FILE__) . '/../../config/require.php';
// ?????? ?????? ????? ????????????? ???????? ???????
Header('Content-Type: application/json; charset=cp1251');
Header('Content-disposition: attachment;filename=status.json');
$contest = isset($_GET['contest']) ? $_GET['contest'] : $curcontest;
$status = getStatus($contest, isset($_GET['since']) ? $_GET['since'] : NULL);
$problems = getProblems($contest);
$list = array();
$i = 0;
foreach ($status as $_ => $status) {
    if (isset($_GET['since']) && $_GET['since'] > 0 && ++$i === 10) {
        break;
    }
    if (!$is_admin && $status->getTime() > 4 * 3600) {
        break;
    }
    $item = array();
    $item[] = '"submitId":' . $status->getSubmitId();
    $item[] = '"userId":' . $status->getUserId();
    $item[] = '"taskId":' . $status->getTaskId();
    $item[] = '"time":' . $status->getTime();
    $item[] = '"timestamp":' . $status->getTimestamp();
    $item[] = '"result":"' . ('OK' === $status->getResult() ? 'AC' : $status->getResult()) . '"';
    $item[] = '"task":"' . $status->getTask() . '"';
    $item[] = '"nickname":"' . $status->getNickname() . '"';
    $s = str_replace("\n", '', $status->getInfo());
    $s = str_replace("\r", '', $s);
    $item[] = '"info":"' . $s . '"';
    $item[] = '"studyplace":"' . str_replace("\"", "\\\"", $status->getStudyplace()) . '"';