mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-16 15:23:29 +00:00
fix(sleep): say why consistency or timing has no value
A rhythm sub-score below three nights with a main sleep was dropped from the blend and its row read "no data", although the nights were there; since a nap-only day no longer has a place on the clock, a ring worn for only a few nights reaches that state more often. Each withheld consistency or timing sub-score now carries the reason (`few_nights`, `no_main_sleep`) and the score value carries how many nights the rhythm is built from, so the row reads "not enough nights yet (2 of 3)" or "latest night had no main sleep" instead. Neither is ever shown as 0. Refs #1204
This commit is contained in:
1 parent
40b1389970
commit
d38ceb4beb
13 files changed
+166
-4
No files matched your search
@@ -67,6 +67,35 @@ describe("<ScoreAnatomyView>", () => {
|
||||
expect(html).not.toContain("absolute top-3 right-3");
|
||||
});
|
||||
|
||||
it("names why a contributor is missing when the caller knows", () => {
|
||||
const html = render(
|
||||
<ScoreAnatomyView
|
||||
title="Sleep score"
|
||||
score={70}
|
||||
contributors={[
|
||||
{ key: "sufficiency", label: "Sufficiency", value: 90, weight: 1 },
|
||||
{
|
||||
key: "consistency",
|
||||
label: "Consistency",
|
||||
value: null,
|
||||
weight: 0,
|
||||
missingLabel: "not enough nights yet (2 of 3)",
|
||||
},
|
||||
{ key: "composition", label: "Composition", value: null, weight: 0 },
|
||||
]}
|
||||
coverage={COVERAGE}
|
||||
confidence={CONFIDENCE}
|
||||
provenance={PROVENANCE}
|
||||
method="m"
|
||||
/>,
|
||||
);
|
||||
expect(html).toContain("not enough nights yet (2 of 3)");
|
||||
// A missing contributor without a reason keeps the general note.
|
||||
expect(html).toContain("no data");
|
||||
// Neither reads as a 0 score.
|
||||
expect(html).not.toMatch(/>0, weighted/);
|
||||
});
|
||||
|
||||
it("tints the card + leans the ring hue when a hue is passed (F1)", () => {
|
||||
const html = render(
|
||||
<ScoreAnatomyView
|
||||
|
||||
@@ -238,6 +238,14 @@ export function CompositeScoreAnatomy({
|
||||
label: t(`insights.derived.composite.SLEEP_SCORE.sub.${s.key}`),
|
||||
value: s.value,
|
||||
weight: s.weight,
|
||||
missingLabel:
|
||||
s.gap === "few_nights"
|
||||
? t("insights.derived.composite.SLEEP_SCORE.gap.fewNights", {
|
||||
count: v.rhythmNights ?? 0,
|
||||
})
|
||||
: s.gap === "no_main_sleep"
|
||||
? t("insights.derived.composite.SLEEP_SCORE.gap.noMainSleep")
|
||||
: undefined,
|
||||
}))
|
||||
.sort(rankByImpact);
|
||||
} else if (metric === "READINESS") {
|
||||
|
||||
@@ -58,6 +58,12 @@ export interface AnatomyContributor {
|
||||
value: number | null;
|
||||
/** Effective weight share after null-redistribution, 0..1. */
|
||||
weight: number;
|
||||
/**
|
||||
* What a missing contributor still needs, when the server says why it is
|
||||
* missing (the sleep score's rhythm sub-scores). Shown in place of the
|
||||
* generic "no data".
|
||||
*/
|
||||
missingLabel?: string;
|
||||
}
|
||||
|
||||
export interface ScoreAnatomyViewProps {
|
||||
@@ -238,7 +244,8 @@ function ContributorRow({ contributor }: { contributor: AnatomyContributor }) {
|
||||
value: Math.round(clamped),
|
||||
weight: weightPct,
|
||||
})
|
||||
: t("insights.derived.anatomy.contributorMissing")}
|
||||
: (contributor.missingLabel ??
|
||||
t("insights.derived.anatomy.contributorMissing"))}
|
||||
</span>
|
||||
</div>
|
||||
<div
|
||||
|
||||
Reference in new issue
Block a user