fix(labs): stop projecting lab trends from stale or short series

A marker whose newest reading is more than a year old is now reported
as of that reading (projection "stale"), with no exit date and no
already-outside verdict. The projection horizon is capped at the span
the readings cover, so a line is never carried further ahead than the
data reaches back. The detail read keeps the newest 2000 readings
rather than the oldest.
This commit is contained in:
Marc-André Bombeck committed 2026-10-21 22:40:43 +02:00
1 parent 5f563623d7
commit e482f76508
16 files changed
+165 -30

No files matched your search

+46
View File
@@ -128,4 +128,50 @@ describe("computeLabTrend", () => {
computeLabTrend(falling, { low: 90, high: 140 }, atYears(2)),
).toMatchObject({ projection: "exits", exitBound: "low" });
});
it("never carries the line further ahead than the readings reach back", () => {
// 10 a year over one year (span 1.0); band top 125 sits 1.5 years past
// the last reading. Inside the three-year cap, outside the one-year span.
const short = readings([
[0, 100],
[0.5, 105],
[1, 110],
]);
expect(
computeLabTrend(short, { low: 70, high: 125 }, atYears(1)),
).toMatchObject({ projection: "beyond_horizon", horizonYears: 1 });
// The same line with a top of 118 meets it 0.8 years out: projected.
expect(
computeLabTrend(short, { low: 70, high: 118 }, atYears(1)),
).toMatchObject({ projection: "exits", exitBound: "high" });
});
it("reports a stale series as of its last reading, without a projection", () => {
const line = readings([
[0, 100],
[1, 110],
[2, 120],
]);
// Last reading two years before "now": evaluated on that day.
const stale = computeLabTrend(line, { low: 70, high: 125 }, atYears(4));
expect(stale).toMatchObject({
status: "ok",
projection: "stale",
exitDate: null,
exitBound: null,
fittedNow: 120,
slopePerYear: 10,
});
if (stale.status !== "ok") throw new Error("expected ok");
expect(stale.asOf).toBe(stale.lastAt);
// Carried to today the line would read 140, above the band: a stale
// series never says "already outside".
expect(
computeLabTrend(line, { low: 70, high: 115 }, atYears(4)),
).toMatchObject({ projection: "stale" });
// Eleven months after the last reading it is still current.
expect(
computeLabTrend(line, { low: 70, high: 200 }, atYears(2.9)),
).toMatchObject({ projection: "beyond_horizon" });
});
});