mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-19 00:12:18 +00:00
feat(blood-pressure): label the in-target window dynamically and gate thin data
The BD-Zielbereich tile narrated a static "· 90 T" scope even for a user with only a few weeks of history or a handful of readings — a headline that reads like a stable quarter-long average when it is really a thin sample. Add a shared, reusable window-confidence helper that, given a window length and the readings observed inside it, returns the EFFECTIVE label span (the real calendar span capped at the window, so "· 23 T" until ~90 days of history exist) and a sufficiency flag (false below five readings). The helper is metric-agnostic so the glucose time-in-range / GMI and sleep tiles can reuse it. Wire it into the in-target headline: below the confidence floor the tile shows "sammelt noch Daten" instead of a hard percentage, with the dynamic span label; above it the percentage shows with the real span. The Health-Score BP pillar reads the same sufficiency notion through the shared input builder, so a thin-data user no longer gets a confident pillar grading off a few readings — the all-time rate still rescues a deep-history account with a quiet quarter. The 90-day pair count and effective span thread from the analytics route and the dashboard snapshot through to the tile.
This commit is contained in:
1 parent
461ed5b5e0
commit
e9138bb4f6
20 files changed
+416
-17
No files matched your search
@@ -18,6 +18,7 @@ import {
|
||||
} from "@/lib/analytics/bp-in-target-fast-path";
|
||||
import { computeUserHealthScoreFastPath } from "@/lib/analytics/health-score-fast-path";
|
||||
import { buildHealthScoreBpInputs } from "@/lib/analytics/health-score-inputs";
|
||||
import { computeWindowConfidence } from "@/lib/analytics/window-confidence";
|
||||
import { computeCorrelationHypothesesFastPath } from "@/lib/analytics/correlations-fast-path";
|
||||
|
||||
export const dynamic = "force-dynamic";
|
||||
@@ -257,6 +258,11 @@ async function buildAnalyticsResponse(user: AuthedUser) {
|
||||
*/
|
||||
let bpInTargetPctPriorMonth: number | null = null;
|
||||
let bpInTargetPctPriorYear: number | null = null;
|
||||
// v1.17 W1b — 90-day pair count + effective label span for the tile's
|
||||
// thin-data gate. Surfaced so the BD-Zielbereich tile renders "collecting
|
||||
// data" until the window holds enough readings, with a dynamic span label.
|
||||
let bpInTargetCount90: number | null = null;
|
||||
let bpInTargetSpanDays90: number | null = null;
|
||||
// v1.17 W1b — hold the current + prior-week BP envelopes so the shared
|
||||
// Health-Score input builder grades the pillar off the identical shape the
|
||||
// dashboard snapshot uses (one builder, no per-surface assembly drift).
|
||||
@@ -319,6 +325,15 @@ async function buildAnalyticsResponse(user: AuthedUser) {
|
||||
bpInTargetPctAllTime = windows.allTime?.pct ?? null;
|
||||
bpInTargetPctPriorMonth = windows.priorMonth?.pct ?? null;
|
||||
bpInTargetPctPriorYear = windows.priorYear?.pct ?? null;
|
||||
// v1.17 W1b — count + effective span for the BD-Zielbereich tile's
|
||||
// confidence gate (thin-data → "collecting data"; dynamic span label).
|
||||
bpInTargetCount90 = windows.last90Days?.pairs ?? 0;
|
||||
bpInTargetSpanDays90 = computeWindowConfidence({
|
||||
windowDays: 90,
|
||||
readingCount: bpInTargetCount90,
|
||||
earliestReadingAt: windows.last90EarliestAt,
|
||||
now,
|
||||
}).effectiveSpanDays;
|
||||
}
|
||||
|
||||
// Per-context glucose summaries (canonical mg/dL).
|
||||
@@ -401,6 +416,8 @@ async function buildAnalyticsResponse(user: AuthedUser) {
|
||||
bpInTargetPctAllTime,
|
||||
bpInTargetPctPriorMonth,
|
||||
bpInTargetPctPriorYear,
|
||||
bpInTargetCount90,
|
||||
bpInTargetSpanDays90,
|
||||
glucoseByContext,
|
||||
correlations,
|
||||
healthScore,
|
||||
|
||||
Reference in new issue
Block a user