Public: anyone can read this; the crew can change it.
Migrated from github.com/Trevato/SO-ARM100
workbenchthis machine
A session in /admin/data shows its joint traces, intent against actual, with jam, block, STOP and release marks on the same axis #559
Check · Review · Land done · Live — Landed; nothing deploys from this branch, so this is the end of its path.
smith/arm:smith/548-a-session-in-admin-data-shows-its-joint → main 2 commits fork 2 threads · 2 unresolved
7 files
changed +82
−4
Software/so101/README.md +1 −1
| @@ -86,7 +86,7 @@ A bad parameter is a 400 whose `error` says what to send; POST is 405. Shape of | ||
| 86 | 86 | `/admin/data` draws the facts for the owner and moderators (anyone else: 404), linked from `/admin` and from the Room card in the app's Admin tab. It is a page of its own, so nothing of it loads with the camera and nothing covers it. |
| 87 | 87 | |
| 88 | 88 | - **Overview**: visitors, driving sessions, drivers, minutes driven, snap-backs per 100 releases, p95 time to arrive, jams and arm-link uptime, each a big number with a sparkline. Swipeable cards on a portrait phone; a grid anywhere wider. |
| 89 | - **Precision**: snap-backs by cause (stacked), snap-backs per 100 releases, and the worst sessions; a session opens its numbers, its events (STOP, jam, block, reconnect, app start) on a timeline a minute either side, and the room each minute. | |
| 89 | - **Precision**: snap-backs by cause (stacked), snap-backs per 100 releases, and the worst sessions; a session opens its numbers, its events (STOP, jam, block, reconnect, app start) on a timeline a minute either side, and the room each minute. When the arm's trace was kept for the turn, `GET /data?turn=<id>` also answers it as `trace` (null otherwise), and the dialog draws one small chart per joint, intent (dashed) against actual, with the turn's events marked on the same time axis; hover or tap, or focus a chart and use the arrow keys (Home, End), for exact values. A turn with no trace opens without charts. | |
| 90 | 90 | - **Latency**: p95 time to arrive over time, and the turns by their p95 arrive. |
| 91 | 91 | - **People**: in the room (watchers, driving, in line), visitors anonymous against account, where people drop off, wait in line, turn length, how turns ended, chat volume. |
| 92 | 92 | - **Health**: arm-link uptime; reconnects, app starts, STOPs, jams and blocks; camera fps. |
Software/so101/src/data-api.test.ts +4
| @@ -65,6 +65,10 @@ test("GET /data: anonymous and plain users get 403; the owner and a moderator ge | ||
| 65 | 65 | expect(one.turn).toMatchObject({ id, who: whoIs("a-ada"), ended: "time is up" }); |
| 66 | 66 | expect(one.events.map((e: { kind: string }) => e.kind)).toContain("STOP"); |
| 67 | 67 | expect(one.events.every((e: Record<string, unknown>) => !("who" in e))).toBe(true); |
| 68 | expect(one.trace).toBeNull(); | |
| 69 | facts.trace(id, { session: 1, t0: Date.now(), hz: 5, joints: { shoulder_pan: { intent: [1, 2], actual: [1, 1.5] } } }); | |
| 70 | const traced = (await (await fetch(`${base}/data?turn=${id}`, { headers: owner })).json()) as Record<string, any>; | |
| 71 | expect(traced.trace.joints.shoulder_pan.actual).toEqual([1, 1.5]); | |
| 68 | 72 | expect((await fetch(`${base}/data?turn=${id}`)).status).toBe(403); |
| 69 | 73 | }); |
| 70 | 74 |
Software/so101/src/data-api.ts +3 −2
| @@ -2,7 +2,8 @@ | ||
| 2 | 2 | * GET /data: the Data view's one read, for the owner and moderators (anyone else: 403). |
| 3 | 3 | * ?from=<ms>&to=<ms>&step=<s>[&compare=1] the series over the range, per step (src/data-series.ts); compare=1 adds |
| 4 | 4 | * `previous`, the same length of time just before, on the same steps |
| 5 | * ?turn=<id> one turn: its row, and the events and samples from a minute before to a minute after | |
| 5 | * ?turn=<id> one turn: its row, and the events and samples from a minute before to a minute after, and `trace` (the arm's stored joint | |
| 6 | * intent and read-back, or null) | |
| 6 | 7 | * Every parameter is checked here; a bad one is a 400 that says what to send. |
| 7 | 8 | */ |
| 8 | 9 | |
| @@ -35,7 +36,7 @@ export function serveData(facts: Facts | undefined, lobby: Lobby | undefined, re | ||
| 35 | 36 | if (!row) return answer(res, 404, { error: "no such turn" }); |
| 36 | 37 | const start = Date.parse(row.startedAt); |
| 37 | 38 | const [from, to] = [start - MINUTE, start + row.seconds * 1000 + MINUTE]; |
| 38 | return answer(res, 200, { turn: row, events: facts.events(from, to).filter((e) => ARM_EVENTS.has(e.kind)).map(({ who: _who, ...e }) => e), samples: facts.samples(from, to) }, head); | |
| 39 | return answer(res, 200, { turn: row, events: facts.events(from, to).filter((e) => ARM_EVENTS.has(e.kind)).map(({ who: _who, ...e }) => e), samples: facts.samples(from, to), trace: facts.traceFor(row.id) }, head); | |
| 39 | 40 | } |
| 40 | 41 | const range = parseRange(url.searchParams, now); |
| 41 | 42 | if ("error" in range) return answer(res, 400, range); |
Software/so101/src/data-page.test.ts +1 −1
| @@ -71,7 +71,7 @@ test("/admin links to it, and the page reads only what GET /data answers", async | ||
| 71 | 71 | |
| 72 | 72 | const body = (await (await fetch(`${base}/data`, { headers: owner })).json()) as Record<string, unknown>; |
| 73 | 73 | // besides the series: what ?turn=<id> answers, and the error of a refusal |
| 74 | const turnAnswer = ["turn", "events", "samples", "error"]; | |
| 74 | const turnAnswer = ["turn", "events", "samples", "trace", "error"]; | |
| 75 | 75 | const read = new Set([...DATA_SCRIPT.matchAll(/\bd\.(\w+)/g)].map((m) => m[1]!)); |
| 76 | 76 | for (const key of read) expect([...Object.keys(body), ...turnAnswer]).toContain(key); |
| 77 | 77 | // `s` is the series in the drawing functions, and a chart's own line in timeChart: its keys are left out |
Software/so101/src/data-page.ts +5
| @@ -98,6 +98,11 @@ dialog .close { float: right; } | ||
| 98 | 98 | .turnbar { fill: var(--accent); opacity: .3; } |
| 99 | 99 | .mark { stroke: var(--dim); stroke-width: 2; } |
| 100 | 100 | .mark.stop { stroke: var(--c4); } .mark.jam { stroke: var(--c3); } .mark.block { stroke: var(--c5); } .mark.reconnect { stroke: var(--c2); } .mark.app-start { stroke: var(--c6); } |
| 101 | .jt { display: block; max-width: 100%; height: auto; touch-action: pan-y; } | |
| 102 | .jt .intent { fill: none; stroke: var(--dim); stroke-width: 1.5; stroke-dasharray: 4 3; } | |
| 103 | .jt .actual { fill: none; stroke: var(--c0); stroke-width: 1.5; } | |
| 104 | .jt .cursor { stroke: var(--fg); stroke-width: 1; } | |
| 105 | .readout { margin: 0 0 .5rem; font-size: .8rem; color: var(--dim); min-height: 1.1em; } | |
| 101 | 106 | .events { margin: 0; padding-left: 1.1rem; font-size: .85rem; } |
| 102 | 107 | @media (orientation: landscape) and (min-width: 560px) { |
| 103 | 108 | .strip { grid-auto-flow: row; grid-template-columns: repeat(auto-fit, minmax(9.5rem, 1fr)); grid-auto-columns: auto; overflow: visible; } |
Software/so101/src/data-view.test.ts +13
| @@ -128,6 +128,8 @@ test("the script draws every chart from a real answer, opens a worst session, an | ||
| 128 | 128 | const id = facts.turn({ kind: "turn", ended: { who: ada, reason: "taken over by the owner" }, started: null }, snapshot)!; |
| 129 | 129 | facts.card(id, { releases: 8, snapBacks: { jam: 2 }, jams: 2, arriveP95Ms: 640 }); |
| 130 | 130 | |
| 131 | const t0 = Date.now() - 1000; | |
| 132 | facts.trace(id, { session: 1, t0, hz: 5, joints: { elbow: { intent: [0, 1, 2, 3], actual: [0, 0.5, 1.5, 2.5] } } }); | |
| 131 | 133 | const { document, byId, tbody, ranges, body } = dom(); |
| 132 | 134 | const asked: string[] = []; |
| 133 | 135 | const fetchAs = (url: string) => { |
| @@ -168,6 +170,17 @@ test("the script draws every chart from a real answer, opens a worst session, an | ||
| 168 | 170 | expect(asked).toContain(`/data?turn=${id}`); |
| 169 | 171 | expect(byId.get("turn-body")!.all((n) => n.classes.has("mark")).map((n) => [...n.classes].join(" "))).toEqual(expect.arrayContaining(["mark app-start", "mark jam"])); |
| 170 | 172 | |
| 173 | const joint = byId.get("turn-body")!.all((n) => n.classes.has("jt"))[0]!; | |
| 174 | expect(byId.get("turn-body")!.textContent).toContain("elbow"); | |
| 175 | joint.fire("pointerdown", { clientX: 600 }); | |
| 176 | expect(byId.get("turn-body")!.textContent).toContain("intent 3 · actual 2.50"); | |
| 177 | ||
| 178 | joint.fire("keydown", { key: "Home" }); | |
| 179 | expect(byId.get("turn-body")!.textContent).toContain("intent 0 · actual 0"); | |
| 180 | joint.fire("keydown", { key: "ArrowRight" }); | |
| 181 | expect(byId.get("turn-body")!.textContent).toContain("intent 1 · actual 0.50"); | |
| 182 | expect(joint.getAttribute("tabindex")).toBe("0"); | |
| 183 | ||
| 171 | 184 | // a tap shows exact values, and the finger lifting (which also leaves) does not hide them |
| 172 | 185 | const fig = byId.get("c-room")!.children[0]!; |
| 173 | 186 | const svg = fig.children[0]!; |
Software/so101/src/ui/data-view.js +55
| @@ -389,6 +389,55 @@ | ||
| 389 | 389 | /** An event's kind as a class name: "app start" is app-start, STOP is stop. */ |
| 390 | 390 | const markOf = (kind) => String(kind).toLowerCase().replace(/[^a-z]+/g, "-"); |
| 391 | 391 | |
| 392 | /** One joint: intent and actual on the trace's clock, the turn's events marked, exact values under a finger or pointer. */ | |
| 393 | let joints = 0; | |
| 394 | function jointChart(box, name, j, t0, hz, events) { | |
| 395 | const n = j.actual.length, intent = Array.isArray(j.intent) ? j.intent : []; | |
| 396 | const all = j.actual.concat(intent).filter(finite); | |
| 397 | let lo = Math.min(...all), hi = Math.max(...all); | |
| 398 | if (hi === lo) (lo -= 1), (hi += 1); | |
| 399 | const W = width(box), H = 70, tEnd = t0 + ((n - 1) * 1000) / hz; | |
| 400 | const x = (at) => L + ((at - t0) / (tEnd - t0)) * (W - L - R); | |
| 401 | const y = (v) => H - 4 - ((v - lo) / (hi - lo)) * (H - 8); | |
| 402 | const wrap = html("div", null, null, box); | |
| 403 | const readout = html("p", "readout", name, wrap); | |
| 404 | const rid = `readout-${++joints}`; | |
| 405 | readout.id = rid; | |
| 406 | readout.setAttribute("aria-live", "polite"); | |
| 407 | const root = svg("svg", { viewBox: `0 0 ${W} ${H}`, width: W, height: H, class: "jt", role: "img", tabindex: "0", "aria-label": `${name}: intent against actual; arrow keys step through the samples`, "aria-describedby": rid }, wrap); | |
| 408 | const path = (v) => v.map((p, i) => (finite(p) ? `${x(t0 + (i * 1000) / hz).toFixed(1)},${y(p).toFixed(1)}` : null)).filter(Boolean).join(" "); | |
| 409 | svg("polyline", { points: path(intent), class: "intent" }, root); | |
| 410 | svg("polyline", { points: path(j.actual), class: "actual" }, root); | |
| 411 | for (const e of events) { | |
| 412 | if (e.at < t0 || e.at > tEnd) continue; | |
| 413 | const m = svg("line", { x1: x(e.at), x2: x(e.at), y1: 0, y2: H, class: `mark ${markOf(e.kind)}` }, root); | |
| 414 | svg("title", {}, m).textContent = `${e.kind} at ${new Date(e.at).toLocaleTimeString()}`; | |
| 415 | } | |
| 416 | const cursor = svg("line", { x1: 0, x2: 0, y1: 0, y2: H, class: "cursor", visibility: "hidden" }, root); | |
| 417 | let at = n - 1; | |
| 418 | const put = (i) => { | |
| 419 | at = Math.max(0, Math.min(n - 1, i)); | |
| 420 | const cx = x(t0 + (at * 1000) / hz); | |
| 421 | cursor.setAttribute("x1", cx); | |
| 422 | cursor.setAttribute("x2", cx); | |
| 423 | cursor.setAttribute("visibility", "visible"); | |
| 424 | readout.textContent = `${name} · ${new Date(t0 + (at * 1000) / hz).toLocaleTimeString()} · intent ${fmt(intent[at])} · actual ${fmt(j.actual[at])}`; | |
| 425 | }; | |
| 426 | const show = (ev) => { | |
| 427 | const r = root.getBoundingClientRect(); | |
| 428 | const px = ((ev.clientX - r.left) / (r.width || W)) * W; | |
| 429 | put(Math.round(((px - L) / (W - L - R)) * (n - 1))); | |
| 430 | }; | |
| 431 | root.addEventListener("pointermove", show); | |
| 432 | root.addEventListener("pointerdown", show); | |
| 433 | root.addEventListener("keydown", (ev) => { | |
| 434 | const to = ev.key === "ArrowLeft" ? at - 1 : ev.key === "ArrowRight" ? at + 1 : ev.key === "Home" ? 0 : ev.key === "End" ? n - 1 : null; | |
| 435 | if (to === null) return; | |
| 436 | if (ev.preventDefault) ev.preventDefault(); | |
| 437 | put(to); | |
| 438 | }); | |
| 439 | } | |
| 440 | ||
| 392 | 441 | async function turn(id) { |
| 393 | 442 | const dialog = $("#turn"); |
| 394 | 443 | const body = $("#turn-body"); |
| @@ -432,6 +481,12 @@ | ||
| 432 | 481 | const list = html("ul", "events", null, body); |
| 433 | 482 | if (!d.events.length) html("li", "empty", "No STOP, jam, block, reconnect or app start.", list); |
| 434 | 483 | for (const e of d.events) html("li", null, `${new Date(e.at).toLocaleTimeString()} · ${e.kind}${e.at >= start && e.at <= start + ms ? "" : " (outside the turn)"}`, list); |
| 484 | const tr = d.trace; | |
| 485 | const names = tr && tr.joints && typeof tr.joints === "object" ? Object.keys(tr.joints).filter((k) => tr.joints[k] && Array.isArray(tr.joints[k].actual) && tr.joints[k].actual.length > 1) : []; | |
| 486 | if (names.length && finite(tr.t0) && tr.hz > 0) { | |
| 487 | html("h3", null, "Joints · intent (dashed) against actual", body); | |
| 488 | for (const name of names) jointChart(body, name, tr.joints[name], tr.t0, tr.hz, d.events); | |
| 489 | } | |
| 435 | 490 | const seen = d.samples.filter((m) => m.at >= start && m.at < start + ms); |
| 436 | 491 | if (seen.length) { |
| 437 | 492 | html("h3", null, "The room each minute", body); |
new above
offline
Only pointermove and pointerdown are wired. A keyboard or screen-reader user gets no values. Add tabindex=0 plus a keydown handler for the arrow keys, and make the readout a live region.