Public: anyone can read this; the crew can change it.
The slot bars stay put: quarter hours on the clock at their peak, and red only for a failure #17237
Conflicts with main in 1 file
src/web/flow_slots.ts
check-bars → main 1 commit
5 files
changed +104
−30
docs/design/areas/boards.md +1 −1
| @@ -28,7 +28,7 @@ The card under the Pipeline table (`id="verified"`) adds no class: it is a `card | ||
| 28 | 28 | - `.bd-now`, `.bd-lead` — the bottleneck sentence at 16px and, under it in the muted colour, only the lines that hold right now (conflicted pulls, a held rebase lane, idle pulls). |
| 29 | 29 | - `.bd-block`, `.bd-head`, `.bd-sub` — a block of the page: its `<h2>`, one sentence of what it shows, and its quiet links. |
| 30 | 30 | - `.fl-stages`, `.fl-stage` — /flow's answer under its one sentence: each stage that has anything waiting or worked, one line (`stageSays`: what waits, what is active, what limits it, the oldest wait), the bottleneck in the danger colour. Everything else on /flow folds under one line, and no list shows more than ten rows: the last line, "and N more", links to /flow?all=<list id>, that list whole with its fold open. The same rows carry the merge queue against its targets (#17006), the first fold: one `.fl-stage` per target (`data-target`, `data-met`), and a missed one is marked as the bottleneck is. |
| 31 | - `.sl-block`, `.sl`, `.sl-head` (the name, the busy count and, in `.sl-say`, what waits), `.sl-used`, `.sl-chart`, `.sl-busy`, `.sl-full`, `.sl-wait`, `.sl-line`, `.sl-foot` — the slots above the pipeline (`src/web/flow_slots.ts`): for checks and the crew, "4 of 4 slots busy" in the danger colour with a full badge when every slot is busy and something waits, what waits and its oldest and median wait, the crew's pace when it allows fewer, and the 24 hours as bars with the setting dashed across them (solid red where a bar reaches it, muted below, waiting lighter on top). Change capacity is a button under them. | |
| 31 | - `.sl-block`, `.sl`, `.sl-head` (the name, the busy count and, in `.sl-say`, what waits), `.sl-used`, `.sl-chart`, `.sl-busy`, `.sl-full`, `.sl-wait`, `.sl-line`, `.sl-key`, `.sl-swatch`, `.sl-foot` — the slots above the pipeline (`src/web/flow_slots.ts`): for checks and the crew, "4 of 4 slots busy" in the attention colour with a full badge when every slot is busy and something waits, what waits and its oldest and median wait, the crew's pace when it allows fewer, and the 24 hours as bars with the setting dashed across them. Each bar is a quarter hour on the clock at its peak, so a bar changes only when its runs do. It is solid in the attention colour where every slot was busy (never red: red is a failed run), muted below, with waiting lighter on top. Each bar's title names its quarter and counts, and a `.sl-key` line under the chart gives the colours as `.sl-swatch` squares and says where the 24 hours end. Change capacity is a button under them. | |
| 32 | 32 | - `.pl`, `.pl-cap`, `.pl-trend`, `.pl-spark` — the pipeline: §5's `.table` with every number right-aligned and tabular, a zero in the faint colour, the day's 24 hours as bars. On a phone each stage is a card: its name, then its five numbers in one row with their names over them. |
| 33 | 33 | - `.bd-boards` — the boards as tiles: two across on a phone, four from 720px. Each tile is a `data-nav` row for `j`/`k`. |
| 34 | 34 | - `.folds`, `.fold`, `.fold-title`, `.fold-state`, `.fold-body` — `fold()`: a `disclosure` whose summary is the section's name and one sentence of how it stands now ("nothing queued; 26 landed in the last hour"); the detail is inside. Hairlines between, no card. |
src/flow/slots.ts +40 −12
| @@ -23,12 +23,19 @@ import { forgeRepo } from "../core/forge_repo.ts"; | ||
| 23 | 23 | import { repoPace } from "../crew/autonomy_pace.ts"; |
| 24 | 24 | import { median } from "./estimate_score.ts"; |
| 25 | 25 | |
| 26 | /** The instants the 24 hours are read at: one each quarter hour, oldest first. */ | |
| 26 | /** | |
| 27 | * The 24 hours as quarter hours on the clock (:00, :15, :30, :45), oldest first, the last one the | |
| 28 | * quarter now under way. Each is what that quarter held at its peak, so a bar changes only when its | |
| 29 | * own runs do, never because the reading moved by a minute. | |
| 30 | */ | |
| 27 | 31 | export const SLOT_POINTS = 96; |
| 28 | 32 | const STEP_MS = 15 * 60_000; |
| 29 | 33 | const HOUR_MS = 3_600_000; |
| 30 | 34 | |
| 31 | 35 | export interface SlotPoint { |
| 36 | /** When the quarter hour starts, in ms. */ | |
| 37 | readonly at: number; | |
| 38 | /** The most that ran at once in it, and the most that waited at once. */ | |
| 32 | 39 | readonly running: number; |
| 33 | 40 | readonly queued: number; |
| 34 | 41 | } |
| @@ -181,23 +188,44 @@ function rows(db: Database, since: string): Row[] { | ||
| 181 | 188 | .all(since); |
| 182 | 189 | } |
| 183 | 190 | |
| 191 | /** | |
| 192 | * Each quarter hour's peaks, in one sweep: every start and end is an event at its instant (an end | |
| 193 | * before a start at the same instant), and a quarter's peak is the most counted at once inside it, | |
| 194 | * from what was already running as it began. Quarters are the clock's, the last one ending `now`. | |
| 195 | */ | |
| 196 | function quarterPeaks(spans: readonly { asked: number; started: number; ended: number }[], now: number): SlotPoint[] { | |
| 197 | const first = Math.floor(now / STEP_MS) * STEP_MS - (SLOT_POINTS - 1) * STEP_MS; | |
| 198 | const peaks = (pairs: [number, number][]): number[] => { | |
| 199 | const events: [number, number][] = []; | |
| 200 | for (const [from, to] of pairs) if (from < to && to > first && from <= now) events.push([from, 1], [to, -1]); | |
| 201 | events.sort((a, b) => a[0] - b[0] || a[1] - b[1]); | |
| 202 | const out = new Array<number>(SLOT_POINTS).fill(0); | |
| 203 | let n = 0; | |
| 204 | let e = 0; | |
| 205 | for (; e < events.length && events[e]![0] <= first; e++) n += events[e]![1]; | |
| 206 | for (let q = 0; q < SLOT_POINTS; q++) { | |
| 207 | const end = first + (q + 1) * STEP_MS; | |
| 208 | let peak = n; | |
| 209 | for (; e < events.length && events[e]![0] < end; e++) { | |
| 210 | n += events[e]![1]; | |
| 211 | if (n > peak) peak = n; | |
| 212 | } | |
| 213 | out[q] = peak; | |
| 214 | } | |
| 215 | return out; | |
| 216 | }; | |
| 217 | const running = peaks(spans.map((s) => [s.started, s.ended])); | |
| 218 | const queued = peaks(spans.map((s) => [s.asked, Math.min(s.started, s.ended)])); | |
| 219 | return running.map((r, q) => ({ at: first + q * STEP_MS, running: r, queued: queued[q]! })); | |
| 220 | } | |
| 221 | ||
| 184 | 222 | /** The line for one kind of run, read from its rows at `now`. Pure: rows in, figures out. */ |
| 185 | 223 | export function slotLine(kind: SlotLine["kind"], slots: number, runs: readonly Row[], now: number): SlotLine { |
| 186 | 224 | const t = (iso: string | null): number => (iso === null ? Infinity : Date.parse(iso)); |
| 187 | 225 | // Each run's instants parsed once, not once per point: 96 points over a day's runs was a million |
| 188 | 226 | // parses on every cold home at production's size (#17043). |
| 189 | 227 | const spans = runs.map((r) => ({ asked: t(r.created_at), started: t(r.started_at), ended: t(r.finished_at) })); |
| 190 | const points: SlotPoint[] = []; | |
| 191 | for (let i = SLOT_POINTS - 1; i >= 0; i--) { | |
| 192 | const at = now - i * STEP_MS; | |
| 193 | let running = 0; | |
| 194 | let queued = 0; | |
| 195 | for (const { asked, started, ended } of spans) { | |
| 196 | if (started <= at && at < ended) running++; | |
| 197 | else if (asked <= at && at < Math.min(started, ended)) queued++; | |
| 198 | } | |
| 199 | points.push({ running, queued }); | |
| 200 | } | |
| 228 | const points = quarterPeaks(spans, now); | |
| 201 | 229 | const waitingNow = runs.filter((r) => r.state === "queued"); |
| 202 | 230 | const waits = runs |
| 203 | 231 | .filter((r) => r.started_at !== null && now - t(r.started_at) <= HOUR_MS && now >= t(r.started_at)) |
src/web/flow_slots.ts +18 −9
| @@ -1,8 +1,11 @@ | ||
| 1 | 1 | /** |
| 2 | 2 | * The slots, drawn (`flow/slots.ts`): for checks and for the crew, one line that says how many of |
| 3 | 3 | * the slots are busy against how many there are, what waits and for how long, and a 24-hour |
| 4 | * picture with the ceiling drawn across it, so a saturated lane reads as full at a glance. Bars | |
| 5 | * that reach the line are drawn solid, those below it muted; what waited sits lighter on top. | |
| 4 | * picture with the ceiling drawn across it, so a saturated lane reads as full at a glance. Each bar | |
| 5 | * is a quarter hour on the clock at its peak: every slot busy is the attention colour, fewer is | |
| 6 | * muted, and what waited sits lighter on top. Each bar names its quarter and counts, and a legend | |
| 7 | * says the colours and where the 24 hours end. A bar is never red: red is a failed run, and these | |
| 8 | * are slots, not results. | |
| 6 | 9 | * "Change capacity" goes to the page that sets the ceiling. Shown on /boards and on /flow. |
| 7 | 10 | */ |
| 8 | 11 | |
| @@ -14,9 +17,11 @@ import { isFull, offByMore, roomSaysUpTo, SLOT_POINTS, waitEstimate, type SlotLi | ||
| 14 | 17 | const NAME: Readonly<Record<SlotLine["kind"], string>> = { checks: "Checks", crew: "Crew runs" }; |
| 15 | 18 | const H = 32; |
| 16 | 19 | |
| 20 | const hhmm = (ms: number): string => new Date(ms).toISOString().slice(11, 16); | |
| 21 | ||
| 17 | 22 | /** |
| 18 | * The 24 hours: busy as bars, waiting stacked lighter above, the ceiling as a dashed line. A | |
| 19 | * picture only. | |
| 23 | * The 24 hours: busy as bars, waiting stacked lighter above, the ceiling as a dashed line. Each bar | |
| 24 | * says its quarter hour and what it held, for a pointer and a screen reader. | |
| 20 | 25 | */ |
| 21 | 26 | function chart(l: SlotLine): Html { |
| 22 | 27 | const W = SLOT_POINTS * 3; |
| @@ -24,6 +29,7 @@ function chart(l: SlotLine): Html { | ||
| 24 | 29 | const y = (n: number): number => H - Math.round((n / top) * (H - 2)); |
| 25 | 30 | const bars = l.points.map((p, i) => { |
| 26 | 31 | const x = i * 3; |
| 32 | const said = `${hhmm(p.at)}–${hhmm(p.at + 15 * 60_000)} UTC: up to ${String(p.running)} of ${String(l.slots)} busy${p.queued === 0 ? "" : `, up to ${String(p.queued)} waiting`}`; | |
| 27 | 33 | const run = |
| 28 | 34 | p.running === 0 |
| 29 | 35 | ? null |
| @@ -33,7 +39,7 @@ function chart(l: SlotLine): Html { | ||
| 33 | 39 | y="${String(y(p.running))}" |
| 34 | 40 | width="2" |
| 35 | 41 | height="${String(H - y(p.running))}" |
| 36 | />`; | |
| 42 | ><title>${said}</title></rect>`; | |
| 37 | 43 | const wait = |
| 38 | 44 | p.queued === 0 |
| 39 | 45 | ? null |
| @@ -43,14 +49,17 @@ function chart(l: SlotLine): Html { | ||
| 43 | 49 | y="${String(y(p.running + p.queued))}" |
| 44 | 50 | width="2" |
| 45 | 51 | height="${String(y(p.running) - y(p.running + p.queued))}" |
| 46 | />`; | |
| 52 | >${run === null ? html`<title>${said}</title>` : null}</rect>`; | |
| 47 | 53 | return html`${run}${wait}`; |
| 48 | 54 | }); |
| 49 | 55 | const at = y(l.slots); |
| 50 | return html`<svg class="sl-chart" viewBox="0 0 ${String(W)} ${String(H)}" preserveAspectRatio="none" aria-hidden="true" focusable="false"> | |
| 56 | const last = l.points.at(-1); | |
| 57 | const end = last === undefined ? "" : hhmm(last.at + 15 * 60_000); | |
| 58 | return html`<svg class="sl-chart" viewBox="0 0 ${String(W)} ${String(H)}" preserveAspectRatio="none" role="img" aria-label="${NAME[l.kind]}: the 24 hours to ${end} UTC by quarter hour, each at its peak" focusable="false"> | |
| 51 | 59 | ${bars} |
| 52 | 60 | <line class="sl-line" x1="0" x2="${String(W)}" y1="${String(at)}" y2="${String(at)}" /> |
| 53 | </svg>`; | |
| 61 | </svg> | |
| 62 | <p class="sl-key small"><span class="sl-swatch" data-swatch="full"></span> every slot busy · <span class="sl-swatch" data-swatch="busy"></span> fewer · <span class="sl-swatch" data-swatch="wait"></span> waited · dashed: today's setting · quarter hours to ${end} UTC</p>`; | |
| 54 | 63 | } |
| 55 | 64 | |
| 56 | 65 | /** |
| @@ -90,7 +99,7 @@ function line(l: SlotLine, now: number, admin = false): Html { | ||
| 90 | 99 | <strong>${NAME[l.kind]}</strong> |
| 91 | 100 | <span class="sl-used" data-busy="${String(l.busy)}" data-slots="${String(l.slots)}" |
| 92 | 101 | >${String(l.busy)} of ${String(l.slots)} slots busy</span |
| 93 | >${full ? html` ${badge("full", { tone: "danger" })}` : null} | |
| 102 | >${full ? html` ${badge("full", { tone: "attn" })}` : null} | |
| 94 | 103 | ${says.length === 0 ? null : html`<span class="sl-say small">${says.map((s, i) => html`${i === 0 ? "" : " · "}${s}`)}</span>`} |
| 95 | 104 | </p> |
| 96 | 105 | ${kept(l)} |
src/web/style/components.ts +6 −2
| @@ -1188,11 +1188,15 @@ a[data-palette] { display: none; } | ||
| 1188 | 1188 | .sl { display: grid; gap: 4px; } |
| 1189 | 1189 | .sl-head { margin: 0; display: flex; flex-wrap: wrap; align-items: baseline; gap: 0 8px; } |
| 1190 | 1190 | .sl-used { font-variant-numeric: tabular-nums; } |
| 1191 | .sl[data-full] .sl-used { color: var(--danger); font-weight: 600; } | |
| 1191 | .sl[data-full] .sl-used { color: var(--attn); font-weight: 600; } | |
| 1192 | 1192 | .sl-say { color: var(--muted-fg); } |
| 1193 | 1193 | .sl-chart { display: block; width: 100%; height: 32px; color: var(--muted-fg); } |
| 1194 | 1194 | .sl-busy { fill: currentColor; fill-opacity: .45; } |
| 1195 | .sl-full { fill: var(--danger); } | |
| 1195 | .sl-full { fill: var(--attn); } | |
| 1196 | .sl-key { margin: 0; color: var(--muted-fg); } | |
| 1197 | .sl-swatch { display: inline-block; width: 8px; height: 8px; vertical-align: baseline; background: var(--muted-fg); opacity: .45; } | |
| 1198 | .sl-swatch[data-swatch="full"] { background: var(--attn); opacity: 1; } | |
| 1199 | .sl-swatch[data-swatch="wait"] { opacity: .18; } | |
| 1196 | 1200 | .sl-wait { fill: currentColor; fill-opacity: .18; } |
| 1197 | 1201 | .sl-line { stroke: var(--fg); stroke-width: 1; stroke-dasharray: 4 3; vector-effect: non-scaling-stroke; } |
| 1198 | 1202 | .sl-foot { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin: 0; } |
test/flow-slots.test.ts +39 −6
| @@ -47,15 +47,48 @@ test("a line counts busy, waiting, the oldest and the median wait of the last ho | ||
| 47 | 47 | expect(l.oldestAt).toBe(ago(30)); |
| 48 | 48 | // Started in the last hour: waited 10 and 15 minutes. |
| 49 | 49 | expect(l.medianWaitMs).toBe(12.5 * 60_000); |
| 50 | expect(l.points.at(-1)).toEqual({ running: 2, queued: 2 }); | |
| 51 | // Two hours ago only the old run was running; 3 h 20 m ago it was still waiting to start. | |
| 52 | expect(l.points[SLOT_POINTS - 1 - 8]).toEqual({ running: 1, queued: 0 }); | |
| 53 | expect(l.points[SLOT_POINTS - 1 - 13]).toEqual({ running: 0, queued: 1 }); | |
| 50 | // Quarter hours on the clock, the last the one under way: NOW is 12:00, so it is 12:00–12:15. | |
| 51 | expect(l.points.at(-1)).toEqual({ at: NOW, running: 2, queued: 2 }); | |
| 52 | expect(l.points[0]!.at).toBe(NOW - (SLOT_POINTS - 1) * 15 * 60_000); | |
| 53 | // 10:00–10:15: only the old run ran; 08:30–08:45: it was still waiting to start. | |
| 54 | expect(l.points[SLOT_POINTS - 1 - 8]).toEqual({ at: NOW - 8 * 15 * 60_000, running: 1, queued: 0 }); | |
| 55 | expect(l.points[SLOT_POINTS - 1 - 14]).toEqual({ at: NOW - 14 * 15 * 60_000, running: 0, queued: 1 }); | |
| 54 | 56 | expect(isFull(l)).toBe(true); |
| 55 | 57 | expect(isFull({ ...l, waiting: 0 })).toBe(false); |
| 56 | 58 | expect(isFull({ ...l, busy: 1 })).toBe(false); |
| 57 | 59 | }); |
| 58 | 60 | |
| 61 | test("a bar changes only when its own runs do: read a few minutes apart, every finished quarter is the same, and each is its peak, not an instant", () => { | |
| 62 | // Busy 8 of 8 from 11:02 to 11:13, one free from 11:13 to 11:14, then 8 again: a reading at an | |
| 63 | // instant could catch 7; the quarter's peak is 8 however the reading falls. | |
| 64 | const at = (m: number) => new Date(NOW - 60 * 60_000 + m * 60_000).toISOString(); | |
| 65 | const runs = Array.from({ length: 8 }, (_, i) => ({ | |
| 66 | kind: "check", | |
| 67 | created_at: at(1), | |
| 68 | started_at: at(2), | |
| 69 | finished_at: i === 0 ? at(13) : at(40), | |
| 70 | state: "ok", | |
| 71 | })); | |
| 72 | runs.push({ kind: "check", created_at: at(13), started_at: at(14), finished_at: at(40), state: "ok" }); | |
| 73 | const read = (minutesLater: number) => slotLine("checks", 8, runs, NOW + minutesLater * 60_000).points; | |
| 74 | const a = read(1); | |
| 75 | const b = read(9); | |
| 76 | // The same quarter hours, the same counts: only the quarter still under way may differ. | |
| 77 | expect(a.slice(0, -1)).toEqual(b.slice(0, -1)); | |
| 78 | const eleven = a.find((p) => p.at === NOW - 60 * 60_000)!; | |
| 79 | expect(eleven.running).toBe(8); | |
| 80 | }); | |
| 81 | ||
| 82 | test("drawn, each bar names its quarter hour and counts, the chart says where its 24 hours end, and a legend names the colours", () => { | |
| 83 | const l: SlotLine = { ...slotLine("checks", 4, [], NOW), points: Array.from({ length: SLOT_POINTS }, (_, i) => ({ at: NOW - (SLOT_POINTS - 1 - i) * 15 * 60_000, running: i % 2 === 0 ? 4 : 2, queued: 1 })) }; | |
| 84 | const out = slotsBlock([l], NOW, false).text.replace(/\s+/g, " "); | |
| 85 | expect(out).toContain("<title>12:00–12:15 UTC: up to 2 of 4 busy, up to 1 waiting</title>"); | |
| 86 | expect(out).toContain('aria-label="Checks: the 24 hours to 12:15 UTC by quarter hour, each at its peak"'); | |
| 87 | expect(out).toContain("every slot busy"); | |
| 88 | expect(out).toContain("quarter hours to 12:15 UTC"); | |
| 89 | expect(out).not.toContain("danger"); | |
| 90 | }); | |
| 91 | ||
| 59 | 92 | test("a line parses each run's instants a few times, not once per quarter hour: the cost does not grow with the 96 points (#17043)", () => { |
| 60 | 93 | const runs = Array.from({ length: 200 }, (_, i) => run(i * 7 + 20, i % 3 === 0 ? null : i * 7 + 10, i % 2 === 0 ? i * 7 : null)); |
| 61 | 94 | const real = Date.parse; |
| @@ -70,14 +103,14 @@ test("a line parses each run's instants a few times, not once per quarter hour: | ||
| 70 | 103 | expect(calls).toBeLessThan(runs.length * 12); |
| 71 | 104 | }); |
| 72 | 105 | |
| 73 | test("drawn, a full lane reads as full: the danger badge, solid bars at the line, the setting dashed across", () => { | |
| 106 | test("drawn, a full lane reads as full: the full badge, solid bars at the line, the setting dashed across", () => { | |
| 74 | 107 | const full: SlotLine = { |
| 75 | 108 | ...slotLine("checks", 4, [], NOW), |
| 76 | 109 | busy: 4, |
| 77 | 110 | waiting: 17, |
| 78 | 111 | oldestAt: ago(44), |
| 79 | 112 | medianWaitMs: 12 * 60_000, |
| 80 | points: Array.from({ length: SLOT_POINTS }, () => ({ running: 4, queued: 3 })), | |
| 113 | points: Array.from({ length: SLOT_POINTS }, (_, i) => ({ at: NOW - (SLOT_POINTS - 1 - i) * 15 * 60_000, running: 4, queued: 3 })), | |
| 81 | 114 | }; |
| 82 | 115 | const calm: SlotLine = { |
| 83 | 116 | ...slotLine("crew", 6, [], NOW), |
new above
offline