feat: 完善/优化/新增大批次 + 安全加固 + 性能优化
- 修复再次提交不置顶(排序键改用 last_submit_ts) - 后端结果缓存 + 并发锁(DataCache / ny_build_data / Roster 指纹失效) - 导出 xlsx 多表:按最新成绩 / 按班级分表 / 可选列 - 名单管理:新增改弹窗、删除多选+二次确认、登陆账号列 - 安全:CSRF token + 登录失败限流(5次锁10分钟) - 未匹配答卷一键加入名单(unmatched_map) - 缺考名单增强:复制学号/姓名、按班统计、打印 - 成绩快照 + 跨卷趋势(Snapshot) - 异常检测线索(短时长高分/高频重考/雷同成绩) - 前端性能:虚拟滚动、搜索防抖、后台暂停、失败退避 - 测试沉淀:test-new-features.php + run-all.sh
This commit is contained in:
+93
-2
@@ -235,8 +235,12 @@ class DataService
|
||||
$attemptsTotal = $agg['attempts_total'];
|
||||
|
||||
// 成绩明细默认按提交时间降序(最新在前),学号作为次级排序
|
||||
usort($rows, static function (array $x, array $y): int {
|
||||
$d = ($y['submit_ts'] ?? 0) <=> ($x['submit_ts'] ?? 0);
|
||||
// 重要:排序键必须用「最近一次提交时间 last_submit_ts」,而不是代表行的 submit_ts。
|
||||
// 否则当 dedupe=false(代表成绩=最高分)时,学生重考且分数更低,代表行仍是最高分那次,
|
||||
// submit_ts 不变 → 该行会停在原来的位置只高亮,不会置顶,教师登记时看不到新提交。
|
||||
$sortTs = static fn(array $r): int => (int)($r['last_submit_ts'] ?? 0) ?: (int)($r['submit_ts'] ?? 0);
|
||||
usort($rows, static function (array $x, array $y) use ($sortTs): int {
|
||||
$d = $sortTs($y) <=> $sortTs($x);
|
||||
if ($d !== 0) {
|
||||
return $d;
|
||||
}
|
||||
@@ -290,6 +294,9 @@ class DataService
|
||||
'attempts_total'=> $attemptsTotal,
|
||||
];
|
||||
|
||||
// 异常检测(防作弊线索,仅供教师人工判断,不做自动判定)
|
||||
$anomalies = self::detectAnomalies($rows, $stats);
|
||||
|
||||
return [
|
||||
'project' => [
|
||||
'id' => ny_str($project['id'] ?? $projectId),
|
||||
@@ -303,12 +310,96 @@ class DataService
|
||||
'absent' => $absent,
|
||||
'unmatched' => $unmatched,
|
||||
'stats' => $stats,
|
||||
'anomalies' => $anomalies,
|
||||
'roster' => $students,
|
||||
'roster_count' => count($students),
|
||||
'updated_at' => date('Y-m-d H:i:s'),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 异常检测(防作弊线索):基于聚合后的学生行,输出三类线索供教师人工复核。
|
||||
* 1) 短时长高得分:用时远低于平均(<平均 40% 且 <180s)却接近满分;
|
||||
* 2) 高频重考:考试次数明显多于多数人(>1 且 >= 平均次数+3);
|
||||
* 3) 雷同成绩:多人分数完全相同(疑似互抄,需满足该分数下人数 >=3)。
|
||||
*
|
||||
* 返回值:['fast_high'=>[], 'frequent'=>[], 'identical'=>[['score'=>x,'count'=>n,'names'=>[...]]]]
|
||||
*/
|
||||
public static function detectAnomalies(array $rows, array $stats): array
|
||||
{
|
||||
$avgDur = (int)($stats['avg_duration'] ?? 0);
|
||||
$fullHint = max(1, (float)($stats['max_score'] ?? 100));
|
||||
|
||||
$fastHigh = [];
|
||||
$frequent = [];
|
||||
$attemptsAll = [];
|
||||
|
||||
foreach ($rows as $r) {
|
||||
$dur = $r['duration'] ?? null;
|
||||
$score = $r['score'] ?? null;
|
||||
$attempts = (int)($r['attempts'] ?? 1);
|
||||
$attemptsAll[] = $attempts;
|
||||
|
||||
// 短时长高得分:有时长记录、明显快于平均、分数 >= 满分 85%
|
||||
if ($dur !== null && $avgDur > 0 && $dur < max(60, (int)($avgDur * 0.4))
|
||||
&& $score !== null && $score >= $fullHint * 0.85) {
|
||||
$fastHigh[] = [
|
||||
'sid' => (string)($r['sid'] ?? ''),
|
||||
'name' => (string)($r['name'] ?? ''),
|
||||
'cls' => (string)($r['cls'] ?? ''),
|
||||
'score' => $score,
|
||||
'duration' => $dur,
|
||||
'duration_txt' => (string)($r['duration_txt'] ?? ''),
|
||||
];
|
||||
}
|
||||
|
||||
// 高频重考:考试次数明显偏多
|
||||
if ($attempts > 1) {
|
||||
$frequent[] = [
|
||||
'sid' => (string)($r['sid'] ?? ''),
|
||||
'name' => (string)($r['name'] ?? ''),
|
||||
'cls' => (string)($r['cls'] ?? ''),
|
||||
'attempts' => $attempts,
|
||||
'best_score' => $r['best_score'] ?? null,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
// 高频重考阈值:平均次数 + 3(且至少 4 次才够"高频")
|
||||
$avgAttempts = $attemptsAll !== [] ? array_sum($attemptsAll) / count($attemptsAll) : 0;
|
||||
$freqThreshold = max(4, (int)ceil($avgAttempts + 3));
|
||||
$frequent = array_values(array_filter($frequent, static fn($f) => $f['attempts'] >= $freqThreshold));
|
||||
usort($frequent, static fn($a, $b) => $b['attempts'] <=> $a['attempts']);
|
||||
|
||||
// 雷同成绩:按分数分组,出现 >=3 人同分(且分数不为 null)视为疑似
|
||||
$scoreGroups = [];
|
||||
foreach ($rows as $r) {
|
||||
$score = $r['score'] ?? null;
|
||||
if ($score === null) {
|
||||
continue;
|
||||
}
|
||||
$key = (string)$score;
|
||||
$scoreGroups[$key][] = [
|
||||
'sid' => (string)($r['sid'] ?? ''),
|
||||
'name' => (string)($r['name'] ?? ''),
|
||||
'cls' => (string)($r['cls'] ?? ''),
|
||||
];
|
||||
}
|
||||
$identical = [];
|
||||
foreach ($scoreGroups as $score => $members) {
|
||||
if (count($members) >= 3) {
|
||||
$identical[] = ['score' => (float)$score, 'count' => count($members), 'members' => $members];
|
||||
}
|
||||
}
|
||||
usort($identical, static fn($a, $b) => $b['count'] <=> $a['count']);
|
||||
|
||||
return [
|
||||
'fast_high' => $fastHigh,
|
||||
'frequent' => $frequent,
|
||||
'identical' => $identical,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 把聚合后的学生行展开为"每次考试一行",用于导出全部考试记录 / 明细内全部展示。
|
||||
* 每行携带该次考试的成绩、提交时间、时长,以及该学生的总考试次数 attempts 与第几次 idx。
|
||||
|
||||
Reference in New Issue
Block a user