// `deck.goals.baseMaxDays` (rev9-a9, 12 Nov): a loss goal's base is the latest weight he gave by the goal's date -- // however long before. On the real record that put "(FROM 368)" on a goal set eight years after he said 368. With // the knob a base counts only when its weight was SAID at most that many days before the goal; a staler one is no // base -- no "(FROM …)" on the note, no target and no tick on the dial. Unset, every base counts, as before. import assert from "node:assert/strict"; import test from "node:test"; import { goalMarks, goalWords } from "./chrome-instruments.mjs"; import { estimateSchedule, validateChrome } from "./deck.mjs"; import { goalStates } from "./measure-extras.mjs"; import { goalBoard } from "./measure-goals.mjs"; import { goalBaseMaxDays, measureSlice } from "./measure-slice.mjs"; const PAL = { bg: "#0F1312", fg: "#EDF0EC", muted: "#98A29B", accent: "#22AB83", amber: "#E8A33F" }; const render = (goals) => ({ width: 1920, height: 1080, fps: 30, transition: 0.4, palette: PAL, chrome: { engine: "hyperframes", layout: "deck", deck: { measure: { scopes: ["weight"], scale: { min: 100, max: 400 }, asOf: "2026-11-12" }, ...(goals === undefined ? {} : { goals }) } } }); const schema = { kind: "measure", unit: "lb", yMin: 100, yMax: 400, bandGapDays: 60, tracks: [{ key: "weight", role: "value", label: "Weight" }], forms: ["current", "past", "delta", "goal", "goal_loss"] }; const row = (o) => ({ scope: "weight", scopeBasis: "his words", scopeConfidence: "read", valueKind: "uttered", flags: [], asOf: null, ...o }); // The gaps the real record has: 8 years, 0 days, 279 days, 434 days. const LEDGER = [ row({ id: "a1", date: "2015-01-10", population: "current", value: 368, display: "368 lb", entryId: "c1" }), row({ id: "g8y", date: "2023-01-08", population: "goal_loss", value: -100, display: "lose 100", entryId: "c2" }), row({ id: "b1", date: "2023-03-01", population: "current", value: 350, display: "350 lb", entryId: "c3" }), row({ id: "g0", date: "2023-03-01", population: "goal_loss", value: -50, display: "lose 50", entryId: "c4" }), row({ id: "g279", date: "2023-12-05", population: "goal_loss", value: -60, display: "lose 60", entryId: "c5" }), row({ id: "g434", date: "2024-05-08", population: "goal_loss", value: -70, display: "lose 70", entryId: "c6" }), ]; function sliced(r, ledger = LEDGER) { const timeline = Array.from({ length: 7 }, (_, i) => ({ type: "clip", id: `c${i + 1}`, video: "v", start: 10 * i, end: 10 * i + 8, cite: 1, section: 0, quote: "q", onscreen: { title: `Clip ${i + 1}` } })); const manifest = { slug: "m", title: "M", provenance: {}, render: r, timeline, ledgerSchema: schema, ledger }; const doc = estimateSchedule(manifest); const m = measureSlice(manifest, doc, {}); const goalAfter = (id) => m.state[m.events.findIndex((e) => e.row === id) + 1].goal; return { m, schedule: { ...doc, measure: m }, goalAfter }; } test("unset: every base counts, however old -- and each carries the date its weight was said", () => { assert.equal(goalBaseMaxDays({ render: render(undefined) }), null); assert.equal(goalBaseMaxDays({ render: render(true) }), null); const { goalAfter } = sliced(render({ base: true })); assert.deepEqual(goalAfter("g8y").base, { value: 368, row: "a1", from: "stated", date: "2015-01-10" }); assert.equal(goalAfter("g8y").value, 268); assert.deepEqual(["g0", "g279", "g434"].map((id) => [goalAfter(id).base.row, goalAfter(id).base.date, goalAfter(id).value]), [["b1", "2023-03-01", 300], ["b1", "2023-03-01", 290], ["b1", "2023-03-01", 280]]); }); test("365: a base said 0 or 279 days before the goal stays; 434 days and eight years are no base -- no target, his words", () => { const r = render({ base: true, baseMaxDays: 365 }); assert.deepEqual(validateChrome(r.chrome, r), []); const { m, schedule, goalAfter } = sliced(r); assert.deepEqual(["g8y", "g0", "g279", "g434"].map((id) => goalAfter(id).base?.row ?? null), [null, "b1", "b1", null]); assert.deepEqual(["g8y", "g0", "g279", "g434"].map((id) => goalAfter(id).value), [null, 300, 290, null]); assert.equal(goalWords(goalAfter("g8y")), "LOSE 100"); assert.equal(goalWords(goalAfter("g434")), "LOSE 70"); assert.match(goalWords(goalAfter("g279")), /^GOAL 290 · LOSE 60/); // The notes: "(FROM …)" only where the base stands. const states = goalStates(schedule, r); const baseOf = (text) => states[states.length - 1].notes.find((n) => n.text === text)?.base ?? null; assert.deepEqual([baseOf("LOSE 100"), baseOf("LOSE 50"), baseOf("LOSE 60"), baseOf("LOSE 70")], [null, "(FROM 350)", "(FROM 350)", null]); // The dial: a goal with no base has no weight to mark -- no tick from a base it does not have. const marks = goalMarks(goalBoard(m), m.scale); const tick = (id) => marks.find((x) => x.goal.row === id).angle !== null; assert.deepEqual(["g8y", "g0", "g279", "g434"].map(tick), [false, true, true, false]); // Unset, all four are marked. const before = sliced(render({ base: true })).m; assert.deepEqual(goalMarks(goalBoard(before), before.scale).map((x) => x.angle !== null), [true, true, true, true]); }); test("the day counts from when the weight was SAID, never a remembered weight's as-of; the edge day is inside", () => { const ledger = [ row({ id: "p1", date: "2024-06-01", asOf: "2016-01-01", population: "past", value: 390, display: "≈390 lb", entryId: "c1" }), row({ id: "g", date: "2024-06-10", population: "goal_loss", value: -100, display: "lose 100", entryId: "c2" }), ]; const kept = sliced(render({ baseMaxDays: 30 }), ledger).goalAfter("g"); assert.deepEqual([kept.base.row, kept.base.from, kept.base.date, kept.value], ["p1", "remembered", "2024-06-01", 290]); assert.equal(sliced(render({ baseMaxDays: 9 }), ledger).goalAfter("g").base.row, "p1", "9 days before, 9 allowed"); assert.equal(sliced(render({ baseMaxDays: 8 }), ledger).goalAfter("g").base, null); // 0: only a weight said on the goal's own day. assert.equal(sliced(render({ baseMaxDays: 0 })).goalAfter("g0").base.row, "b1"); assert.equal(sliced(render({ baseMaxDays: 0 })).goalAfter("g279").base, null); }); test("the setting is checked: whole days from 0, or null", () => { const problems = (v) => validateChrome(render({ baseMaxDays: v }).chrome, render({ baseMaxDays: v })).join("\n"); assert.equal(problems(null), ""); assert.equal(problems(0), ""); for (const bad of [-1, 1.5, "365", 40000]) assert.match(problems(bad), /deck\.goals\.baseMaxDays must be null \(every base counts\) or whole days from 0 to 36500/, String(bad)); });