2022-10-17 12:42:32 +00:00
< ? php
if ( ! Auth :: check () && UOJConfig :: $data [ 'switch' ][ 'force-login' ]) {
redirectToLogin ();
}
if ( ! isNormalUser ( $myUser ) && UOJConfig :: $data [ 'switch' ][ 'force-login' ]) {
become403Page ();
}
requirePHPLib ( 'form' );
requireLib ( 'bootstrap5' );
$group_id = $_GET [ 'id' ];
if ( ! validateUInt ( $group_id )) {
become404Page ();
}
$list_id = $_GET [ 'list_id' ];
if ( ! validateUInt ( $list_id )) {
become404Page ();
}
$assignment = queryAssignmentByGroupListID ( $group_id , $list_id );
if ( ! $assignment ) {
become404Page ();
}
$group = queryGroup ( $assignment [ 'group_id' ]);
$list = queryProblemList ( $assignment [ 'list_id' ]);
?>
< ? php echoUOJPageHeader ( UOJLocale :: get ( 'assignments' )) ?>
< div class = " row " >
<!-- left col -->
< div class = " col-lg-9 " >
< h1 class = " h2 " >
< small class = " fs-4 " > 作业: </ small >< ? = $list [ 'title' ] ?>
</ h1 >
< ul class = " mt-3 " >
2022-10-21 12:42:48 +00:00
< li > 对应题单: < a class = " text-decoration-none " href = " <?= HTML::url('/problem_list/'. $list['id'] ) ?> " > #<?= $list['id'] ?></a></li>
2022-10-17 12:42:32 +00:00
< li > 所属小组: < a class = " text-decoration-none " href = " <?= HTML::url('/group/'. $group['id'] ) ?> " >< ? = $group [ 'title' ] ?> </a></li>
2022-10-21 12:42:48 +00:00
< li > 结束时间: < ? = $assignment [ 'end_time' ] ?> </li>
2022-10-17 12:42:32 +00:00
</ ul >
< ? php
2022-10-21 12:42:48 +00:00
$problems = DB :: selectAll ( " select problem_id from lists_problems where list_id = { $list [ 'id' ] } " );
$users = queryGroupUsers ( $group [ 'id' ]);
2022-10-17 12:42:32 +00:00
$problem_ids = [];
2022-10-21 12:42:48 +00:00
$usernames = [];
$n_users = count ( $users );
$n_problems = count ( $problems );
2022-10-21 23:46:42 +00:00
$submission_end_time = min ( new DateTime (), DateTime :: createFromFormat ( 'Y-m-d H:i:s' , $assignment [ 'end_time' ]));
2022-10-21 12:42:48 +00:00
foreach ( $problems as $problem ) {
$problem_ids [] = $problem [ 'problem_id' ];
2022-10-17 12:42:32 +00:00
}
2022-10-21 12:42:48 +00:00
sort ( $problem_ids );
foreach ( $users as $user ) {
$usernames [] = $user [ 'username' ];
2022-10-17 12:42:32 +00:00
}
2022-10-21 12:42:48 +00:00
2022-10-21 23:46:42 +00:00
// standings: rank => [total_score, user => [username, realname], scores[]]
2022-10-21 12:42:48 +00:00
$standings = [];
2022-10-17 12:42:32 +00:00
2022-10-21 12:42:48 +00:00
foreach ( $usernames as $username ) {
$user = queryUser ( $username );
$row = [ 'total_score' => 0 ];
2022-10-21 23:46:42 +00:00
$scores = [];
2022-10-17 12:42:32 +00:00
2022-10-21 12:42:48 +00:00
$row [ 'user' ] = [
'username' => $user [ 'username' ],
'realname' => $user [ 'realname' ],
];
2022-10-17 12:42:32 +00:00
2022-10-21 23:46:42 +00:00
$cond = " submitter = ' { $user [ 'username' ] } ' AND unix_timestamp(submit_time) <= " . $submission_end_time -> getTimestamp ();
$cond_problem = " problem_id IN ( " . implode ( ',' , $problem_ids ) . " ) " ;
$query = DB :: query ( " SELECT MAX(id) as id, problem_id, MAX(score) as score FROM submissions WHERE (problem_id, score) IN (SELECT problem_id, MAX(score) FROM submissions WHERE $cond AND $cond_problem GROUP BY problem_id) AND $cond GROUP BY problem_id " );
2022-10-21 12:42:48 +00:00
2022-10-21 23:46:42 +00:00
while ( $_row = DB :: fetch ( $query )) {
$scores [ $_row [ 'problem_id' ]] = [
'submission_id' => $_row [ 'id' ],
'score' => $_row [ 'score' ],
];
}
foreach ( $problem_ids as $problem_id ) {
if ( $scores [ $problem_id ]) {
2022-10-21 12:42:48 +00:00
$row [ 'scores' ][] = [
2022-10-21 23:46:42 +00:00
'submission_id' => $scores [ $problem_id ][ 'submission_id' ],
'score' => intval ( $scores [ $problem_id ][ 'score' ]),
2022-10-21 12:42:48 +00:00
];
2022-10-21 23:46:42 +00:00
$row [ 'total_score' ] += $scores [ $problem_id ][ 'score' ];
2022-10-21 12:42:48 +00:00
} else {
$row [ 'scores' ][] = null ;
}
}
2022-10-17 12:42:32 +00:00
2022-10-21 12:42:48 +00:00
$standings [] = $row ;
}
usort ( $standings , function ( $lhs , $rhs ) {
if ( $lhs [ 'total_score' ] != $rhs [ 'total_score' ]) {
return $rhs [ 'total_score' ] - $lhs [ 'total_score' ];
2022-10-17 12:42:32 +00:00
}
2022-10-21 12:42:48 +00:00
return strcmp ( $lhs [ 'user' ][ 'username' ], $rhs [ 'user' ][ 'username' ]);
});
?>
< div id = " standings " ></ div >
< script >
var n_problems = < ? = $n_problems ?> ;
var max_total_score = < ? = $n_problems * 100 ?> ;
var standings = < ? = json_encode ( $standings ) ?> ;
$ ( '#standings' ) . long_table (
standings ,
1 ,
'<tr>' +
'<th style="width:10em"><?= UOJLocale::get(' username ') ?></th>' +
'<th style="width:2em"><?= UOJLocale::get(' contests :: total score ') ?></th>' +
< ? php foreach ( $problem_ids as $problem_id ) : ?>
'<th style="width:2em">' +
'<a class="text-decoration-none" href="<?= HTML::url(' / problem / ' . $problem_id) ?>">#<?= $problem_id ?></a>' +
'</th>' +
< ? php endforeach ?>
'</tr>' ,
function ( row ) {
var col_tr = '' ;
if ( row [ 'total_score' ] == max_total_score ) {
col_tr += '<tr class="table-success">' ;
2022-10-17 12:42:32 +00:00
} else {
2022-10-21 12:42:48 +00:00
col_tr += '<tr>' ;
2022-10-17 12:42:32 +00:00
}
2022-10-21 12:42:48 +00:00
col_tr += '<td>' + getUserLink ( row [ 'user' ][ 'username' ], row [ 'user' ][ 'realname' ]) + '</td>' ;
col_tr += '<td>' +
'<span class="uoj-score" data-max="' + max_total_score + '" style="color:' + getColOfScore ( row [ 'total_score' ] / n_problems ) + '">' + row [ 'total_score' ] + '</span>' +
'</td>' ;
for ( var i = 0 ; i < row [ 'scores' ] . length ; i ++ ) {
var col = row [ 'scores' ][ i ];
if ( col ) {
if ( col [ 'score' ] == 100 ) {
col_tr += '<td class="table-success">' ;
2022-10-17 12:42:32 +00:00
} else {
2022-10-21 12:42:48 +00:00
col_tr += '<td>' ;
2022-10-17 12:42:32 +00:00
}
2022-10-21 12:42:48 +00:00
col_tr += '<a class="text-decoration-none uoj-score" href="/submission/' + col [ 'submission_id' ] + '" style="color:' + getColOfScore ( col [ 'score' ]) + '">' + col [ 'score' ] + '</a>' ;
col_tr += '</td>' ;
} else {
col_tr += '<td></td>' ;
2022-10-17 12:42:32 +00:00
}
}
2022-10-21 12:42:48 +00:00
col_tr += '</tr>' ;
return col_tr ;
},
{
div_classes : [ 'card' , 'my-3' , 'table-responsive' , 'text-center' ],
2022-10-21 14:04:17 +00:00
table_classes : [ 'table' , 'uoj-table' , 'table-bordered' , 'mb-0' ],
2022-10-21 14:05:44 +00:00
page_len : 50 ,
2022-10-21 14:04:17 +00:00
print_before_table : function () {
var html = '' ;
html += '<div class="card-header bg-transparent text-muted text-start small">' +
2022-10-21 23:46:42 +00:00
'成绩统计截止时间:<?= $submission_end_time->format(' Y - m - d H : m : s ') ?>' +
2022-10-21 14:04:17 +00:00
'</div>' ;
return html ;
}
2022-10-21 12:42:48 +00:00
}
);
</ script >
2022-10-17 12:42:32 +00:00
</ div >
2022-10-21 14:04:17 +00:00
<!-- end left col -->
2022-10-17 12:42:32 +00:00
2022-10-19 03:57:06 +00:00
< aside class = " col-lg-3 mt-3 mt-lg-0 " >
2022-10-17 12:42:32 +00:00
<!-- right col -->
< ? php uojIncludeView ( 'sidebar' , [ 'assignments_hidden' => true ]); ?>
</ aside >
</ div >
< ? php echoUOJPageFooter () ?>