function closeDrawer() { const el = document.getElementById("drawer"); if (el) el.classList.remove("show"); } function sparkline(svg, exams, zs, xs, lastRank) { const w = 520, h = 220, pad = 28; const vals = []; zs.forEach((z, i) => { if (z !== null && z !== undefined) vals.push(z); }); xs.forEach((z) => { if (z !== null && z !== undefined) vals.push(z); }); if (!vals.length) return; const min = Math.min(...vals, -0.5) - 0.3; const max = Math.max(...vals, 0.5) + 0.3; const xAt = (i) => pad + (i * (w - pad * 2)) / Math.max(exams.length - 1, 1); const yAt = (v) => pad + (max - v) * (h - pad * 2) / (max - min); const pts = (arr) => arr.map((v, i) => v == null ? null : `${xAt(i)},${yAt(v)}`).filter(Boolean).join(" "); let raw = ""; zs.forEach((v, i) => { if (v == null) return; raw += ``; }); const pathXs = xs.map((v, i) => (v == null ? null : [xAt(i), yAt(v)])).filter(Boolean); let d = ""; pathXs.forEach((p, i) => { d += (i === 0 ? `M${p[0]} ${p[1]}` : ` L${p[0]} ${p[1]}`); }); const labels = exams.map((e, i) => { const short = String(e).replace("-总分", "").replace("高", ""); return `${short}`; }).join(""); svg.setAttribute("viewBox", `0 0 ${w} ${h}`); svg.innerHTML = ` ${raw} ${labels} 标准分轨迹 · 橙点考试,绿线滤波估计 `; } async function openStudent(aid, sid) { const res = await fetch(`/analysis/${aid}/api/student/${encodeURIComponent(sid)}`); if (!res.ok) return; const s = await res.json(); const box = document.getElementById("drawer"); const body = document.getElementById("drawer-body"); const probs = Object.entries(s.probs || {}).map(([k, v]) => `${k}: ${(v * 100).toFixed(1)}%`).join(" "); body.innerHTML = `

${s.name} ${s.sid}

${s.class_name}班 · ${s.group} · ${s.status || "在籍"} · ${s.subjects || ""}

绿线是卡尔曼估计的稳定水平。如果橙点突然跳开绿线,系统会当成发挥波动,不会立刻改判断。 达线概率 ${probs || "—"}。

考试分数方向内名次标准分滤波
`; const rows = document.getElementById("spark-rows"); (s.z || []).forEach((z, i) => { const exam = (window.HB_EXAMS || [])[i] || `第${i + 1}次`; const score = s.scores ? s.scores[exam] : ""; const rank = (s.ranks || [])[i]; const kf = (s.kf_xs || [])[i]; rows.insertAdjacentHTML("beforeend", ` ${exam}${score ?? "缺考"}${rank ?? "—"} ${z == null ? "—" : z.toFixed(2)} ${kf == null ? "—" : kf.toFixed(2)} `); }); sparkline(document.getElementById("spark"), window.HB_EXAMS || [], s.z || [], s.kf_xs || []); box.classList.add("show"); } async function openClass(aid, group, target, className) { const url = `/analysis/${aid}/api/class?group=${encodeURIComponent(group)}&target=${encodeURIComponent(target)}&class_name=${encodeURIComponent(className)}`; const res = await fetch(url); if (!res.ok) return; const data = await res.json(); const box = document.getElementById("drawer"); const body = document.getElementById("drawer-body"); const rows = data.students.map((s) => { const p = ((s.probs || {})[target] || 0) * 100; const tag = p >= 80 ? "high" : p >= 20 ? "mid" : ""; return ` ${s.name}${s.status || ""} ${(s.ranks || []).slice(-1)[0] ?? "—"} ${p.toFixed(1)}% `; }).join(""); body.innerHTML = `

${className}班学生概率

点击学生可看成绩轨迹。共 ${data.n} 人,下列按达线概率排序。

${rows}
姓名学籍最近名次达线概率
`; box.classList.add("show"); } document.addEventListener("click", (e) => { if (e.target.id === "drawer") closeDrawer(); });