Archilyzer · Source

archilyzer

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

commit b4b066f36f2e4bc106a60818d98b6348535c3662
parent 4c5f8ad81146943c325e28bb01a2ee7fe892701e
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date:   Thu, 12 Nov 2026 20:37:50 -0500

umtool: measure-slice's run start is runStartAt/runStartOf -- a loss goal's base reads it as before

The run open on a day and its remembered start, factored out of goalBase so an
analysis item's deltas resolve against the same start. measureSlice's output is
unchanged (the pin over every ~/reports cut and take: identical to main).

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

Diffstat:
Mumtool/report-to-video/measure-slice.mjs | 65+++++++++++++++++++++++++++++++++++++++++++++--------------------
1 file changed, 45 insertions(+), 20 deletions(-)

diff --git a/umtool/report-to-video/measure-slice.mjs b/umtool/report-to-video/measure-slice.mjs @@ -191,6 +191,47 @@ export function lossRuns(rows, schema) { return { runs, runOf, claims: claims.map((c) => ({ id: c.id, date: c.date, run: runOf.get(c.id) })), total: r1(runs.reduce((n, r) => n + r.peak, 0)) }; } +/** + * THE RUN'S START on day `d`, when the record names one: `{ value, row, date }` + * or null. The run open on `d` is the run of his last loss claim on or before + * it, within bandGapDays, else of his next one within bandGapDays (a day as a + * run begins); its start is a remembered weight about a day within + * bandGapDays before the run's first claim, said by `d` (the latest said + * wins). A loss goal's base (measureSlice) and an analysis item's deltas + * (analysis-plan.mjs) both read it. + * + * @param {string} d + * @param {{ readings: any[], lossClaims: Array<{ id: string, date: string, run: number }>, runById: Map<number, { start: string }>, bandGapDays: number }} ctx + * `readings` his value-track current/past rows, chronological; `lossClaims` and `runById` lossRuns' over his usable rows. + */ +export function runStartAt(d, { readings, lossClaims, runById, bandGapDays }) { + let run = null; + const before = lossClaims.filter((c) => dateKey(c.date) <= dateKey(d)).pop(); + if (before && Math.round(daysBetween(before.date, d)) <= bandGapDays) run = runById.get(before.run) ?? null; + else { + const after = lossClaims.find((c) => dateKey(c.date) > dateKey(d)); + if (after && Math.round(daysBetween(d, after.date)) <= bandGapDays) run = runById.get(after.run) ?? null; + } + if (!run) return null; + const starts = readings.filter((r) => r.population === "past" && r.asOf && dateKey(r.date) <= dateKey(d) && + dateKey(r.asOf) <= dateKey(run.start) && Math.round(daysBetween(r.asOf, run.start)) <= bandGapDays); + const last = starts[starts.length - 1]; + return last ? { value: Number(last.value), row: last.id, date: last.date ?? null } : null; +} + +/** + * runStartAt over a ledger: `rows` every row (only his own on the value track + * are read, as measureSlice reads them), `schema` the ledger's. + */ +export function runStartOf(rows, schema, d) { + const s = measureSchema(schema); + const valueTrack = s.tracks.find((t) => t.role === "value")?.key ?? null; + const own = (rows ?? []).filter((r) => isObj(r) && typeof r.id === "string" && speakerOf(r) === null); + const { runs, claims } = lossRuns(own.filter(isUsable), s); + const readings = chronological(own.filter((r) => r.scope === valueTrack && (r.population === "current" || r.population === "past") && Number.isFinite(Number(r.value)))); + return runStartAt(d, { readings, lossClaims: claims, runById: new Map(runs.map((r) => [r.run, r])), bandGapDays: s.bandGapDays }); +} + // --------------------------------------------------------------------------- // A row as an event // --------------------------------------------------------------------------- @@ -480,20 +521,9 @@ export function measureSlice(manifest, schedule, opts = {}) { /** * A loss goal's target weight: against the start of the run open when he - * set it, when the record knows that start -- a remembered weight about a - * day within bandGapDays before the run's first claim, said by the goal's - * date (the latest said wins) -- else against the last weight he stated by - * then, else none (his words stay the goal). The run open when he set it: - * the run of his last loss claim before it, within bandGapDays, else of his - * next one within bandGapDays (a goal set as a run begins). + * set it, when the record knows that start (runStartAt) -- else against the + * last weight he stated by then, else none (his words stay the goal). */ - const runAt = (d) => { - const before = lossClaims.filter((c) => dateKey(c.date) <= dateKey(d)).pop(); - if (before && Math.round(daysBetween(before.date, d)) <= s.bandGapDays) return runById.get(before.run) ?? null; - const after = lossClaims.find((c) => dateKey(c.date) > dateKey(d)); - if (after && Math.round(daysBetween(d, after.date)) <= s.bandGapDays) return runById.get(after.run) ?? null; - return null; - }; // A loss goal's base (rev 9, 6 Nov): the run's start when the record names one; // else the latest weight he gave by the goal's date -- stated or remembered, // by the day it was his weight (a remembered one's asOf); else none. A target @@ -501,13 +531,8 @@ export function measureSlice(manifest, schedule, opts = {}) { // not 140 lb): his words stay the goal -- "LOSE 100", no weight, no tick. const goalBase = (row) => { const d = row.date; - const run = runAt(d); - if (run) { - const starts = readings.filter((r) => r.population === "past" && r.asOf && dateKey(r.date) <= dateKey(d) && - dateKey(r.asOf) <= dateKey(run.start) && Math.round(daysBetween(r.asOf, run.start)) <= s.bandGapDays); - const last = starts[starts.length - 1]; - if (last) return { value: Number(last.value), row: last.id, from: "runStart", date: last.date ?? null }; - } + const start = runStartAt(d, { readings, lossClaims, runById, bandGapDays: s.bandGapDays }); + if (start) return { value: start.value, row: start.row, from: "runStart", date: start.date }; const known = readings .filter((r) => dateKey(r.date) <= dateKey(d)) .sort((a, b) => dateKey(plotDate(a)).localeCompare(dateKey(plotDate(b))) || dateKey(a.date).localeCompare(dateKey(b.date)));