作业:= UOJList::info('title') ?>
getProblemIDs();
$users = queryGroupUsers($group['id']);
$usernames = [];
$n_users = count($users);
$submission_end_time = min(new DateTime(), DateTime::createFromFormat('Y-m-d H:i:s', $assignment['end_time']));
foreach ($users as $user) {
$usernames[] = $user['username'];
}
// standings: rank => [total_score, user => [username, realname], scores[]]
$standings = [];
foreach ($usernames as $username) {
$user = UOJUser::query($username);
$row = ['total_score' => 0];
$scores = [];
$row['user'] = [
'username' => $user['username'],
'realname' => $user['realname'],
];
$cond = "submitter = '{$user['username']}' AND unix_timestamp(submit_time) <= " . $submission_end_time->getTimestamp();
foreach ($problems as $problem_id) {
$submission = DB::selectFirst("SELECT id, score FROM submissions WHERE problem_id = $problem_id AND $cond ORDER BY score DESC, id DESC");
if ($submission) {
$row['scores'][] = [
'submission_id' => (int)$submission['id'],
'score' => (int)$submission['score'],
];
$row['total_score'] += $submission['score'];
} else {
$row['scores'][] = null;
}
}
$standings[] = $row;
}
usort($standings, function ($lhs, $rhs) {
if ($lhs['total_score'] != $rhs['total_score']) {
return $rhs['total_score'] - $lhs['total_score'];
}
return strcmp($lhs['user']['username'], $rhs['user']['username']);
});
?>