File size: 4,755 Bytes
b4396f0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#!/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 = '  <section><h2>Tiến độ eval</h2><div id="evals"></div>\n'
HTML_NEW = ('  <section><h2>Eval đang chạy</h2><div id="evals_run"></div></section>\n'
            '  <section><h2>Lịch sử eval</h2><div id="evals"></div>\n')

JS_OLD = '''  if(d.eval_progress&&d.eval_progress.length){
    let s="<table><tr><th>Eval</th><th>Thư mục</th><th>Episode</th><th>% xong</th><th>Thành công</th><th>Trạng thái</th><th>Cập nhật</th></tr>";
    for(const e of d.eval_progress){
      const tot=e.expected?e.episodes+"/"+e.expected:e.episodes+" / chưa rõ tổng";
      s+=`<tr><td><b>${e.name}</b></td><td>${e.dir}</td><td>${tot}</td><td>${e.pct===null?"—":e.pct+"%"}</td><td>${e.success} (${e.success_rate===null?"—":e.success_rate+"%"})</td><td style="text-align:left">${ebadge(e.status)}</td><td>${e.age_text||"—"}</td></tr>`;
    }
    $("evals").innerHTML=s+"</table>";
  } else $("evals").innerHTML="<span class='mut'>—</span>";
'''

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+=`<div class="runrow"><div class="runhead"><b>${e.name}</b><span>${tot} episode${e.pct===null?"":" · "+e.pct+"%"} · thành công ${e.success} (${e.success_rate===null?"—":e.success_rate+"%"})</span><span style="margin-left:auto">${ebadge(e.status)}</span></div><div class="pbar"><div class="pfill" style="width:${e.pct===null?0:e.pct}%"></div></div></div>`;
    }
    $("evals_run").innerHTML=s;
  } else $("evals_run").innerHTML="<span class='mut'>Hiện không có eval nào đang chạy</span>";
  if(ehist.length){
    let s="<table><tr><th>Eval</th><th>Thư mục</th><th>Episode</th><th>Tiến độ</th><th>% xong</th><th>Thành công</th><th>Trạng thái</th><th>Cập nhật</th></tr>";
    for(const e of ehist){
      const tot=e.expected?e.episodes+"/"+e.expected:e.episodes+" / chưa rõ tổng";
      s+=`<tr><td><b>${e.name}</b></td><td>${e.dir}</td><td>${tot}</td><td><div class="pbar mini"><div class="pfill ${e.status==="DONE"?"done":"part"}" style="width:${e.pct===null?0:e.pct}%"></div></div></td><td>${e.pct===null?"—":e.pct+"%"}</td><td>${e.success} (${e.success_rate===null?"—":e.success_rate+"%"})</td><td style="text-align:left">${ebadge(e.status)}</td><td>${e.age_text||"—"}</td></tr>`;
    }
    $("evals").innerHTML=s+"</table>";
  } else $("evals").innerHTML="<span class='mut'>—</span>";
'''

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")