File size: 2,145 Bytes
9fc9873 | 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 | 'use strict';
const fmt = n => Number(n || 0).toLocaleString('zh-CN');
function card(title, value, detail) {
const box = document.createElement('article');
for (const [tag, text] of [['h3', title], ['h2', value], ['p', detail]]) {
const node = document.createElement(tag); node.textContent = text; box.appendChild(node);
}
return box;
}
async function refresh() {
try {
const response = await fetch('api/audit-progress', {cache:'no-store'});
if (!response.ok) throw new Error(`HTTP ${response.status}`);
const s = await response.json();
const checked = s.checked || 0, planned = s.planned || 36046;
document.querySelector('#health').textContent = s.stale ? '⚠ 后台状态已超过3分钟未更新,请检查进程;不能视为正常运行。' : (s.phase || '等待审核启动');
document.querySelector('#metrics').replaceChildren(
card('已审核', `${fmt(checked)} / ${fmt(planned)}`, `${(100*checked/planned).toFixed(1)}% 完成;包含复用结果`),
card('机器通过 / 未通过', `${fmt(s.accepted)} / ${fmt(checked-(s.accepted||0))}`, '通过后仍需最终准入验收'),
card('近期速度', s.videos_per_hour ? `${fmt(Math.round(s.videos_per_hour))} 条/小时` : '正在测量', '按实际新增完成量,不把复用算成新算力'),
card('预计剩余', s.eta_seconds != null ? `${(s.eta_seconds/3600).toFixed(1)} 小时` : '待稳定后估算', `复用旧结果 ${fmt(s.reused)} 条`));
document.querySelector('#workers').replaceChildren(...(s.workers || []).map(w =>
card(`GPU ${w.gpu} · ${w.state}`, `${fmt(w.checked)} / ${fmt(w.planned)}`,
`利用率 ${w.utilization ?? '—'}% · 显存 ${w.memory_mib != null ? (w.memory_mib/1024).toFixed(1) : '—'} GiB · ${w.error || ('PID '+(w.pid || '—'))}`)));
document.querySelector('#updated').textContent = `后台更新时间:${s.updated_at ? new Date(s.updated_at*1000).toLocaleString('zh-CN') : '无'}。网页每15秒刷新。`;
} catch (e) { document.querySelector('#health').textContent = `⚠ 无法读取进度:${e.message}`; }
}
refresh(); setInterval(refresh, 15000);
|