#!/usr/bin/env python3 """Dashboard eval split patch (Young's request 2026-11-20 15:09): split the "Tien do eval" section into two subsections. - "Eval dang chay": ONLY rows with status RUNNING, each rendered as a visual progress bar (CSS .pbar/.pfill, width = % complete) with the episode count, % and success count in the row header. When nothing is running it shows "Hien khong co eval nao dang chay" instead of an empty table. - "Lich su eval": every other row (DONE, PARTIAL, UNKNOWN) in the existing table layout, plus a small progress-bar column using the same bar styling (green for DONE, gray otherwise). Data mechanism is unchanged: eval_progress() still scans the result dirs on every collect() and classifies RUNNING/DONE/PARTIAL/UNKNOWN exactly as before; only the presentation/grouping changes. No other dashboard section is touched. Every replacement is exact-match asserted. Backup: server.py.bak-evalsplit-20261120. """ import shutil from pathlib import Path P = Path.home() / "sera_v4_dashboard" / "server.py" src = P.read_text() orig = src CSS_OLD = " .badge.part{background:var(--orange)} .badge.unk{background:#8a97a5}" CSS_NEW = CSS_OLD + "\n" + "\n".join([ " .pbar{background:#e8edf1;border-radius:6px;height:14px;overflow:hidden;margin:5px 0 12px}", " .pfill{background:var(--orange);height:100%;border-radius:6px;transition:width .6s ease}", " .pfill.done{background:var(--green)} .pfill.part{background:#8a97a5}", " .pbar.mini{height:8px;margin:2px 0;min-width:90px}", " .runrow{margin:0 0 6px}", " .runhead{display:flex;gap:10px;align-items:center;flex-wrap:wrap}", ]) HTML_OLD = '

Tiến độ eval

\n' HTML_NEW = ('

Eval đang chạy

\n' '

Lịch sử eval

\n') JS_OLD = ''' if(d.eval_progress&&d.eval_progress.length){ let s=""; for(const e of d.eval_progress){ const tot=e.expected?e.episodes+"/"+e.expected:e.episodes+" / chưa rõ tổng"; s+=``; } $("evals").innerHTML=s+"
EvalThư mụcEpisode% xongThành côngTrạng tháiCập nhật
${e.name}${e.dir}${tot}${e.pct===null?"—":e.pct+"%"}${e.success} (${e.success_rate===null?"—":e.success_rate+"%"})${ebadge(e.status)}${e.age_text||"—"}
"; } else $("evals").innerHTML="—"; ''' JS_NEW = ''' const eruns=(d.eval_progress||[]).filter(e=>e.status==="RUNNING"); const ehist=(d.eval_progress||[]).filter(e=>e.status!=="RUNNING"); if(eruns.length){ let s=""; for(const e of eruns){ const tot=e.expected?e.episodes+"/"+e.expected:e.episodes+" / chưa rõ tổng"; s+=`
${e.name}${tot} episode${e.pct===null?"":" · "+e.pct+"%"} · thành công ${e.success} (${e.success_rate===null?"—":e.success_rate+"%"})${ebadge(e.status)}
`; } $("evals_run").innerHTML=s; } else $("evals_run").innerHTML="Hiện không có eval nào đang chạy"; if(ehist.length){ let s=""; for(const e of ehist){ const tot=e.expected?e.episodes+"/"+e.expected:e.episodes+" / chưa rõ tổng"; s+=``; } $("evals").innerHTML=s+"
EvalThư mụcEpisodeTiến độ% xongThành côngTrạng tháiCập nhật
${e.name}${e.dir}${tot}
${e.pct===null?"—":e.pct+"%"}${e.success} (${e.success_rate===null?"—":e.success_rate+"%"})${ebadge(e.status)}${e.age_text||"—"}
"; } else $("evals").innerHTML="—"; ''' REPLACEMENTS = [ (CSS_OLD, CSS_NEW), (HTML_OLD, HTML_NEW), (JS_OLD, JS_NEW), ] for i, (old, new) in enumerate(REPLACEMENTS): n = src.count(old) assert n == 1, f"replacement {i}: anchor found {n} times (expected 1)" src = src.replace(old, new) assert src != orig shutil.copy(P, P.with_name("server.py.bak-evalsplit-20261120")) P.write_text(src) print(f"dashboard server.py eval-split patched OK ({len(REPLACEMENTS)} replacements), backup at server.py.bak-evalsplit-20261120")