mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-08 20:42:43 +00:00
feat(insights): make sleep debt a configurable source ladder with a computed explainer
Generalise sleep debt onto the existing per-metric source-priority picker (a new sleepDebt ladder, native-above-computed, default WHOOP > Oura > Polar > computed) instead of assuming one provider. The rhythm read resolves the active source off the ladder and carries it on the DTO; when the active source is our own COMPUTED engine — every user today, since no provider ships a native sleep-debt balance — the Sleep page explains what the figure means and that it differs from a wearable's native number. The computed model itself is unchanged and correct (a short rolling balance of need minus sleep, surplus-credited); only stale comments that still referenced the old 14-night window are corrected.
This commit is contained in:
1 parent
c862b4880f
commit
d570d558fa
15 files changed
+245
-23
No files matched your search
@@ -39,6 +39,7 @@ const READY_DTO: SleepRhythmDto = {
|
||||
nightsCounted: 10,
|
||||
windowNights: 14,
|
||||
nightsUntilReady: 0,
|
||||
source: "COMPUTED",
|
||||
},
|
||||
chronotype: {
|
||||
state: "ready",
|
||||
|
||||
@@ -23,6 +23,7 @@ const PARTIAL_DEBT: SleepDebtDto = {
|
||||
nightsCounted: 3,
|
||||
windowNights: 5,
|
||||
nightsUntilReady: 1,
|
||||
source: "COMPUTED",
|
||||
};
|
||||
|
||||
const READY_DEBT: SleepDebtDto = {
|
||||
@@ -32,6 +33,7 @@ const READY_DEBT: SleepDebtDto = {
|
||||
nightsCounted: 5,
|
||||
windowNights: 5,
|
||||
nightsUntilReady: 0,
|
||||
source: "COMPUTED",
|
||||
};
|
||||
|
||||
const LEARNING_CHRONO: ChronotypeDto = {
|
||||
|
||||
@@ -47,6 +47,7 @@ const READY_DTO: SleepRhythmDto = {
|
||||
nightsCounted: 5,
|
||||
windowNights: 5,
|
||||
nightsUntilReady: 0,
|
||||
source: "COMPUTED",
|
||||
},
|
||||
chronotype: {
|
||||
state: "ready",
|
||||
|
||||
@@ -4,6 +4,7 @@ import { Moon } from "lucide-react";
|
||||
|
||||
import { useTranslations } from "@/lib/i18n/context";
|
||||
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
|
||||
import { InfoHint } from "@/components/ui/info-hint";
|
||||
import { LearningGate } from "@/components/ui/learning-gate";
|
||||
import type { SleepDebtDto } from "./use-sleep-rhythm";
|
||||
|
||||
@@ -37,6 +38,13 @@ export function SleepDebtCard({ debt }: { debt: SleepDebtDto }) {
|
||||
<CardTitle className="text-base font-semibold">
|
||||
{t("insights.sleep.debt.title")}
|
||||
</CardTitle>
|
||||
{/* v1.25.0 — when the active source on the user's sleep-debt ladder
|
||||
is our own COMPUTED engine (every user today, until a provider
|
||||
ships a native debt), explain what the figure means and that it
|
||||
differs from a wearable's native number. */}
|
||||
{debt.source === "COMPUTED" ? (
|
||||
<InfoHint label={t("insights.sleep.debt.computedInfo")} />
|
||||
) : null}
|
||||
</div>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
|
||||
@@ -89,6 +89,8 @@ const METRIC_LABEL_KEYS: Record<SourcePriorityMetricKey, string> = {
|
||||
recovery: "settings.sections.sources.metrics.recovery",
|
||||
// v1.18.10 I-5 — native-vs-derived stress ladder.
|
||||
stress: "settings.sections.sources.metrics.stress",
|
||||
// v1.25.0 — native-vs-computed sleep-debt ladder.
|
||||
sleepDebt: "settings.sections.sources.metrics.sleepDebt",
|
||||
};
|
||||
|
||||
const SOURCE_LABEL_KEYS: Record<string, string> = {
|
||||
|
||||
Reference in new issue
Block a user