Archilyzer · Source

archilyzer

Archilyzer
git clone https://archilyzer.pages.dev/source/archilyzer.git
Log | Files | Refs | README | LICENSE

commit 3eb74e3bad96120b1f0457c6b5e23499da1a4b94
parent b4b066f36f2e4bc106a60818d98b6348535c3662
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date:   Thu, 12 Nov 2026 20:45:39 -0500

umtool: the analysis item -- its plan, its page and its module (render path, part 1)

analysis-plan.mjs: a `{type: "analysis"}` entry's plan from the ledger -- the
series' points (a delta against the run's start, runStartAt), the line and the
axes (trail-plan's trailLine/trailLayout), the band, the marks, the pace rows
(pounds and days computed; a bound end makes the row a bound, over or under in
the right direction), the status rows, the length (the audio's span, else 7 s,
at most 8) -- and every refusal and warning naming its row.
chrome-analysis.mjs: the page (cueList/pageHtml) -- calm: the line draws, the
rows land; a bound point hollow and its stretches dotted; with audio the
clip's citation and its QR. modules/analysis.mjs: the segment module.
compose-chrome passes a `context` to a module's page (the build's metadata).

Co-Authored-By: Claude <noreply@anthropic.com>

Diffstat:
Aumtool/report-to-video/analysis-plan.mjs | 427+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Aumtool/report-to-video/analysis-plan.test.mjs | 187+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Aumtool/report-to-video/chrome-analysis.mjs | 242+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Aumtool/report-to-video/chrome-analysis.test.mjs | 100+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mumtool/report-to-video/chrome-instruments.mjs | 4++--
Mumtool/report-to-video/compose-chrome.mjs | 12++++++++----
Aumtool/report-to-video/modules/analysis.mjs | 86+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mumtool/report-to-video/modules/index.mjs | 3++-
8 files changed, 1054 insertions(+), 7 deletions(-)

diff --git a/umtool/report-to-video/analysis-plan.mjs b/umtool/report-to-video/analysis-plan.mjs @@ -0,0 +1,427 @@ +// THE ANALYSIS ITEM'S PLAN (lane analysis-ending, 12 Nov): an ending built +// from the ledger, not from a clip -- a chart of a named run of his weights +// with a shaded band, a pace table, a status row and ONE reading line, +// inserted into the cut as a timeline entry of its own: +// +// { "type": "analysis", "id": "an1", "title": "What his own numbers say", +// "kicker": "THE KETO RUN · EVERY WEIGHT HE STATED", +// "series": { "rows": ["w91", "w87", …] } // or { "from": "<date|row>", "to": "<date|row>" } +// "band": { "from": "2026-10-23", "to": "2026-11-03", "label": "WORLD SERIES" }, +// "marks": [{ "row": "w118", "label": "offers the scale video", "quote": "…" }], +// "pace": [{ "from": "2026-09-24", "to": "2026-10-15", "note": "…" }], +// "status": [{ "label": "SCALE VIDEO", "value": "NOT POSTED", "note": "offered 23 Oct", "color": "red", "row": "p01" }], +// "reading": "…", "footnote": "…", "mark": 300, +// "audio": { "clip": "c46", "start": 4112.6, "end": 4127.1 }, // optional +// "seconds": 7 } // without audio; at most 8 +// +// DATA, NOT DRAWING. Every figure on screen is computed here from a ledger +// row and carries that row's id: a point's weight (a `delta` resolved against +// the run's start, measure-slice.mjs runStartAt -- the base a loss goal reads), +// a mark's figure and date, a pace row's pounds and days. Nothing typed is a +// number the item draws (a label or note with a digit is a lint warning; a +// status figure names its row). A row the ledger lacks refuses the item. +// +// A BOUND IS NEVER AN EXACT FIGURE. A point whose row is a bound ("< 300") is +// drawn hollow (as the trail draws a qualified weight) with its glyph; a pace +// row that ends on one is a bound too, in the right direction on each side: +// ending on "< 300" the loss is OVER the figure, starting on it UNDER it. +// +// PURE: the entry, the ledger, the schema and the timeline in, plain data out. +import { dateKey } from "./ledger-shared.mjs"; +import { dayNumber, fmtSigned, fmtWeight } from "./measure-draw.mjs"; +import { isUsable, runStartOf, speakerOf } from "./measure-slice.mjs"; +import { measureQualifier, measureSchema, plotDate } from "./measure-totals.mjs"; +import { playEdges } from "./mute.mjs"; +import { gapsOf } from "./gaps.mjs"; +import { trailLayout, trailLine } from "./trail-plan.mjs"; + +/** The silent item's length: its default and its ceiling (no dead air), and the floor any item has. */ +export const ANALYSIS_SECONDS = Object.freeze({ silent: 7, silentMax: 8, min: 4 }); + +/** How many rows each table holds on the frame. */ +export const ANALYSIS_LIMITS = Object.freeze({ pace: 5, status: 2, marks: 6, rows: 120 }); + +/** The palette roles a status figure may be drawn in (or a #hex). */ +export const ANALYSIS_COLORS = Object.freeze(["accent", "amber", "red", "fg", "muted"]); + +/** The keys an analysis entry may carry. */ +export const ANALYSIS_KEYS = Object.freeze([ + "type", "id", "title", "kicker", "series", "band", "marks", "pace", "status", "reading", "footnote", "mark", "audio", "seconds", + "onscreen", "note", "drafted", +]); + +const isObj = (v) => v !== null && typeof v === "object" && !Array.isArray(v); +const isIso = (v) => typeof v === "string" && /^\d{4}-\d{2}-\d{2}$/.test(v); +const hasDigit = (s) => /\d/.test(String(s ?? "")); +const r2 = (v) => Math.round(v * 100) / 100; +const MON = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]; + +/** "2026-10-23" as "23 Oct". */ +export function dayMonth(iso) { + const m = /^(\d{4})-(\d{2})-(\d{2})/.exec(String(iso ?? "")); + return m ? `${Number(m[3])} ${MON[Number(m[2]) - 1]}` : ""; +} + +/** A span's two dates as the pace table says them: "24 Sep → 15 Oct", one month once: "15 → 23 Oct". */ +export function spanWords(a, b) { + const [da, db] = [dayMonth(a), dayMonth(b)]; + const [na, ma] = da.split(" "); + const [nb, mb] = db.split(" "); + return ma === mb ? `${na} → ${nb} ${mb}` : `${da} → ${db}`; +} + +/** The item's length: the audio's span, else `seconds` (default ANALYSIS_SECONDS.silent). */ +export function analysisSeconds(entry) { + const a = entry?.audio; + if (isObj(a) && Number.isFinite(Number(a.start)) && Number.isFinite(Number(a.end)) && Number(a.end) > Number(a.start)) { + return r2(Number(a.end) - Number(a.start)); + } + const s = Number(entry?.seconds); + return Number.isFinite(s) && s > 0 ? s : ANALYSIS_SECONDS.silent; +} + +/** The ledger a cut's analysis reads: the variant's whole measure record (selectVariant keeps it), else the ledger. */ +export const analysisLedger = (manifest) => (Array.isArray(manifest?.measureLedger) ? manifest.measureLedger : manifest?.ledger ?? []); + +/** + * The bound a pace row's figure is, from its two ends' qualifiers: the true change against the computed one. Ending + * on "< v" (the weight was under v) the change is LESS than computed (more lost); starting on it, MORE (less lost); + * ">" the other way. Both ends bounding opposite ways: no bound can be said ("unknown"). Null: exact. + * + * @returns {null | "lt" | "gt" | "unknown"} + */ +export function paceBound(qa, qb) { + const dirs = []; + if (qa === "<") dirs.push("gt"); + if (qa === ">") dirs.push("lt"); + if (qb === "<") dirs.push("lt"); + if (qb === ">") dirs.push("gt"); + if (!dirs.length) return null; + return dirs.every((d) => d === dirs[0]) ? dirs[0] : "unknown"; +} + +/** + * A pace row's bound as words before its figure, by size: "over" when the change is bigger than the figure says + * (a loss of more than 10.5), "under" when smaller (a loss of less than 8.5, or a gain). Null: exact. + */ +export function boundWord(lb, bound) { + if (!bound) return null; + if (bound === "unknown") return "unknown"; + const bigger = lb < 0 ? bound === "lt" : bound === "gt"; + return bigger ? "over" : "under"; +} + +/** + * Every reason the item cannot be drawn (`errors`) and what is said about it (`warnings`), each naming the entry and + * the row. `ctx`: `{ ledger, schema, timeline, render }` -- the WHOLE ledger (analysisLedger), the ledger's schema, + * the cut's timeline. + */ +export function analysisProblems(entry, ctx) { + return resolve(entry, ctx).problems; +} + +/** + * The plan: the points (each `{ n, row, value, day, date, said, kind, qualifier, bound, base? }`), the line through + * them (trailLine: one point a day, the one said last, in date order), the axes laid in `box` (trailLayout, one + * cluster: `lo`/`hi`, `X`/`Y`, `grid`, `months`), the band, the marks, the pace rows, the status rows, the words, + * the audio and the seconds. Throws the errors (analysisProblems) when there are any. + */ +export function analysisPlan(entry, ctx, box = { x0: 70, x1: 800, y0: 150, y1: 560 }) { + const r = resolve(entry, ctx); + if (r.problems.errors.length) throw new Error(r.problems.errors.join("; ")); + const { points } = r; + const line = trailLine(points); + const mark = Number.isFinite(Number(entry.mark)) && entry.mark !== null && entry.mark !== "" ? Number(entry.mark) : null; + const L = trailLayout(points, box, { thr: Infinity, mark }); + const pos = new Map(points.map((p) => [p.n, { x: L.X(p.day), y: L.Y(p.value) }])); + const step = L.hi - L.lo > 60 ? 20 : 10; + const grid = []; + for (let v = Math.ceil(L.lo / step) * step; v <= L.hi; v += step) if (v !== mark) grid.push({ v, y: L.Y(v) }); + const c = L.clusters[0]; + const months = []; + if (c) { + const d0 = new Date(c.from * 86400000); + let y = d0.getUTCFullYear(), m = d0.getUTCMonth() + 1; + for (;; m += 1) { + if (m > 11) { m = 0; y += 1; } + const day = Date.UTC(y, m, 1) / 86400000; + if (day > c.to) break; + if (day >= c.from) months.push({ day, x: L.X(day), text: m === 0 ? `JAN ${y}` : MON[m].toUpperCase() }); + } + } + const band = r.band ? { ...r.band, x0: L.X(r.band.fromDay), x1: L.X(r.band.toDay) } : null; + const marks = r.marks.map((k) => ({ ...k, at: pos.get(k.n) })); + return { + title: String(entry.title ?? "").trim(), + kicker: String(entry.kicker ?? "").trim(), + reading: String(entry.reading ?? "").trim(), + footnote: String(entry.footnote ?? "").trim(), + points, line: line.map((p) => p.n), pos, layout: { lo: L.lo, hi: L.hi, X: L.X, Y: L.Y, grid, months, mark, markY: mark !== null ? L.Y(mark) : null }, + band, marks, pace: r.pace, status: r.status, audio: r.audio, seconds: analysisSeconds(entry), + first: points.length ? line[0] : null, last: points.length ? line[line.length - 1] : null, + }; +} + +/** The figures the plan draws, one line each with its row -- what `--dry-run` prints. */ +export function analysisFigures(plan) { + const out = []; + for (const p of plan.points) { + out.push(`point ${p.row}: ${p.qualifier ?? ""}${fmtWeight(p.value)} on ${p.date}${p.base ? ` (${p.raw} from ${p.base.row} ${fmtWeight(p.base.value)})` : ""}${p.bound ? " -- a bound, drawn hollow" : ""}`); + } + if (plan.band) out.push(`band ${plan.band.from} → ${plan.band.to} "${plan.band.label}"`); + plan.pace.forEach((x, i) => out.push( + `pace[${i}] ${x.span}: ${x.word ? `${x.word} ` : ""}${x.text} (${x.from.row} ${fmtWeight(x.from.value)} → ${x.to.row} ${fmtWeight(x.to.value)}), ${x.days} days${x.boundRows.length ? ` -- a bound: ${x.boundRows.join(", ")}` : ""}`, + )); + plan.marks.forEach((k, i) => out.push(`marks[${i}] ${k.row}: ${k.text}`)); + plan.status.forEach((s, i) => out.push(`status[${i}] ${s.label}: ${s.value}${s.note ? ` · ${s.note}` : ""}${s.row ? ` (${s.row})` : ""}`)); + if (plan.audio) out.push(`audio ${plan.audio.clip} ${plan.audio.start}–${plan.audio.end} (${plan.seconds} s)`); + else out.push(`silent, ${plan.seconds} s`); + return out; +} + +// --------------------------------------------------------------------------- + +function resolve(entry, { ledger = [], schema = null, timeline = [], render = {} } = {}) { + const errors = []; + const warnings = []; + const id = entry?.id ?? "?"; + const at = `timeline ${id} (analysis)`; + const out = { problems: { errors, warnings }, points: [], band: null, marks: [], pace: [], status: [], audio: null }; + if (!isObj(entry)) { errors.push(`${at}: not an object`); return out; } + for (const k of Object.keys(entry)) if (!ANALYSIS_KEYS.includes(k)) errors.push(`${at}: unknown key "${k}"`); + if (!String(entry.title ?? "").trim()) errors.push(`${at}: title is empty`); + if (typeof entry.reading !== "string" || !entry.reading.trim()) errors.push(`${at}: reading is empty -- the item says ONE reading`); + if (render && (Number(render.height) > Number(render.width) || render.format === "vertical")) { + errors.push(`${at}: an analysis item has no vertical form -- a 9:16 cut cannot carry it`); + } + + const s = measureSchema(schema ?? {}); + const valueTrack = s.tracks.find((t) => t.role === "value")?.key ?? null; + const rows = (ledger ?? []).filter((r) => isObj(r) && typeof r.id === "string"); + const byId = new Map(rows.map((r) => [r.id, r])); + const order = new Map(rows.map((r, i) => [r.id, i])); + + // ---- the series ---------------------------------------------------------- + const series = entry.series; + const weightRow = (r) => r.scope === valueTrack && ["current", "past", "delta"].includes(r.population); + let picked = []; + if (isObj(series) && Array.isArray(series.rows)) { + if (!series.rows.length) errors.push(`${at}: series.rows is empty`); + if (series.rows.length > ANALYSIS_LIMITS.rows) errors.push(`${at}: series.rows has ${series.rows.length} rows (at most ${ANALYSIS_LIMITS.rows})`); + const seen = new Set(); + for (const rid of series.rows) { + const r = byId.get(String(rid)); + if (!r) { errors.push(`${at}: series row ${rid} is not in the ledger`); continue; } + if (seen.has(r.id)) { errors.push(`${at}: series row ${rid} is named twice`); continue; } + seen.add(r.id); + if (!weightRow(r)) { errors.push(`${at}: series row ${rid} is not a weight (${r.scope}/${r.population}) -- a series is current, past or delta rows of the ${valueTrack ?? "value"} track`); continue; } + if (speakerOf(r) !== null) { errors.push(`${at}: series row ${rid} is ${speakerOf(r)}'s, not his`); continue; } + if (!isUsable(r)) warnings.push(`${at}: series row ${rid} is unresolved -- in no tally, drawn because the item names it`); + picked.push(r); + } + } else if (isObj(series) && (series.from !== undefined || series.to !== undefined)) { + const a = endDay(series.from, byId), b = endDay(series.to, byId); + if (!a.ok) errors.push(`${at}: series.from ${a.why}`); + if (!b.ok) errors.push(`${at}: series.to ${b.why}`); + if (a.ok && b.ok) { + if (b.day < a.day) errors.push(`${at}: series.to (${b.date}) is before series.from (${a.date})`); + picked = rows.filter((r) => weightRow(r) && speakerOf(r) === null && isUsable(r) && Number.isFinite(Number(r.value)) && + dayNumber(plotDate(r)) >= a.day && dayNumber(plotDate(r)) <= b.day); + if (!picked.length) errors.push(`${at}: no weight of his between ${a.date} and ${b.date}`); + } + } else errors.push(`${at}: series is { rows: [ids] } or { from, to }`); + + const points = []; + for (const r of picked) { + const raw = Number(r.value); + if (r.value === null || r.value === "" || !Number.isFinite(raw)) { errors.push(`${at}: series row ${r.id} has no number`); continue; } + const date = dateKey(plotDate(r)); + const day = dayNumber(date); + if (!Number.isFinite(day)) { errors.push(`${at}: series row ${r.id} has no date`); continue; } + const q = measureQualifier(r, s); + let value = raw; + let base = null; + if (r.population === "delta") { + base = runStartOf(rows, schema, r.date); + if (!base) { errors.push(`${at}: series row ${r.id} is a delta (${raw}) with no run start in the record to resolve it against`); continue; } + value = r2(base.value + raw); + } + points.push({ + row: r.id, value, raw, day, date, said: r.date ?? date, population: r.population, + kind: r.population === "past" ? "remembered" : r.population === "delta" ? "delta" : "stated", + qualifier: q, bound: q === "<" || q === ">", ...(base ? { base: { row: base.row, value: base.value } } : {}), + }); + } + // `t` is the order he SAID them (date, then the ledger's order): of two weights for one day the line takes the later. + points.sort((p, q) => dateKey(p.said).localeCompare(dateKey(q.said)) || order.get(p.row) - order.get(q.row)); + points.forEach((p, i) => { p.t = i; p.n = i; }); + out.points = points; + const firstDay = points.length ? Math.min(...points.map((p) => p.day)) : NaN; + const lastDay = points.length ? Math.max(...points.map((p) => p.day)) : NaN; + const pointOf = (v) => { + if (typeof v !== "string" || !v.trim()) return { ok: false, why: "is missing" }; + if (isIso(v)) { + const on = points.filter((p) => p.day === dayNumber(v)); + if (!on.length) return { ok: false, why: `${v}: no point of the series on that day` }; + return { ok: true, p: on.reduce((a, b) => (b.t > a.t ? b : a)) }; + } + const p = points.find((x) => x.row === v); + if (p) return { ok: true, p }; + return { ok: false, why: byId.has(v) ? `${v} is not a point of the series` : `${v} is not in the ledger` }; + }; + + // ---- the band ------------------------------------------------------------ + if (entry.band !== undefined && entry.band !== null) { + const b = entry.band; + if (!isObj(b)) errors.push(`${at}: band is { from, to, label }`); + else { + const a = endDay(b.from, byId), z = endDay(b.to, byId); + if (!a.ok) errors.push(`${at}: band.from ${a.why}`); + if (!z.ok) errors.push(`${at}: band.to ${z.why}`); + if (a.ok && z.ok) { + if (z.day < a.day) errors.push(`${at}: band.to (${z.date}) is before band.from (${a.date})`); + else if (points.length && (a.day < firstDay || z.day > lastDay)) { + errors.push(`${at}: band ${a.date} → ${z.date} is outside the series (${isoOf(firstDay)} → ${isoOf(lastDay)})`); + } else out.band = { from: a.date, to: z.date, fromDay: a.day, toDay: z.day, label: String(b.label ?? "").trim() }; + } + if (hasDigit(b.label) && !/\b(19|20)\d\d\b/.test(String(b.label))) warnings.push(`${at}: band.label "${b.label}" has a number -- the item draws figures from rows`); + } + } + + // ---- the marks ----------------------------------------------------------- + const marks = Array.isArray(entry.marks) ? entry.marks : entry.marks === undefined ? [] : null; + if (marks === null) errors.push(`${at}: marks is a list`); + else { + if (marks.length > ANALYSIS_LIMITS.marks) errors.push(`${at}: ${marks.length} marks (at most ${ANALYSIS_LIMITS.marks})`); + marks.forEach((m, i) => { + if (!isObj(m)) { errors.push(`${at}: marks[${i}] is { row, label, quote? }`); return; } + const f = pointOf(String(m.row ?? "")); + if (!f.ok) { errors.push(`${at}: marks[${i}].row ${f.why}`); return; } + const label = String(m.label ?? "").trim(); + if (hasDigit(label)) warnings.push(`${at}: marks[${i}].label "${label}" has a number -- the mark's figure and date are drawn from ${f.p.row}`); + const quote = typeof m.quote === "string" ? m.quote.trim() : ""; + const rowQuote = String(byId.get(f.p.row)?.quote ?? ""); + if (quote && rowQuote && !quoteIn(quote, rowQuote)) warnings.push(`${at}: marks[${i}].quote is not in ${f.p.row}'s quote -- say whose words they are`); + const fig = `${f.p.qualifier === "<" || f.p.qualifier === ">" || f.p.qualifier === "≈" ? `${f.p.qualifier} ` : ""}${fmtWeight(f.p.value)}`; + out.marks.push({ i, row: f.p.row, n: f.p.n, label, quote, text: `${fig} · ${dayMonth(f.p.date)}${label ? ` · ${label}` : ""}` }); + }); + } + + // ---- the pace ------------------------------------------------------------ + const pace = Array.isArray(entry.pace) ? entry.pace : entry.pace === undefined ? [] : null; + if (pace === null) errors.push(`${at}: pace is a list`); + else { + if (pace.length > ANALYSIS_LIMITS.pace) errors.push(`${at}: ${pace.length} pace rows (at most ${ANALYSIS_LIMITS.pace})`); + pace.forEach((x, i) => { + if (!isObj(x)) { errors.push(`${at}: pace[${i}] is { from, to, note? }`); return; } + const a = pointOf(x.from), b = pointOf(x.to); + if (!a.ok) errors.push(`${at}: pace[${i}].from ${a.why}`); + if (!b.ok) errors.push(`${at}: pace[${i}].to ${b.why}`); + if (!a.ok || !b.ok) return; + const days = b.p.day - a.p.day; + if (days <= 0) { errors.push(`${at}: pace[${i}] ends (${b.p.date}) on or before it starts (${a.p.date})`); return; } + const lb = r2(b.p.value - a.p.value); + const bound = paceBound(a.p.bound ? a.p.qualifier : null, b.p.bound ? b.p.qualifier : null); + const boundRows = [a.p, b.p].filter((p) => p.bound).map((p) => p.row); + const note = String(x.note ?? "").trim(); + if (hasDigit(note)) warnings.push(`${at}: pace[${i}].note "${note}" has a number -- the row's pounds and days are computed`); + if (bound) warnings.push(`${at}: pace[${i}] ends on a bound (${boundRows.map((r) => `${r} ${points.find((p) => p.row === r).qualifier} ${fmtWeight(points.find((p) => p.row === r).value)}`).join(", ")}) -- drawn as ${bound === "unknown" ? "no figure (its bounds go both ways)" : `${boundWord(lb, bound)} ${fmtSigned(lb)} lb`}`); + out.pace.push({ + i, span: spanWords(a.p.date, b.p.date), from: pick(a.p), to: pick(b.p), lb, days, note, + bound, boundRows, word: boundWord(lb, bound), text: bound === "unknown" ? "—" : `${fmtSigned(lb)} lb`, + }); + }); + } + + // ---- the status ---------------------------------------------------------- + const status = Array.isArray(entry.status) ? entry.status : entry.status === undefined ? [] : null; + if (status === null) errors.push(`${at}: status is a list`); + else { + if (status.length > ANALYSIS_LIMITS.status) errors.push(`${at}: ${status.length} status rows (at most ${ANALYSIS_LIMITS.status})`); + status.forEach((x, i) => { + if (!isObj(x)) { errors.push(`${at}: status[${i}] is { label, value, note, color, row? }`); return; } + const color = x.color === undefined || x.color === null || x.color === "" ? "fg" : String(x.color); + if (!ANALYSIS_COLORS.includes(color) && !/^#[0-9a-fA-F]{6}$/.test(color)) errors.push(`${at}: status[${i}].color "${color}" is ${ANALYSIS_COLORS.join(", ")} or a #rrggbb`); + const row = x.row === undefined || x.row === null || x.row === "" ? null : String(x.row); + if (row && !byId.has(row)) errors.push(`${at}: status[${i}].row ${row} is not in the ledger`); + if (!String(x.label ?? "").trim() || !String(x.value ?? "").trim()) errors.push(`${at}: status[${i}] needs a label and a value`); + if (!row && (hasDigit(x.value) || hasDigit(x.note))) warnings.push(`${at}: status[${i}] has a number and no row -- name the row it comes from (row)`); + if (row && hasDigit(x.note) && byId.get(row)?.date && !String(x.note).includes(dayMonth(byId.get(row).date))) { + warnings.push(`${at}: status[${i}].note "${x.note}" does not say ${row}'s date (${dayMonth(byId.get(row).date)})`); + } + out.status.push({ i, label: String(x.label ?? "").trim(), value: String(x.value ?? "").trim(), note: String(x.note ?? "").trim(), color, row }); + }); + } + + // ---- the words and the length ------------------------------------------- + if (hasDigit(entry.reading) && !/\b(19|20)\d\d\b/.test(String(entry.reading))) warnings.push(`${at}: reading has a number -- the item's figures are the chart's and the table's`); + if (entry.mark !== undefined && entry.mark !== null && !Number.isFinite(Number(entry.mark))) errors.push(`${at}: mark is a number (the line across, e.g. 300)`); + const a = entry.audio; + if (a !== undefined && a !== null) { + if (!isObj(a)) errors.push(`${at}: audio is { clip, start, end }`); + else { + const clip = (timeline ?? []).find((e) => e?.id === a.clip) ?? null; + const st = Number(a.start), en = Number(a.end); + if (!clip) errors.push(`${at}: audio.clip ${a.clip ?? "(none)"} is not an entry of the cut`); + else if (clip.type !== "clip") errors.push(`${at}: audio.clip ${a.clip} is a ${clip.type} entry, not a clip`); + if (!Number.isFinite(st) || !Number.isFinite(en) || en <= st) errors.push(`${at}: audio.start and audio.end are source seconds, end after start`); + else if (clip?.type === "clip") { + if (st < Number(clip.start) - 1e-6 || en > Number(clip.end) + 1e-6) { + errors.push(`${at}: audio ${st}–${en} is outside ${clip.id}'s window ${clip.start}–${clip.end}`); + } else { + out.audio = { clip: clip.id, start: st, end: en, video: clip.video ?? null }; + const heard = playedSpans(clip, render).filter((g) => g.from < en && g.to > st); + if (heard.length) { + const o = heard.map((g) => `${r2(Math.max(st, g.from))}–${r2(Math.min(en, g.to))}`).join(", "); + warnings.push(`${at}: the audio's span plays in the cut too (${clip.id} plays ${o}): its words are heard twice`); + } + } + } + if (entry.seconds !== undefined && Number(entry.seconds) !== analysisSeconds(entry)) { + warnings.push(`${at}: seconds is the audio's length (${analysisSeconds(entry)}) -- the ${entry.seconds} is not read`); + } + } + } else { + const secs = analysisSeconds(entry); + if (entry.seconds !== undefined && !(Number(entry.seconds) > 0)) errors.push(`${at}: seconds is a number of seconds`); + else if (secs > ANALYSIS_SECONDS.silentMax) errors.push(`${at}: held ${secs} s with no audio (at most ${ANALYSIS_SECONDS.silentMax}: no dead air) -- shorten it or give it audio from a clip`); + } + if (analysisSeconds(entry) < ANALYSIS_SECONDS.min) errors.push(`${at}: ${analysisSeconds(entry)} s is too short to read (at least ${ANALYSIS_SECONDS.min})`); + return out; +} + +const pick = (p) => ({ row: p.row, date: p.date, value: p.value, qualifier: p.qualifier }); +const isoOf = (day) => new Date(day * 86400000).toISOString().slice(0, 10); + +/** A date or a row id as a day: `{ ok, day, date }` or `{ ok: false, why }`. */ +function endDay(v, byId) { + if (typeof v !== "string" || !v.trim()) return { ok: false, why: "is missing" }; + if (isIso(v)) return { ok: true, day: dayNumber(v), date: v }; + const r = byId.get(v); + if (!r) return { ok: false, why: `${v} is not a date or a row of the ledger` }; + const d = dateKey(plotDate(r)); + return Number.isFinite(dayNumber(d)) ? { ok: true, day: dayNumber(d), date: d } : { ok: false, why: `${v} has no date` }; +} + +/** The source spans a clip plays in the cut: its play window less its gaps. */ +function playedSpans(clip, render) { + const { from, to } = playEdges(clip, render); + if (!Number.isFinite(from) || !Number.isFinite(to)) return []; + const gaps = [...gapsOf(clip)].sort((x, y) => x.from - y.from); + const out = []; + let at = from; + for (const g of gaps) { + if (g.to <= at || g.from >= to) continue; + if (g.from > at) out.push({ from: at, to: g.from }); + at = Math.max(at, g.to); + } + if (at < to) out.push({ from: at, to }); + return out; +} + +const norm = (s) => String(s).toLowerCase().replace(/[’']/g, "'").replace(/[^a-z0-9' ]+/g, " ").replace(/\s+/g, " ").trim(); +/** Each part of a quote (split at an ellipsis) found in the row's words. */ +function quoteIn(quote, words) { + const w = norm(words); + return quote.split(/…|\.\.\./).map(norm).filter(Boolean).every((part) => w.includes(part)); +} diff --git a/umtool/report-to-video/analysis-plan.test.mjs b/umtool/report-to-video/analysis-plan.test.mjs @@ -0,0 +1,187 @@ +// The analysis item's plan (analysis-plan.mjs): every figure from a ledger row, deltas against the run's start, bounds +// never exact (in the right direction on both sides of a pace row), and the refusals the lint names. +import { test } from "node:test"; +import assert from "node:assert/strict"; + +import { + analysisFigures, analysisPlan, analysisProblems, analysisSeconds, boundWord, dayMonth, paceBound, spanWords, +} from "./analysis-plan.mjs"; + +// The first use's shape (quartering-diet, 12 Nov): ids, dates and values only -- no quotes. +const SCHEMA = { + kind: "measure", unit: "lb", bandGapDays: 60, forms: ["current", "past", "delta", "goal", "goal_loss"], + tracks: [{ key: "weight", role: "value", label: "Weight" }], + fields: [{ key: "qualifier", label: "Bound", kind: "enum", options: [">", "<", "≈"], render: "cell" }], +}; +const W = (id, population, date, value, extra = {}) => ({ id, scope: "weight", population, date, value, ...extra }); +const LEDGER = [ + W("w81", "delta", "2026-07-21", -40, { retro: true }), + W("w83", "delta", "2026-07-23", -5), + W("w87", "current", "2026-07-31", 338), + W("w91", "past", "2026-08-03", 349, { asOf: "2026-07-19" }), + W("w93", "current", "2026-08-03", 335.5), + W("w104", "delta", "2026-09-04", -31.5), + W("w110", "current", "2026-09-24", 310.5), + W("w115", "current", "2026-10-15", 300, { qualifier: "<" }), + W("w117", "current", "2026-10-23", 291), + W("w118", "current", "2026-10-26", 291.5, { asOf: "2026-10-23" }), + W("w122", "delta", "2026-11-03", -58.2), + W("w137", "current", "2026-11-07", 288.5), + W("x1", "current", "2026-10-01", 250, { speaker: "madamsavvy" }), + { id: "p01", scope: "promise", population: "promise", date: "2026-10-23" }, +]; +const TIMELINE = [ + { type: "clip", id: "c46", video: "v1", start: 4111.4, end: 4158.8, cutStart: 4112.6, cutEnd: 4158.5, gaps: [{ from: 4127.15, to: 4132.45 }] }, + { type: "card", id: "k1", seconds: 4 }, +]; +const CTX = { ledger: LEDGER, schema: SCHEMA, timeline: TIMELINE, render: { width: 1920, height: 1080, fps: 30 } }; +const ITEM = { + type: "analysis", id: "an1", title: "What his own numbers say", kicker: "THE RUN", + series: { rows: ["w91", "w87", "w93", "w104", "w110", "w115", "w118", "w122", "w137"] }, + band: { from: "2026-10-23", to: "2026-11-03", label: "WORLD SERIES" }, + marks: [{ row: "w118", label: "offers the scale video" }, { row: "w115", label: "" }], + pace: [{ from: "2026-09-24", to: "2026-10-15" }, { from: "2026-10-15", to: "2026-10-23" }, { from: "2026-10-23", to: "2026-11-03", note: "the World Series" }, { from: "w122", to: "w137" }], + status: [{ label: "SCALE VIDEO", value: "NOT POSTED", note: "offered 23 Oct", color: "red", row: "p01" }], + reading: "By his own numbers the loss is steady.", footnote: "All figures are his own statements.", mark: 300, +}; +const errorsOf = (e, ctx = CTX) => analysisProblems(e, ctx).errors; +const warningsOf = (e, ctx = CTX) => analysisProblems(e, ctx).warnings; + +test("every point is its row's weight at its plot date; a delta is the run's start plus it, naming the start", () => { + const plan = analysisPlan(ITEM, CTX); + const by = Object.fromEntries(plan.points.map((p) => [p.row, p])); + assert.equal(by.w91.value, 349); + assert.equal(by.w91.date, "2026-07-19"); + assert.equal(by.w118.date, "2026-10-23"); + assert.equal(by.w104.value, 317.5); + assert.deepEqual(by.w104.base, { row: "w91", value: 349 }); + assert.equal(by.w122.value, 290.8); + assert.deepEqual(by.w122.base, { row: "w91", value: 349 }); + assert.equal(by.w115.bound, true); + assert.equal(by.w115.qualifier, "<"); + // The line runs in date order: w91 (19 Jul) first. + assert.equal(plan.points[plan.line[0]].row, "w91"); + assert.equal(plan.points[plan.line.at(-1)].row, "w137"); +}); + +test("pace rows: pounds and days computed, never typed; a date names the point that day", () => { + const { pace } = analysisPlan(ITEM, CTX); + assert.deepEqual(pace.map((x) => [x.from.row, x.to.row, x.lb, x.days]), [ + ["w110", "w115", -10.5, 21], ["w115", "w118", -8.5, 8], ["w118", "w122", -0.7, 11], ["w122", "w137", -2.3, 4], + ]); + assert.equal(pace[0].span, "24 Sep → 15 Oct"); + assert.equal(pace[1].span, "15 → 23 Oct"); + assert.equal(pace[2].text, "−0.7 lb"); + assert.equal(pace[2].bound, null); +}); + +test("a bound end is a bound in the right direction: ending on < 300 the loss is OVER, starting on it UNDER", () => { + const { pace } = analysisPlan(ITEM, CTX); + assert.equal(pace[0].bound, "lt"); + assert.equal(pace[0].word, "over"); + assert.deepEqual(pace[0].boundRows, ["w115"]); + assert.equal(pace[1].bound, "gt"); + assert.equal(pace[1].word, "under"); + // And the other glyph: ending on "> v" the change is more than computed (less lost); starting on it, more lost. + assert.equal(paceBound(null, ">"), "gt"); + assert.equal(paceBound(">", null), "lt"); + assert.equal(boundWord(-10, paceBound(null, ">")), "under"); + assert.equal(boundWord(-10, paceBound(">", null)), "over"); + // Both ends agreeing: the same bound; bounding opposite ways (both "<", both ">"): no figure can be said. + assert.equal(paceBound("<", ">"), "gt"); + assert.equal(paceBound(">", "<"), "lt"); + assert.equal(paceBound("<", "<"), "unknown"); + assert.equal(paceBound(">", ">"), "unknown"); + assert.equal(paceBound("<", null), "gt"); + // A gain ending on "< v": the true change is smaller -- "under" a gain is the bigger figure's words reversed. + assert.equal(boundWord(4, "lt"), "under"); + assert.equal(boundWord(4, "gt"), "over"); + const w = warningsOf(ITEM); + assert.ok(w.some((x) => /pace\[0\] ends on a bound \(w115 < 300\) -- drawn as over −10\.5 lb/.test(x)), w.join("\n")); + assert.ok(w.some((x) => /pace\[1\] ends on a bound \(w115 < 300\) -- drawn as under −8\.5 lb/.test(x)), w.join("\n")); +}); + +test("--dry-run's figures name every row", () => { + const lines = analysisFigures(analysisPlan(ITEM, CTX)); + assert.ok(lines.includes("point w104: 317.5 on 2026-09-04 (-31.5 from w91 349)"), lines.join("\n")); + assert.ok(lines.includes("point w115: <300 on 2026-10-15 -- a bound, drawn hollow")); + assert.ok(lines.some((l) => l.startsWith("pace[0] 24 Sep → 15 Oct: over −10.5 lb (w110 310.5 → w115 300), 21 days -- a bound: w115"))); + assert.ok(lines.includes("marks[0] w118: 291.5 · 23 Oct · offers the scale video")); + assert.ok(lines.includes("marks[1] w115: < 300 · 15 Oct")); + assert.ok(lines.includes("silent, 7 s")); +}); + +test("series as a span: his own weights between two dates (another speaker's never)", () => { + const plan = analysisPlan({ ...ITEM, series: { from: "2026-09-01", to: "w137" }, pace: [], marks: [], band: null }, CTX); + assert.deepEqual(plan.points.map((p) => p.row).sort(), ["w104", "w110", "w115", "w117", "w118", "w122", "w137"].sort()); + // Two weights for 23 Oct (w117 said that day, w118 said on the 26th of the 23rd): the line takes the one said last. + const onDay = plan.line.map((n) => plan.points[n]).filter((p) => p.date === "2026-10-23"); + assert.deepEqual(onDay.map((p) => p.row), ["w118"]); +}); + +test("refusals, each naming the row", () => { + assert.ok(errorsOf({ ...ITEM, series: { rows: ["w91", "w999"] } }).some((e) => /series row w999 is not in the ledger/.test(e))); + assert.ok(errorsOf({ ...ITEM, series: { rows: ["w91", "p01"] } }).some((e) => /series row p01 is not a weight/.test(e))); + assert.ok(errorsOf({ ...ITEM, series: { rows: ["w91", "x1"] } }).some((e) => /series row x1 is madamsavvy's/.test(e))); + assert.ok(errorsOf({ ...ITEM, band: { from: "2026-07-01", to: "2026-08-01", label: "" } }).some((e) => /band 2026-07-01 → 2026-08-01 is outside the series \(2026-07-19 → 2026-11-07\)/.test(e))); + assert.ok(errorsOf({ ...ITEM, pace: [{ from: "2026-09-24" }] }).some((e) => /pace\[0\]\.to is missing/.test(e))); + assert.ok(errorsOf({ ...ITEM, pace: [{ from: "2026-09-25", to: "w137" }] }).some((e) => /pace\[0\]\.from 2026-09-25: no point of the series on that day/.test(e))); + assert.ok(errorsOf({ ...ITEM, pace: [{ from: "w137", to: "w110" }] }).some((e) => /pace\[0\] ends \(2026-09-24\) on or before it starts/.test(e))); + assert.ok(errorsOf({ ...ITEM, marks: [{ row: "w117" }] }).some((e) => /marks\[0\]\.row w117 is not a point of the series/.test(e))); + assert.ok(errorsOf({ ...ITEM, reading: " " }).some((e) => /reading is empty/.test(e))); + assert.ok(errorsOf({ ...ITEM, status: [{ label: "X", value: "Y", row: "zz" }] }).some((e) => /status\[0\]\.row zz is not in the ledger/.test(e))); + assert.ok(errorsOf({ ...ITEM, status: [{ label: "X", value: "Y", color: "pink" }] }).some((e) => /status\[0\]\.color "pink"/.test(e))); + assert.ok(errorsOf({ ...ITEM, bogus: 1 }).some((e) => /unknown key "bogus"/.test(e))); + // A delta with no run start in the record to resolve it against. + const lone = { ...CTX, ledger: [W("d1", "delta", "2020-01-05", -3), W("s1", "current", "2020-01-01", 200)] }; + assert.ok(errorsOf({ ...ITEM, series: { rows: ["s1", "d1"] }, band: null, pace: [], marks: [], status: [] }, lone).some((e) => /series row d1 is a delta \(-3\) with no run start/.test(e))); + assert.throws(() => analysisPlan({ ...ITEM, series: { rows: ["w999"] } }, CTX), /w999 is not in the ledger/); +}); + +test("audio: the clip must be a clip of the cut, its span inside its window; a span the cut plays is said", () => { + assert.ok(errorsOf({ ...ITEM, audio: { clip: "c99", start: 1, end: 9 } }).some((e) => /audio\.clip c99 is not an entry of the cut/.test(e))); + assert.ok(errorsOf({ ...ITEM, audio: { clip: "k1", start: 1, end: 9 } }).some((e) => /audio\.clip k1 is a card entry, not a clip/.test(e))); + assert.ok(errorsOf({ ...ITEM, audio: { clip: "c46", start: 4100, end: 4120 } }).some((e) => /audio 4100–4120 is outside c46's window 4111\.4–4158\.8/.test(e))); + const ok = { ...ITEM, audio: { clip: "c46", start: 4112.6, end: 4127.1 } }; + assert.deepEqual(errorsOf(ok), []); + assert.equal(analysisSeconds(ok), 14.5); + assert.ok(warningsOf(ok).some((w) => /the audio's span plays in the cut too \(c46 plays 4112\.6–4127\.1\)/.test(w))); + // Inside a gap of the clip: not heard twice. + const inGap = { ...ITEM, audio: { clip: "c46", start: 4127.5, end: 4132 } }; + assert.ok(!warningsOf(inGap).some((w) => /heard twice/.test(w))); +}); + +test("length: silent 7 s by default, at most 8 without audio; no vertical form", () => { + assert.equal(analysisSeconds(ITEM), 7); + assert.deepEqual(errorsOf({ ...ITEM, seconds: 8 }), []); + assert.ok(errorsOf({ ...ITEM, seconds: 9 }).some((e) => /held 9 s with no audio \(at most 8/.test(e))); + assert.ok(errorsOf({ ...ITEM, seconds: 2 }).some((e) => /too short to read/.test(e))); + assert.ok(errorsOf(ITEM, { ...CTX, render: { width: 1080, height: 1920 } }).some((e) => /no vertical form/.test(e))); + assert.ok(errorsOf(ITEM, { ...CTX, render: { width: 1920, height: 1080, format: "vertical" } }).some((e) => /no vertical form/.test(e))); +}); + +test("numbers typed into words are said: a mark label, a pace note, a status without its row", () => { + const w = warningsOf({ + ...ITEM, marks: [{ row: "w115", label: "under 300" }], pace: [{ from: "w110", to: "w137", note: "3 weeks" }], + status: [{ label: "S", value: "5 days", note: "x" }], + }); + assert.ok(w.some((x) => /marks\[0\]\.label "under 300" has a number -- the mark's figure and date are drawn from w115/.test(x))); + assert.ok(w.some((x) => /pace\[0\]\.note "3 weeks" has a number/.test(x))); + assert.ok(w.some((x) => /status\[0\] has a number and no row/.test(x))); + assert.ok(!warningsOf(ITEM).some((x) => /status/.test(x))); +}); + +test("words: a day and a span", () => { + assert.equal(dayMonth("2026-10-23"), "23 Oct"); + assert.equal(spanWords("2026-10-23", "2026-11-03"), "23 Oct → 3 Nov"); + assert.equal(spanWords("2026-11-03", "2026-11-07"), "3 → 7 Nov"); +}); + +test("axes: one cluster fitted to the points (trailLayout), a tick per month, the mark", () => { + const plan = analysisPlan(ITEM, CTX, { x0: 0, x1: 1000, y0: 0, y1: 400 }); + assert.equal(plan.layout.lo, 280); + assert.equal(plan.layout.hi, 360); + assert.deepEqual(plan.layout.months.map((m) => m.text), ["JUL", "AUG", "SEP", "OCT", "NOV"]); + assert.equal(plan.layout.mark, 300); + assert.ok(plan.band.x1 > plan.band.x0); +}); diff --git a/umtool/report-to-video/chrome-analysis.mjs b/umtool/report-to-video/chrome-analysis.mjs @@ -0,0 +1,242 @@ +// THE ANALYSIS ITEM'S PAGE (module `analysis`, a segment): the plan +// (analysis-plan.mjs) drawn full frame on the deck's ground, faces and colours +// -- the chart of the run on the left (its grid, its month ticks, the band, the +// mark line, one line through the points, the marks), the pace table and the +// status rows on the right, the reading and the footnote across the foot, and, +// with audio, the clip's citation and its QR (its picture is never shown). +// +// CALM, NOT A TRAILER: no slam, no hit, no camera move. The title fades in, +// the axes and the band after it, the line draws point to point in date order +// (each point coming up as the line reaches it, its mark after it), the pace +// rows land one by one, then the status, then the reading. +// +// PURE: an entry, its context and the faces in, an HTML string out (a cue +// interpreter, measure-draw.mjs pageHtml/cueList -- seekable from either side). +import { colorsOf, fontStack } from "./chrome-instruments.mjs"; +import { mix, rgba } from "./chrome-deck.mjs"; +import { analysisPlan } from "./analysis-plan.mjs"; +import { cueList, esc, fmtWeight, pageHtml, r4 } from "./measure-draw.mjs"; + +/** The motion's seconds (at full length; a short item's motion is scaled to leave ANALYSIS_MOTION.hold at the end). */ +export const ANALYSIS_MOTION = Object.freeze({ + title: 0.5, axes: 0.3, band: 0.8, lineFrom: 0.8, line: 2.2, point: 0.3, mark: 0.35, + rowGap: 0.25, row: 0.35, rowRise: 10, reading: 0.5, hold: 1.5, +}); + +/** The frame, in the 1280x720 units the page is laid out in (scaled to the render). */ +export const ANALYSIS_BOX = Object.freeze({ x0: 70, x1: 800, y0: 150, y1: 560, panel: 850, panelR: 1230, qr: 150 }); + +/** When each thing lands, in the item's own seconds: `{ title, axes, band, points: Map(n -> t), marks, rows: [t], reading, foot, end }`. */ +export function analysisTimes(plan) { + const M = ANALYSIS_MOTION; + const line = plan.line.map((n) => plan.pos.get(n)); + const span = line.length > 1 ? line.reduce((s, p, i) => (i ? s + Math.hypot(p.x - line[i - 1].x, p.y - line[i - 1].y) : 0), 0) : 0; + const natural = M.lineFrom + M.line + 0.1 + (plan.pace.length + plan.status.length) * M.rowGap + M.row + 0.1 + M.reading + 0.2; + const k = Math.min(1, Math.max(0.4, (plan.seconds - M.hold) / natural)); + const at = (v) => r4(v * k); + const points = new Map(); + let walked = 0; + plan.line.forEach((n, i) => { + if (i) walked += Math.hypot(line[i].x - line[i - 1].x, line[i].y - line[i - 1].y); + points.set(n, at(M.lineFrom + (span ? (walked / span) * M.line : 0))); + }); + // A point that is not on the line (another weight for its day): with the line's point that day. + for (const p of plan.points) if (!points.has(p.n)) points.set(p.n, points.get(plan.line.find((n) => plan.points[n].day === p.day)) ?? at(M.lineFrom)); + const rowsFrom = M.lineFrom + M.line + 0.1; + const rows = [...plan.pace, ...plan.status].map((_, i) => at(rowsFrom + i * M.rowGap)); + const reading = at(rowsFrom + rows.length * M.rowGap + M.row + 0.1); + return { k, title: 0, axes: at(0.3), band: at(M.band), points, rows, reading, foot: r4(reading + at(0.2)), end: r4(reading + at(M.reading + 0.2)) }; +} + +/** + * The page. `ctx` = `{ ledger, schema, timeline, render }` (analysis-plan.mjs); `opts` = `{ fonts, gsap, cite, qrSrc }`: + * the faces (instrumentFonts), the clip's citation line and its QR's asset (both null without audio). + */ +export function analysisHtml(entry, ctx, opts = {}) { + const render = ctx.render ?? {}; + const W = Number(render.width) || 1920, H = Number(render.height) || 1080; + const u = W / 1280; + const px = (v) => Math.round(v * u * 100) / 100; + const fps = render.fps ?? 30; + const fonts = opts.fonts ?? {}; + const C = colorsOf(render); + const B = ANALYSIS_BOX; + const plan = analysisPlan(entry, ctx, { x0: px(B.x0), x1: px(B.x1), y0: px(B.y0), y1: px(B.y1) }); + const T = analysisTimes(plan); + const M = ANALYSIS_MOTION; + const L = cueList(fps); + const parts = []; + const show = (k, at, dur, extra = {}, ease = "power1.out") => L.add(k, at, dur, { autoAlpha: 1, ...extra }, ease); + const hidden = (k, extra = {}) => L.set(k, { autoAlpha: 0, ...extra }); + const color = (c) => (c === "accent" ? C.accent : c === "amber" ? C.amber : c === "red" ? C.needle : c === "muted" ? C.muted : c === "fg" ? C.fg : c); + const lay = plan.layout; + + // The title. + parts.push(`<div class="kick" data-k="kick">${esc(plan.kicker)}</div><div class="ttl" data-k="ttl">${esc(plan.title)}</div>`); + hidden("kick", { y: px(8) }); + hidden("ttl", { y: px(8) }); + show("kick", T.title, M.title, { y: 0 }); + show("ttl", T.title + 0.1, M.title, { y: 0 }); + + // The axes: a rule and its figure per grid step, a tick and a name per month, the mark line. + const axes = []; + for (const g of lay.grid) axes.push(`<div class="grid" style="top:${g.y}px"></div><div class="gv" style="top:${g.y}px">${g.v}</div>`); + axes.push(`<div class="base" style="top:${px(B.y1)}px"></div>`); + for (const m of lay.months) axes.push(`<div class="mt" style="left:${m.x}px; top:${px(B.y1)}px"></div><div class="mn" style="left:${m.x}px; top:${r4(px(B.y1) + px(10))}px">${m.text}</div>`); + if (lay.mark !== null) axes.push(`<div class="markl" style="top:${lay.markY}px"></div><div class="gv mk" style="top:${lay.markY}px">${lay.mark}</div>`); + parts.push(`<div class="axes" data-k="axes">${axes.join("")}</div>`); + hidden("axes"); + show("axes", T.axes, 0.5); + + // The band. + if (plan.band) { + const bw = Math.max(px(2), plan.band.x1 - plan.band.x0); + parts.push(`<div class="band" data-k="band" style="left:${plan.band.x0}px; width:${r4(bw)}px"></div>`); + parts.push(`<div class="bandl" data-k="bandl" style="left:${r4(plan.band.x0 + bw / 2)}px">${esc(plan.band.label)}${plan.band.label ? " · " : ""}${esc(dm(plan.band.from))} – ${esc(dm(plan.band.to))}</div>`); + hidden("band"); + hidden("bandl"); + show("band", T.band, 0.6); + show("bandl", T.band + 0.15, 0.5); + } + + // The line, point to point in date order; a stretch to or from a bound is quieter and dotted (the bound is no exact figure). + const byN = new Map(plan.points.map((p) => [p.n, p])); + for (let i = 1; i < plan.line.length; i += 1) { + const a = plan.pos.get(plan.line[i - 1]), b = plan.pos.get(plan.line[i]); + const loose = byN.get(plan.line[i - 1]).bound || byN.get(plan.line[i]).bound; + const k = `s${i}`; + parts.push(`<div class="seg${loose ? " loose" : ""}" data-k="${k}"></div>`); + L.set(k, { x: a.x, y: a.y, width: r4(Math.hypot(b.x - a.x, b.y - a.y)), rotation: r4((Math.atan2(b.y - a.y, b.x - a.x) * 180) / Math.PI), scaleX: 0, transformOrigin: "0% 50%" }); + const t0 = T.points.get(plan.line[i - 1]), t1 = T.points.get(plan.line[i]); + L.add(k, t0, Math.max(0.05, t1 - t0), { scaleX: 1 }, "none"); + } + // The points: solid, or hollow when the row is a bound (or "about"): never drawn as an exact figure. + for (const p of plan.points) { + const at = plan.pos.get(p.n); + const hollow = p.bound || p.qualifier === "≈"; + parts.push(`<div class="pt${hollow ? " q" : ""}" data-k="p${p.n}"></div>`); + L.set(`p${p.n}`, { x: at.x, y: at.y, autoAlpha: 0, scale: 0.6 }); + L.add(`p${p.n}`, T.points.get(p.n), M.point, { autoAlpha: 1, scale: 1 }, "power1.out"); + } + // The marks: the row's figure and day, the operator's words, his quote under them -- beside the point, on the + // side away from the line (right of a point in the chart's first half, left and below in its second). + const mid = (px(B.x0) + px(B.x1)) / 2; + plan.marks.forEach((m, i) => { + const right = m.at.x > mid; + const style = right + ? `right:${r4(W - m.at.x + px(10))}px; top:${r4(m.at.y + px(10))}px; text-align:right` + : `left:${r4(m.at.x + px(10))}px; top:${r4(m.at.y - px(30))}px`; + parts.push(`<div class="mk1" data-k="m${i}" style="${style}"><div class="mt1">${esc(m.text)}</div>${m.quote ? `<div class="mq">“${esc(m.quote)}”</div>` : ""}</div>`); + hidden(`m${i}`); + show(`m${i}`, r4(T.points.get(m.n) + 0.15), M.mark); + }); + + // The pace table and the status rows: each lands (a short rise and a fade), one after another. + const rows = []; + plan.pace.forEach((x) => { + const sub = [`${x.days} days`, x.note, x.bound ? boundNote(x) : ""].filter(Boolean).join(" · "); + rows.push(`<div class="row"><div class="l"><div class="lt">${esc(x.span.toUpperCase())}</div><div class="ls">${esc(sub)}</div></div>` + + `<div class="v${x.bound ? " b" : ""}">${x.word && x.word !== "unknown" ? `<span class="bw">${x.word}</span>` : ""}${esc(x.text)}</div></div>`); + }); + plan.status.forEach((x) => { + rows.push(`<div class="row"><div class="l"><div class="lt">${esc(x.label)}</div>${x.note ? `<div class="ls">${esc(x.note)}</div>` : ""}</div>` + + `<div class="v st" style="color:${esc(color(x.color))}">${esc(x.value)}</div></div>`); + }); + parts.push(`<div class="side">${rows.map((r, i) => r.replace('<div class="row">', `<div class="row" data-k="r${i}">`)).join("")}</div>`); + rows.forEach((_, i) => { + hidden(`r${i}`, { y: px(M.rowRise) }); + show(`r${i}`, T.rows[i], M.row, { y: 0 }, "power2.out"); + }); + + // The reading, the footnote, and with audio the clip's citation and its code. + const narrow = !!opts.qrSrc; + parts.push(`<div class="foot${narrow ? " narrow" : ""}"><div class="rd" data-k="rd">${esc(plan.reading)}</div>` + + `${plan.footnote ? `<div class="fn" data-k="fn">${esc(plan.footnote)}</div>` : ""}` + + `${opts.cite ? `<div class="ci" data-k="ci">${esc(opts.cite)}</div>` : ""}</div>`); + hidden("rd"); + show("rd", T.reading, M.reading); + if (plan.footnote) { hidden("fn"); show("fn", T.foot, M.reading); } + if (opts.cite) { hidden("ci"); show("ci", T.foot, M.reading); } + if (opts.qrSrc) { + parts.push(`<img class="qr" data-k="qr" src="${esc(opts.qrSrc)}" alt="">`); + hidden("qr"); + show("qr", T.foot, M.reading); + } + + const { init, cues } = L.build(); + const css = ` + .bg { position: absolute; inset: 0; background: ${C.bg}; } + .kick { position: absolute; left: ${px(B.x0)}px; top: ${px(36)}px; font-family: ${fontStack(fonts, "condensed")}; font-size: ${px(20)}px; + letter-spacing: 0.14em; color: ${C.muted}; white-space: nowrap; } + .ttl { position: absolute; left: ${px(B.x0)}px; top: ${px(62)}px; font-family: ${fontStack(fonts, "display")}; font-size: ${px(40)}px; + color: ${C.fg}; white-space: nowrap; } + .axes { position: absolute; inset: 0; } + .grid, .base, .markl { position: absolute; left: ${px(B.x0)}px; width: ${r4(px(B.x1) - px(B.x0))}px; height: 0; border-top: 1px solid ${C.rule}; } + .base { border-top-color: ${mix(C.bg, C.fg, 0.28)}; } + .markl { border-top: ${px(1.5)}px dashed ${rgba(C.accent, 0.7)}; } + .gv { position: absolute; right: ${r4(W - px(B.x0) + px(10))}px; transform: translateY(-50%); font-family: ${fontStack(fonts, "condensed")}; + font-size: ${px(15)}px; color: ${C.muted}; letter-spacing: 0.04em; } + .gv.mk { color: ${C.accent}; font-family: ${fontStack(fonts, "bold")}; } + .mt { position: absolute; width: 1px; height: ${px(6)}px; background: ${mix(C.bg, C.fg, 0.28)}; } + .mn { position: absolute; transform: translateX(-50%); font-family: ${fontStack(fonts, "condensed")}; font-size: ${px(15)}px; + color: ${C.muted}; letter-spacing: 0.08em; white-space: nowrap; } + .band { position: absolute; top: ${px(B.y0)}px; height: ${r4(px(B.y1) - px(B.y0))}px; background: ${rgba(C.amber, 0.13)}; } + .bandl { position: absolute; top: ${px(B.y0 - 24)}px; transform: translateX(-50%); font-family: ${fontStack(fonts, "condensed")}; + font-size: ${px(15)}px; letter-spacing: 0.08em; color: ${C.amber}; white-space: nowrap; } + .seg { position: absolute; left: 0; top: 0; height: ${px(3)}px; margin-top: -${px(1.5)}px; background: ${C.accent}; border-radius: ${px(2)}px; } + .seg.loose { height: 0; margin-top: -${px(1)}px; background: none; border-top: ${px(2)}px dotted ${rgba(C.accent, 0.7)}; border-radius: 0; } + .pt { position: absolute; left: 0; top: 0; width: ${px(8)}px; height: ${px(8)}px; margin: -${px(4)}px 0 0 -${px(4)}px; border-radius: 50%; background: ${C.accent}; } + .pt.q { width: ${px(11)}px; height: ${px(11)}px; margin: -${px(5.5)}px 0 0 -${px(5.5)}px; background: ${C.bg}; border: ${px(2)}px solid ${C.accent}; } + .mk1 { position: absolute; max-width: ${px(420)}px; } + .mt1 { font-family: ${fontStack(fonts, "condensed")}; font-size: ${px(15)}px; color: ${C.fg}; white-space: nowrap; } + .mq { font-family: ${fontStack(fonts, "condensed")}; font-size: ${px(14)}px; color: ${C.amber}; font-style: italic; margin-top: ${px(2)}px; } + .side { position: absolute; left: ${px(B.panel)}px; width: ${px(B.panelR - B.panel)}px; top: ${px(B.y0)}px; } + .row { display: flex; justify-content: space-between; align-items: center; padding: ${px(10)}px 0; border-bottom: 1px solid ${C.rule}; } + .row .lt { font-family: ${fontStack(fonts, "condensed")}; font-size: ${px(17)}px; letter-spacing: 0.05em; color: ${C.muted}; white-space: nowrap; } + .row .ls { font-family: ${fontStack(fonts, "condensed")}; font-size: ${px(14)}px; color: ${C.muted}; margin-top: ${px(3)}px; white-space: nowrap; } + .row .v { font-family: ${fontStack(fonts, "display")}; font-size: ${px(30)}px; color: ${C.fg}; white-space: nowrap; text-align: right; } + .row .v.b { color: ${mix(C.bg, C.fg, 0.82)}; } + .row .v.st { font-size: ${px(28)}px; } + .row .bw { font-family: ${fontStack(fonts, "condensed")}; font-size: ${px(16)}px; letter-spacing: 0.06em; color: ${C.muted}; + text-transform: uppercase; margin-right: ${px(8)}px; vertical-align: ${px(4)}px; } + .foot { position: absolute; left: ${px(B.x0)}px; right: ${px(1280 - B.panelR)}px; top: ${px(604)}px; } + .foot.narrow { right: ${px(1280 - B.panelR + B.qr + 24)}px; } + .rd { font-family: ${fontStack(fonts, "regular")}; font-size: ${px(24)}px; line-height: 1.3; color: ${C.fg}; } + .fn { font-family: ${fontStack(fonts, "condensed")}; font-size: ${px(15)}px; color: ${C.muted}; margin-top: ${px(6)}px; } + .ci { font-family: ${fontStack(fonts, "condensed")}; font-size: ${px(14)}px; color: ${C.muted}; margin-top: ${px(4)}px; letter-spacing: 0.03em; } + .qr { position: absolute; left: ${px(B.panelR - B.qr)}px; top: ${px(720 - 16 - B.qr)}px; width: ${px(B.qr)}px; height: ${px(B.qr)}px; }`; + return pageHtml({ + id: "analysis", W, H, fps, fonts, gsap: opts.gsap, + data: { total: plan.seconds, window: null, init, cues }, + css, + body: `<div class="bg"></div>${parts.join("")}`, + }); +} + +const MON = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]; +const dm = (iso) => { + const m = /^(\d{4})-(\d{2})-(\d{2})/.exec(String(iso ?? "")); + return m ? `${Number(m[3])} ${MON[Number(m[2]) - 1]}`.toUpperCase() : ""; +}; + +/** The words under a bounded pace row: which end is a bound, as he said it ("to < 300"). */ +function boundNote(x) { + const end = (e) => `${e.qualifier} ${fmtWeight(e.value)}`; + const ends = []; + if (x.boundRows.includes(x.from.row)) ends.push(`from ${end(x.from)}`); + if (x.boundRows.includes(x.to.row)) ends.push(`to ${end(x.to)}`); + return ends.join(", "); +} + +/** + * The clip's citation as the page prints it: "HEARD: <channel> · <title> · <date> · <m:ss>" from attributionParts' + * parts (attribution.mjs) -- the build's own, with the source's metadata when it has it. + */ +export function analysisCite(parts) { + if (!parts) return null; + const at = Number(parts.at); + const clock = Number.isFinite(at) + ? `${Math.floor(at / 3600) ? `${Math.floor(at / 3600)}:${String(Math.floor((at % 3600) / 60)).padStart(2, "0")}` : Math.floor(at / 60)}:${String(Math.floor(at % 60)).padStart(2, "0")}` + : ""; + return ["HEARD:", [parts.channel, parts.title, parts.date, clock].filter((x) => x && String(x).trim()).join(" · ")].join(" "); +} diff --git a/umtool/report-to-video/chrome-analysis.test.mjs b/umtool/report-to-video/chrome-analysis.test.mjs @@ -0,0 +1,100 @@ +// The analysis item's page (chrome-analysis.mjs): the plan's figures and nothing else, calm motion (no slam, no +// overshoot, nothing grows past its size), a bound drawn hollow, the clip's citation and code only with audio. +import { test } from "node:test"; +import assert from "node:assert/strict"; + +import { analysisCite, analysisHtml, analysisTimes } from "./chrome-analysis.mjs"; +import { analysisPlan } from "./analysis-plan.mjs"; + +const SCHEMA = { + kind: "measure", unit: "lb", bandGapDays: 60, + tracks: [{ key: "weight", role: "value", label: "Weight" }], + fields: [{ key: "qualifier", label: "Bound", kind: "enum", options: [">", "<", "≈"], render: "cell" }], +}; +const W = (id, population, date, value, extra = {}) => ({ id, scope: "weight", population, date, value, ...extra }); +const LEDGER = [ + W("w83", "delta", "2026-07-23", -5), + W("w91", "past", "2026-08-03", 349, { asOf: "2026-07-19" }), + W("w104", "delta", "2026-09-04", -31.5), + W("w110", "current", "2026-09-24", 310.5), + W("w115", "current", "2026-10-15", 300, { qualifier: "<" }), + W("w118", "current", "2026-10-26", 291.5, { asOf: "2026-10-23" }), + W("w137", "current", "2026-11-07", 288.5), +]; +const CTX = { + ledger: LEDGER, schema: SCHEMA, render: { width: 1920, height: 1080, fps: 30, palette: { bg: "#0f1311", fg: "#edf0ec" } }, + timeline: [{ type: "clip", id: "c46", video: "v1", start: 100, end: 160 }], +}; +const ITEM = { + type: "analysis", id: "an1", title: "What his own numbers say", kicker: "THE RUN", + series: { rows: ["w91", "w104", "w110", "w115", "w118", "w137"] }, + band: { from: "2026-10-23", to: "2026-11-07", label: "WORLD SERIES" }, + marks: [{ row: "w118", label: "offers the scale video" }], + pace: [{ from: "w110", to: "w115" }, { from: "w115", to: "w118" }], + status: [{ label: "SCALE VIDEO", value: "NOT POSTED", note: "offered 23 Oct", color: "red" }], + reading: "The loss is steady.", footnote: "His own statements.", mark: 300, +}; +const dataOf = (html) => JSON.parse(/<script id="analysis-data" type="application\/json">(.*?)<\/script>/s.exec(html)[1]); + +test("the page draws the plan's figures, a bound hollow and its pace rows over/under", () => { + const html = analysisHtml(ITEM, CTX); + assert.match(html, /data-duration="7"/); + assert.match(html, /What his own numbers say/); + assert.match(html, /<span class="bw">over<\/span>−10\.5 lb/); + assert.match(html, /<span class="bw">under<\/span>−8\.5 lb/); + assert.match(html, /21 days · to &lt; 300/); + assert.match(html, /8 days · from &lt; 300/); + assert.match(html, /291\.5 · 23 Oct · offers the scale video/); + assert.match(html, /NOT POSTED/); + const plan = analysisPlan(ITEM, CTX); + const bound = plan.points.find((p) => p.row === "w115"); + assert.match(html, new RegExp(`class="pt q" data-k="p${bound.n}"`)); + assert.equal((html.match(/class="pt q"/g) ?? []).length, 1); + // The stretches to and from the bound are dotted: never an exact line through it. + assert.equal((html.match(/class="seg loose"/g) ?? []).length, 2); + // No audio: no citation, no code. + assert.doesNotMatch(html, /class="qr"|class="ci"/); +}); + +test("calm: no overshoot ease, nothing scaled past its size, every cue inside the item", () => { + const html = analysisHtml(ITEM, CTX); + const { cues, init } = dataOf(html); + assert.ok(cues.length > 10); + for (const c of cues) { + assert.doesNotMatch(String(c.ease), /back|elastic|bounce/, `${c.k} eases ${c.ease}`); + if (c.to.scale !== undefined) assert.ok(c.to.scale <= 1, `${c.k} scales to ${c.to.scale}`); + assert.ok(c.at + c.dur <= 7 + 1e-6, `${c.k} ends at ${c.at + c.dur}`); + } + for (const [k, v] of Object.entries(init)) if (v.scale !== undefined) assert.ok(v.scale <= 1, k); +}); + +test("the line reaches each point in date order; the rows land after it, the reading last", () => { + const plan = analysisPlan(ITEM, CTX); + const T = analysisTimes(plan); + const ts = plan.line.map((n) => T.points.get(n)); + assert.deepEqual([...ts].sort((a, b) => a - b), ts); + assert.ok(T.rows[0] >= ts.at(-1)); + assert.ok(T.reading > T.rows.at(-1)); + assert.ok(T.end <= plan.seconds); +}); + +test("a short silent item's motion is scaled to leave its hold", () => { + const plan = analysisPlan({ ...ITEM, seconds: 5 }, CTX); + const T = analysisTimes(plan); + assert.ok(T.k < 1); + assert.ok(T.end <= 5 - 1 + 1e-6, `ends ${T.end}`); +}); + +test("with audio: the citation line and the code", () => { + const html = analysisHtml({ ...ITEM, audio: { clip: "c46", start: 110, end: 124.5 } }, CTX, { + cite: analysisCite({ channel: "chan", title: "A stream", date: "2026-10-26", at: 4112.6 }), qrSrc: "assets/qr00.png", + }); + assert.match(html, /data-duration="14\.5"/); + assert.match(html, /HEARD: chan · A stream · 2026-10-26 · 1:08:32/); + assert.match(html, /<img class="qr" data-k="qr" src="assets\/qr00\.png"/); + assert.match(html, /\.foot\.narrow/); +}); + +test("deterministic", () => { + assert.equal(analysisHtml(ITEM, CTX), analysisHtml(ITEM, CTX)); +}); diff --git a/umtool/report-to-video/chrome-instruments.mjs b/umtool/report-to-video/chrome-instruments.mjs @@ -38,7 +38,7 @@ export const INSTRUMENT_MOTION = Object.freeze({ /** The faces a measure page draws in: the deck's, and the manifest's display and condensed faces when it names them. */ export const INSTRUMENT_FONTS = Object.freeze({ display: "MeasureDisplay", condensed: "MeasureCond" }); -const fontStack = (fonts, which) => +export const fontStack = (fonts, which) => which === "display" ? `'${fonts.MeasureDisplay ? "MeasureDisplay" : "DeckSansBold"}', sans-serif` : which === "condensed" @@ -46,7 +46,7 @@ const fontStack = (fonts, which) => : which === "bold" ? "'DeckSansBold', sans-serif" : "'DeckSans', sans-serif"; /** The palette roles every instrument draws in. */ -function colorsOf(render, dial = resolveDial(render)) { +export function colorsOf(render, dial = resolveDial(render)) { const pal = render.palette ?? {}; const bg = pal.bg ?? "#0f1311", fg = pal.fg ?? "#edf0ec"; return { diff --git a/umtool/report-to-video/compose-chrome.mjs b/umtool/report-to-video/compose-chrome.mjs @@ -743,11 +743,11 @@ export async function fxThumbs(schedule, base, render, assetsDir) { * handed what it may touch -- the faces, the QR maker, the shots -- as * helpers, so a module never reaches into the file system itself. */ -async function regionHtml(region, { manifest, manifestDir, base, projDir, assetsDir, schedule, duration, from, window, teaser, transition }) { +async function regionHtml(region, { manifest, manifestDir, base, projDir, assetsDir, schedule, duration, from, window, teaser, transition, context = null }) { const mod = regionModule(region); const render = manifest.render; return mod.page({ - manifest, render, manifestDir, base, projDir, assetsDir, schedule, duration, from, window, entry: teaser, transition, + manifest, render, manifestDir, base, projDir, assetsDir, schedule, duration, from, window, entry: teaser, transition, context, fonts: (names, opts) => copyFonts(render, assetsDir, names, opts), qrs: (urls, size) => qrPngsFor(urls, render, size, assetsDir), // `threads`, a Set: the posts whose thread shot was drawn in place of their shot are added to it. @@ -862,6 +862,10 @@ export function runRenderer(cmd, args) { * lead is the dissolve and the black): the build passes its own, so a * `--no-xfade` build composes the lead it plays; default the manifest's. * + * Analysis (`region: "analysis"`, `segment` = the entry's id): as the teaser, + * `chrome/analysis-<id>/`; `context` (`{ meta }`, the build's source metadata + * of its audio clip) names the clip on its citation line. + * * `schedule` (an object) overrides reading `out/<variant>/schedule.json`. * * @returns {Promise<{ projDir: string, frames: string|null, still: string|null, @@ -873,7 +877,7 @@ export async function composeChrome({ schedule = null, preview = false, doRender = false, fps = null, workers = null, quality = "high", format = "png-sequence", still = null, png = null, from = 0, duration = null, window = null, segment = null, transition = null, - lease = null, want = null, render: renderOverride = null, + lease = null, want = null, render: renderOverride = null, context = null, }) { // The variant's view, and its own out directory. Handed the whole manifest // the band would draw claims this cut never makes, and the deck would name @@ -944,7 +948,7 @@ export async function composeChrome({ // keys hold only while it is shown (frame-keys.mjs). const drawn = await regionHtml(region, { manifest, manifestDir: path.dirname(path.resolve(manifestPath)), base, projDir, assetsDir, schedule: sched, - duration: duration != null ? Number(duration) : null, from, window: win, teaser, transition: D, + duration: duration != null ? Number(duration) : null, from, window: win, teaser, transition: D, context, }); const html = typeof drawn === "string" ? drawn : drawn.html; const pageItems = typeof drawn === "string" ? null : drawn.items ?? null; diff --git a/umtool/report-to-video/modules/analysis.mjs b/umtool/report-to-video/modules/analysis.mjs @@ -0,0 +1,86 @@ +// THE ANALYSIS ITEM (module `analysis`, a segment): an ending built from the +// ledger -- a chart of a named run of his weights, a pace table, a status row +// and one reading line -- inserted into the cut as a timeline entry of its own +// (`{ type: "analysis" }`, analysis-plan.mjs). chrome-analysis.mjs writes the +// page; the build encodes its frames into segments/<id>.mp4 with the sound of +// the clip it names under it, or silence (build-video's buildAnalysisSegment). +import { analysisLedger, analysisProblems, analysisSeconds } from "../analysis-plan.mjs"; +import { attributionParts } from "../attribution.mjs"; +import { deckQrUrl, resolveDeck } from "../deck.mjs"; +import { defineModule } from "./contract.mjs"; +import { instrumentFonts } from "./instruments-shared.mjs"; + +/** The context an item's plan reads, from the cut's manifest. */ +export const analysisContext = (manifest) => ({ + ledger: analysisLedger(manifest), schema: manifest?.ledgerSchema ?? null, timeline: manifest?.timeline ?? [], render: manifest?.render ?? {}, +}); + +/** Every analysis entry's errors, as the build refuses them. */ +export function validateAnalysisEntries(manifest) { + return (manifest?.timeline ?? []).filter((e) => e?.type === "analysis").flatMap((e) => analysisProblems(e, analysisContext(manifest)).errors); +} + +/** Every analysis entry's warnings, as the lint says them. */ +export function analysisWarnings(manifest, { only = null } = {}) { + return (manifest?.timeline ?? []).filter((e) => e?.type === "analysis" && (!only || e.id === only)).flatMap((e) => analysisProblems(e, analysisContext(manifest)).warnings); +} + +/** + * The audio clip's citation parts and QR link: the clip at the audio's start -- with the source's metadata when the + * build has it (`meta`), else the entry's own words. Null without audio. + */ +export function analysisSource(entry, manifest, meta = null) { + const a = entry?.audio; + if (!a) return null; + const clip = (manifest?.timeline ?? []).find((e) => e?.id === a.clip && e.type === "clip"); + if (!clip) return null; + const at = { ...clip, cite: Number(a.start), start: Number(a.start) }; + const links = resolveDeck(manifest?.render ?? {}).qr?.links; + return { + parts: attributionParts(at, meta ?? {}, manifest?.provenance ?? {}), + url: deckQrUrl(at, manifest?.provenance ?? {}, { ...(links ? { links } : {}), meta }), + }; +} + +export default defineModule({ + id: "analysis", + version: 1, + z: 0, + kind: "segment", + slot: "full", + title: "Analysis", + summary: "An ending built from the ledger: a chart of a named run of his weights, a pace table, a status row and one reading line, as its own segment.", + validate: (_value, { manifest }) => validateAnalysisEntries(manifest), + docs: { + heading: "Analysis item", + intro: "A timeline entry `{ type: \"analysis\", … }` (analysis-plan.mjs; [report-video.md](report-video.md#the-analysis-item)): a full-frame ending drawn from the LEDGER -- a chart of a named run of his weights (`series`: rows, or a span; a delta resolved against the run's start), a shaded `band`, `marks`, a `pace` table whose pounds and days are computed, `status` rows and ONE `reading` -- the line drawing in, the rows landing; with `audio` a clip's sound under it (its citation and QR on the page, its picture not), else silent for `seconds` (7, at most 8). Every figure traces to a ledger row; a bound (\"< 300\") is drawn hollow and a pace row ending on one says over/under.", + rows: [ + ["an `analysis` entry", "`title`, `kicker`, `series`, `band`, `marks`, `pace`, `status`, `reading`, `footnote`, `mark`, `audio?`, `seconds?`", "`umtool timeline <p> [--take <t>] add-analysis <json|@file>` · `set-analysis <id> <json|@file>`"], + ], + }, + region: "analysis", + workers: "wide", + noun: "the analysis item's", + entry(manifest, segment) { + const e = (manifest.timeline ?? []).find((x) => x.id === segment && x.type === "analysis") ?? null; + if (!e) return null; + const errors = analysisProblems(e, analysisContext(manifest)).errors; + if (errors.length) throw new Error(errors.join("; ")); + return e; + }, + seconds: (entry) => analysisSeconds(entry), + names: ({ preview, entry }) => ({ project: `analysis-${preview ? "preview-" : ""}${entry.id}`, stem: `analysis-${entry.id}` }), + async page(ctx) { + const { analysisHtml, analysisCite, ANALYSIS_BOX } = await import("../chrome-analysis.mjs"); + const fonts = await instrumentFonts(ctx); + const src = analysisSource(ctx.entry, ctx.manifest, ctx.context?.meta ?? null); + let qrSrc = null; + if (src?.url) { + const byUrl = await ctx.qrs([src.url], Math.round((ANALYSIS_BOX.qr * (Number(ctx.render.width) || 1920)) / 1280)); + qrSrc = byUrl.get(src.url) ?? null; + } + return analysisHtml(ctx.entry, analysisContext(ctx.manifest), { fonts, cite: src ? analysisCite(src.parts) : null, qrSrc }); + }, + // A cue interpreter: a changed item recaptures only the frames its change is on. + frameKeys: { data: "analysis-data", omit: ["init", "cues"] }, +}); diff --git a/umtool/report-to-video/modules/index.mjs b/umtool/report-to-video/modules/index.mjs @@ -25,6 +25,7 @@ import threads from "./threads.mjs"; import flips from "./flips.mjs"; import finale from "./finale.mjs"; import teaser from "./teaser.mjs"; +import analysis from "./analysis.mjs"; import subtitle from "./subtitle.mjs"; import qr from "./qr.mjs"; import rail from "./rail.mjs"; @@ -53,7 +54,7 @@ export { assertRegion, defineModule, MODULE_KINDS, MODULE_SLOTS, PLAY_CLOCKS, RE /** Every module, by z (stack order), then id. */ export const MODULES = Object.freeze( - [chart, shell, subtitle, qr, rail, sectionTitle, counter, claims, feed, popupPosts, stamp, stats, fx, threads, flips, finale, teaser, intro, blur, pair, chapter, status, chat, shelf, diet, peak, goals, promise, streak, dial, odometer, trail, dialFinale, runsFinale] + [chart, shell, subtitle, qr, rail, sectionTitle, counter, claims, feed, popupPosts, stamp, stats, fx, threads, flips, finale, teaser, analysis, intro, blur, pair, chapter, status, chat, shelf, diet, peak, goals, promise, streak, dial, odometer, trail, dialFinale, runsFinale] .sort((a, b) => a.z - b.z || a.id.localeCompare(b.id)), );