mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-17 07:42:23 +00:00
fix(insights): keep impossible readings out of the personal band
The baseline-drift card reported a pulse in the hundreds of millions against a usual range in the tens of thousands. Neither figure is a heart rate, and both came from the same place. The application declares a plausibility domain per metric, and every interactive, import, MCP and Telegram write validates against it. The derivation layer did not ask. So a single stored value outside that domain — a provider unit-decode slip, or a row from a writer that never had the gate — was folded into the day mean, carried by the median into the band, and then held against itself as "currently". The two numbers in the sentence were wrong by different amounts, which is why the line read as nonsense rather than as an exaggeration. Both readers now refuse a value the application has already declared impossible: the per-day means behind the band, and the latest-day mean the deviation reads. A day left with no plausible reading contributes nothing rather than a fabricated point, and the vital drops out of the comparison — the coverage floor already knows how to report an absent day. The rollup branch applies the same rule to a bucket mean, since the rollup writer averages whatever is stored. Everything downstream of `readDayMeanSeries` inherits it, which is every consumer of the usual range: the band strip, the drift card, the changepoint detector, readiness, trajectory, the coach read. The card also printed raw doubles. Each figure now renders at the metric's own decimal precision through the shared formatter, so a mean reads as a number rather than as a float and follows the reader's number convention. Left open, and recorded for a separate pass: the provider sync writers do not enforce the domain on the way in, so the impossible rows keep landing.
This commit is contained in:
1 parent
4e9e8649ec
commit
4563bce5b3
6 files changed
+399
-25
No files matched your search
@@ -3,8 +3,9 @@
|
||||
import { useQuery } from "@tanstack/react-query";
|
||||
import { Activity, ArrowDownRight, ArrowUpRight } from "lucide-react";
|
||||
|
||||
import { useTranslations } from "@/lib/i18n/context";
|
||||
import { useFormatters, useTranslations } from "@/lib/i18n/context";
|
||||
import { useAuth } from "@/hooks/use-auth";
|
||||
import { metricFractionDigits } from "@/lib/measurements/value-domain";
|
||||
import { cn } from "@/lib/utils";
|
||||
import { apiGet } from "@/lib/api/api-fetch";
|
||||
import { queryKeys } from "@/lib/query-keys";
|
||||
@@ -44,6 +45,7 @@ export function HealthStatusCard({
|
||||
className,
|
||||
}: HealthStatusCardProps) {
|
||||
const { t } = useTranslations();
|
||||
const fmt = useFormatters();
|
||||
const { isAuthenticated } = useAuth();
|
||||
|
||||
const { data } = useQuery({
|
||||
@@ -60,6 +62,14 @@ export function HealthStatusCard({
|
||||
return key ? t(key) : type;
|
||||
};
|
||||
|
||||
// The engines hand over raw doubles. Interpolating one straight into the
|
||||
// sentence prints whatever floating-point produced — a pulse mean reads
|
||||
// "68.33333333333333" — and reads in the wrong number convention for every
|
||||
// locale that does not use a dot. Render each figure at the metric's own
|
||||
// decimal precision, through the same formatter the rest of the app uses.
|
||||
const metricValue = (type: string, value: number): string =>
|
||||
fmt.number(value, metricFractionDigits(type));
|
||||
|
||||
return (
|
||||
<section
|
||||
data-slot="health-status-section"
|
||||
@@ -100,9 +110,9 @@ export function HealthStatusCard({
|
||||
</p>
|
||||
<p className="text-muted-foreground text-xs leading-snug">
|
||||
{t("insights.healthStatus.rangeContext", {
|
||||
value: d.value,
|
||||
low: d.low,
|
||||
high: d.high,
|
||||
value: metricValue(d.type, d.value),
|
||||
low: metricValue(d.type, d.low),
|
||||
high: metricValue(d.type, d.high),
|
||||
})}
|
||||
</p>
|
||||
</div>
|
||||
@@ -137,8 +147,8 @@ export function HealthStatusCard({
|
||||
</p>
|
||||
<p className="text-muted-foreground text-xs leading-snug">
|
||||
{t("insights.healthStatus.shiftContext", {
|
||||
before: s.beforeMean,
|
||||
after: s.afterMean,
|
||||
before: metricValue(s.metric, s.beforeMean),
|
||||
after: metricValue(s.metric, s.afterMean),
|
||||
})}
|
||||
</p>
|
||||
</div>
|
||||
|
||||
Reference in new issue
Block a user