The wall kept its old signature after showing the empty message, so the charts never came back while the stats at the top kept updating. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
548 lines
31 KiB
JavaScript
548 lines
31 KiB
JavaScript
const $ = (s, el = document) => el.querySelector(s);
|
|
const PALETTE = ["#5eead4", "#f472b6", "#fbbf24", "#60a5fa", "#a78bfa", "#fb923c", "#4ade80", "#f87171", "#22d3ee", "#e879f9", "#a3e635", "#94a3b8"];
|
|
const strip = (m) => m.replace(/^opencode(-go)?\//, "").replace(/-free$/, "");
|
|
// The provider prefix is shown only when two selected models would otherwise look the same.
|
|
const short = (m) => {
|
|
const base = strip(m);
|
|
const clash = (state.allModels ?? []).some((o) => o !== m && strip(o) === base);
|
|
return clash ? m.replace(/-free$/, "") : base;
|
|
};
|
|
const fmt = (n, d = 1) => (n == null || Number.isNaN(n) ? "-" : Number(n).toFixed(d));
|
|
const esc = (s) => String(s ?? "").replace(/[&<>"]/g, (c) => ({ "&": "&", "<": "<", ">": ">", '"': """ })[c]);
|
|
|
|
const state = { shared: false, runs: [], models: [], benchmarks: [], sel: { run: new Set(), model: new Set(), benchmark: new Set() } };
|
|
const charts = new Map();
|
|
|
|
// ---- URL state -------------------------------------------------------------
|
|
function loadSel() {
|
|
const q = new URLSearchParams(location.search);
|
|
for (const k of Object.keys(state.sel)) state.sel[k] = new Set((q.get(k) ?? "").split(",").filter(Boolean));
|
|
state.shared = q.get("shared") === "1";
|
|
$("#shared").checked = state.shared;
|
|
}
|
|
function saveSel() {
|
|
const q = new URLSearchParams();
|
|
for (const [k, v] of Object.entries(state.sel)) if (v.size) q.set(k, [...v].join(","));
|
|
if (state.shared) q.set("shared", "1");
|
|
history.replaceState(null, "", q.size ? `?${q}` : location.pathname);
|
|
}
|
|
const qs = () => {
|
|
const q = new URLSearchParams();
|
|
for (const [k, v] of Object.entries(state.sel)) if (v.size) q.set(k, [...v].join(","));
|
|
if (state.shared) q.set("shared", "1");
|
|
return q.toString();
|
|
};
|
|
const api = (path, extra = "") => fetch(`${path}?${qs()}${extra}`).then((r) => r.json());
|
|
|
|
// ---- Filters ---------------------------------------------------------------
|
|
function renderFilter(key, label, options, head = "") {
|
|
const el = $(`#f-${key}`);
|
|
const sel = state.sel[key];
|
|
const open = el.classList.contains("open");
|
|
el.innerHTML = `<button type="button">${label}${sel.size ? ` (${sel.size})` : ""} ▾</button>
|
|
<div class="menu">${head}${options.map((o) => `<label><input type="checkbox" value="${esc(o.value)}" ${(o.checked ?? sel.has(String(o.value))) ? "checked" : ""}>${esc(o.label)}${o.lite ? `<span class="tag">lite</span>` : ""}<span class="sub">${esc(o.sub ?? "")}</span></label>`).join("")}</div>`;
|
|
el.classList.toggle("open", open);
|
|
$("button", el).onclick = (e) => { e.stopPropagation(); document.querySelectorAll(".filter.open").forEach((f) => f !== el && f.classList.remove("open")); el.classList.toggle("open"); };
|
|
el.querySelectorAll("input[value]").forEach((i) => (i.onchange = () => {
|
|
if (key === "benchmark") {
|
|
const set = effectiveSuites();
|
|
i.checked ? set.add(i.value) : set.delete(i.value);
|
|
commitSuites(set);
|
|
} else i.checked ? sel.add(i.value) : sel.delete(i.value);
|
|
saveSel(); refresh();
|
|
}));
|
|
el.querySelectorAll("input[data-group]").forEach((i) => (i.onchange = () => {
|
|
const set = effectiveSuites();
|
|
const ids = i.dataset.group === "all" ? state.benchmarks.map((b) => b.id) : state.benchmarks.filter((b) => b.lite).map((b) => b.id);
|
|
const on = ids.every((id) => set.has(id));
|
|
for (const id of ids) on ? set.delete(id) : set.add(id);
|
|
commitSuites(set);
|
|
saveSel(); refresh();
|
|
}));
|
|
el.querySelectorAll("input[data-group]").forEach((i) => { i.indeterminate = i.dataset.indeterminate === "1"; });
|
|
}
|
|
|
|
// An empty benchmark selection means "no filter", so it is shown as every suite ticked.
|
|
// "none" is a placeholder that matches no suite, so unticking everything shows an empty selection.
|
|
function effectiveSuites() {
|
|
const all = state.benchmarks.map((b) => b.id);
|
|
return state.sel.benchmark.size ? new Set([...state.sel.benchmark].filter((id) => all.includes(id))) : new Set(all);
|
|
}
|
|
function commitSuites(set) {
|
|
const sel = state.sel.benchmark;
|
|
sel.clear();
|
|
if (set.size === state.benchmarks.length) return;
|
|
if (set.size === 0) sel.add("none");
|
|
else set.forEach((id) => sel.add(id));
|
|
}
|
|
function suiteGroup(name, label, ids, set) {
|
|
const n = ids.filter((id) => set.has(id)).length;
|
|
const checked = ids.length > 0 && n === ids.length;
|
|
return `<label class="group"><input type="checkbox" data-group="${name}" data-indeterminate="${n > 0 && !checked ? 1 : 0}" ${checked ? "checked" : ""}>${label}<span class="sub">${ids.length}</span></label>`;
|
|
}
|
|
document.addEventListener("click", (e) => { if (!e.target.closest(".filter")) document.querySelectorAll(".filter.open").forEach((f) => f.classList.remove("open")); });
|
|
$("#reset").onclick = () => { for (const s of Object.values(state.sel)) s.clear(); state.shared = false; $("#shared").checked = false; saveSel(); refresh(); };
|
|
$("#shared").onchange = (e) => { state.shared = e.target.checked; saveSel(); refresh(); };
|
|
|
|
function renderFilters(summary) {
|
|
renderFilter("run", "Run", state.runs.map((r) => ({ value: r.id, label: `#${r.id} ${r.name}`, sub: `${r.completed}/${r.total}` })));
|
|
const models = [...new Set([...state.models, ...summary.models.map((m) => m.model)])].sort();
|
|
renderFilter("model", "Model", models.map((m) => ({ value: m, label: short(m) })));
|
|
const set = effectiveSuites();
|
|
const head = suiteGroup("all", "All suites", state.benchmarks.map((b) => b.id), set) + suiteGroup("lite", "All lite suites", state.benchmarks.filter((b) => b.lite).map((b) => b.id), set) + `<hr>`;
|
|
renderFilter("benchmark", "Benchmark", state.benchmarks.map((b) => ({ value: b.id, label: b.title, lite: b.lite, sub: `${b.tasks}`, checked: set.has(b.id) })), head);
|
|
}
|
|
|
|
// ---- Runs strip ------------------------------------------------------------
|
|
function renderRuns() {
|
|
$("#runs-strip").innerHTML = state.runs.map((r) => {
|
|
const pct = r.total ? (r.completed / r.total) * 100 : 0;
|
|
return `<div class="run-chip ${state.sel.run.has(String(r.id)) ? "sel" : ""}" data-id="${r.id}">
|
|
<div class="row"><span class="name">#${r.id} ${esc(r.name)}</span><span class="pill ${r.status}">${r.status}</span></div>
|
|
<div class="row"><small style="color:var(--muted)">${r.completed}/${r.total} tasks${r.running ? `, ${r.running} running` : ""}</small>
|
|
${r.status === "running" ? `<small><a href="#" data-cancel="${r.id}" style="color:var(--bad)">cancel</a></small>` : ""}</div>
|
|
<div class="meter"><i style="width:${pct}%"></i></div></div>`;
|
|
}).join("") || `<div class="empty">No runs yet. Start one with "New run" or <code>bun src/cli.ts run</code>.</div>`;
|
|
document.querySelectorAll(".run-chip").forEach((c) => (c.onclick = (e) => {
|
|
if (e.target.dataset.cancel) return;
|
|
const id = c.dataset.id, s = state.sel.run;
|
|
s.has(id) ? s.delete(id) : s.add(id);
|
|
saveSel(); refresh();
|
|
}));
|
|
document.querySelectorAll("[data-cancel]").forEach((a) => (a.onclick = async (e) => {
|
|
e.preventDefault();
|
|
await fetch(`/api/runs/${a.dataset.cancel}/cancel`, { method: "POST" });
|
|
refresh();
|
|
}));
|
|
}
|
|
|
|
// ---- Charts ----------------------------------------------------------------
|
|
Chart.defaults.color = "#8b96a5";
|
|
Chart.defaults.borderColor = "#222a33";
|
|
Chart.defaults.font.family = getComputedStyle(document.body).fontFamily;
|
|
Chart.defaults.animation = { duration: 250 };
|
|
|
|
const colorOf = (m) => PALETTE[Math.max(0, state.allModels.indexOf(m)) % PALETTE.length];
|
|
|
|
const overlaps = (a, b) => a.x < b.x + b.w && b.x < a.x + a.w && a.y < b.y + b.h && b.y < a.y + a.h;
|
|
const inflate = (b, d) => ({ x: b.x - d, y: b.y - d, w: b.w + 2 * d, h: b.h + 2 * d });
|
|
const inside = (b, x, y) => x >= b.x && x <= b.x + b.w && y >= b.y && y <= b.y + b.h;
|
|
function segHitsBox(a, b, box) {
|
|
const n = Math.max(2, Math.ceil(Math.hypot(b.x - a.x, b.y - a.y) / 3));
|
|
for (let i = 0; i <= n; i++) if (inside(box, a.x + ((b.x - a.x) * i) / n, a.y + ((b.y - a.y) * i) / n)) return true;
|
|
return false;
|
|
}
|
|
function segsCross(a, b, c, d) {
|
|
const o = (p, q, r) => Math.sign((q.x - p.x) * (r.y - q.y) - (q.y - p.y) * (r.x - q.x));
|
|
return o(a, b, c) !== o(a, b, d) && o(c, d, a) !== o(c, d, b);
|
|
}
|
|
|
|
const DOT = 4, DOT_HOVER = 6;
|
|
const DIM = 0.15;
|
|
|
|
// Places each point label near its point so that it overlaps no other label, point or leader line.
|
|
// Candidates are tried from nearest to farthest. A leader line joins a label to its point once the label moves away.
|
|
// Hovering a point or label dims every other point, label and line.
|
|
const labelPlugin = {
|
|
id: "pointLabels",
|
|
afterDatasetsDraw(chart) {
|
|
const { ctx, chartArea, width } = chart;
|
|
ctx.save();
|
|
ctx.font = "11px " + Chart.defaults.font.family;
|
|
const H = 13, R = DOT + 3;
|
|
const pts = [];
|
|
chart.data.datasets.forEach((ds, i) =>
|
|
chart.getDatasetMeta(i).data.forEach((pt, j) => {
|
|
const label = ds.data[j]?.label;
|
|
if (label) pts.push({ ds: i, x: pt.x, y: pt.y, label, w: ctx.measureText(label).width });
|
|
}));
|
|
const markers = pts.map((p) => ({ x: p.x - R, y: p.y - R, w: 2 * R, h: 2 * R }));
|
|
const boxes = [], lines = [];
|
|
const dirs = [0, 180, -40, 40, 140, -140, -90, 90, -20, 20, 160, -160, -65, 65, 115, -115];
|
|
const radii = [R + 2, 24, 40, 60, 84, 112, 144];
|
|
pts.sort((a, b) => a.y - b.y || a.x - b.x);
|
|
const layout = [];
|
|
for (const p of pts) {
|
|
let best = null;
|
|
// Strictest layout first. Later tiers relax the rules so that every point still gets a label:
|
|
// 0 = nothing overlaps, 1 = lines may cross lines, 2 = lines may cross labels and markers, 3 = labels only avoid labels.
|
|
search: for (const tier of [0, 1, 2, 3]) {
|
|
for (const r of radii) {
|
|
for (const deg of dirs) {
|
|
const dx = Math.cos((deg * Math.PI) / 180), dy = Math.sin((deg * Math.PI) / 180);
|
|
const ax = p.x + dx * r, ay = p.y + dy * r;
|
|
const box = { x: dx > 0.3 ? ax : dx < -0.3 ? ax - p.w : ax - p.w / 2, y: dy < -0.3 ? ay - H : dy > 0.3 ? ay : ay - H / 2, w: p.w, h: H };
|
|
if (box.x < chartArea.left + 2 || box.x + box.w > width - 2 || box.y < 2 || box.y + box.h > chartArea.bottom + 6) continue;
|
|
const pad = inflate(box, 2);
|
|
if (boxes.some((o) => overlaps(pad, o))) continue;
|
|
if (tier < 3 && markers.some((m, i) => pts[i] !== p && overlaps(pad, m))) continue;
|
|
const from = { x: p.x, y: p.y };
|
|
const to = { x: Math.min(Math.max(p.x, box.x), box.x + box.w), y: Math.min(Math.max(p.y, box.y), box.y + box.h) };
|
|
const far = Math.hypot(to.x - from.x, to.y - from.y) > R + 3;
|
|
if (far) {
|
|
if (tier < 3 && lines.some((l) => segHitsBox(l.a, l.b, pad))) continue;
|
|
if (tier < 2 && boxes.some((o) => segHitsBox(from, to, inflate(o, 1)))) continue;
|
|
if (tier < 2 && markers.some((m, i) => pts[i] !== p && segHitsBox(from, to, inflate(m, -2)))) continue;
|
|
if (tier < 1 && lines.some((l) => segsCross(from, to, l.a, l.b))) continue;
|
|
}
|
|
best = { box, from, to, far };
|
|
break search;
|
|
}
|
|
}
|
|
}
|
|
if (!best) continue;
|
|
boxes.push(best.box);
|
|
if (best.far) lines.push({ a: best.from, b: best.to });
|
|
layout.push({ ...p, ...best });
|
|
}
|
|
chart._labelLayout = layout;
|
|
const hover = chart._hover ?? null;
|
|
// Crosshair for the hovered point: dashed lines to both axes and its exact values.
|
|
const hp = hover == null ? null : layout.find((l) => l.ds === hover);
|
|
if (hp) {
|
|
const color = colorOf(chart.data.datasets[hp.ds].modelId);
|
|
const d = chart.data.datasets[hp.ds].data[0];
|
|
const xs = (chart._fmtX ?? ((v) => String(v)))(d.x), ys = fmt(d.score, 1);
|
|
ctx.save();
|
|
ctx.setLineDash([4, 4]);
|
|
ctx.lineWidth = 1;
|
|
ctx.strokeStyle = "rgba(203,213,225,.55)";
|
|
ctx.beginPath();
|
|
ctx.moveTo(hp.x, hp.y); ctx.lineTo(hp.x, chartArea.bottom);
|
|
ctx.moveTo(hp.x, hp.y); ctx.lineTo(chartArea.left, hp.y);
|
|
ctx.stroke();
|
|
ctx.setLineDash([]);
|
|
ctx.font = "600 11px " + Chart.defaults.font.family;
|
|
// Values go on the axes, outside the plot, over the tick labels (a solid backing hides the ticks beneath).
|
|
const pill = (text, cx, cy, align) => {
|
|
const w = ctx.measureText(text).width + 10;
|
|
let bx = align === "right" ? cx - w : cx - w / 2;
|
|
bx = Math.min(Math.max(bx, 0), width - w);
|
|
ctx.fillStyle = "#11151a";
|
|
ctx.fillRect(bx, cy - 9, w, 18);
|
|
ctx.strokeStyle = color;
|
|
ctx.lineWidth = 1;
|
|
ctx.strokeRect(bx + 0.5, cy - 8.5, w - 1, 17);
|
|
ctx.fillStyle = color;
|
|
ctx.textAlign = "center";
|
|
ctx.textBaseline = "middle";
|
|
ctx.fillText(text, bx + w / 2, cy);
|
|
};
|
|
// Erase tick labels the value boxes would only partly cover, so no stub of them shows.
|
|
const erase = (scale, horizontal, center, size) => {
|
|
ctx.save();
|
|
ctx.font = "12px " + Chart.defaults.font.family;
|
|
ctx.fillStyle = "#11151a";
|
|
for (const t of scale.ticks) {
|
|
const w = ctx.measureText(String(t.label ?? t.value)).width;
|
|
const pos = scale.getPixelForValue(t.value);
|
|
if (horizontal && Math.abs(pos - center) < size / 2 + w / 2 + 3) ctx.fillRect(pos - w / 2 - 3, chartArea.bottom + 9, w + 6, 18);
|
|
if (!horizontal && Math.abs(pos - center) < size / 2 + 11) ctx.fillRect(chartArea.left - w - 14, pos - 9, w + 12, 18);
|
|
}
|
|
ctx.restore();
|
|
};
|
|
const wx = ctx.measureText(xs).width + 10, wy = ctx.measureText(ys).width + 10;
|
|
erase(chart.scales.x, true, hp.x, wx);
|
|
erase(chart.scales.y, false, hp.y, 18);
|
|
pill(ys, chartArea.left - 4, hp.y, "right");
|
|
pill(xs, hp.x, chartArea.bottom + 18, "center");
|
|
ctx.restore();
|
|
}
|
|
for (const l of layout) {
|
|
ctx.globalAlpha = hover == null || hover === l.ds ? 1 : DIM;
|
|
if (l.far) {
|
|
ctx.strokeStyle = "rgba(148,163,184,.55)";
|
|
ctx.beginPath();
|
|
ctx.moveTo(l.from.x, l.from.y);
|
|
ctx.lineTo(l.to.x, l.to.y);
|
|
ctx.stroke();
|
|
}
|
|
ctx.fillStyle = hover === l.ds ? "#ffffff" : "#cbd5e1";
|
|
ctx.fillText(l.label, l.box.x, l.box.y + H - 3);
|
|
}
|
|
ctx.restore();
|
|
},
|
|
afterEvent(chart, args) {
|
|
// Replays come from update() and carry a stale pointer position. Real events decide the hover.
|
|
if (args.replay) return;
|
|
const e = args.event;
|
|
let hit = null;
|
|
if (e.type !== "mouseout" && e.x != null) {
|
|
const layout = chart._labelLayout ?? [];
|
|
// The nearest dot wins when dots overlap. A label hit counts when no dot is under the cursor.
|
|
let bestD = DOT_HOVER + 3;
|
|
for (const l of layout) {
|
|
const d = Math.hypot(e.x - l.x, e.y - l.y);
|
|
if (d <= bestD) { bestD = d; hit = l.ds; }
|
|
}
|
|
if (hit == null) hit = layout.find((l) => inside(inflate(l.box, 2), e.x, e.y))?.ds ?? null;
|
|
}
|
|
if (hit !== (chart._hover ?? null)) {
|
|
chart._hover = hit;
|
|
chart.update("none");
|
|
chart.draw();
|
|
}
|
|
},
|
|
};
|
|
|
|
// Chart.js only reports events while the pointer is over a canvas, so a fast exit, a scroll or a
|
|
// live refresh can leave a hover behind. This clears any hover whose pointer is no longer over its chart.
|
|
const pointer = { x: -1, y: -1 };
|
|
function clearHover(chart) {
|
|
if (chart._hover == null) return;
|
|
chart._hover = null;
|
|
chart._lastEvent = null; // update() replays the last mouse event, which would hover the chart again
|
|
chart.update("none");
|
|
chart.draw();
|
|
}
|
|
function validateHover() {
|
|
for (const chart of charts.values()) {
|
|
if (chart._hover == null) continue;
|
|
const r = chart.canvas.getBoundingClientRect();
|
|
const over = pointer.x >= r.left && pointer.x <= r.right && pointer.y >= r.top && pointer.y <= r.bottom;
|
|
if (!over) clearHover(chart);
|
|
}
|
|
}
|
|
window.addEventListener("mousemove", (e) => { pointer.x = e.clientX; pointer.y = e.clientY; validateHover(); }, true);
|
|
window.addEventListener("scroll", validateHover, { passive: true, capture: true });
|
|
window.addEventListener("blur", () => { pointer.x = pointer.y = -1; validateHover(); });
|
|
document.addEventListener("mouseleave", () => { pointer.x = pointer.y = -1; validateHover(); });
|
|
|
|
function mount(id, config) {
|
|
const canvas = document.getElementById(id);
|
|
if (!canvas) return;
|
|
const old = charts.get(id);
|
|
if (old) {
|
|
old.data = config.data;
|
|
old.options = config.options;
|
|
old._fmtX = config.fmtX;
|
|
old.update();
|
|
return;
|
|
}
|
|
const chart = new Chart(canvas, { ...config, plugins: [labelPlugin] });
|
|
chart._fmtX = config.fmtX;
|
|
canvas.addEventListener("mouseleave", () => clearHover(chart));
|
|
charts.set(id, chart);
|
|
}
|
|
|
|
function card(id, title, sub, opts = {}) {
|
|
return `<div class="card ${opts.wide ? "wide" : ""}"><h2>${esc(title)}</h2><p class="sub">${esc(sub ?? "")}</p><div class="chart ${opts.tall ? "tall" : ""}"><canvas id="${id}"></canvas></div></div>`;
|
|
}
|
|
|
|
// Partial results (tasks still pending) are drawn with diagonal stripes instead of a solid fill.
|
|
const patterns = new Map();
|
|
function stripe(color) {
|
|
if (!patterns.has(color)) {
|
|
const c = document.createElement("canvas");
|
|
c.width = c.height = 6;
|
|
const g = c.getContext("2d");
|
|
g.fillStyle = color + "40";
|
|
g.fillRect(0, 0, 6, 6);
|
|
g.strokeStyle = color;
|
|
g.lineWidth = 2;
|
|
g.beginPath();
|
|
g.moveTo(-1, 7); g.lineTo(7, -1);
|
|
g.moveTo(-1, 1); g.lineTo(1, -1);
|
|
g.moveTo(5, 7); g.lineTo(7, 5);
|
|
g.stroke();
|
|
patterns.set(color, g.createPattern(c, "repeat"));
|
|
}
|
|
return patterns.get(color);
|
|
}
|
|
|
|
const hbar = (labels, values, colors, extra = {}) => ({
|
|
type: "bar",
|
|
data: { labels, datasets: [{ data: values, backgroundColor: colors.map((c, i) => (extra.partial?.[i] ? stripe(c) : c)), borderColor: colors, borderWidth: extra.partial ? colors.map((_, i) => (extra.partial[i] ? 1 : 0)) : 0, borderRadius: 4 }] },
|
|
options: {
|
|
indexAxis: "y", maintainAspectRatio: false,
|
|
plugins: { legend: { display: false }, tooltip: { callbacks: { label: (c) => `${fmt(c.parsed.x, extra.dec ?? 1)}${extra.unit ?? ""}${extra.notes?.[c.dataIndex] ? " " + extra.notes[c.dataIndex] : ""}` } } },
|
|
scales: { x: { min: 0, max: extra.max, grid: { color: "#1a2028" } }, y: { grid: { display: false } } },
|
|
},
|
|
});
|
|
|
|
// Reversed log scale: the axis plots -log10(100 - score), so each step toward 100 gets the same room as 0 to 90.
|
|
// 100 itself is drawn as 99.9.
|
|
const TOP = 99.9;
|
|
const flip = (s) => -Math.log10(100 - Math.min(Math.max(s, 0), TOP));
|
|
const FLIP_TICKS = [0, 50, 80, 90, 95, 99, 100];
|
|
|
|
function scatter(models, xKey, xLabel, log = false, fmtX = (v) => fmt(v, 1)) {
|
|
const pts = models.filter((m) => m.index != null);
|
|
return {
|
|
fmtX,
|
|
type: "scatter",
|
|
data: { datasets: pts.map((m) => ({ modelId: m.model, label: short(m.model), data: [{ x: m[xKey], y: flip(m.index), score: m.index, label: short(m.model) }], backgroundColor: (c) => { const h = c.chart._hover; return h == null || h === c.datasetIndex ? (m.partial ? stripe(colorOf(m.model)) : colorOf(m.model)) : colorOf(m.model) + "26"; }, borderColor: (c) => { const h = c.chart._hover; return h == null || h === c.datasetIndex ? colorOf(m.model) : colorOf(m.model) + "26"; }, borderWidth: m.partial ? 1 : 0, pointRadius: DOT, pointHoverRadius: DOT_HOVER })) },
|
|
options: {
|
|
maintainAspectRatio: false,
|
|
interaction: { mode: "nearest", intersect: true },
|
|
layout: { padding: { right: 8 } },
|
|
plugins: {
|
|
legend: { display: false },
|
|
tooltip: { enabled: false }, // the hover highlight and the labels identify each point
|
|
},
|
|
scales: {
|
|
x: { type: log ? "logarithmic" : "linear", grace: "4%", title: { display: true, text: xLabel }, grid: { color: "#1a2028" } },
|
|
// Reversed log scale with headroom above 100. Ticks are placed at the transformed positions.
|
|
y: {
|
|
title: { display: true, text: "Intelligence index (reversed log scale)" }, min: flip(0) - 0.05, max: 1.12, grid: { color: "#1a2028" },
|
|
afterBuildTicks: (a) => { a.ticks = FLIP_TICKS.map((s) => ({ value: flip(s === 100 ? TOP : s) })); },
|
|
ticks: { callback: (v) => String(FLIP_TICKS.find((s) => Math.abs(flip(s === 100 ? TOP : s) - v) < 1e-9) ?? "") },
|
|
},
|
|
},
|
|
},
|
|
};
|
|
}
|
|
|
|
function renderWall(summary, hist) {
|
|
const ms = summary.models;
|
|
const wall = $("#wall");
|
|
if (!ms.length) { charts.forEach((c) => c.destroy()); charts.clear(); wall.innerHTML = `<div class="empty card wide">No results for this selection yet.</div>`; delete wall.dataset.sig; /* force a rebuild once results return */ return; }
|
|
const defs = [];
|
|
defs.push({ id: "c-index", html: card("c-index", "Intelligence index", "Mean of per-benchmark scores (0-100). Striped bars are partial: some of that model's tasks are still pending.", { tall: true }) });
|
|
defs.push({ id: "c-hist", html: card("c-hist", "Index across runs", "Past and current runs. One line per model.") });
|
|
defs.push({ id: "c-status", html: card("c-status", "Task status", "Finished, errored, timed out or still pending, per model.") });
|
|
defs.push({ id: "c-x-steps", html: card("c-x-steps", "Intelligence vs steps", "Average agent steps per task. Up and left is better. Striped dots are partial.") });
|
|
defs.push({ id: "c-x-time", html: card("c-x-time", "Intelligence vs time", "Average wall-clock seconds per task. Up and left is better. Striped dots are partial.") });
|
|
defs.push({ id: "c-x-tokens", html: card("c-x-tokens", "Intelligence vs tokens", "Average total tokens per task (log scale). Up and left is better. Striped dots are partial.") });
|
|
for (const b of summary.benchmarks) defs.push({ id: `c-b-${b}`, html: card(`c-b-${b}`, state.benchmarks.find((x) => x.id === b)?.title ?? b, "Mean task score, 0-100.") });
|
|
defs.push({ id: "c-tokens", html: card("c-tokens", "Tokens per task", "Average input + output + reasoning tokens.") });
|
|
defs.push({ id: "c-steps", html: card("c-steps", "Steps per task", "Average agent steps (model calls).") });
|
|
defs.push({ id: "c-time", html: card("c-time", "Time per task", "Average seconds per task. Solid is time in the model. Faded is the rest: startup, tools and gaps.") });
|
|
const sig = defs.map((d) => d.id).join();
|
|
if (wall.dataset.sig !== sig) {
|
|
charts.forEach((c) => c.destroy()); charts.clear();
|
|
wall.innerHTML = defs.map((d) => d.html).join("");
|
|
wall.dataset.sig = sig;
|
|
}
|
|
const names = ms.map((m) => short(m.model)), cols = ms.map((m) => colorOf(m.model));
|
|
mount("c-index", hbar(names, ms.map((m) => m.index ?? 0), cols, { max: 100, notes: ms.map((m) => `(${m.finished}/${m.total} tasks)`), partial: ms.map((m) => m.partial) }));
|
|
const runIds = [...new Set(hist.map((h) => h.run_id))];
|
|
const histModels = [...new Set(hist.map((h) => h.model))];
|
|
mount("c-hist", {
|
|
type: "line",
|
|
data: { labels: runIds.map((id) => `#${id} ${state.runs.find((r) => r.id === id)?.name ?? ""}`), datasets: histModels.map((m) => ({ label: short(m), borderColor: colorOf(m), backgroundColor: colorOf(m), tension: .25, spanGaps: true, data: runIds.map((id) => hist.find((h) => h.run_id === id && h.model === m)?.index ?? null) })) },
|
|
options: { maintainAspectRatio: false, scales: { y: { min: 0, max: 100, grid: { color: "#1a2028" } }, x: { grid: { display: false } } }, plugins: { legend: { labels: { boxWidth: 10 } } } },
|
|
});
|
|
mount("c-x-tokens", scatter(ms, "avgTokens", "tokens per task", true, (v) => Math.round(v).toLocaleString("en-US")));
|
|
mount("c-x-steps", scatter(ms, "avgSteps", "steps per task", false, (v) => fmt(v, 2)));
|
|
mount("c-x-time", scatter(ms, "avgSeconds", "seconds per task", false, (v) => `${fmt(v, 1)} s`));
|
|
const statuses = [["done", "#4ade80"], ["timeout", "#fbbf24"], ["error", "#f87171"], ["running", "#5eead4"], ["pending", "#334155"]];
|
|
mount("c-status", {
|
|
type: "bar",
|
|
data: { labels: names, datasets: statuses.map(([s, c]) => ({ label: s, backgroundColor: c, data: ms.map((m) => m.counts[s] ?? 0) })) },
|
|
options: { indexAxis: "y", maintainAspectRatio: false, scales: { x: { stacked: true, grid: { color: "#1a2028" } }, y: { stacked: true, grid: { display: false } } }, plugins: { legend: { labels: { boxWidth: 10 } } } },
|
|
});
|
|
for (const b of summary.benchmarks) {
|
|
const arr = ms.filter((m) => m.benchmarks[b]).sort((x, y) => y.benchmarks[b].score - x.benchmarks[b].score);
|
|
mount(`c-b-${b}`, hbar(arr.map((m) => short(m.model)), arr.map((m) => m.benchmarks[b].score), arr.map((m) => colorOf(m.model)), { max: 100, notes: arr.map((m) => `(${m.benchmarks[b].n}/${m.benchmarks[b].total})`), partial: arr.map((m) => m.benchmarks[b].pending > 0) }));
|
|
}
|
|
const by = (k) => [...ms].sort((a, b) => a[k] - b[k]);
|
|
for (const [id, key, unit, dec] of [["c-tokens", "avgTokens", "", 0], ["c-steps", "avgSteps", "", 1]]) {
|
|
const s = by(key);
|
|
mount(id, hbar(s.map((m) => short(m.model)), s.map((m) => m[key]), s.map((m) => colorOf(m.model)), { unit, dec }));
|
|
}
|
|
const bySec = by("avgSeconds");
|
|
mount("c-time", timeBars(bySec));
|
|
}
|
|
|
|
// Time per task in two sections: waiting on the model (solid) and everything else (faded).
|
|
// Models without the breakdown fall back to one solid bar for the total.
|
|
function timeBars(ms) {
|
|
const names = ms.map((m) => short(m.model)), cols = ms.map((m) => colorOf(m.model));
|
|
const split = ms.some((m) => m.avgModelSeconds != null);
|
|
if (!split) return hbar(names, ms.map((m) => m.avgSeconds), cols, { unit: " s", partial: ms.map((m) => m.partial) });
|
|
const model = ms.map((m) => m.avgModelSeconds ?? m.avgSeconds);
|
|
const other = ms.map((m) => m.avgOtherSeconds ?? 0);
|
|
return {
|
|
type: "bar",
|
|
data: {
|
|
labels: names,
|
|
datasets: [
|
|
{ label: "Model", data: model, backgroundColor: cols.map((c, i) => (ms[i].partial ? stripe(c) : c)), borderColor: cols, borderWidth: ms.map((m) => (m.partial ? 1 : 0)), stack: "t" },
|
|
{ label: "Other", data: other, backgroundColor: cols.map((c) => c + "40"), borderColor: cols, borderWidth: 1, stack: "t" },
|
|
],
|
|
},
|
|
options: {
|
|
indexAxis: "y", maintainAspectRatio: false,
|
|
plugins: {
|
|
legend: { labels: { boxWidth: 10, generateLabels: () => [{ text: "Model", fontColor: Chart.defaults.color, fillStyle: "#94a3b8", strokeStyle: "#94a3b8", lineWidth: 0 }, { text: "Other", fontColor: Chart.defaults.color, fillStyle: "#94a3b840", strokeStyle: "#94a3b8", lineWidth: 1 }] } },
|
|
tooltip: {
|
|
callbacks: {
|
|
label: (c) => `${c.dataset.label}: ${fmt(c.parsed.x, 1)} s`,
|
|
footer: (items) => `Total: ${fmt(items.reduce((a, i) => a + i.parsed.x, 0), 1)} s`,
|
|
},
|
|
},
|
|
},
|
|
scales: { x: { stacked: true, min: 0, grid: { color: "#1a2028" } }, y: { stacked: true, grid: { display: false } } },
|
|
},
|
|
};
|
|
}
|
|
|
|
// ---- KPIs and table ---------------------------------------------------------
|
|
function renderKpis(s) {
|
|
const top = s.models.find((m) => m.index != null);
|
|
const active = state.runs.filter((r) => r.status === "running").length;
|
|
const k = (v, l) => `<div class="kpi"><div class="v">${v}</div><div class="l">${l}</div></div>`;
|
|
$("#kpis").innerHTML = k(top ? `${esc(short(top.model))} <small style="color:var(--accent)">${fmt(top.index)}</small>` : "-", "Top model") +
|
|
k(s.models.length, "Models") + k(`${s.finished}/${s.total}`, "Tasks scored") + k(active, "Active runs") + k((s.counts.error ?? 0) + (s.counts.timeout ?? 0), "Errors and timeouts") + k(`$${(s.cost ?? 0).toFixed(4)}`, "Reported cost");
|
|
}
|
|
|
|
async function renderTable() {
|
|
const rows = await api("/api/results", "&limit=200");
|
|
$("#results-note").textContent = `latest ${rows.length}`;
|
|
$("#results").innerHTML = `<thead><tr><th>Run</th><th>Model</th><th>Benchmark</th><th>Task</th><th>Status</th><th class="num">Score</th><th class="num">Tokens</th><th class="num">Steps</th><th class="num">Time</th></tr></thead><tbody>${rows.map((r) =>
|
|
`<tr class="clickable" data-id="${r.id}"><td>#${r.run_id}</td><td>${esc(short(r.model))}</td><td>${esc(r.benchmark)}</td><td>${esc(r.task_id)}</td><td class="s-${r.status}">${r.status}</td><td class="num">${fmt(r.score, 2)}</td><td class="num">${r.tokens_in + r.tokens_out + r.tokens_reasoning}</td><td class="num">${r.steps}</td><td class="num">${fmt(r.duration_ms / 1000, 0)}s</td></tr>`).join("")}</tbody>`;
|
|
document.querySelectorAll("#results tr.clickable").forEach((tr) => (tr.onclick = async () => {
|
|
const r = await fetch(`/api/results/${tr.dataset.id}`).then((x) => x.json());
|
|
$("#dlg-body").innerHTML = `<h3>${esc(short(r.model))} on ${esc(r.benchmark)}/${esc(r.task_id)}</h3>
|
|
<p>Status <b class="s-${r.status}">${r.status}</b>, score ${fmt(r.score, 2)}, ${r.steps} steps, ${r.tokens_in + r.tokens_out + r.tokens_reasoning} tokens, ${fmt(r.duration_ms / 1000, 0)} s</p>
|
|
${r.error ? `<p class="s-error">${esc(r.error)}</p>` : ""}<h4>Grader output</h4><pre>${esc(r.grader_output) || "(none)"}</pre><h4>Assistant text</h4><pre>${esc(r.assistant_text) || "(none)"}</pre>
|
|
<div class="actions"><button value="close">Close</button></div>`;
|
|
$("#dlg").showModal();
|
|
}));
|
|
}
|
|
|
|
// ---- New run dialog ---------------------------------------------------------
|
|
$("#new-run").onclick = () => {
|
|
const checks = (name, items) => `<div class="checks">${items.map((i) => `<label><input type="checkbox" name="${name}" value="${esc(i.value)}" checked>${esc(i.label)}</label>`).join("")}</div>`;
|
|
$("#dlg-body").innerHTML = `<h3>New run</h3>
|
|
<div class="field"><label>Name</label><input name="name" placeholder="optional"></div>
|
|
<label>Models</label>${checks("models", state.models.map((m) => ({ value: m, label: short(m) })))}
|
|
<label>Benchmarks</label>${checks("benchmarks", state.benchmarks.map((b) => ({ value: b.id, label: `${b.title} (${b.tasks})` })))}
|
|
<div class="field"><label>Tasks per benchmark (blank = all)</label><input name="limit" type="number" min="1"></div>
|
|
<div class="field"><label>Concurrency</label><input name="concurrency" type="number" min="1" value="4"></div>
|
|
<div class="actions"><button type="button" class="ghost" id="cancel-run">Cancel</button><button type="button" id="start-run">Start</button></div>`;
|
|
$("#dlg").showModal();
|
|
$("#cancel-run").onclick = () => $("#dlg").close();
|
|
$("#start-run").onclick = async () => {
|
|
const f = $("#dlg-body");
|
|
const vals = (n) => [...f.querySelectorAll(`input[name=${n}]:checked`)].map((i) => i.value);
|
|
const body = { name: f.name?.value || f.querySelector("[name=name]").value, models: vals("models"), benchmarks: vals("benchmarks"), limit: Number(f.querySelector("[name=limit]").value) || undefined, concurrency: Number(f.querySelector("[name=concurrency]").value) || 4 };
|
|
const { id } = await fetch("/api/runs", { method: "POST", headers: { "content-type": "application/json" }, body: JSON.stringify(body) }).then((r) => r.json());
|
|
$("#dlg").close();
|
|
state.sel.run = new Set([String(id)]); saveSel(); refresh();
|
|
};
|
|
};
|
|
|
|
// ---- Refresh loop -----------------------------------------------------------
|
|
let busy = false, again = false;
|
|
async function refresh() {
|
|
if (busy) { again = true; return; }
|
|
busy = true;
|
|
try {
|
|
[state.runs, state.models, state.benchmarks] = await Promise.all([fetch("/api/runs").then((r) => r.json()), state.models.length ? state.models : fetch("/api/models").then((r) => r.json()), state.benchmarks.length ? state.benchmarks : fetch("/api/benchmarks").then((r) => r.json())]);
|
|
const [summary, hist] = await Promise.all([api("/api/summary"), api("/api/history")]);
|
|
state.allModels = [...new Set([...state.models, ...summary.models.map((m) => m.model)])].sort();
|
|
renderRuns(); renderFilters(summary); renderKpis(summary); renderWall(summary, hist); validateHover(); await renderTable();
|
|
} finally {
|
|
busy = false;
|
|
if (again) { again = false; setTimeout(refresh, 300); }
|
|
}
|
|
}
|
|
|
|
loadSel();
|
|
await refresh();
|
|
let timer;
|
|
new EventSource("/api/events").onmessage = () => { clearTimeout(timer); timer = setTimeout(refresh, 400); };
|
|
|
|
fetch("/api/config").then((r) => r.json()).then((c) => document.body.classList.toggle("readonly", !!c.readonly)).catch(() => {});
|