Archilyzer · Source

archilyzer

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

commit 28c114ed64c38042d6fa63d034e8174362eef1e7
parent 5c25855eff043b174bc31dc8b8c616c5b12260f8
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date:   Thu,  5 Nov 2026 23:09:52 -0500

umtool: the measure extras -- goal stack, moving start, promise clock, diet badge

Four main-engine modules that read the schedule's `measure` slice (weight video
rev 9, CONTRACT.md), each an HTML+GSAP cue page the render captures and Play
iframes (`deck:seek`, `<region>:ready`), registered at the end of MODULES:

- `goals`: every goal/goalLoss drops a sticky note on a pile; the same goal in
  the same words merges into its note with a count and comes to the front; a
  goal with a `deadline` counts down to measure.asOfRender ("by Christmas ·
  50 days left · needs 226.5"), the date parsed from his words (Christmas,
  Halloween, New Year, Thanksgiving, end of year, "next year", a named year,
  a month and day, an ISO date); words with no date keep their label only.
- `peak`: each remembered start in totals.peakDrift a tick on a small fixed
  scale, a retelling a count (365.7 ×3 … ≈390 ×5), the drift bracketed.
- `promise`: from the promise on, days to the in-record date of what is on
  screen, each check's words flashed in, counted on to the render date from
  the finale (else 4 s after the last event); kept is "POSTED" in green.
  Drawn over the finale (z 95).
- `diet`: a rubber stamp that slams on at each change of regime or diet
  number, in the regime's ink; a null diet after one fades to "No diet".

Each state is its own block, handed to the frame keys as an item gated by its
autoAlpha, so between events every frame is one frame and the render reuses
it. Settings at render.chrome.deck.goals|peak|promise|diet (show, position,
x/y, scale, hold, finale, and each its own), validated in modules/settings.mjs;
validateChrome now allows every deck key a SETTINGS entry owns. The slice
flows through scheduleSlices (the producer adds the same line). Defaults sit
at anchors of the footage box clear of the instrument panel's column and of
the top-left, where the streams' face cam most often is. A deck cut with no
measure slice draws none of them (tested on the r28 fixture manifests).
knobs.md's Modules section regenerated.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

Diffstat:
Mumtool/docs/knobs.md | 50+++++++++++++++++++++++++++++++++++++++++++++++++-
Aumtool/report-to-video/chrome-measure-extras.mjs | 450+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mumtool/report-to-video/deck.mjs | 5++++-
Aumtool/report-to-video/fixtures/measure-extras/make-fixture.mjs | 45+++++++++++++++++++++++++++++++++++++++++++++
Aumtool/report-to-video/fixtures/measure-extras/measure.json | 1+
Aumtool/report-to-video/measure-extras.mjs | 495+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Aumtool/report-to-video/measure-extras.test.mjs | 222+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Aumtool/report-to-video/modules/diet.mjs | 33+++++++++++++++++++++++++++++++++
Aumtool/report-to-video/modules/goals.mjs | 35+++++++++++++++++++++++++++++++++++
Mumtool/report-to-video/modules/index.mjs | 7++++++-
Aumtool/report-to-video/modules/measure-extras-module.mjs | 81+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Aumtool/report-to-video/modules/measure-extras-settings.mjs | 180+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Aumtool/report-to-video/modules/peak.mjs | 34++++++++++++++++++++++++++++++++++
Aumtool/report-to-video/modules/promise.mjs | 37+++++++++++++++++++++++++++++++++++++
Mumtool/report-to-video/modules/rail.test.mjs | 2+-
Mumtool/report-to-video/modules/registry.test.mjs | 7++++---
Mumtool/report-to-video/modules/settings.mjs | 7+++++++
17 files changed, 1684 insertions(+), 7 deletions(-)

diff --git a/umtool/docs/knobs.md b/umtool/docs/knobs.md @@ -1466,10 +1466,14 @@ filter. A knob absent is its default, and a module whose knobs are all absent dr | [Then and now (pair)](#then-and-now-pair) `pair` | Two clips on one subject, each with its date: a then \| now strip (or a then→now card) with the pair's caption. (a page over the whole cut) | `render.chrome.pair` | | [Status ledger](#status-ledger) `status` | A row per item -- announced, then followed up or not -- filling a column as the cut plays. (a page over the whole cut) | `render.chrome.status` | | [Effects](#effects) `fx` | Overlays on the picture: receipts, a zoom, a scrubber, captions. (a page over the whole cut) | `render.chrome.fx` | +| [Diet badge](#diet-badge) `diet` | The diet he names as a stamp that slams on at each change, with its number; "No diet" when the state says so. (a page over the whole cut) | `render.chrome.deck.diet` | +| [Moving start](#moving-start) `peak` | The starting weight as he retells it: a tick per telling on a small scale, a count per repeat, the drift bracketed. (a page over the whole cut) | `render.chrome.deck.peak` | +| [Goal stack](#goal-stack) `goals` | Each goal he names as a sticky note on a pile -- a repeat merged with its count, a deadline counted down to the render date. (a page over the whole cut) | `render.chrome.deck.goals` | | [Thread rail](#thread-rail) `threads` | A card per thread beside the footage, lit as its clips play. (a page over the whole cut) | `render.chrome.threads` | | [Flips](#flips) `flips` | Pairs of what was said then and now, in the side panel. (a page over the whole cut) | `render.chrome.flips` | | [Chapters](#chapters) `chapter` | A section bumper over the first seconds of the clip it opens: title, subtitle, date. (pages at their own seconds) | `render.chrome.chapter` | | [Finale](#finale) `finale` | The cut's last clips under the rail redrawn large, the final totals and stats cards. (pages at their own seconds) | `render.chrome.deck.finale` | +| [Promise clock](#promise-clock) `promise` | Days since a promise -- to the clip on screen, then to the render date -- with each check's words and whether it was kept. (a page over the whole cut) | `render.chrome.deck.promise` | ### Play the cut and the live preview @@ -1481,7 +1485,7 @@ it can be seeked. `POST /api/report/chrome/preview` returns every such module th build's predicate) as `layers: [{id, z, region, clock, ready, geometry, src | windows}]`; the client lays them by z over the deck's page, a whole-cut page for the whole cut, a window module's page only inside each window. -Declaring `play`: `stats`, `pair`, `status`, `fx`, `threads`, `flips`, `chapter`. +Declaring `play`: `stats`, `pair`, `status`, `fx`, `diet`, `peak`, `goals`, `threads`, `flips`, `chapter`, `promise`. Still drawn by their own paths (the response's `src`, `feed`, `posts`, `stamp` and `finale` keys), and what moving each onto `play` needs: the deck (`shell`) -- its typed words patched in live (`deck:text`) and the `deck:ready` @@ -1686,6 +1690,39 @@ Overlays on the picture -- receipts, a zoom, the scrubber, a kinetic quote, punc | beside popup posts that move the footage (`deck.posts.shift`) | the effects are drawn over the footage box where it stays, so an effect on screen WHILE the posts hold the footage aside is refused, naming both and their seconds — a zoom, receipts, a quote or a punch-in on its own clip's span; a whip, glitch or THEN/NOW wipe around its cut; the scrubber and the odometer over every clip (so beside any shift). A persisting bar holds it aside from its first post to its glide back. Apart in time, both are drawn. `umtool check` reads the estimated schedule; the build checks again on the measured one before any chrome is drawn | `deck.posts.shift=false`, the feed, or move one of them | | the zoom's timing (`fx.zoom.at`, `.hold`) | up 0.2 s into the clip's clean span (the card rises in over 0.38 s, `back.out`); its focus box draws 0.55 s later (0.45 s); it pushes in on the box at `at` — seconds into the clip, default as soon as the box has drawn — over 1 s (`power2.inOut`), then drifts slowly on the detail. It leaves with a 0.3 s fade 0.3 s before the clip's clean span ends, or with `hold` (0.5–10 s) that long after the push lands (never past the clip's own leave) | `fx.zoom='{…,"hold":4}'` | +### Diet badge + +The diet he names as a rubber stamp in a corner of the footage box (`render.chrome.deck.diet`, measure-extras.mjs): at each change of the state's diet -- its regime or its diet number -- a new stamp slams on (in big and turned, onto the page, a shake), the regime's word in its ink and "DIET #n" under it with the ledger's words when they say more ("Keto · 5 carbs a day"); a change of words alone fades the new stamp in. A null diet after one fades to "NO DIET" in grey. It draws `state.diet` as the measure slice gives it -- the off-scope rule ("off GLP-1" while on keto is still keto) is the ledger's. The inks default to the quartering-diet regimes' (keto #E0913C, carnivore #C9534B, fasting #4E9BD8, calories #3FA9A0, glp1 #B168C6, other #8E97A8, off #98A29B). + +| Knob | Range · default | From a terminal | +|---|---|---| +| `deck.diet` | `true` · `false` · `{show, position, x, y, scale, hold, finale, colors, labels}` · default on with a measure slice | `umtool look <p> deck.diet=false` | +| `deck.diet.position`, `.x`/`.y`, `.scale` | an anchor in the footage box · design px · 0.5–2 · default `bottom-left`, unset, 1 | `umtool look <p> deck.diet.position=top-right` | +| `deck.diet.hold`, `.finale` | null (up from the first diet on) or 2–600 s · `hide` `show` · default null, `hide` | `umtool look <p> deck.diet.hold=15` | +| `deck.diet.colors`, `.labels` | `{<regime>: #hex}` · `{<regime>: words ≤40}` · default the regimes' inks and names | `umtool look <p> deck.diet.labels='{"glp1":"Ozempic"}'` | + +### Moving start + +The weight he says he started at, as he retells it (`render.chrome.deck.peak`, measure-extras.mjs): each remembered weight that is one of the measure totals' `peakDrift` values (`values: "drift"`; `all` draws every remembered weight) adds a tick on a small vertical scale -- the scale's range is fixed over the whole cut, so nothing rescales -- with its value, a retelling of the same number a count ("≈390 ×5"), the newest lit; the spread from the lowest to the highest so far is bracketed in red and written under it ("+24.3 lb"). Up for `hold` seconds after each telling (default 12). + +| Knob | Range · default | From a terminal | +|---|---|---| +| `deck.peak` | `true` · `false` · `{show, position, x, y, scale, hold, finale, title, values, color}` · default on with a measure slice | `umtool look <p> deck.peak=false` | +| `deck.peak.position`, `.x`/`.y`, `.scale` | an anchor in the footage box · design px · 0.5–2 · default `top-right`, unset, 1 | `umtool look <p> deck.peak.scale=0.9` | +| `deck.peak.hold`, `.finale` | null (stays up) or 2–600 s · `hide` `show` · default 12, `hide` | `umtool look <p> deck.peak.hold=null` | +| `deck.peak.title`, `.values`, `.color` | ≤40 · `drift` `all` · #hex · default "The start keeps moving", `drift`, #FF5A4E | `umtool look <p> deck.peak.values=all` | + +### Goal stack + +A sticky note per goal on a pile in a corner of the footage box, read off the schedule's `measure` slice (`render.chrome.deck.goals`, measure-extras.mjs): each goal or goalLoss event drops one, turned a little, onto the pile; the same goal in the same words ("lose 100") merges into its note with a count ("×8") and comes to the front; `max` notes show, the newest in front, with the goals set so far under them. A goal with a `deadline` counts down to `measure.asOfRender` ("by Christmas · 50 days left · needs 226.5"): Christmas is the next 25 Dec from the day he said it, "next year" a year on, a named year that year; words that name no date ("by my birthday") keep their label and no countdown. On whenever the cut has a measure slice with a goal on camera; `false` turns it off. Up for `hold` seconds after each goal (default 20), the pile as it stands each time. The four measure extras sit at anchors of the footage box by default, clear of the instrument panel's right column and of the top-left, where the streams' face cam most often is (the diet badge bottom-left, the goal stack bottom-right, the moving start top-right, the promise clock top-centre); `position` or `x`/`y` move one. + +| Knob | Range · default | From a terminal | +|---|---|---| +| `deck.goals` | `true` · `false` · `{show, position, x, y, scale, hold, finale, max, color, countdown}` · default on with a measure slice | `umtool look <p> deck.goals=false` | +| `deck.goals.position`, `.x`/`.y`, `.scale` | `top-left` `top-right` `bottom-left` `bottom-right` `top-center` `bottom-center` · design px · 0.5–2 · default `bottom-right`, unset, 1 | `umtool look <p> deck.goals.position=bottom-left` | +| `deck.goals.max`, `.color`, `.countdown` | 1–8 notes · #hex paper · bool · default 4, the palette's amber, `true` | `umtool look <p> deck.goals.max=6` | +| `deck.goals.hold`, `.finale` | null (up from the first goal on) or 2–600 s after each · `hide` `show` · default 20, `hide` | `umtool look <p> deck.goals.hold=null` | + ### Thread rail A card per thread in the side panel beside the footage, lit as its clips play; a thread’s outcome stamped on its last clip (`render.chrome.threads`, threads.mjs). @@ -1721,4 +1758,15 @@ The full reference is [The finale](#the-finale-the-timeline-in-primary-view). It | `deck.finale` | `{video, motion, totals, stats, statsTitle, railLabels, pips, timelineShare, claims}` | `umtool look <p> deck.finale='{…}'` | | a clip's `layout` | `finale` on one run of clips at the end | `umtool set <p> <clip> layout=finale` | +### Promise clock + +A days-since counter for a promise (`render.chrome.deck.promise`, measure-extras.mjs), from the promise's event on: "SCALE VIDEO OFFERED 23 OCT", the days from the day he said it to the in-record date of the latest event on screen, and "NONE POSTED" in red until a row says it was kept ("POSTED", green). Each promise check's words come in under it with a flash (`checks`: the row's `label`, or its transcript `quote`). From the finale's start -- else 4 s after the last event -- the days count on, a day a step, to `measure.asOfRender`. Laid over the finale (z 95) unless `finale: "hide"`. + +| Knob | Range · default | From a terminal | +|---|---|---| +| `deck.promise` | `true` · `false` · `{show, position, x, y, scale, hold, finale, label, verb, kept, broken, checks}` · default on with a measure slice | `umtool look <p> deck.promise=false` | +| `deck.promise.position`, `.x`/`.y`, `.scale` | an anchor in the footage box · design px · 0.5–2 · default `top-center`, unset, 1 | `umtool look <p> deck.promise.position=bottom-center` | +| `deck.promise.hold`, `.finale` | null (stays up) or 2–600 s · `hide` `show` · default null, `show` | `umtool look <p> deck.promise.finale=hide` | +| `deck.promise.label`, `.verb`, `.kept`, `.broken`, `.checks` | ≤40 each · `label` `quote` · default the row's display, "offered", "Posted", "None posted", `label` | `umtool look <p> deck.promise.label='scale video'` | + <!-- modules:end --> diff --git a/umtool/report-to-video/chrome-measure-extras.mjs b/umtool/report-to-video/chrome-measure-extras.mjs @@ -0,0 +1,450 @@ +// THE MEASURE EXTRAS' PAGES (weight video rev 9, lane measure-extras): the +// goal stack, the moving start, the promise clock and the diet badge, each a +// cue page (chrome-cues.mjs) over the whole cut -- the render captures it +// frame by frame (HyperFrames png-sequence) and Play iframes the SAME page, +// seeked by `deck:seek`, posting `<region>:ready`. +// +// Each STATE (measure-extras.mjs) is its own block, shown over exactly its +// span and handed to the frame keys as an item gated by its own autoAlpha: +// a frame keys only the block on screen, so between two events every frame +// is the same frame and the render reuses it. Motion is the block's own: the +// note that lands, the tick that grows, the stamp that slams -- each a cue +// with its FROM stated, so a seek from anywhere lands on the same pixels. +// +// PURE: a schedule and a render block in, `{ html, items }` out. +import { rgba } from "./chrome-deck.mjs"; +import { compileCues, cuePageHtml, esc, INSTANT, joinSpans, r4, spanEvents } from "./chrome-cues.mjs"; +import { + daysLeftText, dietStates, goalStates, measureExtraGeometry, measureOf, MEASURE_BOXES, + monthYear, peakStates, promiseStates, shortDate, upSpans, weightText, +} from "./measure-extras.mjs"; +import { MEASURE_RED, resolveMeasureExtra } from "./modules/measure-extras-settings.mjs"; + +/** How each module's panel comes in and goes out, s. */ +export const MEASURE_FADE = Object.freeze({ in: 0.35, out: 0.4 }); + +const feedOf = (schedule) => schedule?.layout === "feed"; + +/** The page's frame: its region, its pixel scale against its design box, its fps. */ +function frameOf(id, schedule, render) { + const geo = measureExtraGeometry(id, render, { feed: feedOf(schedule) }); + const k = geo.width / MEASURE_BOXES[id].width; + const px = (v) => Math.max(1, Math.round(v * k)); + return { geo, k, px, fps: schedule.fps ?? render.fps ?? 30 }; +} + +/** The display face, when the render names one (`fontDisplay`): the condensed extra-bold, else the deck's bold. */ +const displayFace = (fonts) => (fonts?.display + ? `@font-face { font-family: 'MeasureDisplay'; font-weight: 400; font-style: normal; src: url('${esc(fonts.display)}'); }` + : ""); +const DISPLAY = "'MeasureDisplay', 'DeckSansBold', sans-serif"; + +/** + * The cues every state page shares: the panel `pn` up over the module's spans, + * each state `s<j>` shown from its `at` to the next one's (+ `overlap`, while + * the next one's entrance runs), and the state's own events. + */ +function stateCues(states, spans, { overlap = 0, own = () => [] } = {}, initExtra = {}) { + const init = { pn: { autoAlpha: 0 }, ...initExtra }; + const ev = []; + for (const sp of spans) ev.push(...spanEvents("pn", sp.in, sp.out, { fadeIn: MEASURE_FADE.in, fadeOut: MEASURE_FADE.out })); + states.forEach((st, j) => { + const k = `s${j}`; + init[k] = { autoAlpha: 0 }; + const until = states[j + 1] ? states[j + 1].at + overlap : null; + ev.push({ k, at: st.at, dur: INSTANT, to: { autoAlpha: 1 }, ease: "none" }); + if (until !== null) ev.push({ k, at: until, dur: INSTANT, to: { autoAlpha: 0 }, ease: "none" }); + ev.push(...own(st, j, init)); + }); + return compileCues(init, ev); +} + +const page = (id, schedule, opts, { geo, fps }, css, body, init, cues, ids) => cuePageHtml({ + id, W: geo.width, H: geo.height, fps, fonts: opts.fonts, gsapSrc: opts.gsap, css: `${displayFace(opts.fonts)}\n ${css}`, + body, init, cues, whole: { total: schedule.total, from: opts.from, duration: opts.duration, ids }, +}); + +// --------------------------------------------------------------------------- +// GOALS: the sticky notes. +// --------------------------------------------------------------------------- + +/** A note's place at `depth` in the pile (0 the front), region pixels. */ +function notePlace(note, depth, px, H) { + return { + x: px(40 + note.dx + 6 * depth), + y: H - px(46 + 150) - px(36 * depth), + rotation: r4(note.rot + (depth ? (depth % 2 ? -2.5 : 2) : 0)), + }; +} + +/** The goal stack's page: `{ html, items }`. */ +export function goalsHtml(schedule, render, opts = {}) { + const cfg = resolveMeasureExtra("goals", render); + const m = measureOf(schedule); + const states = goalStates(schedule, render); + if (!cfg || !m || !states.length) throw new Error("goals: the schedule's measure slice has no goal on camera"); + const F = frameOf("goals", schedule, render); + const { geo, px } = F; + const H = geo.height; + const pal = render.palette; + const paper = cfg.color ?? pal.amber ?? "#E8A33F"; + const spans = upSpans(states.map((s) => s.at), cfg, schedule); + const items = []; + const { init, cues } = stateCues(states, spans, { + own: (st, j, init) => { + const ev = []; + for (const n of st.notes) { + const k = `s${j}.${n.id}`; + const to = notePlace(n, n.depth, px, H); + if (n.key === st.top) { + // The new note lands: from above, turned, a size up -- onto the pile. + init[k] = { x: to.x - px(30), y: to.y - px(230), rotation: r4(to.rotation + 13), scale: 1.12, opacity: 0 }; + ev.push({ k, at: st.at, dur: 0.42, to: { x: to.x, y: to.y, rotation: to.rotation, scale: 1, opacity: 1 }, ease: "back.out(1.3)" }); + if (n.count > 1) { + init[`${k}c`] = { scale: 1.9, opacity: 0 }; + ev.push({ k: `${k}c`, at: st.at + 0.3, dur: 0.32, to: { scale: 1, opacity: 1 }, ease: "back.out(2.2)" }); + } + } else if (n.prev !== null && n.prev !== n.depth) { + const from = notePlace(n, n.prev, px, H); + init[k] = { x: from.x, y: from.y, rotation: from.rotation }; + ev.push({ k, at: st.at, dur: 0.36, to: { x: to.x, y: to.y, rotation: to.rotation }, ease: "power2.out" }); + } else { + init[k] = { x: to.x, y: to.y, rotation: to.rotation }; + } + } + return ev; + }, + }); + const blocks = states.map((st, j) => { + const notes = st.notes.map((n) => { + const k = `s${j}.${n.id}`; + const dl = cfg.countdown && n.deadline + ? `<div class="dl">${esc(n.deadline)}${n.days !== null ? ` · ${esc(daysLeftText(n.days))}` : ""}</div>${n.target !== null ? `<div class="dl2">needs ${esc(weightText(n.target))}</div>` : ""}` + : ""; + const count = n.count > 1 ? `<div class="ct" data-k="${k}c">×${n.count}</div>` : ""; + const shade = n.depth ? `<div class="sh" style="opacity:${r4(Math.min(0.5, 0.14 * n.depth))}"></div>` : ""; + return `<div class="note${dl ? " due" : ""}" data-k="${k}" style="z-index:${20 - n.depth}"><div class="tape"></div><div class="nh">Goal${n.date ? ` · ${esc(monthYear(n.date))}` : ""}</div><div class="nt">${esc(n.text)}</div>${dl}${count}${shade}</div>`; + }).join(""); + const html = `<div class="st" data-k="s${j}">${notes}<div class="hd"><span class="hn">${st.goalsSet}</span> goal${st.goalsSet === 1 ? "" : "s"} set</div></div>`; + items.push({ key: `s${j}`, gate: [`s${j}`, "autoAlpha"], html }); + return html; + }); + const css = ` + #pn { position: absolute; inset: 0; visibility: hidden; opacity: 0; } + .st { position: absolute; inset: 0; visibility: hidden; opacity: 0; } + .note { position: absolute; left: 0; top: 0; width: ${px(290)}px; height: ${px(150)}px; padding: ${px(14)}px ${px(18)}px; + border-radius: ${px(3)}px; color: #2a1c06; overflow: hidden; + background: linear-gradient(168deg, ${paper} 0%, ${paper} 62%, ${rgba(paper, 0.86)} 100%); + box-shadow: 0 ${px(10)}px ${px(22)}px rgba(0, 0, 0, 0.45), 0 ${px(1)}px ${px(2)}px rgba(0, 0, 0, 0.3); + display: flex; flex-direction: column; justify-content: center; gap: ${px(2)}px; } + .tape { position: absolute; left: 50%; top: ${px(-8)}px; width: ${px(84)}px; height: ${px(24)}px; margin-left: ${px(-42)}px; + background: rgba(255, 255, 255, 0.38); transform: rotate(-3deg); } + .nh { font-family: 'DeckSansBold', sans-serif; font-size: ${px(15)}px; line-height: ${px(18)}px; letter-spacing: 0.14em; + text-transform: uppercase; color: rgba(42, 28, 6, 0.62); } + .nt { font-family: ${DISPLAY}; font-size: ${px(54)}px; line-height: ${px(58)}px; white-space: nowrap; letter-spacing: 0.01em; } + .due .nt { font-size: ${px(44)}px; line-height: ${px(48)}px; } + .dl { font-family: 'DeckSansBold', sans-serif; font-size: ${px(19)}px; line-height: ${px(23)}px; color: #7d150c; white-space: nowrap; } + .dl2 { font-family: 'DeckSansBold', sans-serif; font-size: ${px(18)}px; line-height: ${px(22)}px; color: rgba(42, 28, 6, 0.8); white-space: nowrap; } + /* The count sits in the note's top strip: what shows of a note further down the pile. */ + .ct { position: absolute; right: ${px(12)}px; top: ${px(6)}px; min-width: ${px(54)}px; height: ${px(30)}px; padding: 0 ${px(9)}px; + border-radius: ${px(15)}px; background: #2a1c06; color: ${paper}; text-align: center; + font-family: ${DISPLAY}; font-size: ${px(24)}px; line-height: ${px(30)}px; } + .sh { position: absolute; inset: 0; background: #000; pointer-events: none; } + .hd { position: absolute; left: ${px(10)}px; bottom: ${px(4)}px; height: ${px(32)}px; padding: 0 ${px(14)}px; border-radius: ${px(16)}px; + background: ${rgba(pal.bg, 0.88)}; color: ${pal.muted}; font-family: 'DeckSansBold', sans-serif; font-size: ${px(17)}px; + line-height: ${px(32)}px; letter-spacing: 0.12em; text-transform: uppercase; white-space: nowrap; } + .hn { color: ${paper}; font-family: ${DISPLAY}; font-size: ${px(22)}px; letter-spacing: 0.02em; }`; + const body = `<div id="pn" data-k="pn"> + ${blocks.join("\n ")} + </div>`; + return { html: page("goals", schedule, opts, F, css, body, init, cues, states.map((_, j) => `s${j}`)), items }; +} + +// --------------------------------------------------------------------------- +// PEAK: the moving start. +// --------------------------------------------------------------------------- + +/** Label rows on a scale: each wanted y, pushed apart to `gap` and kept in [top, bottom]. */ +export function spreadLabels(ys, gap, top, bottom) { + const order = ys.map((y, i) => ({ y, i })).sort((a, b) => a.y - b.y); + const out = order.map((o) => o.y); + for (let i = 1; i < out.length; i += 1) out[i] = Math.max(out[i], out[i - 1] + gap); + if (out.length && out[out.length - 1] > bottom) { + out[out.length - 1] = bottom; + for (let i = out.length - 2; i >= 0; i -= 1) out[i] = Math.min(out[i], out[i + 1] - gap); + } + if (out.length && out[0] < top) { + out[0] = top; + for (let i = 1; i < out.length; i += 1) out[i] = Math.max(out[i], out[i - 1] + gap); + } + const res = new Array(ys.length); + order.forEach((o, n) => { res[o.i] = out[n]; }); + return res; +} + +/** The moving start's page: `{ html, items }`. */ +export function peakHtml(schedule, render, opts = {}) { + const cfg = resolveMeasureExtra("peak", render); + const states = peakStates(schedule, render); + if (!cfg || !states.length) throw new Error("peak: the schedule's measure slice has no remembered start on camera"); + const F = frameOf("peak", schedule, render); + const { geo, px } = F; + const pal = render.palette; + const red = cfg.color ?? MEASURE_RED; + const [lo, hi] = states[0].range; + const top = px(96); + const bottom = geo.height - px(84); + const yOf = (v) => r4(bottom - ((v - lo) / (hi - lo)) * (bottom - top)); + const rulerX = px(72); + // The ruler: a tick a pound, a number every five. + const marks = []; + for (let v = Math.ceil(lo); v <= hi; v += 1) { + const major = v % 5 === 0; + marks.push(`<div class="mk${major ? " mj" : ""}" style="top:${yOf(v)}px"></div>${major ? `<div class="ml" style="top:${r4(yOf(v) - px(9))}px">${v}</div>` : ""}`); + } + const spans = upSpans(states.map((s) => s.at), cfg, schedule); + const items = []; + const { init, cues } = stateCues(states, spans, { + own: (st, j, init) => { + const ev = []; + const t = st.ticks.find((x) => x.latest); + const k = `s${j}.t${String(t.value).replace(".", "_")}`; + if (!st.repeat) { + init[`${k}b`] = { scaleX: 0 }; + init[`${k}l`] = { opacity: 0, x: px(-12) }; + ev.push({ k: `${k}b`, at: st.at, dur: 0.35, to: { scaleX: 1 }, ease: "power3.out" }); + ev.push({ k: `${k}l`, at: st.at + 0.15, dur: 0.3, to: { opacity: 1, x: 0 }, ease: "power2.out" }); + } else { + init[`${k}n`] = { scale: 1.8, opacity: 0 }; + ev.push({ k: `${k}n`, at: st.at + 0.05, dur: 0.32, to: { scale: 1, opacity: 1 }, ease: "back.out(2.2)" }); + } + // The drift bracket grows to its new extent. + const prev = states[j - 1]; + if (prev && (prev.lo !== st.lo || prev.hi !== st.hi)) { + init[`s${j}.br`] = { y: r4(yOf(prev.hi) - yOf(st.hi)), height: r4(yOf(prev.lo) - yOf(prev.hi)) }; + ev.push({ k: `s${j}.br`, at: st.at + 0.1, dur: 0.45, to: { y: 0, height: r4(yOf(st.lo) - yOf(st.hi)) }, ease: "power2.out" }); + } + return ev; + }, + }); + const labelGap = px(30); + const blocks = states.map((st, j) => { + const ys = st.ticks.map((t) => yOf(t.value)); + const ly = spreadLabels(ys, labelGap, top - px(8), bottom + px(8)); + const ticks = st.ticks.map((t, i) => { + const k = `s${j}.t${String(t.value).replace(".", "_")}`; + const cls = t.latest ? " now" : ""; + const lead = Math.abs(ly[i] - ys[i]) > 1 + ? `<svg class="ld" style="top:${r4(Math.min(ys[i], ly[i]) - 1)}px;height:${r4(Math.abs(ly[i] - ys[i]) + 2)}px" viewBox="0 0 ${px(14)} ${r4(Math.abs(ly[i] - ys[i]) + 2)}" preserveAspectRatio="none"><line x1="0" y1="${ys[i] < ly[i] ? 1 : r4(Math.abs(ly[i] - ys[i]) + 1)}" x2="${px(14)}" y2="${ys[i] < ly[i] ? r4(Math.abs(ly[i] - ys[i]) + 1) : 1}" /></svg>` + : ""; + const n = t.count > 1 ? `<span class="tn" data-k="${k}n">×${t.count}</span>` : ""; + return `<div class="tb${cls}" data-k="${k}b" style="top:${r4(ys[i] - px(2))}px"></div>${lead}<div class="tl${cls}" data-k="${k}l" style="top:${r4(ly[i] - px(15))}px"><span class="tv">${t.approx ? "≈" : ""}${esc(weightText(t.value))}</span>${n}</div>`; + }).join(""); + const br = st.hi > st.lo + ? `<div class="br" data-k="s${j}.br" style="top:${yOf(st.hi)}px;height:${r4(yOf(st.lo) - yOf(st.hi))}px"></div>` + : ""; + const foot = `<div class="ft"><div class="fd${st.hi > st.lo ? "" : " one"}">${st.hi > st.lo ? `+${esc(weightText(st.drift))} lb` : `${st.ticks[0].approx ? "≈" : ""}${esc(weightText(st.lo))} lb`}</div><div class="fs">${st.hi > st.lo ? "between his tellings" : "his first telling"} · told ${st.told}×</div></div>`; + const html = `<div class="st" data-k="s${j}">${br}${ticks}${foot}</div>`; + items.push({ key: `s${j}`, gate: [`s${j}`, "autoAlpha"], html }); + return html; + }); + const css = ` + #pn { position: absolute; inset: 0; visibility: hidden; opacity: 0; border-radius: ${px(10)}px; + background: ${rgba(pal.bg, 0.88)}; border-left: ${px(5)}px solid ${pal.muted}; + box-shadow: 0 ${px(8)}px ${px(26)}px rgba(0, 0, 0, 0.4); } + .ti { position: absolute; left: ${px(20)}px; right: ${px(16)}px; top: ${px(16)}px; font-family: 'DeckSansBold', sans-serif; + font-size: ${px(19)}px; line-height: ${px(24)}px; letter-spacing: 0.1em; text-transform: uppercase; color: ${pal.fg}; } + .ti small { display: block; margin-top: ${px(2)}px; font-family: 'DeckSans', sans-serif; font-size: ${px(16)}px; letter-spacing: 0.02em; + text-transform: none; color: ${pal.muted}; white-space: nowrap; } + .ru { position: absolute; left: ${rulerX}px; top: ${top}px; width: ${px(2)}px; height: ${r4(bottom - top)}px; background: ${rgba(pal.muted, 0.7)}; } + .mk { position: absolute; left: ${rulerX - px(6)}px; width: ${px(6)}px; height: ${px(1)}px; background: ${rgba(pal.muted, 0.55)}; } + .mk.mj { left: ${rulerX - px(12)}px; width: ${px(12)}px; height: ${px(2)}px; background: ${pal.muted}; } + .ml { position: absolute; left: ${px(14)}px; width: ${px(40)}px; text-align: right; font-size: ${px(15)}px; line-height: ${px(18)}px; + color: ${pal.muted}; font-variant-numeric: tabular-nums; } + .st { position: absolute; inset: 0; visibility: hidden; opacity: 0; } + .tb { position: absolute; left: ${rulerX + px(2)}px; width: ${px(40)}px; height: ${px(4)}px; border-radius: ${px(2)}px; + background: ${pal.muted}; transform-origin: 0 50%; } + .tb.now { background: ${pal.fg}; box-shadow: 0 0 ${px(10)}px ${rgba(pal.fg, 0.6)}; } + .ld { position: absolute; left: ${rulerX + px(42)}px; width: ${px(14)}px; overflow: visible; } + .ld line { stroke: ${pal.muted}; stroke-width: ${px(1.5)}; } + .tl { position: absolute; left: ${rulerX + px(58)}px; height: ${px(30)}px; white-space: nowrap; color: ${pal.muted}; + display: flex; align-items: baseline; gap: ${px(6)}px; } + .tl.now { color: ${pal.fg}; } + .tv { font-family: ${DISPLAY}; font-size: ${px(27)}px; line-height: ${px(30)}px; font-variant-numeric: tabular-nums; } + .tn { display: inline-block; font-family: 'DeckSansBold', sans-serif; font-size: ${px(19)}px; color: ${red}; transform-origin: 0 70%; } + .br { position: absolute; left: ${px(32)}px; width: ${px(10)}px; border: ${px(3)}px solid ${red}; border-right: none; + border-radius: ${px(3)}px 0 0 ${px(3)}px; } + .ft { position: absolute; left: ${px(20)}px; right: ${px(14)}px; bottom: ${px(14)}px; } + .fd { font-family: ${DISPLAY}; font-size: ${px(36)}px; line-height: ${px(38)}px; color: ${red}; white-space: nowrap; } + .fd.one { color: ${pal.fg}; } + .fs { font-size: ${px(15)}px; line-height: ${px(19)}px; color: ${pal.muted}; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }`; + const body = `<div id="pn" data-k="pn"> + <div class="ti">${esc(cfg.title)}<small>what he says he started at</small></div> + <div class="ru"></div> + ${marks.join("")} + ${blocks.join("\n ")} + </div>`; + return { html: page("peak", schedule, opts, F, css, body, init, cues, states.map((_, j) => `s${j}`)), items }; +} + +// --------------------------------------------------------------------------- +// PROMISE: the days since. +// --------------------------------------------------------------------------- + +/** The promise clock's page: `{ html, items }`. */ +export function promiseHtml(schedule, render, opts = {}) { + const cfg = resolveMeasureExtra("promise", render); + const states = promiseStates(schedule, render); + if (!cfg || !states.length) throw new Error("promise: the schedule's measure slice has no promise on camera"); + const F = frameOf("promise", schedule, render); + const { px } = F; + const pal = render.palette; + const red = MEASURE_RED; + const green = pal.accent ?? "#22AB83"; + const spans = upSpans(states.map((s) => s.at), cfg, schedule); + const items = []; + const { init, cues } = stateCues(states, spans, { + own: (st, j, init) => { + const ev = []; + const prev = states[j - 1]; + st.rows.forEach((r, i) => { + const k = `s${j}.r${i}`; + if (prev && prev.rows[i] && prev.rows[i].days !== r.days) { + init[`${k}d`] = { y: px(-14), opacity: 0.35 }; + ev.push({ k: `${k}d`, at: st.at, dur: 0.18, to: { y: 0, opacity: 1 }, ease: "power2.out" }); + } + if (r.fresh) { + init[`${k}f`] = { opacity: 0.9 }; + init[`${k}q`] = { x: px(18), opacity: 0 }; + ev.push({ k: `${k}q`, at: st.at, dur: 0.3, to: { x: 0, opacity: 1 }, ease: "power2.out" }); + ev.push({ k: `${k}f`, at: st.at + 0.15, dur: 1.4, to: { opacity: 0 }, ease: "power1.in" }); + } + }); + return ev; + }, + }); + const blocks = states.map((st, j) => { + const rows = st.rows.map((r, i) => { + const k = `s${j}.r${i}`; + const days = r.days === 0 ? "Today" : `${r.days} day${r.days === 1 ? "" : "s"}`; + const q = r.check + ? `<div class="ck" data-k="${k}q"><div class="cf" data-k="${k}f"></div><span class="qm">“</span>${esc(r.check.text.replace(/^["“”]+|["“”]+$/g, ""))}<span class="qm">”</span>${r.check.date ? ` <span class="cd">· ${esc(shortDate(r.check.date))}</span>` : ""}</div>` + : `<div class="ck none">no word on it since</div>`; + return `<div class="row${r.kept ? " kept" : ""}"><div class="hd">${esc(r.what)} ${esc(cfg.verb)} ${esc(shortDate(r.said))}</div><div class="mid"><div class="dy" data-k="${k}d">${esc(days)}</div><div class="to">as of<br>${esc(shortDate(r.to))}</div><div class="pill">${esc(r.kept ? cfg.kept : cfg.broken)}</div></div>${q}</div>`; + }).join(""); + const html = `<div class="st${st.rows.some((r) => r.kept) ? " kept" : ""}" data-k="s${j}">${rows}</div>`; + items.push({ key: `s${j}`, gate: [`s${j}`, "autoAlpha"], html }); + return html; + }); + const css = ` + #pn { position: absolute; inset: 0; visibility: hidden; opacity: 0; } + .st { position: absolute; inset: 0; visibility: hidden; opacity: 0; border-radius: ${px(10)}px; + background: ${rgba(pal.bg, 0.92)}; border-left: ${px(6)}px solid ${red}; + box-shadow: 0 ${px(8)}px ${px(26)}px rgba(0, 0, 0, 0.45); padding: ${px(14)}px ${px(22)}px ${px(12)}px ${px(22)}px; } + .st.kept { border-left-color: ${green}; } + .row { display: flex; flex-direction: column; gap: ${px(4)}px; } + .hd { font-family: 'DeckSansBold', sans-serif; font-size: ${px(21)}px; line-height: ${px(26)}px; letter-spacing: 0.12em; + text-transform: uppercase; color: ${pal.muted}; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; } + .mid { display: flex; align-items: center; justify-content: space-between; gap: ${px(16)}px; height: ${px(78)}px; } + .dy { font-family: ${DISPLAY}; font-size: ${px(74)}px; line-height: ${px(78)}px; color: ${pal.fg}; text-transform: uppercase; + white-space: nowrap; font-variant-numeric: tabular-nums; } + .to { flex: 1 1 auto; align-self: flex-end; padding-bottom: ${px(14)}px; font-family: 'DeckSansBold', sans-serif; font-size: ${px(16)}px; + line-height: ${px(19)}px; letter-spacing: 0.1em; text-transform: uppercase; color: ${pal.muted}; white-space: nowrap; } + .pill { flex: none; padding: 0 ${px(16)}px; height: ${px(42)}px; border-radius: ${px(6)}px; background: ${red}; color: #fff; + font-family: 'DeckSansBold', sans-serif; font-size: ${px(23)}px; line-height: ${px(42)}px; letter-spacing: 0.1em; + text-transform: uppercase; white-space: nowrap; } + .kept .pill { background: ${green}; } + .ck { position: relative; font-size: ${px(20)}px; line-height: ${px(25)}px; color: ${pal.fg}; padding: ${px(2)}px ${px(6)}px; + margin-left: ${px(-6)}px; border-radius: ${px(4)}px; + display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; } + .ck.none { color: ${pal.muted}; } + .cf { position: absolute; inset: 0; background: ${rgba(pal.amber ?? "#E8A33F", 0.55)}; opacity: 0; border-radius: ${px(4)}px; } + .qm { color: ${pal.amber ?? pal.muted}; font-family: 'DeckSansBold', sans-serif; } + .cd { color: ${pal.muted}; white-space: nowrap; }`; + const body = `<div id="pn" data-k="pn"> + ${blocks.join("\n ")} + </div>`; + return { html: page("promise", schedule, opts, F, css, body, init, cues, states.map((_, j) => `s${j}`)), items }; +} + +// --------------------------------------------------------------------------- +// DIET: the stamp. +// --------------------------------------------------------------------------- + +/** The stamp's words a size that fits its box: the condensed face at ~0.5 em a letter. */ +export function stampSize(label, room) { + const n = Math.max(1, [...String(label)].length); + return Math.max(30, Math.min(76, Math.floor(room / (0.52 * n)))); +} + +// An ink texture: fractal noise as the stamp's alpha, so it reads pressed, not printed. +const INK = "url(\"data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='240' height='120'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.8' numOctaves='2' seed='7'/><feColorMatrix values='0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -1.6 1.75'/></filter><rect width='240' height='120' filter='url(%23n)'/></svg>\")"; + +/** The diet badge's page: `{ html, items }`. */ +export function dietHtml(schedule, render, opts = {}) { + const cfg = resolveMeasureExtra("diet", render); + const states = dietStates(schedule, render); + if (!cfg || !states.length) throw new Error("diet: the schedule's measure slice has no diet on camera"); + const F = frameOf("diet", schedule, render); + const { geo, px } = F; + const pal = render.palette; + const SLAM = 0.16; + const spans = upSpans(states.map((s) => s.at), cfg, schedule); + const items = []; + const { init, cues } = stateCues(states, spans, { + overlap: SLAM, + own: (st, j, init) => { + const k = `s${j}.s`; + const ev = []; + if (!st.diet) { + init[k] = { opacity: 0 }; + ev.push({ k, at: st.at, dur: 0.5, to: { opacity: 0.6 }, ease: "power1.out" }); + } else if (st.slam) { + // The slam: in from big and turned, hard onto the page, then a shake. + init[k] = { scale: 2.3, rotation: -15, opacity: 0 }; + ev.push({ k, at: st.at, dur: SLAM, to: { scale: 1, rotation: -5, opacity: 1 }, ease: "power4.in" }); + init[`s${j}.w`] = { x: 0 }; + const shake = [px(8), px(-6), px(4), px(-2), 0]; + shake.forEach((x, n) => ev.push({ k: `s${j}.w`, at: st.at + SLAM + n * 0.045, dur: 0.045, to: { x }, ease: "sine.inOut" })); + } else { + init[k] = { opacity: 0 }; + ev.push({ k, at: st.at, dur: 0.3, to: { opacity: 1 }, ease: "power1.out" }); + } + return ev; + }, + }); + // The words' room in design pixels (the box less the stamp's border and padding). + const room = MEASURE_BOXES.diet.width - 110; + const blocks = states.map((st, j) => { + const d = st.diet; + const label = d ? d.label : cfg.labels.off ?? "No diet"; + const ink = d ? d.color : pal.muted; + const size = stampSize(label, room); + const sub = d + ? `<div class="sb"><span class="dn">Diet${d.n !== null ? ` #${d.n}` : ""}</span>${d.detail ? `<span class="dd">${esc(d.detail)}</span>` : ""}</div>` + : `<div class="sb"><span class="dd">he says he is on none</span></div>`; + const html = `<div class="st" data-k="s${j}"><div class="wr" data-k="s${j}.w"><div class="sp${d ? "" : " off"}" data-k="s${j}.s"><div class="ink" style="color:${ink};border-color:${ink}"><div class="lb" style="font-size:${px(size)}px;line-height:${px(Math.round(size * 1.02))}px">${esc(label)}</div>${sub}</div></div></div></div>`; + items.push({ key: `s${j}`, gate: [`s${j}`, "autoAlpha"], html }); + return html; + }); + const css = ` + #pn { position: absolute; inset: 0; visibility: hidden; opacity: 0; } + .st { position: absolute; inset: 0; visibility: hidden; opacity: 0; display: flex; align-items: center; justify-content: center; } + .wr { display: flex; align-items: center; justify-content: center; } + /* The plate is solid (it has to read over any footage); only the ink is pressed. */ + .sp { max-width: ${geo.width - px(40)}px; border-radius: ${px(10)}px; background: ${rgba(pal.bg, 0.93)}; padding: ${px(6)}px; + box-shadow: 0 ${px(8)}px ${px(22)}px rgba(0, 0, 0, 0.5); transform: rotate(-5deg); } + .ink { padding: ${px(6)}px ${px(22)}px ${px(10)}px ${px(22)}px; border: ${px(6)}px solid; border-radius: ${px(7)}px; + box-shadow: inset 0 0 0 ${px(3)}px ${rgba(pal.bg, 0.9)}, inset 0 0 0 ${px(5)}px currentColor; + display: flex; flex-direction: column; align-items: center; + -webkit-mask-image: ${INK}; mask-image: ${INK}; -webkit-mask-size: ${px(240)}px ${px(120)}px; mask-size: ${px(240)}px ${px(120)}px; } + .lb { font-family: ${DISPLAY}; text-transform: uppercase; letter-spacing: 0.03em; white-space: nowrap; } + .sb { display: flex; align-items: baseline; gap: ${px(12)}px; margin-top: ${px(2)}px; white-space: nowrap; max-width: 100%; } + .dn { font-family: 'DeckSansBold', sans-serif; font-size: ${px(22)}px; letter-spacing: 0.16em; text-transform: uppercase; } + .dd { font-family: 'DeckSansBold', sans-serif; font-size: ${px(20)}px; color: ${pal.fg}; overflow: hidden; text-overflow: ellipsis; } + .off .dd { color: ${pal.muted}; }`; + const body = `<div id="pn" data-k="pn"> + ${blocks.join("\n ")} + </div>`; + return { html: page("diet", schedule, opts, F, css, body, init, cues, states.map((_, j) => `s${j}`)), items }; +} diff --git a/umtool/report-to-video/deck.mjs b/umtool/report-to-video/deck.mjs @@ -175,7 +175,10 @@ export function validateChrome(chrome, render = {}) { // (counter.mjs: the tally's named series). // `rail` (rail.mjs: `{labels}`) likewise has no default to fill, nor // `sectionTitle` (section-title.mjs: the current section's name). - unknownKeys(d, [...Object.keys(DECK_DEFAULTS), "finale", "claims", "counter", "rail", "sectionTitle"], w, errors); + // So are the measure extras' (`goals`, `peak`, `promise`, `diet`: + // measure-extras-settings.mjs) -- every deck key a SETTINGS entry owns. + const owned = SETTINGS.filter((s) => s.deck && !s.whole).map((s) => s.key.slice("deck.".length)); + unknownKeys(d, [...new Set([...Object.keys(DECK_DEFAULTS), "finale", "claims", "counter", "rail", "sectionTitle", ...owned])], w, errors); deckChecked = true; } errors.push(...entry.validate(settingValue(chrome, entry), { render, chrome, deck: d, where: w })); diff --git a/umtool/report-to-video/fixtures/measure-extras/make-fixture.mjs b/umtool/report-to-video/fixtures/measure-extras/make-fixture.mjs @@ -0,0 +1,45 @@ +// The measure extras' test fixture (measure-extras.test.mjs), made from the +// synthetic measure slice the weight-video lanes shared (real quartering-diet +// ledger rows, fake cut times; 438 KB): only what the goal stack, the moving +// start, the promise clock and the diet badge read -- every goal, remembered +// weight, promise and check, the diet events that change the state's diet -- +// and of each state only the fields they read. +// +// node umtool/report-to-video/fixtures/measure-extras/make-fixture.mjs <measure-slice.fixture.json> +// +// writes measure.json beside this file. Synthetic times, like every fixture. +import { readFileSync, writeFileSync } from "node:fs"; +import { fileURLToPath } from "node:url"; + +const src = process.argv[2]; +if (!src) { + console.error("usage: make-fixture.mjs <measure-slice.fixture.json>"); + process.exit(2); +} +const m = JSON.parse(readFileSync(src, "utf8")); +const KINDS = new Set(["goal", "goalLoss", "remembered", "promise", "promiseCheck"]); +const EVENT_KEYS = ["t", "row", "segment", "date", "asOf", "kind", "value", "qualifier", "display", "label", "deadline", "regime", "event", "promise", "source"]; +const STATE_KEYS = ["t", "goal", "goals", "diet", "promises"]; +const pick = (o, keys) => Object.fromEntries(keys.filter((k) => o[k] !== undefined).map((k) => [k, o[k]])); + +const events = []; +const state = [pick(m.state[0], STATE_KEYS)]; +let dietKey = null; +m.events.forEach((e, i) => { + const s = m.state[i + 1]; + const d = s?.diet ? `${s.diet.regime}|${s.diet.n}|${s.diet.display}` : "none"; + const keep = KINDS.has(e.kind) || (e.kind === "diet" && d !== dietKey); + dietKey = d; + if (!keep) return; + events.push({ ...pick(e, EVENT_KEYS), ...(e.kind === "promise" || e.kind === "promiseCheck" ? { quote: e.quote } : {}) }); + state.push(pick(s, STATE_KEYS)); +}); +const out = { + version: m.version, unit: m.unit, scale: m.scale, asOfRender: m.asOfRender, scopes: m.scopes, + events, hidden: [], state, + totals: pick(m.totals, ["goals", "goalRepeats", "diets", "peakDrift"]), + _fixture: "measure-extras test fixture: made by make-fixture.mjs from the lanes' synthetic measure slice (real ledger rows, fake cut times)", +}; +const file = fileURLToPath(new URL("./measure.json", import.meta.url)); +writeFileSync(file, JSON.stringify(out) + "\n"); +console.log(`${file}: ${events.length} events, ${(JSON.stringify(out).length / 1024).toFixed(1)} KB`); diff --git a/umtool/report-to-video/fixtures/measure-extras/measure.json b/umtool/report-to-video/fixtures/measure-extras/measure.json @@ -0,0 +1 @@ +{"version":1,"unit":"lb","scale":{"min":220,"max":400},"asOfRender":"2026-11-05","scopes":["weight","regime"],"events":[{"t":8,"row":"r01","segment":"s000","date":"2018-02-06","asOf":null,"kind":"diet","value":null,"qualifier":null,"display":"Some diet","label":"says he is on a diet he does not name","deadline":null,"regime":"other","event":"on","source":"clip"},{"t":11.96,"row":"r02","segment":"s001","date":"2018-02-20","asOf":null,"kind":"diet","value":null,"qualifier":null,"display":"Some diet","label":"says he is on a diet he does not name","deadline":null,"regime":"other","event":"on","source":"clip"},{"t":27.78,"row":"w02","segment":"s005","date":"2021-01-06","asOf":null,"kind":"goalLoss","value":-40,"qualifier":null,"display":"lose 40","label":"the 2021 new-year goal","deadline":null,"regime":null,"event":null,"source":"clip"},{"t":31.74,"row":"r05","segment":"s006","date":"2021-04-02","asOf":null,"kind":"diet","value":null,"qualifier":null,"display":"Some diet","label":"says he is on a diet he does not name","deadline":null,"regime":"other","event":"on","source":"clip"},{"t":39.65,"row":"r07","segment":"s008","date":"2021-09-14","asOf":null,"kind":"diet","value":null,"qualifier":null,"display":"Keto","label":"starts keto","deadline":null,"regime":"keto","event":"start","source":"clip"},{"t":43.6,"row":"w06","segment":"s009","date":"2021-09-14","asOf":null,"kind":"goalLoss","value":-100,"qualifier":null,"display":"lose 100","label":"needs to lose 100, at the first keto start","deadline":null,"regime":null,"event":null,"source":"clip"},{"t":47.56,"row":"r09","segment":"s010","date":"2021-09-18","asOf":null,"kind":"diet","value":null,"qualifier":null,"display":"Keto","label":"says he is on keto","deadline":null,"regime":"keto","event":"on","source":"clip"},{"t":55.47,"row":"r10","segment":"s012","date":"2022-07-27","asOf":null,"kind":"diet","value":null,"qualifier":null,"display":"Some diet","label":"starts a diet he does not name","deadline":null,"regime":"other","event":"start","source":"clip"},{"t":63.38,"row":"w08","segment":"s014","date":"2022-07-27","asOf":null,"kind":"goalLoss","value":-30,"qualifier":null,"display":"lose 30","label":"the five-month goal","deadline":null,"regime":null,"event":null,"source":"clip"},{"t":67.34,"row":"r14","segment":"s015","date":"2022-12-30","asOf":null,"kind":"diet","value":null,"qualifier":null,"display":"Carnivore","label":"says he is on carnivore","deadline":null,"regime":"carnivore","event":"on","source":"clip"},{"t":71.3,"row":"w09","segment":"s016","date":"2022-12-30","asOf":null,"kind":"goalLoss","value":-50,"qualifier":null,"display":"lose 50","label":"the 2023 new-year goal","deadline":null,"regime":null,"event":null,"source":"clip"},{"t":75.25,"row":"w11","segment":"s017","date":"2023-01-13","asOf":null,"kind":"goalLoss","value":-50,"qualifier":null,"display":"lose 50","label":"fifty by summer","deadline":null,"regime":null,"event":null,"source":"clip"},{"t":79.21,"row":"r15","segment":"s018","date":"2023-02-09","asOf":null,"kind":"diet","value":null,"qualifier":null,"display":"Some diet","label":"starts a diet he does not name","deadline":null,"regime":"other","event":"start","source":"clip"},{"t":83.16,"row":"r17","segment":"s019","date":"2023-03-01","asOf":null,"kind":"diet","value":null,"qualifier":null,"display":"Some diet","label":"starts a diet he does not name","deadline":null,"regime":"other","event":"start","source":"clip"},{"t":87.12,"row":"r18","segment":"s020","date":"2023-03-01","asOf":null,"kind":"diet","value":null,"qualifier":null,"display":"Calories","label":"starts counting calories","deadline":null,"regime":"calories","event":"start","source":"clip"},{"t":95.03,"row":"w13","segment":"s022","date":"2023-03-02","asOf":null,"kind":"goalLoss","value":-100,"qualifier":null,"display":"lose 100","label":"'at least 100' at his then-fattest","deadline":null,"regime":null,"event":null,"source":"clip"},{"t":102.95,"row":"r20","segment":"s024","date":"2023-05-04","asOf":null,"kind":"diet","value":null,"qualifier":null,"display":"Some diet","label":"says he is on a diet he does not name","deadline":null,"regime":"other","event":"on","source":"clip"},{"t":110.86,"row":"w16","segment":"s026","date":"2023-06-07","asOf":null,"kind":"goalLoss","value":-75,"qualifier":null,"display":"lose 75","label":"seventy-five to go","deadline":null,"regime":null,"event":null,"source":"clip"},{"t":118.77,"row":"r23","segment":"s028","date":"2023-07-20","asOf":null,"kind":"diet","value":null,"qualifier":null,"display":"Calories","label":"starts counting calories","deadline":null,"regime":"calories","event":"start","source":"clip"},{"t":126.68,"row":"w19","segment":"s030","date":"2023-07-26","asOf":null,"kind":"goalLoss","value":-75,"qualifier":null,"display":"lose 75","label":"seventy-five, then fifty, in one breath","deadline":null,"regime":null,"event":null,"source":"clip"},{"t":134.59,"row":"r25","segment":"s032","date":"2023-08-21","asOf":null,"kind":"diet","value":null,"qualifier":null,"display":"Some diet","label":"starts a diet he does not name","deadline":null,"regime":"other","event":"start","source":"clip"},{"t":138.55,"row":"w21","segment":"s033","date":"2023-09-29","asOf":"2023-07-01","kind":"remembered","value":390,"qualifier":"≈","display":"390 lb","label":"the scale that ruined a vacation","deadline":null,"regime":null,"event":null,"source":"clip"},{"t":142.51,"row":"w22","segment":"s034","date":"2023-10-12","asOf":null,"kind":"goalLoss","value":-100,"qualifier":null,"display":"lose 100","label":"what he told his doctor","deadline":null,"regime":null,"event":null,"source":"clip"},{"t":146.46,"row":"r29","segment":"s035","date":"2023-12-14","asOf":null,"kind":"diet","value":null,"qualifier":null,"display":"Carnivore","label":"says he is on carnivore","deadline":null,"regime":"carnivore","event":"on","source":"clip"},{"t":150.42,"row":"r31","segment":"s036","date":"2024-01-02","asOf":null,"kind":"diet","value":null,"qualifier":null,"display":"Fasting","label":"starts intermittent fasting","deadline":null,"regime":"fasting","event":"start","source":"clip"},{"t":154.37,"row":"r32","segment":"s037","date":"2024-01-09","asOf":null,"kind":"diet","value":null,"qualifier":null,"display":"Fasting","label":"says he is on intermittent fasting","deadline":null,"regime":"fasting","event":"on","source":"clip"},{"t":158.33,"row":"r33","segment":"s038","date":"2024-01-12","asOf":null,"kind":"diet","value":null,"qualifier":null,"display":"Carnivore","label":"says he is on carnivore","deadline":null,"regime":"carnivore","event":"on","source":"clip"},{"t":166.24,"row":"w26","segment":"s040","date":"2024-01-12","asOf":"2023-12-31","kind":"remembered","value":365.7,"qualifier":null,"display":"365.7 lb","label":"365.7 - the most precise number he ever gives","deadline":null,"regime":null,"event":null,"source":"clip"},{"t":170.2,"row":"w27","segment":"s041","date":"2024-01-12","asOf":null,"kind":"goal","value":250,"qualifier":"≈","display":"250","label":"'I look good at like 250'","deadline":null,"regime":null,"event":null,"source":"clip"},{"t":174.15,"row":"r34","segment":"s042","date":"2024-01-26","asOf":null,"kind":"diet","value":null,"qualifier":null,"display":"Fasting","label":"says he is on intermittent fasting","deadline":null,"regime":"fasting","event":"on","source":"clip"},{"t":182.07,"row":"w29","segment":"s044","date":"2024-01-26","asOf":null,"kind":"goalLoss","value":-50,"qualifier":null,"display":"lose 50","label":"the end of the 2024 goal ladder","deadline":null,"regime":null,"event":null,"source":"clip"},{"t":189.98,"row":"w31","segment":"s046","date":"2024-01-30","asOf":"2023-12-31","kind":"remembered","value":365.7,"qualifier":null,"display":"365.7 lb","label":"365.7, restated","deadline":null,"regime":null,"event":null,"source":"clip"},{"t":193.93,"row":"w32","segment":"s047","date":"2024-01-30","asOf":null,"kind":"goal","value":230,"qualifier":null,"display":"220-240","label":"'when I'm at like 220 to 240, I'm good'","deadline":null,"regime":null,"event":null,"source":"clip"},{"t":201.85,"row":"r35","segment":"s049","date":"2024-02-13","asOf":null,"kind":"diet","value":null,"qualifier":null,"display":"Fasting","label":"says he is on intermittent fasting","deadline":null,"regime":"fasting","event":"on","source":"clip"},{"t":205.8,"row":"r36","segment":"s050","date":"2024-02-28","asOf":null,"kind":"diet","value":null,"qualifier":null,"display":"Fasting","label":"says he is on intermittent fasting","deadline":null,"regime":"fasting","event":"on","source":"clip"},{"t":209.76,"row":"r37","segment":"s051","date":"2024-04-02","asOf":null,"kind":"diet","value":null,"qualifier":null,"display":"Carnivore","label":"says he is on carnivore","deadline":null,"regime":"carnivore","event":"on","source":"clip"},{"t":213.71,"row":"r38","segment":"s052","date":"2024-04-09","asOf":null,"kind":"diet","value":null,"qualifier":null,"display":"Fasting","label":"says he is on intermittent fasting","deadline":null,"regime":"fasting","event":"on","source":"clip"},{"t":217.67,"row":"r39","segment":"s053","date":"2024-04-18","asOf":null,"kind":"diet","value":null,"qualifier":null,"display":"Fasting","label":"starts intermittent fasting","deadline":null,"regime":"fasting","event":"start","source":"clip"},{"t":225.58,"row":"w35","segment":"s055","date":"2024-04-25","asOf":"2008-06-30","kind":"remembered","value":368,"qualifier":null,"display":"368 lb","label":"368 at his wedding","deadline":null,"regime":null,"event":null,"source":"clip"},{"t":229.54,"row":"r41","segment":"s056","date":"2024-05-07","asOf":null,"kind":"diet","value":null,"qualifier":null,"display":"Carnivore","label":"says he is on carnivore","deadline":null,"regime":"carnivore","event":"on","source":"clip"},{"t":237.45,"row":"r42","segment":"s058","date":"2024-05-14","asOf":null,"kind":"diet","value":null,"qualifier":null,"display":"Fasting","label":"says he is on intermittent fasting","deadline":null,"regime":"fasting","event":"on","source":"clip"},{"t":245.36,"row":"r43","segment":"s060","date":"2024-07-09","asOf":null,"kind":"diet","value":null,"qualifier":null,"display":"Keto","label":"says he is on keto","deadline":null,"regime":"keto","event":"on","source":"clip"},{"t":249.32,"row":"r44","segment":"s061","date":"2024-07-30","asOf":null,"kind":"diet","value":null,"qualifier":null,"display":"Keto","label":"says he is on keto","deadline":null,"regime":"keto","event":"on","source":"clip"},{"t":257.23,"row":"r46","segment":"s063","date":"2024-07-31","asOf":null,"kind":"diet","value":null,"qualifier":null,"display":"Calories","label":"starts counting calories","deadline":null,"regime":"calories","event":"start","source":"clip"},{"t":261.19,"row":"r47","segment":"s064","date":"2024-08-22","asOf":null,"kind":"diet","value":null,"qualifier":null,"display":"Carnivore","label":"says he is on carnivore","deadline":null,"regime":"carnivore","event":"on","source":"clip"},{"t":265.14,"row":"r48","segment":"s065","date":"2024-09-03","asOf":null,"kind":"diet","value":null,"qualifier":null,"display":"Fasting","label":"starts intermittent fasting","deadline":null,"regime":"fasting","event":"start","source":"clip"},{"t":269.1,"row":"r49","segment":"s066","date":"2024-10-03","asOf":null,"kind":"diet","value":null,"qualifier":null,"display":"Carnivore","label":"says he is on carnivore","deadline":null,"regime":"carnivore","event":"on","source":"clip"},{"t":273.05,"row":"r50","segment":"s067","date":"2024-10-16","asOf":null,"kind":"diet","value":null,"qualifier":null,"display":"Fasting","label":"starts intermittent fasting","deadline":null,"regime":"fasting","event":"start","source":"clip"},{"t":277.01,"row":"w40","segment":"s068","date":"2024-11-04","asOf":null,"kind":"goalLoss","value":-70,"qualifier":null,"display":"lose 70","label":"seventy to go, post-election","deadline":null,"regime":null,"event":null,"source":"clip"},{"t":280.97,"row":"r51","segment":"s069","date":"2024-11-05","asOf":null,"kind":"diet","value":null,"qualifier":null,"display":"Keto","label":"starts keto","deadline":null,"regime":"keto","event":"start","source":"clip"},{"t":288.88,"row":"w41","segment":"s071","date":"2024-11-05","asOf":null,"kind":"goalLoss","value":-30,"qualifier":null,"display":"lose 30","label":"thirty by Christmas","deadline":null,"regime":null,"event":null,"source":"clip"},{"t":292.84,"row":"r52","segment":"s072","date":"2024-11-07","asOf":null,"kind":"diet","value":null,"qualifier":null,"display":"Fasting","label":"starts intermittent fasting","deadline":null,"regime":"fasting","event":"start","source":"clip"},{"t":296.79,"row":"r53","segment":"s073","date":"2024-11-11","asOf":null,"kind":"diet","value":null,"qualifier":null,"display":"Carnivore","label":"starts carnivore","deadline":null,"regime":"carnivore","event":"start","source":"clip"},{"t":304.7,"row":"r54","segment":"s075","date":"2024-11-26","asOf":null,"kind":"diet","value":null,"qualifier":null,"display":"Keto","label":"says he is on keto","deadline":null,"regime":"keto","event":"on","source":"clip"},{"t":308.66,"row":"r55","segment":"s076","date":"2024-12-03","asOf":null,"kind":"diet","value":null,"qualifier":null,"display":"Keto","label":"says he is on keto","deadline":null,"regime":"keto","event":"on","source":"clip"},{"t":312.62,"row":"w44","segment":"s077","date":"2024-12-24","asOf":null,"kind":"goalLoss","value":-100,"qualifier":null,"display":"lose 100","label":"the round hundred again","deadline":null,"regime":null,"event":null,"source":"clip"},{"t":316.57,"row":"r56","segment":"s078","date":"2025-01-02","asOf":null,"kind":"diet","value":null,"qualifier":null,"display":"Carnivore","label":"starts carnivore","deadline":null,"regime":"carnivore","event":"start","source":"clip"},{"t":324.48,"row":"r59","segment":"s080","date":"2025-03-11","asOf":null,"kind":"diet","value":null,"qualifier":null,"display":"Some diet","label":"starts a diet he does not name","deadline":null,"regime":"other","event":"start","source":"clip"},{"t":328.44,"row":"r60","segment":"s081","date":"2025-03-20","asOf":null,"kind":"diet","value":null,"qualifier":null,"display":"Fasting","label":"starts intermittent fasting","deadline":null,"regime":"fasting","event":"start","source":"clip"},{"t":336.35,"row":"r61","segment":"s083","date":"2025-03-27","asOf":null,"kind":"diet","value":null,"qualifier":null,"display":"Carnivore","label":"starts carnivore","deadline":null,"regime":"carnivore","event":"start","source":"clip"},{"t":340.31,"row":"r62","segment":"s084","date":"2025-04-08","asOf":null,"kind":"diet","value":null,"qualifier":null,"display":"Fasting","label":"says he is on intermittent fasting","deadline":null,"regime":"fasting","event":"on","source":"clip"},{"t":344.26,"row":"w46","segment":"s085","date":"2025-04-08","asOf":null,"kind":"goalLoss","value":-100,"qualifier":null,"display":"lose 100","label":"a promise with a one-year clock","deadline":null,"regime":null,"event":null,"source":"clip"},{"t":356.13,"row":"w50","segment":"s088","date":"2025-05-02","asOf":null,"kind":"goalLoss","value":-100,"qualifier":null,"display":"lose 100","label":"a hundred by Christmas","deadline":null,"regime":null,"event":null,"source":"clip"},{"t":360.09,"row":"w51","segment":"s089","date":"2025-05-02","asOf":"2025-02-01","kind":"remembered","value":370,"qualifier":null,"display":"370 lb","label":"370 at the start of the 2025 run","deadline":null,"regime":null,"event":null,"source":"clip"},{"t":364.04,"row":"r63","segment":"s090","date":"2025-05-06","asOf":null,"kind":"diet","value":null,"qualifier":null,"display":"Carnivore","label":"says he is on carnivore","deadline":null,"regime":"carnivore","event":"on","source":"clip"},{"t":368,"row":"r64","segment":"s091","date":"2025-05-28","asOf":null,"kind":"diet","value":null,"qualifier":null,"display":"Fasting","label":"starts intermittent fasting","deadline":null,"regime":"fasting","event":"start","source":"clip"},{"t":371.96,"row":"r65","segment":"s092","date":"2025-06-06","asOf":null,"kind":"diet","value":null,"qualifier":null,"display":"Some diet","label":"starts a diet he does not name","deadline":null,"regime":"other","event":"start","source":"clip"},{"t":379.87,"row":"r66","segment":"s094","date":"2025-06-25","asOf":null,"kind":"diet","value":null,"qualifier":null,"display":"Carnivore","label":"says he is on carnivore","deadline":null,"regime":"carnivore","event":"on","source":"clip"},{"t":383.82,"row":"r67","segment":"s095","date":"2025-07-15","asOf":null,"kind":"diet","value":null,"qualifier":null,"display":"Fasting","label":"says he is on intermittent fasting","deadline":null,"regime":"fasting","event":"on","source":"clip"},{"t":387.78,"row":"w55","segment":"s096","date":"2025-07-15","asOf":"2024-07-01","kind":"remembered","value":390,"qualifier":"≈","display":"390 lb","label":"390, 'last year'","deadline":null,"regime":null,"event":null,"source":"clip"},{"t":391.74,"row":"w56","segment":"s097","date":"2025-07-15","asOf":"2024-05-09","kind":"remembered","value":335,"qualifier":null,"display":"330-340 lb","label":"the crash diet floor","deadline":null,"regime":null,"event":null,"source":"clip"},{"t":395.69,"row":"w57","segment":"s098","date":"2025-07-15","asOf":null,"kind":"goal","value":265,"qualifier":null,"display":"260-270","label":"'I'll look thin'","deadline":null,"regime":null,"event":null,"source":"clip"},{"t":399.65,"row":"r68","segment":"s099","date":"2025-07-15","asOf":null,"kind":"diet","value":null,"qualifier":null,"display":"GLP-1","label":"says he is on the shot","deadline":null,"regime":"glp1","event":"on","source":"clip"},{"t":403.6,"row":"r70","segment":"s100","date":"2025-07-29","asOf":null,"kind":"diet","value":null,"qualifier":null,"display":"Carnivore","label":"says he is on carnivore","deadline":null,"regime":"carnivore","event":"on","source":"clip"},{"t":407.56,"row":"r71","segment":"s101","date":"2025-08-15","asOf":null,"kind":"diet","value":null,"qualifier":null,"display":"Fasting","label":"says he is on intermittent fasting","deadline":null,"regime":"fasting","event":"on","source":"clip"},{"t":415.47,"row":"w60","segment":"s103","date":"2025-08-15","asOf":"2025-04-15","kind":"remembered","value":387,"qualifier":null,"display":"387 lb","label":"387, four months earlier","deadline":null,"regime":null,"event":null,"source":"clip"},{"t":419.43,"row":"w61","segment":"s104","date":"2025-08-15","asOf":"2026-04-01","kind":"goal","value":275,"qualifier":null,"display":"275","label":"275 by his birthday","deadline":null,"regime":null,"event":null,"source":"clip"},{"t":435.25,"row":"r74","segment":"s108","date":"2025-10-03","asOf":null,"kind":"diet","value":null,"qualifier":null,"display":"Fasting","label":"says he is on intermittent fasting","deadline":null,"regime":"fasting","event":"on","source":"clip"},{"t":439.21,"row":"r75","segment":"s109","date":"2025-10-03","asOf":null,"kind":"diet","value":null,"qualifier":null,"display":"Carnivore","label":"says he is on carnivore","deadline":null,"regime":"carnivore","event":"on","source":"clip"},{"t":447.12,"row":"r76","segment":"s111","date":"2025-10-07","asOf":null,"kind":"diet","value":null,"qualifier":null,"display":"Some diet","label":"starts a diet he does not name","deadline":null,"regime":"other","event":"start","source":"clip"},{"t":451.08,"row":"r77","segment":"s112","date":"2025-10-08","asOf":null,"kind":"diet","value":null,"qualifier":null,"display":"cutting carbs","label":"says he is on counting calories","deadline":null,"regime":"calories","event":"on","source":"clip"},{"t":458.99,"row":"w68","segment":"s114","date":"2025-10-08","asOf":null,"kind":"goalLoss","value":-100,"qualifier":null,"display":"lose 100","label":"still a hundred to go","deadline":null,"regime":null,"event":null,"source":"clip"},{"t":462.95,"row":"w69","segment":"s115","date":"2025-10-09","asOf":null,"kind":"goalLoss","value":-150,"qualifier":null,"display":"lose 150","label":"'like 150'","deadline":null,"regime":null,"event":null,"source":"clip"},{"t":478.77,"row":"w72","segment":"s119","date":"2025-12-09","asOf":null,"kind":"goalLoss","value":-20,"qualifier":null,"display":"lose 20","label":"twenty a year","deadline":null,"regime":null,"event":null,"source":"clip"},{"t":486.68,"row":"w73","segment":"s121","date":"2026-01-09","asOf":"2025-02-01","kind":"remembered","value":385,"qualifier":null,"display":"380-390 lb","label":"the Hawaii peak","deadline":null,"regime":null,"event":null,"source":"clip"},{"t":494.59,"row":"r82","segment":"s123","date":"2026-01-16","asOf":null,"kind":"diet","value":null,"qualifier":null,"display":"Fasting","label":"says he is on intermittent fasting","deadline":null,"regime":"fasting","event":"on","source":"clip"},{"t":506.46,"row":"w77","segment":"s126","date":"2026-01-16","asOf":"2026-04-01","kind":"goal","value":320,"qualifier":null,"display":"320","label":"320 by his birthday","deadline":null,"regime":null,"event":null,"source":"clip"},{"t":510.42,"row":"w78","segment":"s127","date":"2026-01-16","asOf":null,"kind":"goal","value":240,"qualifier":"≈","display":"240","label":"the eventual target","deadline":null,"regime":null,"event":null,"source":"clip"},{"t":514.37,"row":"r83","segment":"s128","date":"2026-02-05","asOf":null,"kind":"diet","value":null,"qualifier":null,"display":"Keto","label":"starts keto","deadline":null,"regime":"keto","event":"start","source":"clip"},{"t":518.33,"row":"r85","segment":"s129","date":"2026-03-17","asOf":null,"kind":"diet","value":null,"qualifier":null,"display":"Carnivore","label":"starts carnivore","deadline":null,"regime":"carnivore","event":"start","source":"clip"},{"t":522.29,"row":"r86","segment":"s130","date":"2026-03-24","asOf":null,"kind":"diet","value":null,"qualifier":null,"display":"Keto","label":"starts keto","deadline":null,"regime":"keto","event":"start","source":"clip"},{"t":526.24,"row":"r87","segment":"s131","date":"2026-04-13","asOf":null,"kind":"diet","value":null,"qualifier":null,"display":"Fasting","label":"starts intermittent fasting","deadline":null,"regime":"fasting","event":"start","source":"clip"},{"t":538.11,"row":"r90","segment":"s134","date":"2026-07-09","asOf":null,"kind":"diet","value":null,"qualifier":null,"display":"Carnivore","label":"starts carnivore","deadline":null,"regime":"carnivore","event":"start","source":"clip"},{"t":542.07,"row":"r91","segment":"s135","date":"2026-07-20","asOf":null,"kind":"diet","value":null,"qualifier":null,"display":"Keto","label":"starts keto","deadline":null,"regime":"keto","event":"start","source":"clip"},{"t":549.98,"row":"r92","segment":"s137","date":"2026-07-21","asOf":null,"kind":"diet","value":null,"qualifier":null,"display":"Keto","label":"says he is on keto","deadline":null,"regime":"keto","event":"on","source":"clip"},{"t":569.76,"row":"w85","segment":"s142","date":"2026-07-28","asOf":null,"kind":"goalLoss","value":-50,"qualifier":null,"display":"lose 50","label":"fifty by the end of 2026","deadline":null,"regime":null,"event":null,"source":"clip"},{"t":581.63,"row":"w88","segment":"s145","date":"2026-07-31","asOf":null,"kind":"goal","value":250,"qualifier":null,"display":"250","label":"'closer to 250'","deadline":null,"regime":null,"event":null,"source":"clip"},{"t":585.58,"row":"w89","segment":"s146","date":"2026-07-31","asOf":"2025-02-01","kind":"remembered","value":390,"qualifier":null,"display":"390 lb","label":"390 on the scale, remembered again","deadline":null,"regime":null,"event":null,"source":"clip"},{"t":589.54,"row":"w90","segment":"s147","date":"2026-07-31","asOf":null,"kind":"goal","value":235,"qualifier":null,"display":"230-240","label":"230-240, computed from a height chart on air","deadline":null,"regime":null,"event":null,"source":"clip"},{"t":593.49,"row":"w91","segment":"s148","date":"2026-08-03","asOf":"2026-07-19","kind":"remembered","value":349,"qualifier":null,"display":"349 lb","label":"349 on keto day one - first time he names a start weight","deadline":null,"regime":null,"event":null,"source":"clip"},{"t":597.45,"row":"w92","segment":"s149","date":"2026-08-03","asOf":"2026-07-27","kind":"remembered","value":342,"qualifier":null,"display":"342 lb","label":"342 on 27 July (same ladder)","deadline":null,"regime":null,"event":null,"source":"clip"},{"t":605.36,"row":"r96","segment":"s151","date":"2026-08-06","asOf":null,"kind":"diet","value":null,"qualifier":null,"display":"Keto · 5 carbs a day","label":"says he is on keto","deadline":null,"regime":"keto","event":"on","source":"clip"},{"t":617.23,"row":"r101","segment":"s154","date":"2026-08-17","asOf":null,"kind":"diet","value":null,"qualifier":null,"display":"Keto + fasting Thu/Fri","label":"adds two fasting days a week","deadline":null,"regime":"fasting","event":"start","source":"clip"},{"t":644.92,"row":"w103","segment":"s161","date":"2026-08-28","asOf":"2023-12-31","kind":"remembered","value":365.7,"qualifier":null,"display":"365.7 lb","label":"365.7 - \"when I started this weight loss journey\"","deadline":null,"regime":null,"event":null,"source":"clip"},{"t":660.75,"row":"r102","segment":"s165","date":"2026-09-11","asOf":null,"kind":"diet","value":null,"qualifier":null,"display":"IF 2-3 days · ~400 kcal","label":"\"most days I eat like four hundred calories\"","deadline":null,"regime":"calories","event":"on","source":"clip"},{"t":676.57,"row":"w109","segment":"s169","date":"2026-09-17","asOf":"2024-09-01","kind":"remembered","value":390,"qualifier":"≈","display":"390 lb","label":"390 on a Florida scale \"two years ago\"","deadline":null,"regime":null,"event":null,"source":"clip"},{"t":684.48,"row":"w111","segment":"s171","date":"2026-09-24","asOf":null,"kind":"goal","value":225,"qualifier":"≈","display":"225","label":"\"two and a quarter\" (happy at 240)","deadline":null,"regime":null,"event":null,"source":"clip"},{"t":700.31,"row":"w116","segment":"s175","date":"2026-10-15","asOf":"2025-02-01","kind":"remembered","value":390,"qualifier":"≈","display":"390 lb","label":"\"almost 390 when I started my weight loss journey\"","deadline":null,"regime":null,"event":null,"source":"clip"},{"t":704.26,"row":"r104","segment":"s176","date":"2026-10-15","asOf":null,"kind":"diet","value":null,"qualifier":null,"display":"Keto + IF + walking","label":"\"Keto + Intermittent fasting + walking. That's it.\" (X)","deadline":null,"regime":"fasting","event":"on","source":"post"},{"t":712.18,"row":"p01","segment":"s178","date":"2026-10-23","asOf":null,"kind":"promise","value":null,"qualifier":null,"display":"scale video","label":"\"Buy 5 bags … I'll post a video of the scale. If I'm lying … $100\"","deadline":null,"regime":null,"event":null,"source":"post","quote":"291. Buy 5 bags if Huck's blend and I'll post a video of the scale"},{"t":720.09,"row":"w120","segment":"s180","date":"2026-10-31","asOf":null,"kind":"goalLoss","value":-65,"qualifier":null,"display":"lose 65","label":"65 by Christmas (was 50, then 60)","deadline":"by Christmas","regime":null,"event":null,"source":"post"},{"t":724.04,"row":"p02","segment":"s181","date":"2026-11-03","asOf":null,"kind":"promiseCheck","value":null,"qualifier":null,"display":"brush-off","label":"\"just pull up a video from three months ago\"","deadline":null,"regime":null,"event":null,"promise":"p01","source":"clip","quote":"you have to get on a scale it's like brother just pull up a video from three months ago"}],"hidden":[],"state":[{"t":0,"goal":null,"goals":[],"diet":null,"promises":[]},{"t":8,"goal":null,"goals":[],"diet":{"regime":"other","display":"Some diet","row":"r01","n":1},"promises":[]},{"t":11.96,"goal":null,"goals":[],"diet":{"regime":"other","display":"Some diet","row":"r02","n":2},"promises":[]},{"t":27.78,"goal":{"value":null,"loss":40,"deadline":null,"row":"w02"},"goals":["w02"],"diet":{"regime":"other","display":"Some diet","row":"r02","n":2},"promises":[]},{"t":31.74,"goal":{"value":null,"loss":40,"deadline":null,"row":"w02"},"goals":["w02"],"diet":{"regime":"other","display":"Some diet","row":"r05","n":3},"promises":[]},{"t":39.65,"goal":{"value":null,"loss":40,"deadline":null,"row":"w02"},"goals":["w02"],"diet":{"regime":"keto","display":"Keto","row":"r07","n":4},"promises":[]},{"t":43.6,"goal":{"value":null,"loss":100,"deadline":null,"row":"w06"},"goals":["w02","w06"],"diet":{"regime":"keto","display":"Keto","row":"r07","n":4},"promises":[]},{"t":47.56,"goal":{"value":null,"loss":100,"deadline":null,"row":"w06"},"goals":["w02","w06"],"diet":{"regime":"keto","display":"Keto","row":"r09","n":5},"promises":[]},{"t":55.47,"goal":{"value":null,"loss":100,"deadline":null,"row":"w06"},"goals":["w02","w06"],"diet":{"regime":"other","display":"Some diet","row":"r10","n":6},"promises":[]},{"t":63.38,"goal":{"value":210,"loss":30,"deadline":null,"row":"w08"},"goals":["w02","w06","w08"],"diet":{"regime":"other","display":"Some diet","row":"r10","n":6},"promises":[]},{"t":67.34,"goal":{"value":210,"loss":30,"deadline":null,"row":"w08"},"goals":["w02","w06","w08"],"diet":{"regime":"carnivore","display":"Carnivore","row":"r14","n":7},"promises":[]},{"t":71.3,"goal":{"value":190,"loss":50,"deadline":null,"row":"w09"},"goals":["w02","w06","w08","w09"],"diet":{"regime":"carnivore","display":"Carnivore","row":"r14","n":7},"promises":[]},{"t":75.25,"goal":{"value":190,"loss":50,"deadline":null,"row":"w11"},"goals":["w02","w06","w08","w09","w11"],"diet":{"regime":"carnivore","display":"Carnivore","row":"r14","n":7},"promises":[]},{"t":79.21,"goal":{"value":190,"loss":50,"deadline":null,"row":"w11"},"goals":["w02","w06","w08","w09","w11"],"diet":{"regime":"other","display":"Some diet","row":"r15","n":8},"promises":[]},{"t":83.16,"goal":{"value":190,"loss":50,"deadline":null,"row":"w11"},"goals":["w02","w06","w08","w09","w11"],"diet":{"regime":"other","display":"Some diet","row":"r17","n":9},"promises":[]},{"t":87.12,"goal":{"value":190,"loss":50,"deadline":null,"row":"w11"},"goals":["w02","w06","w08","w09","w11"],"diet":{"regime":"calories","display":"Calories","row":"r18","n":10},"promises":[]},{"t":95.03,"goal":{"value":140,"loss":100,"deadline":null,"row":"w13"},"goals":["w02","w06","w08","w09","w11","w13"],"diet":{"regime":"calories","display":"Calories","row":"r18","n":10},"promises":[]},{"t":102.95,"goal":{"value":140,"loss":100,"deadline":null,"row":"w13"},"goals":["w02","w06","w08","w09","w11","w13"],"diet":{"regime":"other","display":"Some diet","row":"r20","n":11},"promises":[]},{"t":110.86,"goal":{"value":165,"loss":75,"deadline":null,"row":"w16"},"goals":["w02","w06","w08","w09","w11","w13","w16"],"diet":{"regime":"other","display":"Some diet","row":"r20","n":11},"promises":[]},{"t":118.77,"goal":{"value":165,"loss":75,"deadline":null,"row":"w16"},"goals":["w02","w06","w08","w09","w11","w13","w16"],"diet":{"regime":"calories","display":"Calories","row":"r23","n":12},"promises":[]},{"t":126.68,"goal":{"value":165,"loss":75,"deadline":null,"row":"w19"},"goals":["w02","w06","w08","w09","w11","w13","w16","w19"],"diet":{"regime":"calories","display":"Calories","row":"r23","n":12},"promises":[]},{"t":134.59,"goal":{"value":165,"loss":75,"deadline":null,"row":"w19"},"goals":["w02","w06","w08","w09","w11","w13","w16","w19"],"diet":{"regime":"other","display":"Some diet","row":"r25","n":13},"promises":[]},{"t":138.55,"goal":{"value":165,"loss":75,"deadline":null,"row":"w19"},"goals":["w02","w06","w08","w09","w11","w13","w16","w19"],"diet":{"regime":"other","display":"Some diet","row":"r25","n":13},"promises":[]},{"t":142.51,"goal":{"value":140,"loss":100,"deadline":null,"row":"w22"},"goals":["w02","w06","w08","w09","w11","w13","w16","w19","w22"],"diet":{"regime":"other","display":"Some diet","row":"r25","n":13},"promises":[]},{"t":146.46,"goal":{"value":140,"loss":100,"deadline":null,"row":"w22"},"goals":["w02","w06","w08","w09","w11","w13","w16","w19","w22"],"diet":{"regime":"carnivore","display":"Carnivore","row":"r29","n":14},"promises":[]},{"t":150.42,"goal":{"value":140,"loss":100,"deadline":null,"row":"w22"},"goals":["w02","w06","w08","w09","w11","w13","w16","w19","w22"],"diet":{"regime":"fasting","display":"Fasting","row":"r31","n":15},"promises":[]},{"t":154.37,"goal":{"value":140,"loss":100,"deadline":null,"row":"w22"},"goals":["w02","w06","w08","w09","w11","w13","w16","w19","w22"],"diet":{"regime":"fasting","display":"Fasting","row":"r32","n":16},"promises":[]},{"t":158.33,"goal":{"value":140,"loss":100,"deadline":null,"row":"w22"},"goals":["w02","w06","w08","w09","w11","w13","w16","w19","w22"],"diet":{"regime":"carnivore","display":"Carnivore","row":"r33","n":17},"promises":[]},{"t":166.24,"goal":{"value":140,"loss":100,"deadline":null,"row":"w22"},"goals":["w02","w06","w08","w09","w11","w13","w16","w19","w22"],"diet":{"regime":"carnivore","display":"Carnivore","row":"r33","n":17},"promises":[]},{"t":170.2,"goal":{"value":250,"loss":null,"deadline":null,"row":"w27"},"goals":["w02","w06","w08","w09","w11","w13","w16","w19","w22","w27"],"diet":{"regime":"carnivore","display":"Carnivore","row":"r33","n":17},"promises":[]},{"t":174.15,"goal":{"value":250,"loss":null,"deadline":null,"row":"w27"},"goals":["w02","w06","w08","w09","w11","w13","w16","w19","w22","w27"],"diet":{"regime":"fasting","display":"Fasting","row":"r34","n":18},"promises":[]},{"t":182.07,"goal":{"value":190,"loss":50,"deadline":null,"row":"w29"},"goals":["w02","w06","w08","w09","w11","w13","w16","w19","w22","w27","w29"],"diet":{"regime":"fasting","display":"Fasting","row":"r34","n":18},"promises":[]},{"t":189.98,"goal":{"value":190,"loss":50,"deadline":null,"row":"w29"},"goals":["w02","w06","w08","w09","w11","w13","w16","w19","w22","w27","w29"],"diet":{"regime":"fasting","display":"Fasting","row":"r34","n":18},"promises":[]},{"t":193.93,"goal":{"value":230,"loss":null,"deadline":null,"row":"w32"},"goals":["w02","w06","w08","w09","w11","w13","w16","w19","w22","w27","w29","w32"],"diet":{"regime":"fasting","display":"Fasting","row":"r34","n":18},"promises":[]},{"t":201.85,"goal":{"value":230,"loss":null,"deadline":null,"row":"w32"},"goals":["w02","w06","w08","w09","w11","w13","w16","w19","w22","w27","w29","w32"],"diet":{"regime":"fasting","display":"Fasting","row":"r35","n":19},"promises":[]},{"t":205.8,"goal":{"value":230,"loss":null,"deadline":null,"row":"w32"},"goals":["w02","w06","w08","w09","w11","w13","w16","w19","w22","w27","w29","w32"],"diet":{"regime":"fasting","display":"Fasting","row":"r36","n":20},"promises":[]},{"t":209.76,"goal":{"value":230,"loss":null,"deadline":null,"row":"w32"},"goals":["w02","w06","w08","w09","w11","w13","w16","w19","w22","w27","w29","w32"],"diet":{"regime":"carnivore","display":"Carnivore","row":"r37","n":21},"promises":[]},{"t":213.71,"goal":{"value":230,"loss":null,"deadline":null,"row":"w32"},"goals":["w02","w06","w08","w09","w11","w13","w16","w19","w22","w27","w29","w32"],"diet":{"regime":"fasting","display":"Fasting","row":"r38","n":22},"promises":[]},{"t":217.67,"goal":{"value":230,"loss":null,"deadline":null,"row":"w32"},"goals":["w02","w06","w08","w09","w11","w13","w16","w19","w22","w27","w29","w32"],"diet":{"regime":"fasting","display":"Fasting","row":"r39","n":23},"promises":[]},{"t":225.58,"goal":{"value":230,"loss":null,"deadline":null,"row":"w32"},"goals":["w02","w06","w08","w09","w11","w13","w16","w19","w22","w27","w29","w32"],"diet":{"regime":"fasting","display":"Fasting","row":"r39","n":23},"promises":[]},{"t":229.54,"goal":{"value":230,"loss":null,"deadline":null,"row":"w32"},"goals":["w02","w06","w08","w09","w11","w13","w16","w19","w22","w27","w29","w32"],"diet":{"regime":"carnivore","display":"Carnivore","row":"r41","n":24},"promises":[]},{"t":237.45,"goal":{"value":230,"loss":null,"deadline":null,"row":"w32"},"goals":["w02","w06","w08","w09","w11","w13","w16","w19","w22","w27","w29","w32"],"diet":{"regime":"fasting","display":"Fasting","row":"r42","n":25},"promises":[]},{"t":245.36,"goal":{"value":230,"loss":null,"deadline":null,"row":"w32"},"goals":["w02","w06","w08","w09","w11","w13","w16","w19","w22","w27","w29","w32"],"diet":{"regime":"keto","display":"Keto","row":"r43","n":26},"promises":[]},{"t":249.32,"goal":{"value":230,"loss":null,"deadline":null,"row":"w32"},"goals":["w02","w06","w08","w09","w11","w13","w16","w19","w22","w27","w29","w32"],"diet":{"regime":"keto","display":"Keto","row":"r44","n":27},"promises":[]},{"t":257.23,"goal":{"value":230,"loss":null,"deadline":null,"row":"w32"},"goals":["w02","w06","w08","w09","w11","w13","w16","w19","w22","w27","w29","w32"],"diet":{"regime":"calories","display":"Calories","row":"r46","n":28},"promises":[]},{"t":261.19,"goal":{"value":230,"loss":null,"deadline":null,"row":"w32"},"goals":["w02","w06","w08","w09","w11","w13","w16","w19","w22","w27","w29","w32"],"diet":{"regime":"carnivore","display":"Carnivore","row":"r47","n":29},"promises":[]},{"t":265.14,"goal":{"value":230,"loss":null,"deadline":null,"row":"w32"},"goals":["w02","w06","w08","w09","w11","w13","w16","w19","w22","w27","w29","w32"],"diet":{"regime":"fasting","display":"Fasting","row":"r48","n":30},"promises":[]},{"t":269.1,"goal":{"value":230,"loss":null,"deadline":null,"row":"w32"},"goals":["w02","w06","w08","w09","w11","w13","w16","w19","w22","w27","w29","w32"],"diet":{"regime":"carnivore","display":"Carnivore","row":"r49","n":31},"promises":[]},{"t":273.05,"goal":{"value":230,"loss":null,"deadline":null,"row":"w32"},"goals":["w02","w06","w08","w09","w11","w13","w16","w19","w22","w27","w29","w32"],"diet":{"regime":"fasting","display":"Fasting","row":"r50","n":32},"promises":[]},{"t":277.01,"goal":{"value":170,"loss":70,"deadline":null,"row":"w40"},"goals":["w02","w06","w08","w09","w11","w13","w16","w19","w22","w27","w29","w32","w40"],"diet":{"regime":"fasting","display":"Fasting","row":"r50","n":32},"promises":[]},{"t":280.97,"goal":{"value":170,"loss":70,"deadline":null,"row":"w40"},"goals":["w02","w06","w08","w09","w11","w13","w16","w19","w22","w27","w29","w32","w40"],"diet":{"regime":"keto","display":"Keto","row":"r51","n":33},"promises":[]},{"t":288.88,"goal":{"value":210,"loss":30,"deadline":null,"row":"w41"},"goals":["w02","w06","w08","w09","w11","w13","w16","w19","w22","w27","w29","w32","w40","w41"],"diet":{"regime":"keto","display":"Keto","row":"r51","n":33},"promises":[]},{"t":292.84,"goal":{"value":210,"loss":30,"deadline":null,"row":"w41"},"goals":["w02","w06","w08","w09","w11","w13","w16","w19","w22","w27","w29","w32","w40","w41"],"diet":{"regime":"fasting","display":"Fasting","row":"r52","n":34},"promises":[]},{"t":296.79,"goal":{"value":210,"loss":30,"deadline":null,"row":"w41"},"goals":["w02","w06","w08","w09","w11","w13","w16","w19","w22","w27","w29","w32","w40","w41"],"diet":{"regime":"carnivore","display":"Carnivore","row":"r53","n":35},"promises":[]},{"t":304.7,"goal":{"value":210,"loss":30,"deadline":null,"row":"w41"},"goals":["w02","w06","w08","w09","w11","w13","w16","w19","w22","w27","w29","w32","w40","w41"],"diet":{"regime":"keto","display":"Keto","row":"r54","n":36},"promises":[]},{"t":308.66,"goal":{"value":210,"loss":30,"deadline":null,"row":"w41"},"goals":["w02","w06","w08","w09","w11","w13","w16","w19","w22","w27","w29","w32","w40","w41"],"diet":{"regime":"keto","display":"Keto","row":"r55","n":37},"promises":[]},{"t":312.62,"goal":{"value":140,"loss":100,"deadline":null,"row":"w44"},"goals":["w02","w06","w08","w09","w11","w13","w16","w19","w22","w27","w29","w32","w40","w41","w44"],"diet":{"regime":"keto","display":"Keto","row":"r55","n":37},"promises":[]},{"t":316.57,"goal":{"value":140,"loss":100,"deadline":null,"row":"w44"},"goals":["w02","w06","w08","w09","w11","w13","w16","w19","w22","w27","w29","w32","w40","w41","w44"],"diet":{"regime":"carnivore","display":"Carnivore","row":"r56","n":38},"promises":[]},{"t":324.48,"goal":{"value":140,"loss":100,"deadline":null,"row":"w44"},"goals":["w02","w06","w08","w09","w11","w13","w16","w19","w22","w27","w29","w32","w40","w41","w44"],"diet":{"regime":"other","display":"Some diet","row":"r59","n":39},"promises":[]},{"t":328.44,"goal":{"value":140,"loss":100,"deadline":null,"row":"w44"},"goals":["w02","w06","w08","w09","w11","w13","w16","w19","w22","w27","w29","w32","w40","w41","w44"],"diet":{"regime":"fasting","display":"Fasting","row":"r60","n":40},"promises":[]},{"t":336.35,"goal":{"value":140,"loss":100,"deadline":null,"row":"w44"},"goals":["w02","w06","w08","w09","w11","w13","w16","w19","w22","w27","w29","w32","w40","w41","w44"],"diet":{"regime":"carnivore","display":"Carnivore","row":"r61","n":41},"promises":[]},{"t":340.31,"goal":{"value":140,"loss":100,"deadline":null,"row":"w44"},"goals":["w02","w06","w08","w09","w11","w13","w16","w19","w22","w27","w29","w32","w40","w41","w44"],"diet":{"regime":"fasting","display":"Fasting","row":"r62","n":42},"promises":[]},{"t":344.26,"goal":{"value":140,"loss":100,"deadline":null,"row":"w46"},"goals":["w02","w06","w08","w09","w11","w13","w16","w19","w22","w27","w29","w32","w40","w41","w44","w46"],"diet":{"regime":"fasting","display":"Fasting","row":"r62","n":42},"promises":[]},{"t":356.13,"goal":{"value":140,"loss":100,"deadline":null,"row":"w50"},"goals":["w02","w06","w08","w09","w11","w13","w16","w19","w22","w27","w29","w32","w40","w41","w44","w46","w50"],"diet":{"regime":"fasting","display":"Fasting","row":"r62","n":42},"promises":[]},{"t":360.09,"goal":{"value":140,"loss":100,"deadline":null,"row":"w50"},"goals":["w02","w06","w08","w09","w11","w13","w16","w19","w22","w27","w29","w32","w40","w41","w44","w46","w50"],"diet":{"regime":"fasting","display":"Fasting","row":"r62","n":42},"promises":[]},{"t":364.04,"goal":{"value":140,"loss":100,"deadline":null,"row":"w50"},"goals":["w02","w06","w08","w09","w11","w13","w16","w19","w22","w27","w29","w32","w40","w41","w44","w46","w50"],"diet":{"regime":"carnivore","display":"Carnivore","row":"r63","n":43},"promises":[]},{"t":368,"goal":{"value":140,"loss":100,"deadline":null,"row":"w50"},"goals":["w02","w06","w08","w09","w11","w13","w16","w19","w22","w27","w29","w32","w40","w41","w44","w46","w50"],"diet":{"regime":"fasting","display":"Fasting","row":"r64","n":44},"promises":[]},{"t":371.96,"goal":{"value":140,"loss":100,"deadline":null,"row":"w50"},"goals":["w02","w06","w08","w09","w11","w13","w16","w19","w22","w27","w29","w32","w40","w41","w44","w46","w50"],"diet":{"regime":"other","display":"Some diet","row":"r65","n":45},"promises":[]},{"t":379.87,"goal":{"value":140,"loss":100,"deadline":null,"row":"w50"},"goals":["w02","w06","w08","w09","w11","w13","w16","w19","w22","w27","w29","w32","w40","w41","w44","w46","w50"],"diet":{"regime":"carnivore","display":"Carnivore","row":"r66","n":46},"promises":[]},{"t":383.82,"goal":{"value":140,"loss":100,"deadline":null,"row":"w50"},"goals":["w02","w06","w08","w09","w11","w13","w16","w19","w22","w27","w29","w32","w40","w41","w44","w46","w50"],"diet":{"regime":"fasting","display":"Fasting","row":"r67","n":47},"promises":[]},{"t":387.78,"goal":{"value":140,"loss":100,"deadline":null,"row":"w50"},"goals":["w02","w06","w08","w09","w11","w13","w16","w19","w22","w27","w29","w32","w40","w41","w44","w46","w50"],"diet":{"regime":"fasting","display":"Fasting","row":"r67","n":47},"promises":[]},{"t":391.74,"goal":{"value":140,"loss":100,"deadline":null,"row":"w50"},"goals":["w02","w06","w08","w09","w11","w13","w16","w19","w22","w27","w29","w32","w40","w41","w44","w46","w50"],"diet":{"regime":"fasting","display":"Fasting","row":"r67","n":47},"promises":[]},{"t":395.69,"goal":{"value":265,"loss":null,"deadline":null,"row":"w57"},"goals":["w02","w06","w08","w09","w11","w13","w16","w19","w22","w27","w29","w32","w40","w41","w44","w46","w50","w57"],"diet":{"regime":"fasting","display":"Fasting","row":"r67","n":47},"promises":[]},{"t":399.65,"goal":{"value":265,"loss":null,"deadline":null,"row":"w57"},"goals":["w02","w06","w08","w09","w11","w13","w16","w19","w22","w27","w29","w32","w40","w41","w44","w46","w50","w57"],"diet":{"regime":"glp1","display":"GLP-1","row":"r68","n":48},"promises":[]},{"t":403.6,"goal":{"value":265,"loss":null,"deadline":null,"row":"w57"},"goals":["w02","w06","w08","w09","w11","w13","w16","w19","w22","w27","w29","w32","w40","w41","w44","w46","w50","w57"],"diet":{"regime":"carnivore","display":"Carnivore","row":"r70","n":49},"promises":[]},{"t":407.56,"goal":{"value":265,"loss":null,"deadline":null,"row":"w57"},"goals":["w02","w06","w08","w09","w11","w13","w16","w19","w22","w27","w29","w32","w40","w41","w44","w46","w50","w57"],"diet":{"regime":"fasting","display":"Fasting","row":"r71","n":50},"promises":[]},{"t":415.47,"goal":{"value":265,"loss":null,"deadline":null,"row":"w57"},"goals":["w02","w06","w08","w09","w11","w13","w16","w19","w22","w27","w29","w32","w40","w41","w44","w46","w50","w57"],"diet":{"regime":"fasting","display":"Fasting","row":"r71","n":50},"promises":[]},{"t":419.43,"goal":{"value":275,"loss":null,"deadline":null,"row":"w61"},"goals":["w02","w06","w08","w09","w11","w13","w16","w19","w22","w27","w29","w32","w40","w41","w44","w46","w50","w57","w61"],"diet":{"regime":"fasting","display":"Fasting","row":"r71","n":50},"promises":[]},{"t":435.25,"goal":{"value":275,"loss":null,"deadline":null,"row":"w61"},"goals":["w02","w06","w08","w09","w11","w13","w16","w19","w22","w27","w29","w32","w40","w41","w44","w46","w50","w57","w61"],"diet":{"regime":"fasting","display":"Fasting","row":"r74","n":51},"promises":[]},{"t":439.21,"goal":{"value":275,"loss":null,"deadline":null,"row":"w61"},"goals":["w02","w06","w08","w09","w11","w13","w16","w19","w22","w27","w29","w32","w40","w41","w44","w46","w50","w57","w61"],"diet":{"regime":"carnivore","display":"Carnivore","row":"r75","n":52},"promises":[]},{"t":447.12,"goal":{"value":275,"loss":null,"deadline":null,"row":"w61"},"goals":["w02","w06","w08","w09","w11","w13","w16","w19","w22","w27","w29","w32","w40","w41","w44","w46","w50","w57","w61"],"diet":{"regime":"other","display":"Some diet","row":"r76","n":53},"promises":[]},{"t":451.08,"goal":{"value":275,"loss":null,"deadline":null,"row":"w61"},"goals":["w02","w06","w08","w09","w11","w13","w16","w19","w22","w27","w29","w32","w40","w41","w44","w46","w50","w57","w61"],"diet":{"regime":"calories","display":"cutting carbs","row":"r77","n":54},"promises":[]},{"t":458.99,"goal":{"value":251,"loss":100,"deadline":null,"row":"w68"},"goals":["w02","w06","w08","w09","w11","w13","w16","w19","w22","w27","w29","w32","w40","w41","w44","w46","w50","w57","w61","w68"],"diet":{"regime":"calories","display":"cutting carbs","row":"r77","n":54},"promises":[]},{"t":462.95,"goal":{"value":201,"loss":150,"deadline":null,"row":"w69"},"goals":["w02","w06","w08","w09","w11","w13","w16","w19","w22","w27","w29","w32","w40","w41","w44","w46","w50","w57","w61","w68","w69"],"diet":{"regime":"calories","display":"cutting carbs","row":"r77","n":54},"promises":[]},{"t":478.77,"goal":{"value":331,"loss":20,"deadline":null,"row":"w72"},"goals":["w02","w06","w08","w09","w11","w13","w16","w19","w22","w27","w29","w32","w40","w41","w44","w46","w50","w57","w61","w68","w69","w72"],"diet":{"regime":"calories","display":"cutting carbs","row":"r77","n":54},"promises":[]},{"t":486.68,"goal":{"value":331,"loss":20,"deadline":null,"row":"w72"},"goals":["w02","w06","w08","w09","w11","w13","w16","w19","w22","w27","w29","w32","w40","w41","w44","w46","w50","w57","w61","w68","w69","w72"],"diet":{"regime":"calories","display":"cutting carbs","row":"r77","n":54},"promises":[]},{"t":494.59,"goal":{"value":331,"loss":20,"deadline":null,"row":"w72"},"goals":["w02","w06","w08","w09","w11","w13","w16","w19","w22","w27","w29","w32","w40","w41","w44","w46","w50","w57","w61","w68","w69","w72"],"diet":{"regime":"fasting","display":"Fasting","row":"r82","n":55},"promises":[]},{"t":506.46,"goal":{"value":320,"loss":null,"deadline":null,"row":"w77"},"goals":["w02","w06","w08","w09","w11","w13","w16","w19","w22","w27","w29","w32","w40","w41","w44","w46","w50","w57","w61","w68","w69","w72","w77"],"diet":{"regime":"fasting","display":"Fasting","row":"r82","n":55},"promises":[]},{"t":510.42,"goal":{"value":240,"loss":null,"deadline":null,"row":"w78"},"goals":["w02","w06","w08","w09","w11","w13","w16","w19","w22","w27","w29","w32","w40","w41","w44","w46","w50","w57","w61","w68","w69","w72","w77","w78"],"diet":{"regime":"fasting","display":"Fasting","row":"r82","n":55},"promises":[]},{"t":514.37,"goal":{"value":240,"loss":null,"deadline":null,"row":"w78"},"goals":["w02","w06","w08","w09","w11","w13","w16","w19","w22","w27","w29","w32","w40","w41","w44","w46","w50","w57","w61","w68","w69","w72","w77","w78"],"diet":{"regime":"keto","display":"Keto","row":"r83","n":56},"promises":[]},{"t":518.33,"goal":{"value":240,"loss":null,"deadline":null,"row":"w78"},"goals":["w02","w06","w08","w09","w11","w13","w16","w19","w22","w27","w29","w32","w40","w41","w44","w46","w50","w57","w61","w68","w69","w72","w77","w78"],"diet":{"regime":"carnivore","display":"Carnivore","row":"r85","n":57},"promises":[]},{"t":522.29,"goal":{"value":240,"loss":null,"deadline":null,"row":"w78"},"goals":["w02","w06","w08","w09","w11","w13","w16","w19","w22","w27","w29","w32","w40","w41","w44","w46","w50","w57","w61","w68","w69","w72","w77","w78"],"diet":{"regime":"keto","display":"Keto","row":"r86","n":58},"promises":[]},{"t":526.24,"goal":{"value":240,"loss":null,"deadline":null,"row":"w78"},"goals":["w02","w06","w08","w09","w11","w13","w16","w19","w22","w27","w29","w32","w40","w41","w44","w46","w50","w57","w61","w68","w69","w72","w77","w78"],"diet":{"regime":"fasting","display":"Fasting","row":"r87","n":59},"promises":[]},{"t":538.11,"goal":{"value":240,"loss":null,"deadline":null,"row":"w78"},"goals":["w02","w06","w08","w09","w11","w13","w16","w19","w22","w27","w29","w32","w40","w41","w44","w46","w50","w57","w61","w68","w69","w72","w77","w78"],"diet":{"regime":"carnivore","display":"Carnivore","row":"r90","n":60},"promises":[]},{"t":542.07,"goal":{"value":240,"loss":null,"deadline":null,"row":"w78"},"goals":["w02","w06","w08","w09","w11","w13","w16","w19","w22","w27","w29","w32","w40","w41","w44","w46","w50","w57","w61","w68","w69","w72","w77","w78"],"diet":{"regime":"keto","display":"Keto","row":"r91","n":61},"promises":[]},{"t":549.98,"goal":{"value":240,"loss":null,"deadline":null,"row":"w78"},"goals":["w02","w06","w08","w09","w11","w13","w16","w19","w22","w27","w29","w32","w40","w41","w44","w46","w50","w57","w61","w68","w69","w72","w77","w78"],"diet":{"regime":"keto","display":"Keto","row":"r92","n":62},"promises":[]},{"t":569.76,"goal":{"value":250,"loss":50,"deadline":null,"row":"w85"},"goals":["w02","w06","w08","w09","w11","w13","w16","w19","w22","w27","w29","w32","w40","w41","w44","w46","w50","w57","w61","w68","w69","w72","w77","w78","w85"],"diet":{"regime":"keto","display":"Keto","row":"r92","n":62},"promises":[]},{"t":581.63,"goal":{"value":250,"loss":null,"deadline":null,"row":"w88"},"goals":["w02","w06","w08","w09","w11","w13","w16","w19","w22","w27","w29","w32","w40","w41","w44","w46","w50","w57","w61","w68","w69","w72","w77","w78","w85","w88"],"diet":{"regime":"keto","display":"Keto","row":"r92","n":62},"promises":[]},{"t":585.58,"goal":{"value":250,"loss":null,"deadline":null,"row":"w88"},"goals":["w02","w06","w08","w09","w11","w13","w16","w19","w22","w27","w29","w32","w40","w41","w44","w46","w50","w57","w61","w68","w69","w72","w77","w78","w85","w88"],"diet":{"regime":"keto","display":"Keto","row":"r92","n":62},"promises":[]},{"t":589.54,"goal":{"value":235,"loss":null,"deadline":null,"row":"w90"},"goals":["w02","w06","w08","w09","w11","w13","w16","w19","w22","w27","w29","w32","w40","w41","w44","w46","w50","w57","w61","w68","w69","w72","w77","w78","w85","w88","w90"],"diet":{"regime":"keto","display":"Keto","row":"r92","n":62},"promises":[]},{"t":593.49,"goal":{"value":235,"loss":null,"deadline":null,"row":"w90"},"goals":["w02","w06","w08","w09","w11","w13","w16","w19","w22","w27","w29","w32","w40","w41","w44","w46","w50","w57","w61","w68","w69","w72","w77","w78","w85","w88","w90"],"diet":{"regime":"keto","display":"Keto","row":"r92","n":62},"promises":[]},{"t":597.45,"goal":{"value":235,"loss":null,"deadline":null,"row":"w90"},"goals":["w02","w06","w08","w09","w11","w13","w16","w19","w22","w27","w29","w32","w40","w41","w44","w46","w50","w57","w61","w68","w69","w72","w77","w78","w85","w88","w90"],"diet":{"regime":"keto","display":"Keto","row":"r92","n":62},"promises":[]},{"t":605.36,"goal":{"value":235,"loss":null,"deadline":null,"row":"w90"},"goals":["w02","w06","w08","w09","w11","w13","w16","w19","w22","w27","w29","w32","w40","w41","w44","w46","w50","w57","w61","w68","w69","w72","w77","w78","w85","w88","w90"],"diet":{"regime":"keto","display":"Keto · 5 carbs a day","row":"r96","n":63},"promises":[]},{"t":617.23,"goal":{"value":235,"loss":null,"deadline":null,"row":"w90"},"goals":["w02","w06","w08","w09","w11","w13","w16","w19","w22","w27","w29","w32","w40","w41","w44","w46","w50","w57","w61","w68","w69","w72","w77","w78","w85","w88","w90"],"diet":{"regime":"fasting","display":"Keto + fasting Thu/Fri","row":"r101","n":64},"promises":[]},{"t":644.92,"goal":{"value":235,"loss":null,"deadline":null,"row":"w90"},"goals":["w02","w06","w08","w09","w11","w13","w16","w19","w22","w27","w29","w32","w40","w41","w44","w46","w50","w57","w61","w68","w69","w72","w77","w78","w85","w88","w90"],"diet":{"regime":"fasting","display":"Keto + fasting Thu/Fri","row":"r101","n":64},"promises":[]},{"t":660.75,"goal":{"value":235,"loss":null,"deadline":null,"row":"w90"},"goals":["w02","w06","w08","w09","w11","w13","w16","w19","w22","w27","w29","w32","w40","w41","w44","w46","w50","w57","w61","w68","w69","w72","w77","w78","w85","w88","w90"],"diet":{"regime":"calories","display":"IF 2-3 days · ~400 kcal","row":"r102","n":65},"promises":[]},{"t":676.57,"goal":{"value":235,"loss":null,"deadline":null,"row":"w90"},"goals":["w02","w06","w08","w09","w11","w13","w16","w19","w22","w27","w29","w32","w40","w41","w44","w46","w50","w57","w61","w68","w69","w72","w77","w78","w85","w88","w90"],"diet":{"regime":"calories","display":"IF 2-3 days · ~400 kcal","row":"r102","n":65},"promises":[]},{"t":684.48,"goal":{"value":225,"loss":null,"deadline":null,"row":"w111"},"goals":["w02","w06","w08","w09","w11","w13","w16","w19","w22","w27","w29","w32","w40","w41","w44","w46","w50","w57","w61","w68","w69","w72","w77","w78","w85","w88","w90","w111"],"diet":{"regime":"calories","display":"IF 2-3 days · ~400 kcal","row":"r102","n":65},"promises":[]},{"t":700.31,"goal":{"value":225,"loss":null,"deadline":null,"row":"w111"},"goals":["w02","w06","w08","w09","w11","w13","w16","w19","w22","w27","w29","w32","w40","w41","w44","w46","w50","w57","w61","w68","w69","w72","w77","w78","w85","w88","w90","w111"],"diet":{"regime":"calories","display":"IF 2-3 days · ~400 kcal","row":"r102","n":65},"promises":[]},{"t":704.26,"goal":{"value":225,"loss":null,"deadline":null,"row":"w111"},"goals":["w02","w06","w08","w09","w11","w13","w16","w19","w22","w27","w29","w32","w40","w41","w44","w46","w50","w57","w61","w68","w69","w72","w77","w78","w85","w88","w90","w111"],"diet":{"regime":"fasting","display":"Keto + IF + walking","row":"r104","n":66},"promises":[]},{"t":712.18,"goal":{"value":225,"loss":null,"deadline":null,"row":"w111"},"goals":["w02","w06","w08","w09","w11","w13","w16","w19","w22","w27","w29","w32","w40","w41","w44","w46","w50","w57","w61","w68","w69","w72","w77","w78","w85","w88","w90","w111"],"diet":{"regime":"fasting","display":"Keto + IF + walking","row":"r104","n":66},"promises":[{"row":"p01","said":"2026-10-23","what":"post a video of the scale","due":null,"kept":false,"checks":[]}]},{"t":720.09,"goal":{"value":226.5,"loss":65,"deadline":"by Christmas","row":"w120"},"goals":["w02","w06","w08","w09","w11","w13","w16","w19","w22","w27","w29","w32","w40","w41","w44","w46","w50","w57","w61","w68","w69","w72","w77","w78","w85","w88","w90","w111","w120"],"diet":{"regime":"fasting","display":"Keto + IF + walking","row":"r104","n":66},"promises":[{"row":"p01","said":"2026-10-23","what":"post a video of the scale","due":null,"kept":false,"checks":[]}]},{"t":724.04,"goal":{"value":226.5,"loss":65,"deadline":"by Christmas","row":"w120"},"goals":["w02","w06","w08","w09","w11","w13","w16","w19","w22","w27","w29","w32","w40","w41","w44","w46","w50","w57","w61","w68","w69","w72","w77","w78","w85","w88","w90","w111","w120"],"diet":{"regime":"fasting","display":"Keto + IF + walking","row":"r104","n":66},"promises":[{"row":"p01","said":"2026-10-23","what":"post a video of the scale","due":null,"kept":false,"checks":["p02"]}]}],"totals":{"goals":29,"goalRepeats":{"lose 100":8},"diets":66,"peakDrift":[365.7,370,385,387,390]},"_fixture":"measure-extras test fixture: made by make-fixture.mjs from the lanes' synthetic measure slice (real ledger rows, fake cut times)"} diff --git a/umtool/report-to-video/measure-extras.mjs b/umtool/report-to-video/measure-extras.mjs @@ -0,0 +1,495 @@ +// THE MEASURE EXTRAS (weight video rev 9, lane measure-extras): what the goal +// stack, the moving start, the promise clock and the diet badge draw, as data +// -- each a list of STATES on the cut's clock, read off the schedule's +// `measure` slice (CONTRACT.md: `measure.events` in cut order, `measure.state` +// the state after each one). chrome-measure-extras.mjs draws them; the +// modules (modules/goals.mjs, peak.mjs, promise.mjs, diet.mjs) register them. +// +// PURE: a schedule and a render block in, plain data out. No fs, no browser. +// +// The rules, as the operator and the contract give them: +// - GOALS: every goal / goalLoss event drops a note on a pile; a goal said +// again in the same words merges into its note with a count ("lose 100 +// ×8") and comes to the front. A goal with a `deadline` counts down to +// `measure.asOfRender` ("by Christmas · 50 days left · needs 226.5"): the +// date is parsed from his words (deadlineDate), and words with no date in +// them ("by my birthday") keep their label and no countdown. +// - PEAK: every remembered weight that is one of the totals' `peakDrift` +// values (the starts he tells: 365.7 → 370 → 385 → 387 → ≈390) adds a tick +// on a small vertical scale, a retelling of the same number a count; the +// spread from the lowest to the highest so far is the drift. +// - PROMISE: from a promise on, the days since he said it -- to the in-record +// date of what is on screen, and from the finale (or a beat after the last +// event) to the render date, counted up a day at a time; each check's words +// under it; kept, "POSTED". +// - DIET: the state's diet, re-stamped at each change of regime or diet +// number; a null diet after one is "NO DIET" (the producer has applied the +// off-scope rule: this only draws state.diet). +import { deckGeometry, feedGeometry } from "./deck.mjs"; +import { resolveMeasureExtra } from "./modules/measure-extras-settings.mjs"; + +const r4 = (v) => Math.round(v * 10000) / 10000; +const isObj = (v) => v !== null && typeof v === "object" && !Array.isArray(v); +const even = (v) => 2 * Math.round(v / 2); + +/** The schedule's measure slice, when it has one the extras can read. */ +export function measureOf(schedule) { + const m = schedule?.measure; + return isObj(m) && Array.isArray(m.events) && Array.isArray(m.state) ? m : null; +} + +// --------------------------------------------------------------------------- +// Dates. +// --------------------------------------------------------------------------- + +const ISO_RE = /^(\d{4})-(\d{2})-(\d{2})$/; +const utc = (iso) => { + const m = ISO_RE.exec(String(iso ?? "")); + return m ? Date.UTC(Number(m[1]), Number(m[2]) - 1, Number(m[3])) : null; +}; +const iso = (ms) => new Date(ms).toISOString().slice(0, 10); + +/** Whole days from `a` to `b` (YYYY-MM-DD), or null. */ +export function daysBetween(a, b) { + const x = utc(a); + const y = utc(b); + return x === null || y === null ? null : Math.round((y - x) / 86400000); +} + +const MONTHS = ["jan", "feb", "mar", "apr", "may", "jun", "jul", "aug", "sep", "oct", "nov", "dec"]; + +/** The n-th weekday (0 Sunday) of a month, as UTC ms. */ +function nthWeekday(year, month, weekday, n) { + const first = new Date(Date.UTC(year, month, 1)).getUTCDay(); + return Date.UTC(year, month, 1 + ((weekday - first + 7) % 7) + 7 * (n - 1)); +} + +/** The days his words can name, each `(year) => ms`. */ +const NAMED_DAYS = [ + [/christmas eve/, (y) => Date.UTC(y, 11, 24)], + [/christmas|xmas/, (y) => Date.UTC(y, 11, 25)], + [/new year'?s eve/, (y) => Date.UTC(y, 11, 31)], + [/new year'?s?(?: day)?|the new year/, (y) => Date.UTC(y, 0, 1)], + [/halloween/, (y) => Date.UTC(y, 9, 31)], + [/thanksgiving/, (y) => nthWeekday(y, 10, 4, 4)], + [/valentine'?s/, (y) => Date.UTC(y, 1, 14)], + [/(?:the )?(?:4th|fourth) of july|july (?:4th|4)|independence day/, (y) => Date.UTC(y, 6, 4)], + [/end of (?:the )?(?:year|(?:19|20)\d{2})|year'?s end/, (y) => Date.UTC(y, 11, 31)], +]; + +/** + * The date a goal's deadline words name, as YYYY-MM-DD, or null when they + * name none he has given ("by my birthday", "by summer"). `said` is the date + * he said it: "by Christmas" is the next Christmas from then (25 Dec of its + * year, or the year after when said after it), "next year" a year on, an + * explicit year that year ("by the end of 2026", "by Halloween 2027"), an ISO + * date itself, "by March 3" the next 3 March. + * + * @param {string | null | undefined} words + * @param {string | null | undefined} said + */ +export function deadlineDate(words, said) { + if (typeof words !== "string" || !words.trim()) return null; + const w = words.toLowerCase().replace(/[’`]/g, "'").replace(/\s+/g, " ").trim(); + const isoIn = /(\d{4}-\d{2}-\d{2})/.exec(w); + if (isoIn && utc(isoIn[1]) !== null) return isoIn[1]; + const base = utc(said); + const saidYear = base === null ? null : new Date(base).getUTCFullYear(); + const yearIn = /\b(20\d{2}|19\d{2})\b/.exec(w); + const next = /\bnext year\b/.test(w); + const pick = (f) => { + if (yearIn) return f(Number(yearIn[1])); + if (saidYear === null) return null; + let at = f(saidYear + (next ? 1 : 0)); + // Said after this year's: the next one. + if (!next && at < base) at = f(saidYear + 1); + return at; + }; + for (const [re, f] of NAMED_DAYS) { + if (re.test(w)) { + const at = pick(f); + return at === null ? null : iso(at); + } + } + // "by March 3", "by 3 March", "by march 3rd". + const md = new RegExp(`\\b(${MONTHS.join("|")})[a-z]*\\.? (\\d{1,2})(?:st|nd|rd|th)?\\b|\\b(\\d{1,2})(?:st|nd|rd|th)? (?:of )?(${MONTHS.join("|")})[a-z]*\\b`).exec(w); + if (md) { + const mon = MONTHS.indexOf(md[1] ?? md[4]); + const day = Number(md[2] ?? md[3]); + if (day >= 1 && day <= 31) { + const at = pick((y) => Date.UTC(y, mon, day)); + return at === null ? null : iso(at); + } + } + return null; +} + +/** "23 Oct" (or "23 Oct 2025" with `year`) from YYYY-MM-DD. */ +export function shortDate(d, { year = false } = {}) { + const m = ISO_RE.exec(String(d ?? "")); + if (!m) return String(d ?? ""); + const mon = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"][Number(m[2]) - 1]; + return `${Number(m[3])} ${mon}${year ? ` ${m[1]}` : ""}`; +} + +/** "Jan 2021" from YYYY-MM-DD. */ +export function monthYear(d) { + const m = ISO_RE.exec(String(d ?? "")); + if (!m) return ""; + return `${["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"][Number(m[2]) - 1]} ${m[1]}`; +} + +/** A weight as he says it: 365.7, 390 (no trailing .0). */ +export const weightText = (v) => (Number.isFinite(v) ? (Math.round(v * 10) % 10 === 0 ? String(Math.round(v)) : (Math.round(v * 10) / 10).toFixed(1)) : ""); + +/** "50 days left" | "1 day left" | "today" | "3 days past". */ +export function daysLeftText(n) { + if (n === null) return ""; + if (n === 0) return "today"; + if (n > 0) return `${n} day${n === 1 ? "" : "s"} left`; + return `${-n} day${n === -1 ? "" : "s"} past`; +} + +// --------------------------------------------------------------------------- +// The shared clock: when each module is up. +// --------------------------------------------------------------------------- + +/** The finale's window in the cut, or null. */ +const finaleOf = (schedule) => (isObj(schedule?.finale) && Number.isFinite(schedule.finale.from) ? schedule.finale : null); + +/** + * When a module is up: from each event to `hold` seconds after it (spans + * that touch joined), or -- `hold` null -- from its first event to the end; + * never inside the finale's window unless `finale: "show"`. + * + * @returns {Array<{ in: number, out: number }>} + */ +export function upSpans(times, cfg, schedule) { + const total = Number(schedule.total) || 0; + const fin = finaleOf(schedule); + const end = fin && cfg.finale !== "show" ? Math.min(total, fin.from) : total; + const ts = times.filter((t) => Number.isFinite(t) && t < end).sort((a, b) => a - b); + if (!ts.length) return []; + if (cfg.hold === null || cfg.hold === undefined) return [{ in: r4(ts[0]), out: r4(end) }]; + const out = []; + for (const t of ts) { + const span = { in: t, out: Math.min(end, t + cfg.hold) }; + const last = out[out.length - 1]; + if (last && span.in <= last.out + 1e-6) last.out = Math.max(last.out, span.out); + else out.push(span); + } + return out.map((s) => ({ in: r4(s.in), out: r4(s.out) })); +} + +/** Each event with the state after it, in cut order (events with no time are not on screen). */ +function stepsOf(m) { + const out = []; + m.events.forEach((e, i) => { + if (!Number.isFinite(e?.t)) return; + out.push({ e, s: m.state[i + 1] ?? m.state[m.state.length - 1] ?? null, i }); + }); + return out.sort((a, b) => a.e.t - b.e.t || a.i - b.i); +} + +/** A stable pseudo-random number in [-1, 1] from a string (a note's jitter). */ +export function jitter(s, salt = 0) { + let h = 2166136261 ^ salt; + for (const ch of String(s)) h = Math.imul(h ^ ch.charCodeAt(0), 16777619); + return ((h >>> 0) % 2001) / 1000 - 1; +} + +// --------------------------------------------------------------------------- +// GOALS +// --------------------------------------------------------------------------- + +/** How a note's words read: "LOSE 100", "≈250 LB", "220–240 LB". */ +export function goalText(e, unit = "lb") { + const d = String(e.display ?? "").trim() || (Number.isFinite(e.value) ? weightText(Math.abs(e.value)) : ""); + if (e.kind === "goalLoss") return d.toUpperCase(); + const q = e.qualifier === "≈" && !d.startsWith("≈") ? "≈" : ""; + const range = d.replace(/(\d)\s*-\s*(\d)/, "$1–$2"); + return /^[≈~<>]?\d/.test(range) ? `${q}${range} ${unit}`.toUpperCase() : range.toUpperCase(); +} + +/** + * The pile's states: one per goal event, `{ at, top, goalsSet, notes }` -- + * `notes` back to front (the last is the one that just landed, `top` its key), + * each `{ key, text, count, date, deadline, deadlineDate, days, target, rot, + * dx, depth, prev }` (`prev` its depth in the state before, null when new). + */ +export function goalStates(schedule, render) { + const m = measureOf(schedule); + const cfg = resolveMeasureExtra("goals", render); + if (!m || !cfg) return []; + const notes = new Map(); + let order = []; + const states = []; + let prevDepth = new Map(); + let n = 0; + for (const { e, s } of stepsOf(m)) { + if (e.kind !== "goal" && e.kind !== "goalLoss") continue; + n += 1; + const text = goalText(e, m.unit ?? "lb"); + const key = text.toLowerCase(); + let note = notes.get(key); + if (!note) { + note = { key, id: `n${notes.size}`, count: 0, rot: r4(jitter(e.row ?? key) * 5), dx: r4(jitter(e.row ?? key, 7) * 10) }; + notes.set(key, note); + } + note.count += 1; + note.text = text; + note.date = e.date ?? null; + note.deadline = typeof e.deadline === "string" && e.deadline.trim() ? e.deadline.trim() : null; + note.deadlineDate = note.deadline ? deadlineDate(note.deadline, e.date) : null; + note.days = note.deadlineDate && m.asOfRender ? daysBetween(m.asOfRender, note.deadlineDate) : null; + // The weight it comes to: a goal's own number, or the state's resolution of a goalLoss. + const target = s?.goal && s.goal.row === e.row && Number.isFinite(s.goal.value) ? s.goal.value + : e.kind === "goal" && Number.isFinite(e.value) ? e.value : null; + note.target = target; + order = [...order.filter((k) => k !== key), key]; + const shown = order.slice(-cfg.max); + const depth = new Map(shown.map((k, i) => [k, shown.length - 1 - i])); + states.push({ + at: r4(e.t), + top: key, + repeat: note.count > 1, + goalsSet: Array.isArray(s?.goals) ? s.goals.length : n, + notes: shown.map((k) => { + const x = notes.get(k); + return { + key: k, id: x.id, text: x.text, count: x.count, date: x.date, deadline: x.deadline, + deadlineDate: x.deadlineDate, days: x.days, target: x.target, rot: x.rot, dx: x.dx, + depth: depth.get(k), prev: k === key ? null : prevDepth.get(k) ?? null, + }; + }), + }); + prevDepth = depth; + } + return states; +} + +// --------------------------------------------------------------------------- +// PEAK +// --------------------------------------------------------------------------- + +const near = (a, b) => Math.abs(a - b) < 0.05; + +/** + * The moving start's states: one per remembered weight it draws, `{ at, + * ticks: [{ value, count, approx, latest }], lo, hi, drift, told }`, and the + * scale's range over the whole cut (`range: [min, max]`) on each. + */ +export function peakStates(schedule, render) { + const m = measureOf(schedule); + const cfg = resolveMeasureExtra("peak", render); + if (!m || !cfg) return []; + const drift = Array.isArray(m.totals?.peakDrift) ? m.totals.peakDrift.filter(Number.isFinite) : []; + const counts = cfg.values === "drift" && drift.length > 0; + const steps = stepsOf(m).filter(({ e }) => e.kind === "remembered" && Number.isFinite(e.value) && (!counts || drift.some((v) => near(v, e.value)))); + if (!steps.length) return []; + const all = steps.map(({ e }) => e.value); + let lo = Math.floor(Math.min(...all) - 3); + let hi = Math.ceil(Math.max(...all) + 3); + if (hi - lo < 12) { + const mid = (hi + lo) / 2; + lo = Math.floor(mid - 6); + hi = Math.ceil(mid + 6); + } + const ticks = new Map(); + const states = []; + steps.forEach(({ e }, j) => { + const v = Math.round(e.value * 10) / 10; + const t = ticks.get(v) ?? { value: v, count: 0, approx: false }; + t.count += 1; + if (e.qualifier === "≈") t.approx = true; + ticks.set(v, t); + const vals = [...ticks.keys()]; + const min = Math.min(...vals); + const max = Math.max(...vals); + states.push({ + at: r4(e.t), + row: e.row ?? null, + latest: v, + repeat: t.count > 1, + ticks: [...ticks.values()].sort((a, b) => a.value - b.value).map((x) => ({ ...x, latest: x.value === v })), + lo: min, hi: max, drift: r4(max - min), told: j + 1, + range: [lo, hi], + }); + }); + return states; +} + +// --------------------------------------------------------------------------- +// PROMISE +// --------------------------------------------------------------------------- + +/** After the last event, how long before the clock counts on to the render date (no finale). */ +export const PROMISE_SETTLE = 4; +/** The count-up to the render date: a day a step, over at most this long. */ +export const PROMISE_COUNT_UP = 1.2; + +/** + * The promise clock's states: `{ at, rows: [{ row, what, said, days, to, kept, + * check: { text, date } | null, fresh }], asOf }` (`to` the date the days are + * counted to; one row, the latest promise) -- a state wherever a row's + * days, its kept or its check changes; `fresh` marks the row whose check just + * came in (it flashes). From the finale's start (else PROMISE_SETTLE after the + * last event) the days count up to `measure.asOfRender`, a day a step. + */ +export function promiseStates(schedule, render) { + const m = measureOf(schedule); + const cfg = resolveMeasureExtra("promise", render); + if (!m || !cfg) return []; + const steps = stepsOf(m); + const first = steps.find(({ e }) => e.kind === "promise"); + if (!first) return []; + const byRow = new Map(m.events.filter((e) => e?.row).map((e) => [e.row, e])); + const total = Number(schedule.total) || 0; + const checkOf = (row) => { + const e = byRow.get(row); + if (!e) return null; + const words = cfg.checks === "quote" ? e.quote || e.label : e.label || e.quote; + return words ? { text: String(words).trim(), date: e.date ?? null } : null; + }; + const rowsAt = (s, dateNow, freshCheck) => (Array.isArray(s?.promises) ? s.promises : []) + .filter((p) => p && p.said) + .slice(-1) + .map((p) => { + const ev = byRow.get(p.row); + const checks = Array.isArray(p.checks) ? p.checks : []; + const last = checks.length ? checkOf(checks[checks.length - 1]) : null; + return { + row: p.row, + what: cfg.label ?? ev?.display ?? p.what ?? "promise", + said: p.said, + days: Math.max(0, daysBetween(p.said, dateNow) ?? 0), + to: dateNow && dateNow > p.said ? dateNow : p.said, + kept: p.kept === true, + check: last, + fresh: !!freshCheck && checks[checks.length - 1] === freshCheck, + }; + }); + const out = []; + let dateNow = null; + let lastSig = null; + let lastS = null; + for (const { e, s } of steps) { + if (e.t < first.e.t) { + if (e.date && (!dateNow || e.date > dateNow)) dateNow = e.date; + continue; + } + if (e.date && (!dateNow || e.date > dateNow)) dateNow = e.date; + const fresh = e.kind === "promiseCheck" ? e.row : null; + const rows = rowsAt(s, dateNow, fresh); + lastS = s; + if (!rows.length) continue; + const sig = JSON.stringify(rows); + if (sig === lastSig) continue; + lastSig = sig; + const at = r4(e.t); + if (out.length && Math.abs(out[out.length - 1].at - at) < 1e-6) out.pop(); + out.push({ at, rows, asOf: false }); + } + if (!out.length) return []; + // On to the render date: from the finale, else a beat after the last event. + const fin = finaleOf(schedule); + const lastAt = out[out.length - 1].at; + const from = fin ? Math.max(lastAt + 0.5, fin.from) : lastAt + PROMISE_SETTLE; + const asOf = m.asOfRender; + if (asOf && from < total - 0.2) { + const base = rowsAt(lastS, dateNow, null); + const target = base.map((r) => Math.max(0, daysBetween(r.said, asOf) ?? 0)); + const steps2 = Math.max(0, ...target.map((d, i) => d - base[i].days)); + if (steps2 > 0) { + const n = Math.min(steps2, 30); + const dt = Math.min(PROMISE_COUNT_UP / n, 0.25); + for (let k = 1; k <= n; k += 1) { + const rows = base.map((r, i) => ({ ...r, days: Math.round(r.days + ((target[i] - r.days) * k) / n), to: asOf, fresh: false })); + out.push({ at: r4(Math.min(total - 0.05, from + (k - 1) * dt)), rows, asOf: k === n }); + } + } else out.push({ at: r4(from), rows: base.map((r) => ({ ...r, to: asOf })), asOf: true }); + } + return out; +} + +// --------------------------------------------------------------------------- +// DIET +// --------------------------------------------------------------------------- + +/** + * The diet badge's states: `{ at, diet: { regime, label, detail, n, color } | + * null, slam }` -- one per change of the state's diet (regime, number or + * words); `slam` when the regime or the number changed (a new stamp), not + * for words alone. The states before any diet are left out; a null after + * one is "No diet", faded in. + */ +export function dietStates(schedule, render) { + const m = measureOf(schedule); + const cfg = resolveMeasureExtra("diet", render); + if (!m || !cfg) return []; + const out = []; + let prev; + let any = false; + for (const { e, s } of stepsOf(m)) { + const d = isObj(s?.diet) ? s.diet : null; + if (!d && !any) continue; + const key = d ? `${d.regime}|${d.n}|${d.display}` : "none"; + if (key === prev?.key) continue; + any = true; + const regime = d ? String(d.regime ?? "other") : "off"; + const label = cfg.labels[regime] ?? regime; + const display = d ? String(d.display ?? "").trim() : ""; + const generic = !display || display.toLowerCase() === label.toLowerCase() || display.toLowerCase() === String(cfg.labels.other ?? "").toLowerCase() || display.toLowerCase() === regime; + const diet = d ? { regime, label, detail: generic ? "" : display, n: Number.isFinite(d.n) ? d.n : null, color: cfg.colors[regime] ?? cfg.colors.other } : null; + const slam = !!d && (!prev?.diet || prev.diet.regime !== regime || prev.diet.n !== diet.n); + const at = r4(e.t); + if (out.length && Math.abs(out[out.length - 1].at - at) < 1e-6) out.pop(); + out.push({ at, diet, slam, key }); + prev = { key, diet }; + } + return out.map(({ key: _k, ...st }) => st); +} + +// --------------------------------------------------------------------------- +// GEOMETRY +// --------------------------------------------------------------------------- + +/** Each module's box in design pixels (1920 wide), before `scale`. */ +export const MEASURE_BOXES = Object.freeze({ + goals: Object.freeze({ width: 400, height: 330 }), + peak: Object.freeze({ width: 280, height: 470 }), + promise: Object.freeze({ width: 620, height: 200 }), + diet: Object.freeze({ width: 440, height: 200 }), +}); + +/** + * A module's region in the frame: its box (MEASURE_BOXES × `scale`, scaled + * with the frame) at its anchor in the footage box (the feed's for a feed + * cut), 24 px in -- or at `x`/`y` (design pixels) when set. Never off the frame. + * + * @param {"goals" | "peak" | "promise" | "diet"} id + * @returns {{ x: number, y: number, width: number, height: number }} + */ +export function measureExtraGeometry(id, render, { feed = false } = {}) { + const cfg = resolveMeasureExtra(id, render) ?? resolveMeasureExtra(id, { chrome: { deck: {} } }); + const g = deckGeometry(render); + const f = feed ? feedGeometry(render).footage : g.footage; + const k = (g.W / 1920) * (cfg.scale ?? 1); + const box = MEASURE_BOXES[id]; + const width = Math.min(even(box.width * k), even(g.W)); + const height = Math.min(even(box.height * k), even(g.H)); + let x; + let y; + if (Number.isFinite(cfg.x) && Number.isFinite(cfg.y)) { + x = cfg.x * (g.W / 1920); + y = cfg.y * (g.W / 1920); + } else { + const inset = Math.round(24 * (g.W / 1920)); + const [v, h] = cfg.position.split("-"); + x = h === "left" ? f.x + inset : h === "right" ? f.x + f.width - inset - width : f.x + (f.width - width) / 2; + y = v === "top" ? f.y + inset : f.y + f.height - inset - height; + } + x = Math.max(0, Math.min(g.W - width, Math.round(x))); + y = Math.max(0, Math.min(g.H - height, Math.round(y))); + return { x, y, width, height }; +} diff --git a/umtool/report-to-video/measure-extras.test.mjs b/umtool/report-to-video/measure-extras.test.mjs @@ -0,0 +1,222 @@ +// The measure extras (measure-extras.mjs, chrome-measure-extras.mjs, modules/goals, +// peak, promise, diet): the goal stack, the moving start, the promise clock and +// the diet badge, read off the schedule's `measure` slice. Fixture: +// fixtures/measure-extras/measure.json (make-fixture.mjs: the lanes' synthetic +// slice, real ledger rows and fake cut times, trimmed to what these read). +import assert from "node:assert/strict"; +import { readFileSync } from "node:fs"; +import path from "node:path"; +import test from "node:test"; +import { fileURLToPath } from "node:url"; + +import { goalsHtml, dietHtml, peakHtml, promiseHtml, spreadLabels, stampSize } from "./chrome-measure-extras.mjs"; +import { estimateSchedule, validateChrome } from "./deck.mjs"; +import { frameKeys } from "./frame-keys.mjs"; +import { + daysBetween, deadlineDate, dietStates, goalStates, goalText, measureExtraGeometry, peakStates, promiseStates, upSpans, +} from "./measure-extras.mjs"; +import { deckOverlays, moduleById, moduleProblems, playModules, scheduleSlices } from "./modules/index.mjs"; +import { resolveMeasureExtra, validateMeasureExtra } from "./modules/measure-extras-settings.mjs"; + +const HERE = path.dirname(fileURLToPath(import.meta.url)); +const MEASURE = JSON.parse(readFileSync(path.join(HERE, "fixtures/measure-extras/measure.json"), "utf8")); +const IDS = ["goals", "peak", "promise", "diet"]; +const PAGES = { goals: goalsHtml, peak: peakHtml, promise: promiseHtml, diet: dietHtml }; + +const RENDER = { + width: 1920, height: 1080, fps: 30, + palette: { bg: "#0F1312", fg: "#EDF0EC", muted: "#98A29B", accent: "#22AB83", amber: "#E8A33F" }, + chrome: { engine: "hyperframes", layout: "deck", deck: {} }, +}; +const withDeck = (deck) => ({ ...RENDER, chrome: { ...RENDER.chrome, deck } }); +const schedule = (measure = MEASURE, extra = {}) => ({ + kind: "deck", fps: 30, total: 740, transition: 0.4, segments: [{ id: "a", start: 0, duration: 740, end: 740 }], measure, ...extra, +}); +const clone = (v) => JSON.parse(JSON.stringify(v)); + +test("deadlineDate: the next named day from when he said it; words with no date in them name none", () => { + assert.equal(deadlineDate("by Christmas", "2026-10-26"), "2026-12-25"); + assert.equal(deadlineDate("by Christmas", "2026-12-28"), "2027-12-25", "said after it: the next one"); + assert.equal(deadlineDate("by Halloween next year", "2026-03-01"), "2027-10-31"); + assert.equal(deadlineDate("by Christmas 2027", "2026-03-01"), "2027-12-25"); + assert.equal(deadlineDate("by the end of 2027", "2026-03-01"), "2027-12-31"); + assert.equal(deadlineDate("by the end of the year", "2026-03-01"), "2026-12-31"); + assert.equal(deadlineDate("by New Year's", "2026-05-01"), "2027-01-01"); + assert.equal(deadlineDate("by Thanksgiving", "2026-05-01"), "2026-11-26"); + assert.equal(deadlineDate("by March 3rd", "2026-05-01"), "2027-03-03"); + assert.equal(deadlineDate("by 2026-12-01", "2026-05-01"), "2026-12-01"); + for (const w of ["by my birthday", "by his birthday", "by summer", "", null]) assert.equal(deadlineDate(w, "2026-05-01"), null, String(w)); + assert.equal(daysBetween("2026-11-05", "2026-12-25"), 50); +}); + +test("goals: a note per goal, a repeat merged with its count and brought to the front, the deadline counted to the render date", () => { + const states = goalStates(schedule(), RENDER); + assert.equal(states.length, 29, "every goal and goalLoss row on camera"); + assert.equal(states.at(-1).goalsSet, 29); + // "lose 100", one note with its count: the seven times the cut shows it (the + // totals' goalRepeats, 8, count the record's off-camera row too). + const lose100 = Math.max(...states.flatMap((s) => s.notes.filter((n) => n.key === "lose 100").map((n) => n.count))); + assert.equal(lose100, MEASURE.events.filter((e) => e.display === "lose 100").length); + assert.equal(lose100, 7); + const rep = states.find((s) => s.top === "lose 100" && s.repeat); + assert.equal(rep.notes.at(-1).key, "lose 100", "the repeat comes to the front"); + assert.equal(rep.notes.at(-1).depth, 0); + assert.ok(rep.notes.length <= 4, "max notes shown (4)"); + // The deadline: "65 by Christmas", 50 days from the render date, the target the state resolved. + const last = states.at(-1).notes.at(-1); + assert.deepEqual([last.text, last.deadline, last.deadlineDate, last.days, last.target], ["LOSE 65", "by Christmas", "2026-12-25", 50, 226.5]); + assert.equal(goalText({ kind: "goal", display: "220-240", qualifier: null }), "220–240 LB"); + assert.equal(goalText({ kind: "goal", display: "250", qualifier: "≈" }), "≈250 LB"); + // A deadline that names no date: its label, no countdown. + const m = clone(MEASURE); + const w61 = m.events.findIndex((e) => e.row === "w61"); + m.events[w61].deadline = "by my birthday"; + const n61 = goalStates(schedule(m), RENDER).find((s) => s.notes.some((n) => n.deadline === "by my birthday")).notes.at(-1); + assert.deepEqual([n61.deadline, n61.deadlineDate, n61.days], ["by my birthday", null, null]); + assert.equal(goalStates(schedule(), withDeck({ goals: { max: 2 } })).at(-1).notes.length, 2); +}); + +test("peak: a tick per telling of a start in the drift, a count per retelling, the drift from lowest to highest", () => { + const states = peakStates(schedule(), RENDER); + const last = states.at(-1); + assert.deepEqual(last.ticks.map((t) => t.value), MEASURE.totals.peakDrift); + const by = Object.fromEntries(last.ticks.map((t) => [t.value, t])); + assert.deepEqual([by[390].count, by[390].approx, by[365.7].count], [5, true, 3], "≈390 ×5, 365.7 ×3"); + assert.equal(last.drift, 24.3); + assert.equal(last.told, 11); + assert.deepEqual(last.range, states[0].range, "the scale's range is fixed over the cut"); + assert.ok(last.range[0] < 365.7 && last.range[1] > 390); + // `values: "all"` draws every remembered weight (the wedding's 368, the keto 349 and 342). + assert.equal(peakStates(schedule(), withDeck({ peak: { values: "all" } })).length, 15); + assert.deepEqual(spreadLabels([100, 104, 300], 30, 0, 400), [100, 130, 300]); +}); + +test("promise: the days to the clip's in-record date, the check flashed, then counted on to the render date", () => { + const states = promiseStates(schedule(), RENDER); + assert.deepEqual(states.map((s) => s.rows[0].days), [0, 8, 11, 12, 13]); + assert.equal(states[0].at, 712.18, "from the promise on"); + assert.equal(states[2].rows[0].fresh, true, "the check's state flashes"); + assert.match(states[2].rows[0].check.text, /pull up a video from three months ago/); + assert.equal(states.at(-1).asOf, true); + assert.equal(states.at(-1).rows[0].to, MEASURE.asOfRender); + assert.equal(states[0].rows[0].what, "scale video"); + assert.equal(states[0].rows[0].kept, false); + // From the finale's start when there is one. + const fin = promiseStates(schedule(MEASURE, { finale: { from: 730, to: 740 } }), RENDER); + assert.equal(fin.at(-2).at, 730); + // Kept: the row says so. + const m = clone(MEASURE); + for (const s of m.state) for (const p of s.promises ?? []) p.kept = true; + assert.equal(promiseStates(schedule(m), RENDER)[0].rows[0].kept, true); + // The quote instead of the label. + assert.match(promiseStates(schedule(), withDeck({ promise: { checks: "quote" } }))[2].rows[0].check.text, /brother just pull up/); +}); + +test("diet: a stamp per change of regime or number, words alone not slammed, a null after one is No diet", () => { + const states = dietStates(schedule(), RENDER); + assert.equal(states[0].diet.label, "Some diet"); + assert.equal(states[0].diet.n, 1); + assert.equal(states[0].slam, true); + assert.equal(states.at(-1).diet.detail, "Keto + IF + walking"); + assert.equal(states.at(-1).diet.color, "#4E9BD8"); + const m = clone(MEASURE); + // The state after the last event: no diet (the producer's off-scope rule said so). + m.state[m.state.length - 1].diet = null; + // And one change of words only. + const k = m.state.findIndex((s) => s.diet?.n === 63); + m.state[k + 1] = { ...m.state[k + 1], diet: { ...m.state[k].diet, display: "Keto · strict" } }; + const s2 = dietStates(schedule(m), RENDER); + assert.equal(s2.at(-1).diet, null); + const words = s2.find((s) => s.diet?.detail === "Keto · strict"); + assert.equal(words.slam, false); + assert.equal(dietStates(schedule(), withDeck({ diet: { labels: { glp1: "Ozempic" } } })).find((s) => s.diet.regime === "glp1").diet.label, "Ozempic"); + assert.ok(stampSize("Counting calories", 330) < stampSize("Keto", 330)); +}); + +test("up: from the first event to the end (or the finale), or `hold` seconds after each", () => { + assert.deepEqual(upSpans([10, 20], { hold: null, finale: "hide" }, { total: 100 }), [{ in: 10, out: 100 }]); + assert.deepEqual(upSpans([10, 20], { hold: null, finale: "hide" }, { total: 100, finale: { from: 90, to: 100 } }), [{ in: 10, out: 90 }]); + assert.deepEqual(upSpans([10, 20], { hold: null, finale: "show" }, { total: 100, finale: { from: 90, to: 100 } }), [{ in: 10, out: 100 }]); + assert.deepEqual(upSpans([10, 15, 40], { hold: 8, finale: "hide" }, { total: 100 }), [{ in: 10, out: 23 }, { in: 40, out: 48 }]); +}); + +test("the pages: a block per state, each an item gated by its own autoAlpha, keyed so unchanged frames are reused", () => { + for (const id of IDS) { + const { html, items } = PAGES[id](schedule(), RENDER, { fonts: { regular: "assets/DeckSans.ttf", bold: "assets/DeckSansBold.ttf" } }); + assert.match(html, new RegExp(`<script id="${id}-data" type="application/json">`), id); + assert.match(html, new RegExp(`postMessage\\(\\{ type: "${id}:ready"`), id); + assert.match(html, /m\.type === "deck:seek"/, id); + assert.ok(items.length > 0 && items.every((it) => it.gate?.[1] === "autoAlpha" && html.includes(it.html)), id); + const fk = frameKeys({ html, region: id, assets: [], fps: 30, frames: 740 * 30, version: "t", items }); + assert.ok(fk, `${id}: the frame-key model reads its page`); + const distinct = new Set(fk).size; + assert.ok(distinct < fk.length / 10, `${id}: ${distinct} distinct frames of ${fk.length}`); + // Before its first event the region is empty: every frame there is the same frame. + assert.equal(fk[0], fk[30 * 5], id); + } +}); + +test("geometry: an anchor in the footage box, or x/y on the frame, scaled; never off the frame", () => { + const f = { x: 173, y: 2, width: 1574, height: 886 }; + const g = measureExtraGeometry("goals", RENDER); + assert.deepEqual([g.x + g.width, g.y + g.height], [f.x + f.width - 24, f.y + f.height - 24], "bottom-right, 24 in"); + const d = measureExtraGeometry("diet", RENDER); + assert.deepEqual([d.x, d.y + d.height], [f.x + 24, f.y + f.height - 24], "bottom-left"); + const p = measureExtraGeometry("promise", RENDER); + assert.equal(p.y, f.y + 24); + assert.ok(Math.abs(p.x + p.width / 2 - (f.x + f.width / 2)) <= 1, "top-centre"); + assert.deepEqual(measureExtraGeometry("peak", withDeck({ peak: { x: 1500, y: 600, scale: 0.5 } })), { x: 1500, y: 600, width: 140, height: 236 }); + const off = measureExtraGeometry("peak", withDeck({ peak: { x: 1900, y: 1000 } })); + assert.ok(off.x + off.width <= 1920 && off.y + off.height <= 1080); +}); + +test("settings: true/false or an object of the module's own keys, refused by name; the deck accepts them", () => { + assert.deepEqual(validateMeasureExtra("goals", { max: 6, position: "bottom-left", hold: null, color: "#ffcc00" }), []); + assert.match(validateMeasureExtra("goals", { maxx: 1 })[0], /goals\.maxx is not a deck setting/); + assert.match(validateMeasureExtra("peak", { position: "middle" })[0], /position must be/); + assert.match(validateMeasureExtra("peak", { x: 10 }).join(), /x and \.y are set together/); + assert.match(validateMeasureExtra("promise", { checks: "both" })[0], /checks must be "label" or "quote"/); + assert.match(validateMeasureExtra("diet", { colors: { keto: "orange" } })[0], /colors\.keto must be a #hex colour/); + assert.match(validateMeasureExtra("diet", 3)[0], /must be true, false or/); + assert.equal(resolveMeasureExtra("goals", withDeck({ goals: false })), null); + assert.equal(resolveMeasureExtra("goals", withDeck({ goals: { show: false } })), null); + assert.equal(resolveMeasureExtra("goals", RENDER).max, 4); + assert.deepEqual(validateChrome(withDeck({ goals: { max: 3 }, peak: true, promise: { finale: "hide" }, diet: false }).chrome, RENDER), []); + assert.match(validateChrome(withDeck({ goals: { max: 30 } }).chrome, RENDER).join(), /goals\.max must be a whole number from 1 to 8/); + assert.match(validateChrome(withDeck({ gaols: {} }).chrome, RENDER).join(), /gaols is not a deck setting/); + assert.match(moduleProblems({ render: withDeck({ diet: { hold: 1 } }), timeline: [] }).diet[0], /diet\.hold must be null/); +}); + +test("the modules: drawn only with a measure slice and something of their own to draw, live in Play, by z", () => { + for (const id of IDS) { + const m = moduleById(id); + assert.equal(m.kind, "overlay-whole"); + assert.equal(m.region, id); + assert.equal(m.configKey, `render.chrome.deck.${id}`); + assert.deepEqual(m.play, { clock: "cut", ready: `${id}:ready` }); + assert.equal(m.on(schedule(), RENDER), true, id); + assert.equal(m.on(schedule(null), RENDER), false, id); + assert.equal(m.on(schedule(), withDeck({ [id]: false })), false, id); + assert.match(m.check(schedule(null), RENDER), /needs a schedule with a measure slice/); + const [r] = m.regions(schedule(), { render: RENDER, outDir: "/o" }); + assert.equal(r.frames, `/o/chrome/${id}-frames`); + } + assert.ok(playModules().some((m) => m.id === "promise")); + assert.ok(moduleById("promise").z > moduleById("finale").z, "the promise clock is drawn over the finale"); + assert.equal(moduleById("goals").on(schedule({ ...MEASURE, events: MEASURE.events.filter((e) => !e.kind.startsWith("goal")) }), RENDER), false); + assert.deepEqual(scheduleSlices(schedule()).measure, MEASURE); +}); + +test("a deck cut without a measure slice renders exactly as before: none of the four is drawn, no slice, its chrome valid", () => { + const MANIFESTS = path.join(HERE, "../../common/testing/draft/manifests"); + for (const name of ["full", "flips"]) { + const m = JSON.parse(readFileSync(path.join(MANIFESTS, `${name}.video.manifest.json`), "utf8")); + const sched = estimateSchedule(m); + assert.equal(sched.measure, undefined); + assert.equal(scheduleSlices(sched).measure, undefined); + const drawn = deckOverlays().filter((x) => x.on(sched, m.render)).map((x) => x.id); + for (const id of IDS) assert.ok(!drawn.includes(id), `${name}: ${id} not drawn`); + const { chrome, ...rest } = m.render; + assert.deepEqual(validateChrome(chrome, rest), []); + } +}); diff --git a/umtool/report-to-video/modules/diet.mjs b/umtool/report-to-video/modules/diet.mjs @@ -0,0 +1,33 @@ +// THE DIET BADGE (module `diet`, region `diet`): the diet he names as a +// rubber stamp that slams on at each change of regime or diet number ("KETO +// · DIET #6"), in the regime's ink; a null diet after one fades to "NO DIET". +// It draws the state's diet as the producer left it (the off-scope rule is +// the ledger's). Read off the schedule's measure slice +// (`render.chrome.deck.diet`; measure-extras.mjs dietStates, +// chrome-measure-extras.mjs dietHtml). +import { dietHtml } from "../chrome-measure-extras.mjs"; +import { dietStates } from "../measure-extras.mjs"; +import { measureExtraModule } from "./measure-extras-module.mjs"; + +export default measureExtraModule({ + id: "diet", + z: 66, + title: "Diet badge", + summary: "The diet he names as a stamp that slams on at each change, with its number; \"No diet\" when the state says so.", + states: dietStates, + html: dietHtml, + needs: "a diet", + ui: [ + { key: "colors", type: "object", label: "Ink per regime ({keto: \"#E0913C\", …})" }, + { key: "labels", type: "object", label: "Words per regime ({glp1: \"Ozempic\", …})" }, + ], + docs: { + intro: "The diet he names as a rubber stamp in a corner of the footage box (`render.chrome.deck.diet`, measure-extras.mjs): at each change of the state's diet -- its regime or its diet number -- a new stamp slams on (in big and turned, onto the page, a shake), the regime's word in its ink and \"DIET #n\" under it with the ledger's words when they say more (\"Keto · 5 carbs a day\"); a change of words alone fades the new stamp in. A null diet after one fades to \"NO DIET\" in grey. It draws `state.diet` as the measure slice gives it -- the off-scope rule (\"off GLP-1\" while on keto is still keto) is the ledger's. The inks default to the quartering-diet regimes' (keto #E0913C, carnivore #C9534B, fasting #4E9BD8, calories #3FA9A0, glp1 #B168C6, other #8E97A8, off #98A29B).", + rows: [ + ["`deck.diet`", "`true` · `false` · `{show, position, x, y, scale, hold, finale, colors, labels}` · default on with a measure slice", "`umtool look <p> deck.diet=false`"], + ["`deck.diet.position`, `.x`/`.y`, `.scale`", "an anchor in the footage box · design px · 0.5–2 · default `bottom-left`, unset, 1", "`umtool look <p> deck.diet.position=top-right`"], + ["`deck.diet.hold`, `.finale`", "null (up from the first diet on) or 2–600 s · `hide` `show` · default null, `hide`", "`umtool look <p> deck.diet.hold=15`"], + ["`deck.diet.colors`, `.labels`", "`{<regime>: #hex}` · `{<regime>: words ≤40}` · default the regimes' inks and names", "`umtool look <p> deck.diet.labels='{\"glp1\":\"Ozempic\"}'`"], + ], + }, +}); diff --git a/umtool/report-to-video/modules/goals.mjs b/umtool/report-to-video/modules/goals.mjs @@ -0,0 +1,35 @@ +// THE GOAL STACK (module `goals`, region `goals`): every goal he names drops a +// sticky note onto a pile in a corner of the footage; the same goal said +// again merges into its note with a count ("lose 100 ×8") and comes to the +// front; a goal with a deadline counts down to the render date ("by +// Christmas · 50 days left · needs 226.5"). Read off the schedule's measure +// slice (`render.chrome.deck.goals`; measure-extras.mjs goalStates, +// chrome-measure-extras.mjs goalsHtml). +import { goalsHtml } from "../chrome-measure-extras.mjs"; +import { goalStates } from "../measure-extras.mjs"; +import { measureExtraModule } from "./measure-extras-module.mjs"; +import { MEASURE_LIMITS } from "./measure-extras-settings.mjs"; + +export default measureExtraModule({ + id: "goals", + z: 68, + title: "Goal stack", + summary: "Each goal he names as a sticky note on a pile -- a repeat merged with its count, a deadline counted down to the render date.", + states: goalStates, + html: goalsHtml, + needs: "a goal (a goal or goalLoss row)", + ui: [ + { key: "max", type: "number", min: MEASURE_LIMITS.max[0], max: MEASURE_LIMITS.max[1], label: "Notes shown", default: 4 }, + { key: "color", type: "color", label: "Paper (default the palette's amber)" }, + { key: "countdown", type: "boolean", label: "Count a deadline down to the render date", default: true }, + ], + docs: { + intro: "A sticky note per goal on a pile in a corner of the footage box, read off the schedule's `measure` slice (`render.chrome.deck.goals`, measure-extras.mjs): each goal or goalLoss event drops one, turned a little, onto the pile; the same goal in the same words (\"lose 100\") merges into its note with a count (\"×8\") and comes to the front; `max` notes show, the newest in front, with the goals set so far under them. A goal with a `deadline` counts down to `measure.asOfRender` (\"by Christmas · 50 days left · needs 226.5\"): Christmas is the next 25 Dec from the day he said it, \"next year\" a year on, a named year that year; words that name no date (\"by my birthday\") keep their label and no countdown. On whenever the cut has a measure slice with a goal on camera; `false` turns it off. Up for `hold` seconds after each goal (default 20), the pile as it stands each time. The four measure extras sit at anchors of the footage box by default, clear of the instrument panel's right column and of the top-left, where the streams' face cam most often is (the diet badge bottom-left, the goal stack bottom-right, the moving start top-right, the promise clock top-centre); `position` or `x`/`y` move one.", + rows: [ + ["`deck.goals`", "`true` · `false` · `{show, position, x, y, scale, hold, finale, max, color, countdown}` · default on with a measure slice", "`umtool look <p> deck.goals=false`"], + ["`deck.goals.position`, `.x`/`.y`, `.scale`", "`top-left` `top-right` `bottom-left` `bottom-right` `top-center` `bottom-center` · design px · 0.5–2 · default `bottom-right`, unset, 1", "`umtool look <p> deck.goals.position=bottom-left`"], + ["`deck.goals.max`, `.color`, `.countdown`", "1–8 notes · #hex paper · bool · default 4, the palette's amber, `true`", "`umtool look <p> deck.goals.max=6`"], + ["`deck.goals.hold`, `.finale`", "null (up from the first goal on) or 2–600 s after each · `hide` `show` · default 20, `hide`", "`umtool look <p> deck.goals.hold=null`"], + ], + }, +}); diff --git a/umtool/report-to-video/modules/index.mjs b/umtool/report-to-video/modules/index.mjs @@ -31,12 +31,16 @@ import chapter from "./chapter.mjs"; import status from "./status.mjs"; import chat from "./chat.mjs"; import sectionTitle from "./section-title.mjs"; +import diet from "./diet.mjs"; +import peak from "./peak.mjs"; +import goals from "./goals.mjs"; +import promise from "./promise.mjs"; export { assertRegion, defineModule, MODULE_KINDS, MODULE_SLOTS, PLAY_CLOCKS, REGION_PLACEMENTS }; /** 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] + [chart, shell, subtitle, qr, rail, sectionTitle, counter, claims, feed, popupPosts, stamp, stats, fx, threads, flips, finale, teaser, intro, blur, pair, chapter, status, chat, diet, peak, goals, promise] .sort((a, b) => a.z - b.z || a.id.localeCompare(b.id)), ); @@ -129,6 +133,7 @@ export function scheduleSlices(doc) { ...(doc.flips ? { flips: doc.flips } : {}), ...(doc.stats ? { stats: doc.stats } : {}), ...(doc.fx ? { fx: doc.fx } : {}), + ...(doc.measure ? { measure: doc.measure } : {}), }; return out; } diff --git a/umtool/report-to-video/modules/measure-extras-module.mjs b/umtool/report-to-video/modules/measure-extras-module.mjs @@ -0,0 +1,81 @@ +// THE MEASURE EXTRAS' MODULE SHAPE (weight video rev 9, lane measure-extras): +// the goal stack, the moving start, the promise clock and the diet badge are +// four modules of one shape -- a whole-cut overlay in a corner of the footage +// box (or at `x`/`y`), its page chrome-measure-extras.mjs's, its states +// measure-extras.mjs's, its settings measure-extras-settings.mjs's at +// `render.chrome.deck.<id>` -- so they are made here, once, and each module +// file says only what is its own. +import path from "node:path"; + +import { measureExtraGeometry, measureOf } from "../measure-extras.mjs"; +import { assertRegion, defineModule } from "./contract.mjs"; +import { + MEASURE_DEFAULTS, MEASURE_FINALE, MEASURE_LIMITS, MEASURE_POSITIONS, resolveMeasureExtra, +} from "./measure-extras-settings.mjs"; +import { settingsOf } from "./settings.mjs"; + +/** The ui fields every one of the four has: on, where, how big, how long, over the finale. */ +const commonUi = (id) => [ + { key: "show", type: "boolean", label: "Drawn (with a measure slice)", default: true }, + { key: "position", type: "enum", options: MEASURE_POSITIONS, label: "Anchor in the footage", default: MEASURE_DEFAULTS[id].position }, + { key: "x", type: "number", min: MEASURE_LIMITS.x[0], max: MEASURE_LIMITS.x[1], label: "x (design px, with y: overrides the anchor)" }, + { key: "y", type: "number", min: MEASURE_LIMITS.y[0], max: MEASURE_LIMITS.y[1], label: "y (design px)" }, + { key: "scale", type: "number", min: MEASURE_LIMITS.scale[0], max: MEASURE_LIMITS.scale[1], step: 0.05, label: "Scale", default: 1 }, + { key: "hold", type: "number", min: MEASURE_LIMITS.hold[0], max: MEASURE_LIMITS.hold[1], label: "Seconds up after each event (empty: stays up)", ...(MEASURE_DEFAULTS[id].hold !== null ? { default: MEASURE_DEFAULTS[id].hold } : {}) }, + { key: "finale", type: "enum", options: MEASURE_FINALE, label: "Over the finale", default: MEASURE_DEFAULTS[id].finale }, +]; + +/** + * One of the four, as a module. + * + * @param {{ id: "goals" | "peak" | "promise" | "diet", z: number, title: string, summary: string, + * states: (schedule: any, render: any) => any[], html: (schedule: any, render: any, opts: any) => { html: string, items: any[] }, + * ui?: any[], docs: { intro: string, rows: string[][] }, needs: string }} spec + */ +export function measureExtraModule(spec) { + const { id } = spec; + const drawn = (schedule, render) => !!measureOf(schedule) && !!resolveMeasureExtra(id, render) && spec.states(schedule, render).length > 0; + return defineModule({ + id, + version: 1, + z: spec.z, + kind: "overlay-whole", + slot: "footage", + title: spec.title, + summary: spec.summary, + configKey: `render.chrome.deck.${id}`, + defaults: MEASURE_DEFAULTS[id], + validate: settingsOf(id).validate, + resolve: (render) => resolveMeasureExtra(id, render), + ui: [...commonUi(id), ...(spec.ui ?? [])], + docs: { heading: spec.title, intro: spec.docs.intro, rows: spec.docs.rows }, + region: id, + workers: "narrow", + noun: `the ${spec.title.toLowerCase()}'s`, + on: drawn, + check: (schedule, render) => { + if (!measureOf(schedule)) return `the ${id} region needs a schedule with a measure slice (a measure ledger and render.chrome.deck.measure)`; + if (!resolveMeasureExtra(id, render)) return `the ${id} region is off (render.chrome.deck.${id})`; + return spec.states(schedule, render).length ? null : `the ${id} region needs ${spec.needs} on camera in the measure slice`; + }, + async page(ctx) { + const fonts = await ctx.fonts({ regular: "DeckSans", bold: "DeckSansBold" }, { strict: true }); + // The condensed display face the video's other chrome uses, when the render names one. + const display = ctx.render.fontDisplay + ? await ctx.asset(ctx.render.fontDisplay, `MeasureDisplay${path.extname(ctx.render.fontDisplay) || ".ttf"}`).catch(() => null) + : null; + return spec.html(ctx.schedule, ctx.render, { fonts: { ...fonts, ...(display ? { display } : {}) }, from: ctx.from, duration: ctx.duration }); + }, + regions(schedule, { render, outDir, frames = null }) { + return [assertRegion({ + name: id, frames: frames ?? path.join(outDir, "chrome", `${id}-frames`), + ...measureExtraGeometry(id, render, { feed: schedule.layout === "feed" }), + })]; + }, + preview: (_slice, { render }) => ({ region: id, geometry: measureExtraGeometry(id, render) }), + // Its page is its live preview: Play the cut seeks it in the cut's seconds (contract.mjs, PLAY). + play: { clock: "cut", ready: `${id}:ready` }, + // A cue interpreter: each state a block, keyed only while it is shown (frame-keys.mjs). + frameKeys: { data: `${id}-data`, omit: ["init", "cues", "window", "total", "ids"] }, + }); +} diff --git a/umtool/report-to-video/modules/measure-extras-settings.mjs b/umtool/report-to-video/modules/measure-extras-settings.mjs @@ -0,0 +1,180 @@ +// THE MEASURE EXTRAS' SETTINGS (weight video rev 9, lane measure-extras): the +// four small modules that read the schedule's `measure` slice beside the scale +// dial -- the goal stack (`goals`), the moving start (`peak`), the promise +// clock (`promise`) and the diet badge (`diet`). Their defaults and validators, +// the one copy. A LEAF like settings.mjs (deck.mjs imports it through +// SETTINGS), so it imports nothing. +// +// render.chrome.deck.goals { show, position, x, y, scale, hold, finale, max, color, countdown } +// render.chrome.deck.peak { show, position, x, y, scale, hold, finale, title, color, values } +// render.chrome.deck.promise { show, position, x, y, scale, hold, finale, label, verb, kept, broken, checks } +// render.chrome.deck.diet { show, position, x, y, scale, hold, finale, colors, labels } +// +// Each is ON whenever the cut has a measure slice (the build writes one only +// for a manifest with a measure ledger and `deck.measure` set) and something +// of its own to draw; `false` (or `show: false`) turns it off, `true` is the +// defaults. Absent, the module draws with its defaults -- and a cut with no +// measure slice draws none of them, so it renders exactly as before. +// +// WHERE THEY SIT. The scale-dial lane's instrument panel takes the right +// column (the dial in its top ~600 px, the odometer and the trail under it), +// so these four default to anchors of the FOOTAGE BOX, clear of it -- and +// clear of the top-left, where the streams' face cam most often sits: the +// diet badge bottom-left, the goal stack bottom-right, the moving start +// top-right (only for a few seconds after each telling), the promise clock +// top-centre (from the promise on, the last beat). `position` moves one to another +// anchor of the footage box; `x`/`y` (design pixels on the 1920×1080 frame) +// put its top-left corner anywhere -- inside the panel column, say -- and +// `scale` sizes it. + +/** The anchors in the footage box a module may sit at (`position`). */ +export const MEASURE_POSITIONS = Object.freeze(["top-left", "top-right", "bottom-left", "bottom-right", "top-center", "bottom-center"]); + +/** What a module does over the finale's window (`finale`): hidden under it, or drawn over it. */ +export const MEASURE_FINALE = Object.freeze(["hide", "show"]); + +/** Which remembered weights the moving start draws (`peak.values`): the totals' drift values, or every one. */ +export const PEAK_VALUES = Object.freeze(["drift", "all"]); + +/** What a promise check's line quotes (`promise.checks`): the ledger row's label, or its transcript quote. */ +export const PROMISE_CHECKS = Object.freeze(["label", "quote"]); + +/** The diet regimes the ledger names (ledgerSchema.regimes), and what the badge calls each. */ +export const DIET_LABELS = Object.freeze({ + keto: "Keto", carnivore: "Carnivore", fasting: "Fasting", calories: "Counting calories", + glp1: "GLP-1", other: "Some diet", off: "No diet", +}); + +/** Each regime's ink (the quartering-diet ledgerSchema's colours). */ +export const DIET_COLORS = Object.freeze({ + keto: "#E0913C", carnivore: "#C9534B", fasting: "#4E9BD8", calories: "#3FA9A0", + glp1: "#B168C6", other: "#8E97A8", off: "#98A29B", +}); + +/** The needle's red (the contract's ~#ff5a4e): the moving start's drift, an unkept promise. */ +export const MEASURE_RED = "#FF5A4E"; + +/** Every module's bounds. */ +export const MEASURE_LIMITS = Object.freeze({ + scale: Object.freeze([0.5, 2]), + hold: Object.freeze([2, 600]), + x: Object.freeze([0, 1920]), + y: Object.freeze([0, 1080]), + max: Object.freeze([1, 8]), + text: 40, + quote: 160, +}); + +const COMMON = Object.freeze({ show: true, position: "top-left", x: null, y: null, scale: 1, hold: null, finale: "hide" }); + +/** Each module's settings and their defaults. */ +export const MEASURE_DEFAULTS = Object.freeze({ + // The sticky notes pile in the bottom-right corner, up for `hold` seconds + // after each goal; `max` notes show, the newest in front; `color` is the + // paper (default the palette's amber). + goals: Object.freeze({ ...COMMON, position: "bottom-right", hold: 20, max: 4, color: null, countdown: true }), + // The moving start: up for `hold` seconds after each retelling. + peak: Object.freeze({ ...COMMON, position: "top-right", hold: 12, title: "The start keeps moving", color: null, values: "drift" }), + // The promise clock: up from the promise on, through the finale. + promise: Object.freeze({ ...COMMON, position: "top-center", finale: "show", label: null, verb: "offered", kept: "Posted", broken: "None posted", checks: "label" }), + // The diet badge: up from the first diet on, re-stamped at every change. + diet: Object.freeze({ ...COMMON, position: "bottom-left", colors: Object.freeze({}), labels: Object.freeze({}) }), +}); + +/** The four ids, in the order they are drawn. */ +export const MEASURE_EXTRAS = Object.freeze(["diet", "peak", "goals", "promise"]); + +const isObj = (v) => v !== null && typeof v === "object" && !Array.isArray(v); +const numIn = (v, lo, hi) => typeof v === "number" && Number.isFinite(v) && v >= lo && v <= hi; +const HEX_RE = /^#(?:[0-9a-fA-F]{3}|[0-9a-fA-F]{6})$/; + +/** + * A module's settings with every default filled in, or null when it is off + * (`false`, or `show: false`). Absent and `true` are the defaults. + * + * @param {"goals" | "peak" | "promise" | "diet"} id + * @param {any} render + */ +export function resolveMeasureExtra(id, render) { + const base = MEASURE_DEFAULTS[id]; + const v = render?.chrome?.deck?.[id]; + if (v === false) return null; + const own = isObj(v) ? v : {}; + const out = { ...base, ...own }; + if (id === "diet") { + out.colors = { ...DIET_COLORS, ...(isObj(own.colors) ? own.colors : {}) }; + out.labels = { ...DIET_LABELS, ...(isObj(own.labels) ? own.labels : {}) }; + } + return out.show === false ? null : out; +} + +function text(v, max, where, errors, { nullable = true } = {}) { + if (v === undefined || (nullable && v === null)) return; + if (typeof v !== "string" || !v.trim()) errors.push(`${where} must be words`); + else if (/[\r\n]/.test(v)) errors.push(`${where} must be one line`); + else if ([...v].length > max) errors.push(`${where} is ${[...v].length} characters (at most ${max})`); +} + +const color = (v, where, errors) => { + if (v === undefined || v === null) return; + if (typeof v !== "string" || !HEX_RE.test(v)) errors.push(`${where} must be a #hex colour`); +}; + +/** + * Every reason `render.chrome.deck.<id>` cannot be drawn, as sentences (empty: + * it can). `true`/`false` or an object of the module's own keys. + * + * @param {"goals" | "peak" | "promise" | "diet"} id + * @returns {string[]} + */ +export function validateMeasureExtra(id, v, where = `render.chrome.deck.${id}`) { + if (v === undefined || typeof v === "boolean") return []; + const keys = Object.keys(MEASURE_DEFAULTS[id]); + if (!isObj(v)) return [`${where} must be true, false or { ${keys.join(", ")} }`]; + const errors = []; + const L = MEASURE_LIMITS; + for (const k of Object.keys(v)) if (!keys.includes(k)) errors.push(`${where}.${k} is not a deck setting (${keys.join(", ")})`); + if (v.show !== undefined && typeof v.show !== "boolean") errors.push(`${where}.show must be true or false`); + if (v.position !== undefined && !MEASURE_POSITIONS.includes(v.position)) { + errors.push(`${where}.position must be ${MEASURE_POSITIONS.map((p) => `"${p}"`).join(", ")}`); + } + for (const k of ["x", "y"]) { + if (v[k] !== undefined && v[k] !== null && !numIn(v[k], L[k][0], L[k][1])) { + errors.push(`${where}.${k} must be null or from ${L[k][0]} to ${L[k][1]} (design pixels on the 1920×1080 frame)`); + } + } + if ((v.x === undefined || v.x === null) !== (v.y === undefined || v.y === null)) errors.push(`${where}.x and .y are set together (or neither)`); + if (v.scale !== undefined && !numIn(v.scale, L.scale[0], L.scale[1])) errors.push(`${where}.scale must be from ${L.scale[0]} to ${L.scale[1]}`); + if (v.hold !== undefined && v.hold !== null && !numIn(v.hold, L.hold[0], L.hold[1])) { + errors.push(`${where}.hold must be null (up from its first event on) or from ${L.hold[0]} to ${L.hold[1]} seconds`); + } + if (v.finale !== undefined && !MEASURE_FINALE.includes(v.finale)) errors.push(`${where}.finale must be "hide" or "show"`); + if (id === "goals") { + if (v.max !== undefined && !(Number.isInteger(v.max) && numIn(v.max, L.max[0], L.max[1]))) { + errors.push(`${where}.max must be a whole number from ${L.max[0]} to ${L.max[1]}`); + } + color(v.color, `${where}.color`, errors); + if (v.countdown !== undefined && typeof v.countdown !== "boolean") errors.push(`${where}.countdown must be true or false`); + } + if (id === "peak") { + text(v.title, L.text, `${where}.title`, errors, { nullable: false }); + color(v.color, `${where}.color`, errors); + if (v.values !== undefined && !PEAK_VALUES.includes(v.values)) errors.push(`${where}.values must be "drift" or "all"`); + } + if (id === "promise") { + for (const k of ["label", "verb", "kept", "broken"]) text(v[k], L.text, `${where}.${k}`, errors, { nullable: k === "label" }); + if (v.checks !== undefined && !PROMISE_CHECKS.includes(v.checks)) errors.push(`${where}.checks must be "label" or "quote"`); + } + if (id === "diet") { + for (const k of ["colors", "labels"]) { + if (v[k] === undefined) continue; + if (!isObj(v[k])) { errors.push(`${where}.${k} must be { <regime>: … }`); continue; } + for (const [r, x] of Object.entries(v[k])) { + if (!/^[a-z][a-z0-9_-]{0,23}$/.test(r)) errors.push(`${where}.${k}.${r} is not a regime key`); + else if (k === "colors") color(x, `${where}.colors.${r}`, errors); + else text(x, L.text, `${where}.labels.${r}`, errors, { nullable: false }); + } + } + } + return errors; +} diff --git a/umtool/report-to-video/modules/peak.mjs b/umtool/report-to-video/modules/peak.mjs @@ -0,0 +1,34 @@ +// THE MOVING START (module `peak`, region `peak`): the weight he says he +// started at, as he retells it -- each telling a tick on a small vertical +// scale with its value and its count (365.7 → 370 → 385 → 387 → ≈390 ×5), the +// drift from the lowest to the highest bracketed. Read off the schedule's +// measure slice (`render.chrome.deck.peak`; measure-extras.mjs peakStates, +// chrome-measure-extras.mjs peakHtml). +import { peakHtml } from "../chrome-measure-extras.mjs"; +import { peakStates } from "../measure-extras.mjs"; +import { measureExtraModule } from "./measure-extras-module.mjs"; +import { PEAK_VALUES } from "./measure-extras-settings.mjs"; + +export default measureExtraModule({ + id: "peak", + z: 67, + title: "Moving start", + summary: "The starting weight as he retells it: a tick per telling on a small scale, a count per repeat, the drift bracketed.", + states: peakStates, + html: peakHtml, + needs: "a remembered starting weight", + ui: [ + { key: "title", type: "text", label: "Heading", default: "The start keeps moving" }, + { key: "values", type: "enum", options: PEAK_VALUES, label: "Which remembered weights", default: "drift" }, + { key: "color", type: "color", label: "The drift's colour (default the needle's red)" }, + ], + docs: { + intro: "The weight he says he started at, as he retells it (`render.chrome.deck.peak`, measure-extras.mjs): each remembered weight that is one of the measure totals' `peakDrift` values (`values: \"drift\"`; `all` draws every remembered weight) adds a tick on a small vertical scale -- the scale's range is fixed over the whole cut, so nothing rescales -- with its value, a retelling of the same number a count (\"≈390 ×5\"), the newest lit; the spread from the lowest to the highest so far is bracketed in red and written under it (\"+24.3 lb\"). Up for `hold` seconds after each telling (default 12).", + rows: [ + ["`deck.peak`", "`true` · `false` · `{show, position, x, y, scale, hold, finale, title, values, color}` · default on with a measure slice", "`umtool look <p> deck.peak=false`"], + ["`deck.peak.position`, `.x`/`.y`, `.scale`", "an anchor in the footage box · design px · 0.5–2 · default `top-right`, unset, 1", "`umtool look <p> deck.peak.scale=0.9`"], + ["`deck.peak.hold`, `.finale`", "null (stays up) or 2–600 s · `hide` `show` · default 12, `hide`", "`umtool look <p> deck.peak.hold=null`"], + ["`deck.peak.title`, `.values`, `.color`", "≤40 · `drift` `all` · #hex · default \"The start keeps moving\", `drift`, #FF5A4E", "`umtool look <p> deck.peak.values=all`"], + ], + }, +}); diff --git a/umtool/report-to-video/modules/promise.mjs b/umtool/report-to-video/modules/promise.mjs @@ -0,0 +1,37 @@ +// THE PROMISE CLOCK (module `promise`, region `promise`): from a promise on, +// "SCALE VIDEO OFFERED 23 OCT · 13 DAYS · NONE POSTED" -- the days counted to +// the in-record date of what is on screen, then on to the render date in the +// finale; each check's words flashed under it; kept, "POSTED" in green. +// Drawn over the finale by default (z 95). Read off the schedule's measure +// slice (`render.chrome.deck.promise`; measure-extras.mjs promiseStates, +// chrome-measure-extras.mjs promiseHtml). +import { promiseHtml } from "../chrome-measure-extras.mjs"; +import { promiseStates } from "../measure-extras.mjs"; +import { measureExtraModule } from "./measure-extras-module.mjs"; +import { PROMISE_CHECKS } from "./measure-extras-settings.mjs"; + +export default measureExtraModule({ + id: "promise", + z: 95, + title: "Promise clock", + summary: "Days since a promise -- to the clip on screen, then to the render date -- with each check's words and whether it was kept.", + states: promiseStates, + html: promiseHtml, + needs: "a promise row", + ui: [ + { key: "label", type: "text", label: "What was promised (default the row's display)" }, + { key: "verb", type: "text", label: "Verb", default: "offered" }, + { key: "kept", type: "text", label: "Kept", default: "Posted" }, + { key: "broken", type: "text", label: "Not kept", default: "None posted" }, + { key: "checks", type: "enum", options: PROMISE_CHECKS, label: "A check's words", default: "label" }, + ], + docs: { + intro: "A days-since counter for a promise (`render.chrome.deck.promise`, measure-extras.mjs), from the promise's event on: \"SCALE VIDEO OFFERED 23 OCT\", the days from the day he said it to the in-record date of the latest event on screen, and \"NONE POSTED\" in red until a row says it was kept (\"POSTED\", green). Each promise check's words come in under it with a flash (`checks`: the row's `label`, or its transcript `quote`). From the finale's start -- else 4 s after the last event -- the days count on, a day a step, to `measure.asOfRender`. Laid over the finale (z 95) unless `finale: \"hide\"`.", + rows: [ + ["`deck.promise`", "`true` · `false` · `{show, position, x, y, scale, hold, finale, label, verb, kept, broken, checks}` · default on with a measure slice", "`umtool look <p> deck.promise=false`"], + ["`deck.promise.position`, `.x`/`.y`, `.scale`", "an anchor in the footage box · design px · 0.5–2 · default `top-center`, unset, 1", "`umtool look <p> deck.promise.position=bottom-center`"], + ["`deck.promise.hold`, `.finale`", "null (stays up) or 2–600 s · `hide` `show` · default null, `show`", "`umtool look <p> deck.promise.finale=hide`"], + ["`deck.promise.label`, `.verb`, `.kept`, `.broken`, `.checks`", "≤40 each · `label` `quote` · default the row's display, \"offered\", \"Posted\", \"None posted\", `label`", "`umtool look <p> deck.promise.label='scale video'`"], + ], + }, +}); diff --git a/umtool/report-to-video/modules/rail.test.mjs b/umtool/report-to-video/modules/rail.test.mjs @@ -47,5 +47,5 @@ test("rail settings: spacing, pitch, and the deck's other keys refused by name", assert.equal(resolveDeck(render({})).pip.pitch, undefined, "no pitch unless set: the deck resolves as it did"); assert.equal(rail.resolve(render({ spacing: "pitch" })).pip.pitch, 28); assert.equal(rail.validate, settingsOf("rail").validate); - assert.deepEqual(SETTINGS.map((s) => s.id), ["stamp", "threads", "flips", "stats", "fx", "chat", "pair", "chapter", "status", "finale", "claims", "counter", "shell", "rail", "section-title", "subtitle", "qr", "popup-posts"]); + assert.deepEqual(SETTINGS.map((s) => s.id), ["stamp", "threads", "flips", "stats", "fx", "chat", "pair", "chapter", "status", "finale", "claims", "counter", "shell", "rail", "section-title", "subtitle", "qr", "popup-posts", "diet", "peak", "goals", "promise"]); }); diff --git a/umtool/report-to-video/modules/registry.test.mjs b/umtool/report-to-video/modules/registry.test.mjs @@ -46,8 +46,9 @@ test("the registry: unique ids and regions, sorted by z, the deck's overlays in const ids = MODULES.map((m) => m.id); assert.equal(new Set(ids).size, ids.length); for (let i = 1; i < MODULES.length; i += 1) assert.ok(MODULES[i - 1].z <= MODULES[i].z); - // The order the build has always laid them in: the finale last. - assert.deepEqual(deckOverlays().map((m) => m.region), ["deck", "feed", "posts", "stamp", "chat", "stats", "pair", "status", "fx", "threads", "flips", "chapter", "finale"]); + // The order the build has always laid them in: the finale last of all but the + // promise clock, which is drawn over it (the measure extras, z 66-68 and 95). + assert.deepEqual(deckOverlays().map((m) => m.region), ["deck", "feed", "posts", "stamp", "chat", "stats", "pair", "status", "fx", "diet", "peak", "goals", "threads", "flips", "chapter", "finale", "promise"]); assert.equal(moduleOfRegion("deck").id, "shell"); assert.equal(regionModule("posts").id, "popup-posts"); assert.throws(() => regionModule("nope"), /unknown chrome region: nope/); @@ -151,7 +152,7 @@ test("play: a live-preview contract only an overlay with a page and regions decl assert.throws(() => defineModule({ ...base, play: { clock: "cut", ready: "x" } }), /play must be/); assert.throws(() => defineModule({ ...base, page: undefined, play: { clock: "cut", ready: "x:ready" } }), /only an overlay with a page/); assert.throws(() => defineModule({ ...base, kind: "segment", play: { clock: "cut", ready: "x:ready" } }), /only an overlay with a page/); - assert.deepEqual(playModules().map((m) => m.id), ["stats", "pair", "status", "fx", "threads", "flips", "chapter"]); + assert.deepEqual(playModules().map((m) => m.id), ["stats", "pair", "status", "fx", "diet", "peak", "goals", "threads", "flips", "chapter", "promise"]); for (const m of playModules()) assert.equal(m.play.ready, `${m.region}:ready`, m.id); }); diff --git a/umtool/report-to-video/modules/settings.mjs b/umtool/report-to-video/modules/settings.mjs @@ -19,6 +19,7 @@ import { validateFx } from "../fx.mjs"; import { validateChat } from "../chat.mjs"; import { validateChapter, validatePair, validateStatus } from "./story-settings.mjs"; import { MARKER_LEVELS, MARKER_LIMITS } from "../marker-limits.mjs"; +import { MEASURE_EXTRAS, validateMeasureExtra } from "./measure-extras-settings.mjs"; /** * Every deck setting and its default. A manifest names only what it changes; @@ -477,6 +478,12 @@ export const SETTINGS = Object.freeze([ { id: "subtitle", key: "deck", configKey: "render.chrome.deck.subtitle", deck: true, whole: true, validate: validateSubtitleSettings }, { id: "qr", key: "deck", configKey: "render.chrome.deck.qr", deck: true, whole: true, validate: validateQrSettings }, { id: "popup-posts", key: "deck", configKey: "render.chrome.deck.posts", deck: true, whole: true, validate: validatePostsSettings }, + // The measure extras (measure-extras-settings.mjs): the goal stack, the moving + // start, the promise clock and the diet badge, each its own deck key. + ...MEASURE_EXTRAS.map((id) => ({ + id, key: `deck.${id}`, configKey: `render.chrome.deck.${id}`, deck: true, + validate: (v, { where }) => validateMeasureExtra(id, v, `${where}.${id}`), + })), ].map((s) => Object.freeze(s))); /** A module's settings entry, or undefined. */