fix(insights): correct signals-of-day extraction and determinism

Drop steps from the signals-of-day set: Apple Health steps ingest as
many intraday stats-prefixed samples, so the newest raw row is a
partial-day fragment, not a daily total — same exclusion already applied
to per-night sleep. Add a glucose signal off the canonical stored value
(the model reads the snapshot, not display units) so the block matches
the priority comment that already claimed it; drop the dead sleep entry
from SIGNAL_PRIORITY. Track the raw extreme magnitude when keeping the
most extreme recent anomaly so a larger anomaly is no longer dropped by
comparing against an already-rounded value. Thread the injected clock
through trendSlope so the emerging-trend cutoff is deterministic under a
test clock. Rename the anomaly day-count to anomalyDaysAgo so the
snapshot hash staleness-tiers it instead of letting the raw count drive
the fingerprint. Cap the returned set at three to match the schema.
This commit is contained in:
Marc-André Bombeck committed 2026-06-19 20:27:36 +02:00
1 parent cdb76f1930
commit ebb9d0c607
2 files changed
+30 -29

No files matched your search

+2 -1
View File
@@ -29,11 +29,12 @@ export interface TrendSlope {
export function trendSlope(
data: DataPoint[],
windowDays: number,
now: number = Date.now(),
): TrendSlope | null {
if (data.length < 2) return null;
const sorted = [...data].sort((a, b) => a.date.getTime() - b.date.getTime());
const cutoff = Date.now() - windowDays * 24 * 60 * 60 * 1000;
const cutoff = now - windowDays * 24 * 60 * 60 * 1000;
const window = sorted.filter((p) => p.date.getTime() >= cutoff);
if (window.length < 2) return null;