diff --git a/api.php b/api.php index 697a32d..1fb2d9d 100644 --- a/api.php +++ b/api.php @@ -217,6 +217,7 @@ try { $statOf = static function (array $stu, array $rs, int $fs): array { $total = count($stu); $submitted = count($rs); + $attempts = array_sum(array_map(static fn($r) => (int)($r['attempts'] ?? 1), $rs)); $scores = array_values(array_filter(array_map(static fn($r) => $r['score'] ?? null, $rs), static fn($v) => $v !== null)); $avg = $scores !== [] ? round(array_sum($scores) / count($scores), 2) : null; $pass = count(array_filter($rs, static fn($r) => ($r['score'] ?? null) !== null && ($r['score'] >= 0.6 * $fs))); @@ -226,6 +227,7 @@ try { return [ 'total' => $total, 'submitted' => $submitted, + 'attempts' => $attempts, 'absent' => max(0, $total - $submitted), 'rate' => $total > 0 ? round($submitted / $total * 100, 1) : 0, 'avg' => $avg, @@ -237,13 +239,16 @@ try { }; // 已提交成员榜:按成绩从高到低,缺成绩者排最后,并给出排名 + // 透传 attempts / attempts_list,供前端展示"同人多刷卷" $membersOf = static function (array $rs): array { $ms = []; foreach ($rs as $r) { $ms[] = [ - 'sid' => (string)($r['sid'] ?? ''), - 'name' => (string)($r['name'] ?? ''), - 'score' => ($r['score'] ?? null), + 'sid' => (string)($r['sid'] ?? ''), + 'name' => (string)($r['name'] ?? ''), + 'score' => ($r['score'] ?? null), + 'attempts' => (int)($r['attempts'] ?? 1), + 'attempts_list' => $r['attempts_list'] ?? [], ]; } usort($ms, static function (array $a, array $b): int { @@ -440,7 +445,7 @@ try { fputcsv($out, [$r['sid'] ?? '', $r['name'] ?? '', $r['cls'] ?? '', $r['grp'] ?? '']); } } else { - fputcsv($out, ['学号', '姓名', '班级', '组别', '成绩', '提交时间', '考试时长', '考试时长(秒)']); + fputcsv($out, ['学号', '姓名', '班级', '组别', '成绩', '提交时间', '考试时长', '考试时长(秒)', '刷题次数']); foreach ($rows as $r) { fputcsv($out, [ $r['sid'] ?? '', @@ -451,6 +456,7 @@ try { $r['submit_at'] ?? '', $r['duration_txt'] ?? '', $r['duration'] === null ? '' : $r['duration'], + (int)($r['attempts'] ?? 1), ]); } } diff --git a/assets/app.js b/assets/app.js index 12ef974..95373f4 100644 --- a/assets/app.js +++ b/assets/app.js @@ -447,10 +447,13 @@ const sig = r.sid + '|' + r.score + '|' + r.submit_at; const changed = state.prevMap[r.sid] && state.prevMap[r.sid] !== sig; const isNew = r.sid && state.newSids.has(r.sid); - const clsName = (changed ? 'diff ' : '') + (isNew ? 'new' : ''); - return '
| 提交时间 | 成绩 | 考试时长 |
|---|