Public: anyone can read this; the crew can change it.
Migrated from github.com/Trevato/SO-ARM100
workbenchthis machine
bench/precision-report.ts prints the weekly precision comment from /precision history #488
Check · Review · Land done · Live — Landed; nothing deploys from this branch, so this is the end of its path.
smith/arm:smith/452-bench-precision-report-ts-prints-the-wee → main 1 commit fork
3 files
changed +165
−0
Software/README.md +6
| @@ -1049,6 +1049,12 @@ Where to read it: | ||
| 1049 | 1049 | `/metrics`): unauthenticated, for the crew's scripts on that network. It holds timing and position aggregates |
| 1050 | 1050 | only: no names, tokens or commands. |
| 1051 | 1051 | |
| 1052 | `bun bench/precision-report.ts <url>` (the arm server's URL) reads the hourly roll-up from `GET /precision` and prints | |
| 1053 | the weekly comment for #439: each headline number this week against last, the worst joint and the open experiment. It | |
| 1054 | only reads; the crew posts it. The experiment is the line below, which the crew edits: | |
| 1055 | ||
| 1056 | Open experiment: none yet | |
| 1057 | ||
| 1052 | 1058 | `bench/precision.ts` replays a fixed gesture script on the fake bus, through the real Governor, with servos that |
| 1053 | 1059 | follow their goals at 1500 ticks/s, and prints the same scorecard (`--json` for the whole card). Every precision pull |
| 1054 | 1060 | quotes its numbers before and after. As of #436 (the time to arrive moves by a few hundred ms from run to run with |
Software/so101/bench/precision-report.test.ts added +57
| @@ -0,0 +1,57 @@ | ||
| 1 | import { expect, test } from "bun:test"; | |
| 2 | import type { Row } from "../src/precision-history.ts"; | |
| 3 | import { experiment, report } from "./precision-report.ts"; | |
| 4 | ||
| 5 | const NOW = Date.parse("2026-10-21T12:00:00Z"); | |
| 6 | const row = (daysAgo: number, o: Partial<Row>): Row => ({ | |
| 7 | at: new Date(NOW - daysAgo * 86400_000).toISOString(), | |
| 8 | commit: "abc", | |
| 9 | sessions: 1, | |
| 10 | seconds: 60, | |
| 11 | trackingP95Deg: 5, | |
| 12 | trackingMaxDeg: 9, | |
| 13 | arriveP95Ms: 400, | |
| 14 | snapBacks: 1, | |
| 15 | releases: 10, | |
| 16 | latencyP95Ms: 20, | |
| 17 | worstJoint: "elbow_flex", | |
| 18 | ...o, | |
| 19 | }); | |
| 20 | ||
| 21 | const hours: Row[] = [ | |
| 22 | row(10, { trackingP95Deg: 9, arriveP95Ms: 600, latencyP95Ms: 30, snapBacks: 2, releases: 10, worstJoint: "wrist_flex" }), | |
| 23 | row(9, { trackingP95Deg: 7 }), | |
| 24 | row(3, { trackingP95Deg: 4, arriveP95Ms: 500, latencyP95Ms: 25, snapBacks: 1, releases: 10, worstJoint: "shoulder_lift" }), | |
| 25 | row(1, { trackingP95Deg: 6, arriveP95Ms: 450, latencyP95Ms: 15, snapBacks: 0, releases: 10, worstJoint: "shoulder_pan" }), | |
| 26 | ]; | |
| 27 | ||
| 28 | test("the report sets this week beside last, with the worst joint and the experiment", () => { | |
| 29 | const text = report({ hours, commit: "abc" }, NOW, "slow the shoulder_pan ramp"); | |
| 30 | expect(text).toBe(`## Precision, week to 2026-10-21 | |
| 31 | ||
| 32 | | | this week | last week | change | | |
| 33 | |---|---|---|---| | |
| 34 | | p95 tracking error | 6.00 ° | 9.00 ° | -3.00 ° | | |
| 35 | | p95 time to arrive | 500 ms | 600 ms | -100 ms | | |
| 36 | | p95 latency | 25 ms | 30 ms | -5 ms | | |
| 37 | | snap-backs per 100 releases | 5.0 | 15.0 | -10.0 | | |
| 38 | ||
| 39 | Hours measured: 2 this week, 2 last. Lower is better in every row; each is the worst hour's p95. | |
| 40 | ||
| 41 | **Worst joint:** shoulder_pan (last week: wrist_flex) | |
| 42 | ||
| 43 | **Open experiment:** slow the shoulder_pan ramp | |
| 44 | `); | |
| 45 | }); | |
| 46 | ||
| 47 | test("an empty history and a missing experiment print dashes, not a crash", () => { | |
| 48 | const text = report({ hours: [], commit: "abc" }, NOW, null); | |
| 49 | expect(text).toContain("| p95 tracking error | – | – | – |"); | |
| 50 | expect(text).toContain("none measured"); | |
| 51 | expect(text).toContain("none named"); | |
| 52 | }); | |
| 53 | ||
| 54 | test("the experiment is the README's 'Open experiment:' line", () => { | |
| 55 | expect(experiment("# x\n\nOpen experiment: try a 2 ° deadband\n\nmore")).toBe("try a 2 ° deadband"); | |
| 56 | expect(experiment("nothing here")).toBeNull(); | |
| 57 | }); |
Software/so101/bench/precision-report.ts added +102
| @@ -0,0 +1,102 @@ | ||
| 1 | /** | |
| 2 | * The weekly precision comment for #439, printed from the hourly roll-up GET /precision keeps. It only reads; the crew posts it. | |
| 3 | * bun bench/precision-report.ts <url> [--readme path] | |
| 4 | * <url> is the arm server (port 8101 on the Pi's private network), which answers /precision without signing in. | |
| 5 | * The open experiment is the line in Software/README.md that starts with "Open experiment:". | |
| 6 | */ | |
| 7 | import { readFileSync } from "node:fs"; | |
| 8 | import { join } from "node:path"; | |
| 9 | import type { Row, Scorecard } from "../src/precision-history.ts"; | |
| 10 | ||
| 11 | const WEEK_MS = 7 * 24 * 3600_000; | |
| 12 | const HOURS = 14 * 24; | |
| 13 | const README = join(import.meta.dir, "../../README.md"); | |
| 14 | ||
| 15 | /** One week of hours, reduced to the four headline numbers: the worst hour of each p95, snap-backs pooled. */ | |
| 16 | export interface Week { | |
| 17 | hours: number; | |
| 18 | trackingP95Deg: number | null; | |
| 19 | arriveP95Ms: number | null; | |
| 20 | latencyP95Ms: number | null; | |
| 21 | snapBacksPer100: number | null; | |
| 22 | worstJoint: string | null; | |
| 23 | } | |
| 24 | ||
| 25 | const worst = (xs: (number | null)[]): number | null => xs.reduce<number | null>((m, x) => (x === null ? m : m === null || x > m ? x : m), null); | |
| 26 | ||
| 27 | export function week(rows: readonly Row[], from: number, to: number): Week { | |
| 28 | const mine = rows.filter((r) => { | |
| 29 | const t = Date.parse(r.at); | |
| 30 | return t > from && t <= to; | |
| 31 | }); | |
| 32 | const releases = mine.reduce((n, r) => n + r.releases, 0); | |
| 33 | const snaps = mine.reduce((n, r) => n + r.snapBacks, 0); | |
| 34 | const hot = mine.filter((r) => r.trackingP95Deg !== null && r.worstJoint).sort((a, b) => b.trackingP95Deg! - a.trackingP95Deg!)[0]; | |
| 35 | return { | |
| 36 | hours: mine.length, | |
| 37 | trackingP95Deg: worst(mine.map((r) => r.trackingP95Deg)), | |
| 38 | arriveP95Ms: worst(mine.map((r) => r.arriveP95Ms)), | |
| 39 | latencyP95Ms: worst(mine.map((r) => r.latencyP95Ms)), | |
| 40 | snapBacksPer100: releases > 0 ? (snaps / releases) * 100 : null, | |
| 41 | worstJoint: hot?.worstJoint ?? null, | |
| 42 | }; | |
| 43 | } | |
| 44 | ||
| 45 | /** The text after "Open experiment:" in the README, or null. */ | |
| 46 | export function experiment(readme: string): string | null { | |
| 47 | const m = /^\s*(?:[-*]\s*)?Open experiment:\s*(.+)$/im.exec(readme); | |
| 48 | return m ? m[1]!.trim() : null; | |
| 49 | } | |
| 50 | ||
| 51 | const num = (x: number | null, digits: number, unit: string) => (x === null ? "–" : `${x.toFixed(digits)}${unit}`); | |
| 52 | function delta(now: number | null, before: number | null, digits: number, unit: string): string { | |
| 53 | if (now === null || before === null) return "–"; | |
| 54 | const d = now - before; | |
| 55 | return `${d > 0 ? "+" : ""}${d.toFixed(digits)}${unit}`; | |
| 56 | } | |
| 57 | ||
| 58 | export function report(card: Pick<Scorecard, "hours" | "commit">, now: number, open: string | null): string { | |
| 59 | const cur = week(card.hours, now - WEEK_MS, now); | |
| 60 | const prev = week(card.hours, now - 2 * WEEK_MS, now - WEEK_MS); | |
| 61 | const line = (name: string, key: "trackingP95Deg" | "arriveP95Ms" | "latencyP95Ms" | "snapBacksPer100", digits: number, unit: string) => | |
| 62 | `| ${name} | ${num(cur[key], digits, unit)} | ${num(prev[key], digits, unit)} | ${delta(cur[key], prev[key], digits, unit)} |`; | |
| 63 | return [ | |
| 64 | `## Precision, week to ${new Date(now).toISOString().slice(0, 10)}`, | |
| 65 | "", | |
| 66 | "| | this week | last week | change |", | |
| 67 | "|---|---|---|---|", | |
| 68 | line("p95 tracking error", "trackingP95Deg", 2, " °"), | |
| 69 | line("p95 time to arrive", "arriveP95Ms", 0, " ms"), | |
| 70 | line("p95 latency", "latencyP95Ms", 0, " ms"), | |
| 71 | line("snap-backs per 100 releases", "snapBacksPer100", 1, ""), | |
| 72 | "", | |
| 73 | `Hours measured: ${cur.hours} this week, ${prev.hours} last. Lower is better in every row; each is the worst hour's p95.`, | |
| 74 | "", | |
| 75 | `**Worst joint:** ${cur.worstJoint ?? "none measured"}${prev.worstJoint ? ` (last week: ${prev.worstJoint})` : ""}`, | |
| 76 | "", | |
| 77 | `**Open experiment:** ${open ?? "none named in Software/README.md"}`, | |
| 78 | "", | |
| 79 | ].join("\n"); | |
| 80 | } | |
| 81 | ||
| 82 | if (import.meta.main) { | |
| 83 | const args = process.argv.slice(2); | |
| 84 | const i = args.indexOf("--readme"); | |
| 85 | const readme = i >= 0 ? args.splice(i, 2)[1] : README; | |
| 86 | const url = args[0]; | |
| 87 | if (!url || !readme) { | |
| 88 | console.error("usage: bun bench/precision-report.ts <url> [--readme path]"); | |
| 89 | process.exit(2); | |
| 90 | } | |
| 91 | const res = await fetch(new URL(`/precision?hours=${HOURS}`, url), { signal: AbortSignal.timeout(10_000) }); | |
| 92 | if (!res.ok) { | |
| 93 | console.error(`GET /precision answered ${res.status}`); | |
| 94 | process.exit(1); | |
| 95 | } | |
| 96 | const card = (await res.json()) as Scorecard; | |
| 97 | let text: string | null = null; | |
| 98 | try { | |
| 99 | text = readFileSync(readme, "utf8"); | |
| 100 | } catch {} | |
| 101 | console.log(report(card, Date.now(), text ? experiment(text) : null)); | |
| 102 | } |
new above
offline