/** * Returns the value as an integer * @param mixed $val * @return int * @throws CastException if the value cannot be safely cast to an integer */ function to_int($val) { if (!safe_int($val)) { throw new CastException("Value could not be converted to int"); } else { return (int) $val; } }
/** * Scoreboard */ function scoreboard($args) { global $DB; checkargs($args, array('cid')); global $cdatas; $filter = array(); if (array_key_exists('category', $args)) { $filter['categoryid'] = array($args['category']); } if (array_key_exists('country', $args)) { $filter['country'] = array($args['country']); } if (array_key_exists('affiliation', $args)) { $filter['affilid'] = array($args['affiliation']); } $scoreboard = genScoreBoard($cdatas[$args['cid']], !$args['public'], $filter); $prob2label = $DB->q('KEYVALUETABLE SELECT probid, shortname FROM contestproblem WHERE cid = %i', $args['cid']); $res = array(); foreach ($scoreboard['scores'] as $teamid => $data) { $row = array('rank' => $data['rank'], 'team' => $teamid); $row['score'] = array('num_solved' => safe_int($data['num_points']), 'total_time' => safe_int($data['total_time'])); $row['problems'] = array(); foreach ($scoreboard['matrix'][$teamid] as $probid => $pdata) { $row['problems'][] = array('problem' => safe_int($probid), 'label' => $prob2label[$probid], 'num_judged' => safe_int($pdata['num_submissions']), 'num_pending' => safe_int($pdata['num_pending']), 'time' => safe_int($pdata['time']), 'solved' => safe_bool($pdata['is_correct'])); } $res[] = $row; } return $res; }
/** * Scoreboard */ function scoreboard($args) { global $DB, $api, $cdatas, $cids; if (isset($args['cid'])) { $cid = safe_int($args['cid']); } else { if (count($cids) == 1) { $cid = reset($cids); } else { $api->createError("No contest ID specified but active contest is ambiguous."); } } $filter = array(); if (array_key_exists('category', $args)) { $filter['categoryid'] = array($args['category']); } if (array_key_exists('country', $args)) { $filter['country'] = array($args['country']); } if (array_key_exists('affiliation', $args)) { $filter['affilid'] = array($args['affiliation']); } $scoreboard = genScoreBoard($cdatas[$cid], !$args['public'], $filter); $prob2label = $DB->q('KEYVALUETABLE SELECT probid, shortname FROM contestproblem WHERE cid = %i', $cid); $res = array(); foreach ($scoreboard['scores'] as $teamid => $data) { $row = array('rank' => $data['rank'], 'team' => $teamid); $row['score'] = array('num_solved' => safe_int($data['num_points']), 'total_time' => safe_int($data['total_time'])); $row['problems'] = array(); foreach ($scoreboard['matrix'][$teamid] as $probid => $pdata) { $prob = array('label' => $prob2label[$probid], 'num_judged' => safe_int($pdata['num_submissions']), 'num_pending' => safe_int($pdata['num_pending']), 'solved' => safe_bool($pdata['is_correct'])); if ($prob['solved']) { $prob['time'] = scoretime($pdata['time']); $first = first_solved($pdata['time'], $scoreboard['summary']['problems'][$probid]['best_time_sort'][$data['sortorder']]); $prob['first_to_solve'] = safe_bool($first); } $row['problems'][] = $prob; } usort($row['problems'], 'cmp_prob_label'); $res[] = $row; } return $res; }