feat: enhance recovery dashboard with optional average sleep KPI and structured insights
- Added an `include_avg_sleep_kpi` parameter to the `build_recovery_dashboard_kpi_tiles` function to conditionally include average sleep data in the dashboard. - Updated the `get_recovery_dashboard_viz_bundle` function to pass the new parameter, ensuring flexibility in data presentation. - Refactored the insights generation in the `vitals_fitness_insights.py` file to utilize a new structured approach for better organization of heart and VO2 insights. - Introduced new components in the frontend for displaying insights, improving the user experience and clarity of vital metrics.
This commit is contained in:
1 parent
857cc1043a
commit
61738cecb7
4 files changed
+291
-258
No files matched your search
@@ -58,13 +58,120 @@ function VitalZoneHint({ item }) {
|
||||
lineHeight: 1.45,
|
||||
}}
|
||||
>
|
||||
<span style={{ fontWeight: 600, color: 'var(--text1)', marginRight: 6 }}>Zuletzt (Snapshot):</span>
|
||||
<span style={{ fontWeight: 600, color: 'var(--text1)', marginRight: 6 }}>Letzte Einordnung (Snapshot):</span>
|
||||
<span style={{ fontWeight: 600, color: stripe }}>{item.zone_label_de}</span>
|
||||
<span style={{ marginLeft: 6 }}>{item.hint_de}</span>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
/** KPI «Herz & autonomes System» — kurze Lesart (kein Ersatz für ärztliche Bewertung). */
|
||||
function HeartAutonomicGuide() {
|
||||
return (
|
||||
<details style={{ marginBottom: 12, fontSize: 11, color: 'var(--text2)' }}>
|
||||
<summary style={{ cursor: 'pointer', fontWeight: 600, color: 'var(--text3)', listStyle: 'none' }}>
|
||||
Einordnungshilfe: KPI «Herz & autonomes System» & Diagramm
|
||||
</summary>
|
||||
<div style={{ marginTop: 8, lineHeight: 1.5, paddingLeft: 2 }}>
|
||||
<p style={{ margin: '0 0 8px' }}>
|
||||
Es handelt sich um <strong>Abweichungen in %</strong> vom älteren Referenzmittel (kurzfristiges Mittel vs. längere
|
||||
Basis) — nicht um absolute Normalwerte.
|
||||
</p>
|
||||
<ul style={{ margin: 0, paddingLeft: 18 }}>
|
||||
<li>
|
||||
<strong>HRV</strong>: Positive % = zuletzt oft über der älteren Basis; sehr personenabhängig.
|
||||
</li>
|
||||
<li>
|
||||
<strong>Ruhepuls</strong>: Negative % = niedriger als die Referenz; bei Training oft unkritisch günstig.
|
||||
</li>
|
||||
</ul>
|
||||
<p style={{ margin: '8px 0 0' }}>
|
||||
Das Liniendiagramm zeigt die Rohverläufe; in anderen Karten kann eine gestrichelte Linie den gleitenden Mittelwert
|
||||
anzeigen.
|
||||
</p>
|
||||
</div>
|
||||
</details>
|
||||
)
|
||||
}
|
||||
|
||||
function SectionInsightCard({ ins }) {
|
||||
const t = ['good', 'warn', 'bad', 'neutral'].includes(ins.tone) ? ins.tone : 'neutral'
|
||||
const stripe = insightBulletStripe(t)
|
||||
const bg =
|
||||
t === 'good' ? getStatusBg('good') : t === 'bad' ? getStatusBg('bad') : t === 'warn' ? getStatusBg('warn') : 'var(--surface2)'
|
||||
return (
|
||||
<div
|
||||
style={{
|
||||
borderRadius: 8,
|
||||
padding: '10px 12px',
|
||||
border: '1px solid var(--border)',
|
||||
borderLeft: `4px solid ${stripe}`,
|
||||
background: bg,
|
||||
}}
|
||||
>
|
||||
<div style={{ fontSize: 12, fontWeight: 600, marginBottom: 4, color: 'var(--text1)' }}>{ins.title_de}</div>
|
||||
<div style={{ fontSize: 12, color: 'var(--text2)', lineHeight: 1.45 }}>{ins.body}</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
function SnapshotCards({ items }) {
|
||||
if (!items?.length) return null
|
||||
return (
|
||||
<div style={{ display: 'flex', flexDirection: 'column', gap: 10, marginBottom: 12 }}>
|
||||
{items.map((it) => {
|
||||
const stripe =
|
||||
it.tone === 'good'
|
||||
? getStatusColor('good')
|
||||
: it.tone === 'bad'
|
||||
? getStatusColor('bad')
|
||||
: it.tone === 'warn'
|
||||
? getStatusColor('warn')
|
||||
: '#6B7280'
|
||||
const bg =
|
||||
it.tone === 'good'
|
||||
? getStatusBg('good')
|
||||
: it.tone === 'bad'
|
||||
? getStatusBg('bad')
|
||||
: it.tone === 'warn'
|
||||
? getStatusBg('warn')
|
||||
: 'var(--surface2)'
|
||||
return (
|
||||
<div
|
||||
key={it.key}
|
||||
style={{
|
||||
borderRadius: 8,
|
||||
padding: '10px 12px',
|
||||
border: '1px solid var(--border)',
|
||||
borderLeft: `4px solid ${stripe}`,
|
||||
background: bg,
|
||||
}}
|
||||
>
|
||||
<div style={{ display: 'flex', flexWrap: 'wrap', alignItems: 'baseline', gap: 8, marginBottom: 4 }}>
|
||||
<span style={{ fontSize: 12, fontWeight: 600, color: 'var(--text1)' }}>{it.label_de}</span>
|
||||
<span style={{ fontSize: 13, fontWeight: 700, color: 'var(--text1)' }}>{it.value_display}</span>
|
||||
<span
|
||||
style={{
|
||||
fontSize: 11,
|
||||
fontWeight: 600,
|
||||
padding: '2px 8px',
|
||||
borderRadius: 6,
|
||||
background: 'var(--surface)',
|
||||
color: stripe,
|
||||
border: `1px solid ${stripe}`,
|
||||
}}
|
||||
>
|
||||
{it.zone_label_de}
|
||||
</span>
|
||||
</div>
|
||||
<div style={{ fontSize: 11, color: 'var(--text2)', lineHeight: 1.45 }}>{it.hint_de}</div>
|
||||
</div>
|
||||
)
|
||||
})}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
function ChartCard({ title, loading, error, children, description }) {
|
||||
return (
|
||||
<div className="card" style={{ marginBottom: 12 }}>
|
||||
@@ -168,11 +275,10 @@ export default function RecoveryDashboardOverview({
|
||||
vitalItemsByKey[it.key] = it
|
||||
})
|
||||
|
||||
const showVitalNarrativeBlock =
|
||||
vitalsHistory &&
|
||||
vitalsHistory.metadata?.confidence !== 'insufficient' &&
|
||||
(((vitalsHistory.analytics?.consolidated_paragraphs || []).length > 0 ||
|
||||
(vitalsHistory.analytics?.bullets || []).length > 0))
|
||||
const sectionInsights = vitalsHistory?.analytics?.section_insights || []
|
||||
const heartSectionInsights = sectionInsights.filter((s) => s.section === 'heart')
|
||||
const vo2SectionInsights = sectionInsights.filter((s) => s.section === 'vo2')
|
||||
const heartSnapshotItems = ['resting_hr', 'hrv', 'blood_pressure'].map((k) => vitalItemsByKey[k]).filter(Boolean)
|
||||
|
||||
const kpiTiles = (viz.kpi_tiles || []).map((t) => ({
|
||||
...t,
|
||||
@@ -383,62 +489,8 @@ export default function RecoveryDashboardOverview({
|
||||
)
|
||||
}
|
||||
|
||||
/** Nur Fließtext Einordnung Vital & Belastung (für Block „Einschätzungen“). */
|
||||
const renderVitalBelastungNarrative = () => {
|
||||
const vh = vitalsHistory
|
||||
if (!vh || vh.metadata?.confidence === 'insufficient') return null
|
||||
const paragraphs = vh.analytics?.consolidated_paragraphs || []
|
||||
const bullets = vh.analytics?.bullets || []
|
||||
const showParagraphs = paragraphs.length > 0
|
||||
const showBulletsFallback = !showParagraphs && bullets.length > 0
|
||||
if (!showParagraphs && !showBulletsFallback) return null
|
||||
return (
|
||||
<div style={{ marginBottom: 0 }}>
|
||||
{showParagraphs ? (
|
||||
<div
|
||||
style={{
|
||||
borderRadius: 8,
|
||||
padding: '12px 14px',
|
||||
border: '1px solid var(--border)',
|
||||
borderLeft: '4px solid var(--accent)',
|
||||
background: 'var(--surface2)',
|
||||
fontSize: 12,
|
||||
color: 'var(--text2)',
|
||||
lineHeight: 1.55,
|
||||
}}
|
||||
>
|
||||
{paragraphs.map((text, i) => (
|
||||
<p key={i} style={{ margin: i === 0 ? 0 : '10px 0 0' }}>
|
||||
{text}
|
||||
</p>
|
||||
))}
|
||||
</div>
|
||||
) : null}
|
||||
{showBulletsFallback ? (
|
||||
<div style={{ display: 'flex', flexDirection: 'column', gap: 8 }}>
|
||||
{bullets.map((b) => (
|
||||
<div
|
||||
key={b.key}
|
||||
style={{
|
||||
borderRadius: 8,
|
||||
padding: '10px 12px',
|
||||
border: '1px solid var(--border)',
|
||||
borderLeft: `4px solid ${insightBulletStripe(b.tone)}`,
|
||||
background: 'var(--surface2)',
|
||||
}}
|
||||
>
|
||||
<div style={{ fontSize: 12, fontWeight: 600, marginBottom: 4 }}>{b.title}</div>
|
||||
<div style={{ fontSize: 12, color: 'var(--text2)', lineHeight: 1.45 }}>{b.body}</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
) : null}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
/** VO2 / SpO2 / Atemfrequenz — Verlauf mit Zonen-Hinweis aus Snapshot; kein Ruhepuls/HRV (siehe kombiniertes Diagramm). */
|
||||
const renderWeitereVitalVerlaeufe = (vitalItemsByKey) => {
|
||||
/** VO2 / SpO2 / Atemfrequenz — Verlauf; VO2-Zusatztexte aus section_insights oben. */
|
||||
const renderWeitereVitalVerlaeufe = (vo2Insights, vitalItemsByKey) => {
|
||||
const vh = vitalsHistory
|
||||
if (!vh) {
|
||||
return <div style={{ padding: 12, fontSize: 12, color: 'var(--text3)' }}>Keine Verlaufs-Daten (Bundle).</div>
|
||||
@@ -462,6 +514,13 @@ export default function RecoveryDashboardOverview({
|
||||
|
||||
return (
|
||||
<div style={{ width: '100%', minWidth: 0 }}>
|
||||
{vo2Insights.length > 0 ? (
|
||||
<div style={{ display: 'flex', flexDirection: 'column', gap: 8, marginBottom: 14 }}>
|
||||
{vo2Insights.map((ins) => (
|
||||
<SectionInsightCard key={ins.key} ins={ins} />
|
||||
))}
|
||||
</div>
|
||||
) : null}
|
||||
<div style={{ fontSize: 11, color: 'var(--text3)', marginBottom: 10 }}>
|
||||
Gestrichelte Linie: gleitender Mittelwert (max. 7 aufeinanderfolgende Messungen). Y-Achse auf den Datenbereich
|
||||
begrenzt.
|
||||
@@ -556,106 +615,6 @@ export default function RecoveryDashboardOverview({
|
||||
)
|
||||
}
|
||||
|
||||
const renderVitalSigns = () => {
|
||||
if (!vitalsData) {
|
||||
return (
|
||||
<div style={{ padding: 20, textAlign: 'center', color: 'var(--text3)', fontSize: 12 }}>
|
||||
Keine Snapshot-Daten zur Vital-Matrix.
|
||||
</div>
|
||||
)
|
||||
}
|
||||
const meta = vitalsData.metadata || {}
|
||||
const items = meta.vital_items || []
|
||||
const ins = meta.confidence === 'insufficient'
|
||||
if (ins && items.length === 0) {
|
||||
return (
|
||||
<div style={{ padding: 20, textAlign: 'center', color: 'var(--text3)', fontSize: 12 }}>
|
||||
{meta.message || 'Keine zusammengefassten Vitalwerte für die Einordnung.'}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
const vitDate = meta.vitals_measured_at
|
||||
const bpDate = meta.blood_pressure_measured_at
|
||||
const disclaimer = meta.disclaimer_de
|
||||
|
||||
return (
|
||||
<>
|
||||
{items.length > 0 ? (
|
||||
<div style={{ display: 'flex', flexDirection: 'column', gap: 10, marginBottom: 14 }}>
|
||||
{items.map((it) => {
|
||||
const stripe =
|
||||
it.tone === 'good'
|
||||
? getStatusColor('good')
|
||||
: it.tone === 'bad'
|
||||
? getStatusColor('bad')
|
||||
: it.tone === 'warn'
|
||||
? getStatusColor('warn')
|
||||
: '#6B7280'
|
||||
const bg =
|
||||
it.tone === 'good'
|
||||
? getStatusBg('good')
|
||||
: it.tone === 'bad'
|
||||
? getStatusBg('bad')
|
||||
: it.tone === 'warn'
|
||||
? getStatusBg('warn')
|
||||
: 'var(--surface2)'
|
||||
return (
|
||||
<div
|
||||
key={it.key}
|
||||
style={{
|
||||
borderRadius: 8,
|
||||
padding: '10px 12px',
|
||||
border: '1px solid var(--border)',
|
||||
borderLeft: `4px solid ${stripe}`,
|
||||
background: bg,
|
||||
}}
|
||||
>
|
||||
<div style={{ display: 'flex', flexWrap: 'wrap', alignItems: 'baseline', gap: 8, marginBottom: 4 }}>
|
||||
<span style={{ fontSize: 12, fontWeight: 600, color: 'var(--text1)' }}>{it.label_de}</span>
|
||||
<span style={{ fontSize: 13, fontWeight: 700, color: 'var(--text1)' }}>{it.value_display}</span>
|
||||
<span
|
||||
style={{
|
||||
fontSize: 11,
|
||||
fontWeight: 600,
|
||||
padding: '2px 8px',
|
||||
borderRadius: 6,
|
||||
background: 'var(--surface)',
|
||||
color: stripe,
|
||||
border: `1px solid ${stripe}`,
|
||||
}}
|
||||
>
|
||||
{it.zone_label_de}
|
||||
</span>
|
||||
</div>
|
||||
<div style={{ fontSize: 11, color: 'var(--text2)', lineHeight: 1.45 }}>{it.hint_de}</div>
|
||||
</div>
|
||||
)
|
||||
})}
|
||||
</div>
|
||||
) : null}
|
||||
|
||||
<div style={{ marginTop: 10, fontSize: 10, color: 'var(--text3)', lineHeight: 1.45 }}>
|
||||
{vitDate ? (
|
||||
<>
|
||||
Baseline-Vitals (Snapshot): <strong>{fmtDate(vitDate)}</strong>
|
||||
</>
|
||||
) : null}
|
||||
{vitDate && bpDate ? ' · ' : null}
|
||||
{bpDate ? (
|
||||
<>
|
||||
Blutdruck: <strong>{fmtDate(bpDate)}</strong>
|
||||
</>
|
||||
) : null}
|
||||
{!vitDate && !bpDate ? <>Bezug: Vital-Matrix {vDays} Tage</> : null}
|
||||
</div>
|
||||
{disclaimer ? (
|
||||
<div style={{ marginTop: 8, fontSize: 10, color: 'var(--text3)', fontStyle: 'italic' }}>{disclaimer}</div>
|
||||
) : null}
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="card section-gap">
|
||||
<div className="card-title" style={{ display: 'flex', flexWrap: 'wrap', alignItems: 'center', gap: 12 }}>
|
||||
@@ -687,9 +646,11 @@ export default function RecoveryDashboardOverview({
|
||||
|
||||
<KpiTilesOverview tiles={kpiTiles} heading="Kennzahlen" marginBottom={16} />
|
||||
|
||||
{insights.length > 0 || showVitalNarrativeBlock ? (
|
||||
{insights.length > 0 ? (
|
||||
<div style={{ marginBottom: 18 }}>
|
||||
<div style={{ fontSize: 12, fontWeight: 600, color: 'var(--text3)', marginBottom: 8 }}>Einschätzungen</div>
|
||||
<div style={{ fontSize: 12, fontWeight: 600, color: 'var(--text3)', marginBottom: 8 }}>
|
||||
Überblick: Recovery & Schlaf
|
||||
</div>
|
||||
<div style={{ display: 'flex', flexDirection: 'column', gap: 10 }}>
|
||||
{insights.map((ins) => {
|
||||
const t = ['good', 'warn', 'bad'].includes(ins.tone) ? ins.tone : 'warn'
|
||||
@@ -709,14 +670,6 @@ export default function RecoveryDashboardOverview({
|
||||
</div>
|
||||
)
|
||||
})}
|
||||
{showVitalNarrativeBlock ? (
|
||||
<div>
|
||||
<div style={{ fontSize: 11, fontWeight: 600, color: 'var(--text3)', marginBottom: 6 }}>
|
||||
Vitalverlauf & Belastung (Text)
|
||||
</div>
|
||||
{renderVitalBelastungNarrative()}
|
||||
</div>
|
||||
) : null}
|
||||
</div>
|
||||
</div>
|
||||
) : null}
|
||||
@@ -732,7 +685,14 @@ export default function RecoveryDashboardOverview({
|
||||
>
|
||||
{renderRecoveryScore()}
|
||||
</ChartCard>
|
||||
<ChartCard title="Schlaf: Dauer & Qualität" description="Dauer (h) und Qualitätsanteil (%) — eigene Achsen.">
|
||||
<ChartCard
|
||||
title="Schlaf: Dauer & Qualität"
|
||||
description={
|
||||
sleepData && sleepData.metadata?.confidence !== 'insufficient' && sleepData.metadata?.avg_duration_hours != null
|
||||
? `Dauer (h) und Qualitätsanteil (%). Mittlere Schlafdauer im Chart-Fenster: ${sleepData.metadata.avg_duration_hours} h — gleiche Information wie früher in der KPI «Ø Schlafdauer», jetzt hier im Schlaf-Kontext.`
|
||||
: 'Dauer (h) und Qualitätsanteil (%). Sobald genug Daten vorliegen, siehst du die mittlere Schlafdauer unter dem Diagramm.'
|
||||
}
|
||||
>
|
||||
{renderSleepQuality()}
|
||||
</ChartCard>
|
||||
<ChartCard title="Schlafschuld" description="Kumulierte Differenz zur Zielschlafdauer.">
|
||||
@@ -741,29 +701,56 @@ export default function RecoveryDashboardOverview({
|
||||
|
||||
<SectionHeading
|
||||
title="Herz & Kreislauf"
|
||||
hint="Ruhepuls und HRV nur hier im kombinierten Verlauf — keine zweite Darstellung darunter."
|
||||
hint="Text-Hinweise und Zonen-Snapshots zu Ruhepuls, HRV und Blutdruck; Verlauf nur im kombinierten Diagramm (keine zweite RHR/HRV-Linie unten)."
|
||||
/>
|
||||
<div className="card" style={{ marginBottom: 12 }}>
|
||||
<div style={{ fontSize: 12, fontWeight: 600, color: 'var(--text3)', marginBottom: 8 }}>Einordnung & Kontext</div>
|
||||
<HeartAutonomicGuide />
|
||||
{heartSectionInsights.length > 0 ? (
|
||||
<div style={{ display: 'flex', flexDirection: 'column', gap: 8, marginBottom: 12 }}>
|
||||
{heartSectionInsights.map((ins) => (
|
||||
<SectionInsightCard key={ins.key} ins={ins} />
|
||||
))}
|
||||
</div>
|
||||
) : null}
|
||||
<div style={{ fontSize: 11, fontWeight: 600, color: 'var(--text3)', marginBottom: 6 }}>Letzte Messwerte (Zonen)</div>
|
||||
<SnapshotCards items={heartSnapshotItems} />
|
||||
{vitalsData?.metadata?.vitals_measured_at || vitalsData?.metadata?.blood_pressure_measured_at ? (
|
||||
<div style={{ fontSize: 10, color: 'var(--text3)', marginBottom: 8, lineHeight: 1.45 }}>
|
||||
{vitalsData?.metadata?.vitals_measured_at ? (
|
||||
<>
|
||||
Baseline-Vitals: <strong>{fmtDate(vitalsData.metadata.vitals_measured_at)}</strong>
|
||||
</>
|
||||
) : null}
|
||||
{vitalsData?.metadata?.vitals_measured_at && vitalsData?.metadata?.blood_pressure_measured_at ? ' · ' : null}
|
||||
{vitalsData?.metadata?.blood_pressure_measured_at ? (
|
||||
<>
|
||||
Blutdruck: <strong>{fmtDate(vitalsData.metadata.blood_pressure_measured_at)}</strong>
|
||||
</>
|
||||
) : null}
|
||||
</div>
|
||||
) : null}
|
||||
{vitalsData?.metadata?.disclaimer_de ? (
|
||||
<div style={{ fontSize: 10, color: 'var(--text3)', fontStyle: 'italic', marginBottom: 10 }}>
|
||||
{vitalsData.metadata.disclaimer_de}
|
||||
</div>
|
||||
) : null}
|
||||
</div>
|
||||
<ChartCard
|
||||
title="HRV & Ruhepuls"
|
||||
description="Zwei Y-Achsen: HRV (ms, links), Ruhepuls (bpm, rechts). Gleiche Tage wie oben."
|
||||
title="HRV & Ruhepuls — Zeitverlauf"
|
||||
description="Zwei Y-Achsen: HRV (ms, links), Ruhepuls (bpm, rechts). Gleicher Zeitraum wie die Charts oben."
|
||||
>
|
||||
{renderHrvRhr()}
|
||||
</ChartCard>
|
||||
|
||||
<SectionHeading
|
||||
title="Weitere Vitalparameter (Verlauf)"
|
||||
hint="VO2max, SpO2 und Atemfrequenz mit Zonen-Einordnung zum letzten Snapshot (farbig unter dem Titel)."
|
||||
hint="VO2max-Trendtexte erscheinen oberhalb des Diagramms. SpO2 und Atemfrequenz: Zonen zum letzten Snapshot unter dem Titel."
|
||||
/>
|
||||
<div className="card" style={{ marginBottom: 12 }}>
|
||||
<div style={{ fontSize: 12, fontWeight: 600, color: 'var(--text3)', marginBottom: 8 }}>Verläufe</div>
|
||||
{renderWeitereVitalVerlaeufe(vitalItemsByKey)}
|
||||
{renderWeitereVitalVerlaeufe(vo2SectionInsights, vitalItemsByKey)}
|
||||
</div>
|
||||
|
||||
<SectionHeading
|
||||
title="Aktuelle Messwerte & Zonen"
|
||||
hint="Neueste Baseline-Vitals und Blutdruck im Fenster — gleiche Logik wie Vital-Seite (keine Diagnose)."
|
||||
/>
|
||||
<ChartCard title="Snapshot & Einordnung">{renderVitalSigns()}</ChartCard>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
Reference in new issue
Block a user