Cut the pause out of hourly charts; contribution graph as one grid
Browse filesHourly strips and sparklines skip the stretch when no agent ran and mark the cut; clicks and hour stepping still map to real hours. The contribution graph is one grid with lane labels in a column on the left.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Files changed (4)
- app.py+4-1
- static/agents.js+68-30
- static/style.css+8-4
- tests/test_api.py+1-1
422 unmodified lines423424425426427428429422 unmodified lines@cachedef run_span():lo, hi = q("SELECT min(hour) lo, max(hour) hi FROM t.agent_hours")[0].values()return {"first_hour": iso_epoch(lo * 3600), "last_hour": iso_epoch(hi * 3600), "hours": hi - lo + 1}HIGHLIGHTS = [("posts", "Most board posts"), ("reasoning_tokens", "Most reasoning tokens"),422 unmodified lines423424425426427428429430431432422 unmodified lines@cachedef run_span():lo, hi = q("SELECT min(hour) lo, max(hour) hi FROM t.agent_hours")[0].values()busy = [r["hour"] for r in q("SELECT DISTINCT hour FROM t.agent_hours WHERE model_calls > 0 ORDER BY hour")]# Stretches of 6+ hours when no agent ran (the run was paused); charts cut them out of the time axis.gaps = [{"from": iso_epoch((a + 1) * 3600), "to": iso_epoch(b * 3600)} for a, b in zip(busy, busy[1:]) if b - a > 6]return {"first_hour": iso_epoch(lo * 3600), "last_hour": iso_epoch(hi * 3600), "hours": hi - lo + 1, "gaps": gaps}HIGHLIGHTS = [("posts", "Most board posts"), ("reasoning_tokens", "Most reasoning tokens"),
9 unmodified lines10111213141520 unmodified lines363738394041424344454647484950515253542 unmodified lines575859606162636465666768697071727374757677787980105 unmodified lines1861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212229 unmodified linesconst agentLink = (name, at) => `/agent/${encodeURIComponent(name)}${at ? `?at=${hourOf(at)}` : ''}`;let highlightsP = null, agentsP = null;async function agentsHome() {document.title = 'PyBot Data Explorer';$app.className = 'wide';20 unmodified lines<a class="hcard" data-nav href="${agentLink(h.agent, h.busiest_hour)}"><span class="label">${esc(h.title)}</span><span class="hv">${fmt(h.value)}</span><span><b>${esc(h.agent)}</b> <span class="muted">${esc(h.lane || 'no trace')}</span></span>${spark(h.spark)}<span class="go">open trace →</span></a>`).join('');document.getElementById('moments').innerHTML = d.moments.map(m => `<li><span class="muted">${time(m.ts).slice(0, 16)}</span> <span>${esc(m.text)}</span><a data-nav href="${agentLink(m.agent, m.ts)}">${esc(m.agent)}'s trace →</a>${m.sha ? ` <a data-nav href="/commits?sha=${m.sha}">commit</a>` : ''}</li>`).join('');}function spark(values) {const n = values.length, max = d3.max(values) || 1, peak = values.indexOf(max);const path = d3.line().x((v, i) => i).y(v => 28 - (v / max) * 26)(values);return `<svg class="spark" viewBox="0 0 ${n} 30" preserveAspectRatio="none" aria-hidden="true"><path d="${path}" vector-effect="non-scaling-stroke"/><line x1="${peak}" x2="${peak}" y1="0" y2="30" vector-effect="non-scaling-stroke"/></svg>`;}function drawContrib(items) {const el = document.getElementById('contrib');if (!el) return;2 unmodified lineslet metric = 'total_tokens';const draw = () => {el.querySelector('svg')?.remove();const S = 11, P = 13, W = el.clientWidth, cols = Math.max(10, Math.floor((W + 2) / P));const vals = items.filter(a => a.has_trace && a[metric] > 0).map(a => a[metric]);const color = d3.scaleSequentialLog(d3.interpolateRgbBasis([cssVar('--ramp0'), cssVar('--ramp1'), cssVar('--ramp2')])).domain([d3.min(vals) || 1, d3.max(vals) || 10]);let y = 0;const blocks = lanes.map(([lane, list]) => {const sorted = list.slice().sort((a, b) => (b[metric] || 0) - (a[metric] || 0)), top = y + 18;y = top + Math.ceil(sorted.length / cols) * P + 10;return { lane, list: sorted, top };});const svg = d3.select(el).insert('svg', '.tip').attr('viewBox', `0 0 ${W} ${y}`).attr('height', y).attr('role', 'img').attr('aria-label', `One square per agent, grouped by lane, coloured by ${metric.replace('_', ' ')}`);svg.append('defs').html(`<pattern id="hatch" width="4" height="4" patternUnits="userSpaceOnUse" patternTransform="rotate(45)"><rect width="4" height="4" fill="${cssVar('--page-bg')}"/><line x1="0" y1="0" x2="0" y2="4" stroke="${cssVar('--muted-color')}" stroke-width="1.5"/></pattern>`);for (const b of blocks) {svg.append('text').attr('class', 'lane').attr('x', 0).attr('y', b.top - 6).text(`${b.lane.toUpperCase()} · ${b.list.length}`);svg.append('g').selectAll('rect').data(b.list).join('rect').attr('x', (a, i) => (i % cols) * P).attr('y', (a, i) => b.top + Math.floor(i / cols) * P).attr('width', S).attr('height', S).attr('fill', a => !a.has_trace ? 'url(#hatch)' : a[metric] > 0 ? color(a[metric]) : cssVar('--ramp0')).attr('tabindex', 0).attr('role', 'link').attr('aria-label', a => `${a.name}, ${a.lane || 'no trace'}`).on('pointerenter focus', (ev, a) => {105 unmodified lines}function drawStrip(a, onPick) {const el = document.getElementById('astrip'), tip = el.querySelector('.tip');const t0 = Date.parse(a.run.first_hour), n = a.run.hours, byHour = new Map(a.hours.rows.map(r => [r[0], r]));let selected = null, svg, x;const draw = () => {el.querySelector('svg')?.remove();const W = el.clientWidth, H = 64;x = d3.scaleLinear().domain([0, n]).range([0, W]);const y = d3.scaleLinear().domain([0, d3.max(a.hours.rows, r => r[4]) || 1]).range([H - 14, 4]);svg = d3.select(el).insert('svg', '.tip').attr('viewBox', `0 0 ${W} ${H}`).attr('height', H).attr('role', 'img').attr('aria-label', 'Output tokens per hour over the run; click an hour to read the trace');svg.append('line').attr('class', 'base').attr('x1', 0).attr('x2', W).attr('y1', H - 14).attr('y2', H - 14);svg.append('g').selectAll('rect').data(a.hours.rows).join('rect').attr('x', r => x((Date.parse(r[0]) - t0) / 3600e3)).attr('width', Math.max(1, x(1) - x(0) - (W > 600 ? 1 : 0))).attr('y', r => y(r[4])).attr('height', r => H - 14 - y(r[4])).attr('class', r => r[0] === selected ? 'sel' : '');for (const tk of d3.timeDay.range(new Date(t0), new Date(t0 + n * 3600e3), W < 500 ? 4 : 2))svg.append('text').attr('x', x((tk - t0) / 3600e3)).attr('y', H - 2).text(d3.utcFormat('%b %-d')(tk));svg.append('rect').attr('width', W).attr('height', H).attr('fill', 'transparent').style('cursor', 'pointer').on('pointermove', ev => {const h = new Date(t0 + Math.floor(x.invert(d3.pointer(ev)[0])) * 3600e3).toISOString().replace('.000Z', 'Z'), r = byHour.get(h);tip.innerHTML = `${time(h).slice(0, 13)}:00 UTC<br>${r ? `${fmt(r[1])} model calls · ${fmt(r[4])} output tokens` : 'no activity'}`;tip.style.left = Math.min(d3.pointer(ev)[0] + 12, el.clientWidth - tip.offsetWidth) + 'px'; tip.style.top = '66px'; tip.style.opacity = 1;}).on('pointerleave', () => { tip.style.opacity = 0; }).on('click', ev => {const i = Math.floor(x.invert(d3.pointer(ev)[0])), hours = a.hours.rows.map(r => r[0]);const target = new Date(t0 + i * 3600e3).toISOString().replace('.000Z', 'Z');onPick(byHour.has(target) ? target : hours.reduce((b, h) => Math.abs(Date.parse(h) - Date.parse(target)) < Math.abs(Date.parse(b) - Date.parse(target)) ? h : b));});};draw();window.redrawChart = draw;new ResizeObserver(() => window.redrawChart === draw && draw()).observe(el);return h => { selected = h; svg.selectAll('g rect').attr('class', r => r[0] === h ? 'sel' : ''); };}9 unmodified lines10111213141516171819202122232425262728293031323334353620 unmodified lines575859606162636465666768697071727374757677782 unmodified lines81828384858687888990919293949596979899100101102103104105106107108109110111105 unmodified lines2172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592609 unmodified linesconst agentLink = (name, at) => `/agent/${encodeURIComponent(name)}${at ? `?at=${hourOf(at)}` : ''}`;let highlightsP = null, agentsP = null;// The run's hours with its pauses cut out: pos[i] is the slot of hour i (null inside a pause), and each// cut takes BREAK slots where a break mark is drawn. Hour i is first_hour + i hours.const BREAK = 4;function hourAxis(run) {const t0 = Date.parse(run.first_hour), n = run.hours, pos = new Array(n).fill(null), breaks = [];const gaps = (run.gaps || []).map(g => [(Date.parse(g.from) - t0) / 3600e3, (Date.parse(g.to) - t0) / 3600e3]);let p = 0;for (let i = 0; i < n; i++) {const g = gaps.find(g => i >= g[0] && i < g[1]);if (!g) pos[i] = p++;else if (i === g[0]) { breaks.push(p + BREAK / 2); p += BREAK; }}const slots = pos.map((x, i) => [x, i]).filter(a => a[0] != null);return {t0, n, pos, breaks, total: p,hourAt: x => new Date(t0 + d3.least(slots, a => Math.abs(a[0] + 0.5 - x))[1] * 3600e3).toISOString().replace('.000Z', 'Z'),slotOf: iso => pos[Math.round((Date.parse(iso) - t0) / 3600e3)],};}const breakMark = (x, y) => `<path class="brk" d="M${x - 4},${y + 4} l4,-8 M${x},${y + 4} l4,-8"/>`;async function agentsHome() {document.title = 'PyBot Data Explorer';$app.className = 'wide';20 unmodified lines<a class="hcard" data-nav href="${agentLink(h.agent, h.busiest_hour)}"><span class="label">${esc(h.title)}</span><span class="hv">${fmt(h.value)}</span><span><b>${esc(h.agent)}</b> <span class="muted">${esc(h.lane || 'no trace')}</span></span>${spark(h.spark, hourAxis(d.run))}<span class="go">open trace →</span></a>`).join('');document.getElementById('moments').innerHTML = d.moments.map(m => `<li><span class="muted">${time(m.ts).slice(0, 16)}</span> <span>${esc(m.text)}</span><a data-nav href="${agentLink(m.agent, m.ts)}">${esc(m.agent)}'s trace →</a>${m.sha ? ` <a data-nav href="/commits?sha=${m.sha}">commit</a>` : ''}</li>`).join('');}function spark(values, ax) {const W = 200, x = d3.scaleLinear().domain([0, ax.total]).range([0, W]), max = d3.max(values) || 1, peak = values.indexOf(max);const path = d3.line().defined((v, i) => ax.pos[i] != null).x((v, i) => x(ax.pos[i] + 0.5)).y(v => 28 - (v / max) * 26)(values);return `<svg class="spark" viewBox="0 0 ${W} 32" preserveAspectRatio="none" aria-hidden="true"><path d="${path}" vector-effect="non-scaling-stroke"/><line x1="${x(ax.pos[peak] + 0.5)}" x2="${x(ax.pos[peak] + 0.5)}" y1="0" y2="30" vector-effect="non-scaling-stroke"/>${ax.breaks.map(b => breakMark(x(b), 28)).join('')}</svg>`;}const SHORT = { conversation: 'convers.', uncertainty: 'uncert.', understanding: 'underst.', 'multi-turn': 'multi-t.', 'no trace': 'no trace' };function drawContrib(items) {const el = document.getElementById('contrib');if (!el) return;2 unmodified lineslet metric = 'total_tokens';const draw = () => {el.querySelector('svg')?.remove();const W = el.clientWidth, narrow = W < 600, S = 11, P = 13, GAP = 6, L = narrow ? 70 : 150;const cols = Math.max(8, Math.floor((W - L + 2) / P));const vals = items.filter(a => a.has_trace && a[metric] > 0).map(a => a[metric]);const color = d3.scaleSequentialLog(d3.interpolateRgbBasis([cssVar('--ramp0'), cssVar('--ramp1'), cssVar('--ramp2')])).domain([d3.min(vals) || 1, d3.max(vals) || 10]);let y = 0;const blocks = lanes.map(([lane, list]) => {const sorted = list.slice().sort((a, b) => (b[metric] || 0) - (a[metric] || 0)), top = y;y = top + Math.ceil(sorted.length / cols) * P + GAP;return { lane, list: sorted, top };});y -= GAP;const svg = d3.select(el).insert('svg', '.tip').attr('viewBox', `0 0 ${W} ${y}`).attr('height', y).attr('role', 'img').attr('aria-label', `One square per agent, grouped by lane, coloured by ${metric.replace('_', ' ')}`);svg.append('defs').html(`<pattern id="hatch" width="4" height="4" patternUnits="userSpaceOnUse" patternTransform="rotate(45)"><rect width="4" height="4" fill="${cssVar('--page-bg')}"/><line x1="0" y1="0" x2="0" y2="4" stroke="${cssVar('--muted-color')}" stroke-width="1.5"/></pattern>`);for (const b of blocks) {const label = svg.append('text').attr('class', 'lane').attr('x', L - 10).attr('y', b.top + S - 1).attr('text-anchor', 'end');if (narrow && b.list.length <= cols) label.text(`${SHORT[b.lane] || b.lane} ${b.list.length}`);else if (narrow) { // two short lines: the name, then the countlabel.append('tspan').text(SHORT[b.lane] || b.lane);label.append('tspan').attr('x', L - 10).attr('dy', P).text(b.list.length);} else label.text(`${b.lane} · ${b.list.length}`);svg.append('g').selectAll('rect').data(b.list).join('rect').attr('x', (a, i) => L + (i % cols) * P).attr('y', (a, i) => b.top + Math.floor(i / cols) * P).attr('width', S).attr('height', S).attr('fill', a => !a.has_trace ? 'url(#hatch)' : a[metric] > 0 ? color(a[metric]) : cssVar('--ramp0')).attr('tabindex', 0).attr('role', 'link').attr('aria-label', a => `${a.name}, ${a.lane || 'no trace'}`).on('pointerenter focus', (ev, a) => {105 unmodified lines}function drawStrip(a, onPick) {const el = document.getElementById('astrip'), tip = el.querySelector('.tip'), ax = hourAxis(a.run);const byHour = new Map(a.hours.rows.map(r => [r[0], r])), rows = a.hours.rows.filter(r => ax.slotOf(r[0]) != null);let selected = null, svg;const draw = () => {el.querySelector('svg')?.remove();const W = el.clientWidth, H = 64, B = H - 14;const x = d3.scaleLinear().domain([0, ax.total]).range([0, W]);const y = d3.scaleLinear().domain([0, d3.max(rows, r => r[4]) || 1]).range([B, 4]);svg = d3.select(el).insert('svg', '.tip').attr('viewBox', `0 0 ${W} ${H}`).attr('height', H).attr('role', 'img').attr('aria-label', 'Output tokens per hour over the run (pauses cut out); click an hour to read the trace');svg.append('line').attr('class', 'base').attr('x1', 0).attr('x2', W).attr('y1', B).attr('y2', B);svg.append('g').attr('class', 'bars').selectAll('rect').data(rows).join('rect').attr('x', r => x(ax.slotOf(r[0]))).attr('width', Math.max(1, x(1) - x(0) - (W > 600 ? 1 : 0))).attr('y', r => y(r[4])).attr('height', r => B - y(r[4])).attr('class', r => r[0] === selected ? 'sel' : '');let last = -1e9;for (const tk of d3.utcDay.range(new Date(ax.t0), new Date(ax.t0 + ax.n * 3600e3))) {const slot = ax.pos[(tk - ax.t0) / 3600e3];if (slot == null || x(slot) - last < (W < 500 ? 56 : 44)) continue; // day ticks only where there is datalast = x(slot);svg.append('line').attr('class', 'tick').attr('x1', last).attr('x2', last).attr('y1', B).attr('y2', B + 3);svg.append('text').attr('x', last).attr('y', H - 2).text(d3.utcFormat('%b %-d')(tk));}svg.append('g').html(ax.breaks.map(b => `<rect class="gapbg" x="${x(b) - 6}" y="${B - 2}" width="12" height="5"/>` + breakMark(x(b), B)).join(''));const hourAt = ev => ax.hourAt(x.invert(d3.pointer(ev)[0]));svg.append('rect').attr('class', 'hit').attr('width', W).attr('height', H).attr('fill', 'transparent').style('cursor', 'pointer').on('pointermove', ev => {const h = hourAt(ev), r = byHour.get(h);tip.innerHTML = `${time(h).slice(0, 13)}:00 UTC<br>${r ? `${fmt(r[1])} model calls · ${fmt(r[4])} output tokens` : 'no activity'}`;tip.style.left = Math.min(d3.pointer(ev)[0] + 12, el.clientWidth - tip.offsetWidth) + 'px'; tip.style.top = '66px'; tip.style.opacity = 1;}).on('pointerleave', () => { tip.style.opacity = 0; }).on('click', ev => {const target = Date.parse(hourAt(ev)); // the nearest hour this agent was activeonPick(d3.least(a.hours.rows.map(r => r[0]), h => Math.abs(Date.parse(h) - target)));});};draw();window.redrawChart = draw;new ResizeObserver(() => window.redrawChart === draw && draw()).observe(el);return h => { selected = h; svg.selectAll('.bars rect').attr('class', r => r[0] === h ? 'sel' : ''); };}
182 unmodified lines1831841851861871881893 unmodified lines193194195196197198199200201182 unmodified lines.sec-head .chips button { padding: 2px 8px; font-size: 11px; }.contrib { position: relative; }.contrib svg { display: block; width: 100%; }.contrib .lane { font: 10px "PB Lead", Helvetica, Arial, sans-serif; letter-spacing: .16em; fill: var(--muted-color); }.contrib rect { cursor: pointer; outline: none; }.contrib rect.on, .contrib rect:focus { stroke: var(--text-color); stroke-width: 1.5; }.legend { display: flex; flex-wrap: wrap; gap: 16px; align-items: center; margin-top: 6px; }3 unmodified lines.moments li { padding: 6px 0; border-bottom: 1px solid var(--faint-color); display: flex; flex-wrap: wrap; gap: 4px 10px; }.astrip { position: relative; border: 1px solid var(--text-color); padding: 6px 8px 0; }.astrip svg { display: block; width: 100%; overflow: visible; }.astrip g rect { fill: var(--text-color); }.astrip g rect.sel { fill: var(--primary-color); }.astrip .base { stroke: var(--faint-color); }.astrip text { fill: var(--muted-color); font: 10px "PB Mono", monospace; }.tb { border: 1px solid var(--text-color); margin-top: 12px; }.tb > header { display: flex; align-items: center; gap: 10px; padding: 6px 10px; border-bottom: 1px solid var(--faint-color); background: var(--surface-bg); }182 unmodified lines1831841851861871881891903 unmodified lines194195196197198199200201202203204205182 unmodified lines.sec-head .chips button { padding: 2px 8px; font-size: 11px; }.contrib { position: relative; }.contrib svg { display: block; width: 100%; }.contrib .lane { font: 10px "PB Lead", Helvetica, Arial, sans-serif; letter-spacing: .14em; text-transform: uppercase; fill: var(--muted-color); }@media (max-width: 640px) { .contrib .lane { font-size: 8.5px; letter-spacing: .08em; } }.contrib rect { cursor: pointer; outline: none; }.contrib rect.on, .contrib rect:focus { stroke: var(--text-color); stroke-width: 1.5; }.legend { display: flex; flex-wrap: wrap; gap: 16px; align-items: center; margin-top: 6px; }3 unmodified lines.moments li { padding: 6px 0; border-bottom: 1px solid var(--faint-color); display: flex; flex-wrap: wrap; gap: 4px 10px; }.astrip { position: relative; border: 1px solid var(--text-color); padding: 6px 8px 0; }.astrip svg { display: block; width: 100%; overflow: visible; }.astrip .bars rect { fill: var(--text-color); }.astrip .bars rect.sel { fill: var(--primary-color); }.astrip .base, .astrip .tick { stroke: var(--muted-color); }.astrip .gapbg { fill: var(--page-bg); }.brk { fill: none; stroke: var(--muted-color); stroke-width: 1.25; }.spark .brk { stroke-width: 1; vector-effect: non-scaling-stroke; }.astrip text { fill: var(--muted-color); font: 10px "PB Mono", monospace; }.tb { border: 1px solid var(--text-color); margin-top: 12px; }.tb > header { display: flex; align-items: center; gap: 10px; padding: 6px 10px; border-bottom: 1px solid var(--faint-color); background: var(--surface-bg); }
122 unmodified lines123124125126127128129122 unmodified linesa = c.get("/api/agents/ann").json()assert a["hours"]["rows"][0][1:] == [12, 12, 1200, 120] and a["busiest_hour"] == "2026-11-01T09:00:00Z"h = c.get("/api/highlights").json()assert h["totals"]["agents"] == 2 and h["totals"]["model_calls"] == 12assert {x["title"]: x["agent"] for x in h["highlights"]}["Most tool calls"] == "ann"assert any(m["text"].startswith("First merged PR: #7") for m in h["moments"])assert c.get("/api/agents?sort=drop").status_code == 400 and c.get("/api/agents/nobody").status_code == 404122 unmodified lines123124125126127128129122 unmodified linesa = c.get("/api/agents/ann").json()assert a["hours"]["rows"][0][1:] == [12, 12, 1200, 120] and a["busiest_hour"] == "2026-11-01T09:00:00Z"h = c.get("/api/highlights").json()assert h["totals"]["agents"] == 2 and h["totals"]["model_calls"] == 12 and h["run"]["gaps"] == []assert {x["title"]: x["agent"] for x in h["highlights"]}["Most tool calls"] == "ann"assert any(m["text"].startswith("First merged PR: #7") for m in h["moments"])assert c.get("/api/agents?sort=drop").status_code == 400 and c.get("/api/agents/nobody").status_code == 404
app.py+4-1
static/agents.js+68-30
static/style.css+8-4
tests/test_api.py+1-1