feat: Konzept-konforme Nutrition Charts (E1-E5 komplett)
Backend Enhancements: - E1: Energy Balance mit 7d/14d rolling averages + balance calculation - E2: Protein Adequacy mit 7d/28d rolling averages - E3: Weekly Macro Distribution (100% stacked bars, ISO weeks, CV) - E4: Nutrition Adherence Score (0-100, goal-aware weighting) - E5: Energy Availability Warning (multi-trigger heuristic system) Frontend Refactoring: - NutritionCharts.jsx komplett überarbeitet - ScoreCard component für E4 (circular score display) - WarningCard component für E5 (ampel system) - Alle Charts zeigen jetzt Trends statt nur Rohdaten - Legend + enhanced metadata display API Updates: - getWeeklyMacroDistributionChart (weeks parameter) - getNutritionAdherenceScore - getEnergyAvailabilityWarning - Removed old getMacroDistributionChart (pie) Konzept-Compliance: - Zeitfenster: 7d, 28d, 90d selectors - Deutlich höhere Aussagekraft durch rolling averages - Goal-mode-abhängige Score-Gewichtung - Cross-domain warning system (nutrition × recovery × body) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
1 parent
176be3233e
commit
4c22f999c4
3 files changed
+796
-175
No files matched your search
@@ -1,8 +1,7 @@
|
||||
import { useState, useEffect } from 'react'
|
||||
import {
|
||||
LineChart, Line, BarChart, Bar, PieChart, Pie, Cell,
|
||||
XAxis, YAxis, Tooltip, ResponsiveContainer, CartesianGrid,
|
||||
ReferenceLine
|
||||
LineChart, Line, BarChart, Bar,
|
||||
XAxis, YAxis, Tooltip, ResponsiveContainer, CartesianGrid, Legend
|
||||
} from 'recharts'
|
||||
import { api } from '../utils/api'
|
||||
import dayjs from 'dayjs'
|
||||
@@ -30,35 +29,145 @@ function ChartCard({ title, loading, error, children }) {
|
||||
)
|
||||
}
|
||||
|
||||
function ScoreCard({ title, score, components, goal_mode, recommendation }) {
|
||||
const scoreColor = score >= 80 ? '#1D9E75' : score >= 60 ? '#F59E0B' : '#EF4444'
|
||||
|
||||
return (
|
||||
<div className="card" style={{marginBottom:12}}>
|
||||
<div style={{fontSize:12,fontWeight:600,color:'var(--text3)',marginBottom:12}}>
|
||||
{title}
|
||||
</div>
|
||||
|
||||
{/* Score Circle */}
|
||||
<div style={{display:'flex',alignItems:'center',justifyContent:'center',marginBottom:16}}>
|
||||
<div style={{
|
||||
width:120,height:120,borderRadius:'50%',
|
||||
border:`8px solid ${scoreColor}`,
|
||||
display:'flex',flexDirection:'column',alignItems:'center',justifyContent:'center'
|
||||
}}>
|
||||
<div style={{fontSize:32,fontWeight:700,color:scoreColor}}>{score}</div>
|
||||
<div style={{fontSize:10,color:'var(--text3)'}}>/ 100</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Components Breakdown */}
|
||||
<div style={{fontSize:11,marginBottom:12}}>
|
||||
{Object.entries(components).map(([key, value]) => {
|
||||
const barColor = value >= 80 ? '#1D9E75' : value >= 60 ? '#F59E0B' : '#EF4444'
|
||||
const label = {
|
||||
'calorie_adherence': 'Kalorien-Adhärenz',
|
||||
'protein_adherence': 'Protein-Adhärenz',
|
||||
'intake_consistency': 'Konsistenz',
|
||||
'food_quality': 'Lebensmittelqualität'
|
||||
}[key] || key
|
||||
|
||||
return (
|
||||
<div key={key} style={{marginBottom:8}}>
|
||||
<div style={{display:'flex',justifyContent:'space-between',marginBottom:2}}>
|
||||
<span style={{color:'var(--text2)',fontSize:10}}>{label}</span>
|
||||
<span style={{color:'var(--text1)',fontSize:10,fontWeight:600}}>{value}</span>
|
||||
</div>
|
||||
<div style={{height:4,background:'var(--surface2)',borderRadius:2,overflow:'hidden'}}>
|
||||
<div style={{height:'100%',width:`${value}%`,background:barColor,transition:'width 0.3s'}}/>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
})}
|
||||
</div>
|
||||
|
||||
{/* Recommendation */}
|
||||
<div style={{
|
||||
padding:8,background:'var(--surface2)',borderRadius:6,
|
||||
fontSize:10,color:'var(--text2)',marginBottom:8
|
||||
}}>
|
||||
💡 {recommendation}
|
||||
</div>
|
||||
|
||||
{/* Goal Mode */}
|
||||
<div style={{fontSize:9,color:'var(--text3)',textAlign:'center'}}>
|
||||
Optimiert für: {goal_mode || 'health'}
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
function WarningCard({ title, warning_level, triggers, message }) {
|
||||
const levelConfig = {
|
||||
'warning': { icon: '⚠️', color: '#EF4444', bg: 'rgba(239, 68, 68, 0.1)' },
|
||||
'caution': { icon: '⚡', color: '#F59E0B', bg: 'rgba(245, 158, 11, 0.1)' },
|
||||
'none': { icon: '✅', color: '#1D9E75', bg: 'rgba(29, 158, 117, 0.1)' }
|
||||
}[warning_level] || levelConfig['none']
|
||||
|
||||
return (
|
||||
<div className="card" style={{marginBottom:12}}>
|
||||
<div style={{fontSize:12,fontWeight:600,color:'var(--text3)',marginBottom:12}}>
|
||||
{title}
|
||||
</div>
|
||||
|
||||
{/* Status Badge */}
|
||||
<div style={{
|
||||
padding:16,background:levelConfig.bg,borderRadius:8,
|
||||
borderLeft:`4px solid ${levelConfig.color}`,marginBottom:12
|
||||
}}>
|
||||
<div style={{fontSize:14,fontWeight:600,color:levelConfig.color,marginBottom:4}}>
|
||||
{levelConfig.icon} {message}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Triggers List */}
|
||||
{triggers && triggers.length > 0 && (
|
||||
<div style={{marginTop:12}}>
|
||||
<div style={{fontSize:10,fontWeight:600,color:'var(--text3)',marginBottom:6}}>
|
||||
Auffällige Indikatoren:
|
||||
</div>
|
||||
<ul style={{margin:0,paddingLeft:20,fontSize:10,color:'var(--text2)'}}>
|
||||
{triggers.map((t, i) => (
|
||||
<li key={i} style={{marginBottom:4}}>{t}</li>
|
||||
))}
|
||||
</ul>
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div style={{fontSize:9,color:'var(--text3)',marginTop:12,fontStyle:'italic'}}>
|
||||
Heuristische Einschätzung, keine medizinische Diagnose
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Nutrition Charts Component (E1-E5)
|
||||
* Nutrition Charts Component (E1-E5) - Konzept-konform v2.0
|
||||
*
|
||||
* Displays 4 nutrition chart endpoints:
|
||||
* - Energy Balance Timeline (E1)
|
||||
* - Macro Distribution (E2)
|
||||
* - Protein Adequacy (E3)
|
||||
* - Nutrition Consistency (E5)
|
||||
* E1: Energy Balance (mit 7d/14d Durchschnitten)
|
||||
* E2: Protein Adequacy (mit 7d/28d Durchschnitten)
|
||||
* E3: Weekly Macro Distribution (100% gestapelte Balken)
|
||||
* E4: Nutrition Adherence Score (0-100, goal-aware)
|
||||
* E5: Energy Availability Warning (Ampel-System)
|
||||
*/
|
||||
export default function NutritionCharts({ days = 28 }) {
|
||||
const [energyData, setEnergyData] = useState(null)
|
||||
const [macroData, setMacroData] = useState(null)
|
||||
const [proteinData, setProteinData] = useState(null)
|
||||
const [consistencyData, setConsistencyData] = useState(null)
|
||||
const [macroWeeklyData, setMacroWeeklyData] = useState(null)
|
||||
const [adherenceData, setAdherenceData] = useState(null)
|
||||
const [warningData, setWarningData] = useState(null)
|
||||
|
||||
const [loading, setLoading] = useState({})
|
||||
const [errors, setErrors] = useState({})
|
||||
|
||||
// Weeks for macro distribution (proportional to days selected)
|
||||
const weeks = Math.max(4, Math.min(52, Math.ceil(days / 7)))
|
||||
|
||||
useEffect(() => {
|
||||
loadCharts()
|
||||
}, [days])
|
||||
|
||||
const loadCharts = async () => {
|
||||
// Load all 4 charts in parallel
|
||||
await Promise.all([
|
||||
loadEnergyBalance(),
|
||||
loadMacroDistribution(),
|
||||
loadProteinAdequacy(),
|
||||
loadConsistency()
|
||||
loadMacroWeekly(),
|
||||
loadAdherence(),
|
||||
loadWarning()
|
||||
])
|
||||
}
|
||||
|
||||
@@ -75,19 +184,6 @@ export default function NutritionCharts({ days = 28 }) {
|
||||
}
|
||||
}
|
||||
|
||||
const loadMacroDistribution = async () => {
|
||||
setLoading(l => ({...l, macro: true}))
|
||||
setErrors(e => ({...e, macro: null}))
|
||||
try {
|
||||
const data = await api.getMacroDistributionChart(days)
|
||||
setMacroData(data)
|
||||
} catch (err) {
|
||||
setErrors(e => ({...e, macro: err.message}))
|
||||
} finally {
|
||||
setLoading(l => ({...l, macro: false}))
|
||||
}
|
||||
}
|
||||
|
||||
const loadProteinAdequacy = async () => {
|
||||
setLoading(l => ({...l, protein: true}))
|
||||
setErrors(e => ({...e, protein: null}))
|
||||
@@ -101,121 +197,127 @@ export default function NutritionCharts({ days = 28 }) {
|
||||
}
|
||||
}
|
||||
|
||||
const loadConsistency = async () => {
|
||||
setLoading(l => ({...l, consistency: true}))
|
||||
setErrors(e => ({...e, consistency: null}))
|
||||
const loadMacroWeekly = async () => {
|
||||
setLoading(l => ({...l, macro: true}))
|
||||
setErrors(e => ({...e, macro: null}))
|
||||
try {
|
||||
const data = await api.getNutritionConsistencyChart(days)
|
||||
setConsistencyData(data)
|
||||
const data = await api.getWeeklyMacroDistributionChart(weeks)
|
||||
setMacroWeeklyData(data)
|
||||
} catch (err) {
|
||||
setErrors(e => ({...e, consistency: err.message}))
|
||||
setErrors(e => ({...e, macro: err.message}))
|
||||
} finally {
|
||||
setLoading(l => ({...l, consistency: false}))
|
||||
setLoading(l => ({...l, macro: false}))
|
||||
}
|
||||
}
|
||||
|
||||
// E1: Energy Balance Timeline
|
||||
const loadAdherence = async () => {
|
||||
setLoading(l => ({...l, adherence: true}))
|
||||
setErrors(e => ({...e, adherence: null}))
|
||||
try {
|
||||
const data = await api.getNutritionAdherenceScore(days)
|
||||
setAdherenceData(data)
|
||||
} catch (err) {
|
||||
setErrors(e => ({...e, adherence: err.message}))
|
||||
} finally {
|
||||
setLoading(l => ({...l, adherence: false}))
|
||||
}
|
||||
}
|
||||
|
||||
const loadWarning = async () => {
|
||||
setLoading(l => ({...l, warning: true}))
|
||||
setErrors(e => ({...e, warning: null}))
|
||||
try {
|
||||
const data = await api.getEnergyAvailabilityWarning(Math.min(days, 28))
|
||||
setWarningData(data)
|
||||
} catch (err) {
|
||||
setErrors(e => ({...e, warning: err.message}))
|
||||
} finally {
|
||||
setLoading(l => ({...l, warning: false}))
|
||||
}
|
||||
}
|
||||
|
||||
// E1: Energy Balance Timeline (mit 7d/14d Durchschnitten)
|
||||
const renderEnergyBalance = () => {
|
||||
if (!energyData || energyData.metadata?.confidence === 'insufficient') {
|
||||
return <div style={{padding:20,textAlign:'center',color:'var(--text3)',fontSize:12}}>
|
||||
Nicht genug Ernährungsdaten
|
||||
Nicht genug Ernährungsdaten (min. 7 Tage)
|
||||
</div>
|
||||
}
|
||||
|
||||
const chartData = energyData.data.labels.map((label, i) => ({
|
||||
date: fmtDate(label),
|
||||
kcal: energyData.data.datasets[0]?.data[i],
|
||||
tdee: energyData.data.datasets[1]?.data[i]
|
||||
täglich: energyData.data.datasets[0]?.data[i],
|
||||
avg7d: energyData.data.datasets[1]?.data[i],
|
||||
avg14d: energyData.data.datasets[2]?.data[i],
|
||||
tdee: energyData.data.datasets[3]?.data[i]
|
||||
}))
|
||||
|
||||
const balance = energyData.metadata?.energy_balance || 0
|
||||
const balanceColor = balance < -200 ? '#EF4444' : balance > 200 ? '#F59E0B' : '#1D9E75'
|
||||
|
||||
return (
|
||||
<>
|
||||
<ResponsiveContainer width="100%" height={200}>
|
||||
<ResponsiveContainer width="100%" height={220}>
|
||||
<LineChart data={chartData} margin={{top:4,right:8,bottom:0,left:-20}}>
|
||||
<CartesianGrid stroke="var(--border)" strokeDasharray="3 3"/>
|
||||
<XAxis dataKey="date" tick={{fontSize:9,fill:'var(--text3)'}} tickLine={false}
|
||||
interval={Math.max(0,Math.floor(chartData.length/6)-1)}/>
|
||||
<YAxis tick={{fontSize:9,fill:'var(--text3)'}} tickLine={false}/>
|
||||
<Tooltip contentStyle={{background:'var(--surface)',border:'1px solid var(--border)',borderRadius:8,fontSize:11}}/>
|
||||
<Line type="monotone" dataKey="kcal" stroke="#1D9E75" strokeWidth={2} name="Kalorien" dot={{r:2}}/>
|
||||
<Line type="monotone" dataKey="tdee" stroke="#888" strokeWidth={1} strokeDasharray="5 5" name="TDEE (geschätzt)" dot={false}/>
|
||||
<Legend wrapperStyle={{fontSize:10}}/>
|
||||
<Line type="monotone" dataKey="täglich" stroke="#ccc" strokeWidth={1.5} dot={{r:1.5}} name="Täglich"/>
|
||||
<Line type="monotone" dataKey="avg7d" stroke="#1D9E75" strokeWidth={2.5} dot={false} name="Ø 7d"/>
|
||||
<Line type="monotone" dataKey="avg14d" stroke="#085041" strokeWidth={2} strokeDasharray="6 3" dot={false} name="Ø 14d"/>
|
||||
<Line type="monotone" dataKey="tdee" stroke="#888" strokeWidth={1.5} strokeDasharray="3 3" dot={false} name="TDEE"/>
|
||||
</LineChart>
|
||||
</ResponsiveContainer>
|
||||
<div style={{marginTop:8,fontSize:10,color:'var(--text3)',textAlign:'center'}}>
|
||||
Ø {energyData.metadata.avg_kcal} kcal/Tag · {energyData.metadata.data_points} Einträge
|
||||
<div style={{marginTop:8,fontSize:10,textAlign:'center'}}>
|
||||
<span style={{color:'var(--text3)'}}>
|
||||
Ø {energyData.metadata.avg_kcal} kcal/Tag ·
|
||||
</span>
|
||||
<span style={{color:balanceColor,fontWeight:600,marginLeft:4}}>
|
||||
Balance: {balance > 0 ? '+' : ''}{balance} kcal/Tag
|
||||
</span>
|
||||
<span style={{color:'var(--text3)',marginLeft:8}}>
|
||||
· {energyData.metadata.data_points} Tage
|
||||
</span>
|
||||
</div>
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
||||
// E2: Macro Distribution (Pie)
|
||||
const renderMacroDistribution = () => {
|
||||
if (!macroData || macroData.metadata?.confidence === 'insufficient') {
|
||||
return <div style={{padding:20,textAlign:'center',color:'var(--text3)',fontSize:12}}>
|
||||
Nicht genug Makronährstoff-Daten
|
||||
</div>
|
||||
}
|
||||
|
||||
const chartData = macroData.data.labels.map((label, i) => ({
|
||||
name: label,
|
||||
value: macroData.data.datasets[0]?.data[i],
|
||||
color: macroData.data.datasets[0]?.backgroundColor[i]
|
||||
}))
|
||||
|
||||
return (
|
||||
<>
|
||||
<ResponsiveContainer width="100%" height={200}>
|
||||
<PieChart>
|
||||
<Pie
|
||||
data={chartData}
|
||||
cx="50%"
|
||||
cy="50%"
|
||||
labelLine={false}
|
||||
label={({name, value}) => `${name}: ${value}%`}
|
||||
outerRadius={70}
|
||||
dataKey="value"
|
||||
>
|
||||
{chartData.map((entry, index) => (
|
||||
<Cell key={`cell-${index}`} fill={entry.color} />
|
||||
))}
|
||||
</Pie>
|
||||
<Tooltip contentStyle={{background:'var(--surface)',border:'1px solid var(--border)',borderRadius:8,fontSize:11}}/>
|
||||
</PieChart>
|
||||
</ResponsiveContainer>
|
||||
<div style={{marginTop:8,fontSize:10,color:'var(--text3)',textAlign:'center'}}>
|
||||
P: {macroData.metadata.protein_g}g · C: {macroData.metadata.carbs_g}g · F: {macroData.metadata.fat_g}g
|
||||
</div>
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
||||
// E3: Protein Adequacy Timeline
|
||||
// E2: Protein Adequacy Timeline (mit 7d/28d Durchschnitten)
|
||||
const renderProteinAdequacy = () => {
|
||||
if (!proteinData || proteinData.metadata?.confidence === 'insufficient') {
|
||||
return <div style={{padding:20,textAlign:'center',color:'var(--text3)',fontSize:12}}>
|
||||
Nicht genug Protein-Daten
|
||||
Nicht genug Protein-Daten (min. 7 Tage)
|
||||
</div>
|
||||
}
|
||||
|
||||
const chartData = proteinData.data.labels.map((label, i) => ({
|
||||
date: fmtDate(label),
|
||||
protein: proteinData.data.datasets[0]?.data[i],
|
||||
targetLow: proteinData.data.datasets[1]?.data[i],
|
||||
targetHigh: proteinData.data.datasets[2]?.data[i]
|
||||
täglich: proteinData.data.datasets[0]?.data[i],
|
||||
avg7d: proteinData.data.datasets[1]?.data[i],
|
||||
avg28d: proteinData.data.datasets[2]?.data[i],
|
||||
targetLow: proteinData.data.datasets[3]?.data[i],
|
||||
targetHigh: proteinData.data.datasets[4]?.data[i]
|
||||
}))
|
||||
|
||||
return (
|
||||
<>
|
||||
<ResponsiveContainer width="100%" height={200}>
|
||||
<ResponsiveContainer width="100%" height={220}>
|
||||
<LineChart data={chartData} margin={{top:4,right:8,bottom:0,left:-20}}>
|
||||
<CartesianGrid stroke="var(--border)" strokeDasharray="3 3"/>
|
||||
<XAxis dataKey="date" tick={{fontSize:9,fill:'var(--text3)'}} tickLine={false}
|
||||
interval={Math.max(0,Math.floor(chartData.length/6)-1)}/>
|
||||
<YAxis tick={{fontSize:9,fill:'var(--text3)'}} tickLine={false}/>
|
||||
<Tooltip contentStyle={{background:'var(--surface)',border:'1px solid var(--border)',borderRadius:8,fontSize:11}}/>
|
||||
<Line type="monotone" dataKey="targetLow" stroke="#888" strokeWidth={1} strokeDasharray="5 5" name="Ziel Min" dot={false}/>
|
||||
<Line type="monotone" dataKey="targetHigh" stroke="#888" strokeWidth={1} strokeDasharray="5 5" name="Ziel Max" dot={false}/>
|
||||
<Line type="monotone" dataKey="protein" stroke="#1D9E75" strokeWidth={2} name="Protein (g)" dot={{r:2}}/>
|
||||
<Legend wrapperStyle={{fontSize:10}}/>
|
||||
<Line type="monotone" dataKey="targetLow" stroke="#888" strokeWidth={1} strokeDasharray="5 5" dot={false} name="Ziel Min"/>
|
||||
<Line type="monotone" dataKey="targetHigh" stroke="#888" strokeWidth={1} strokeDasharray="5 5" dot={false} name="Ziel Max"/>
|
||||
<Line type="monotone" dataKey="täglich" stroke="#ccc" strokeWidth={1.5} dot={{r:1.5}} name="Täglich"/>
|
||||
<Line type="monotone" dataKey="avg7d" stroke="#1D9E75" strokeWidth={2.5} dot={false} name="Ø 7d"/>
|
||||
<Line type="monotone" dataKey="avg28d" stroke="#085041" strokeWidth={2} strokeDasharray="6 3" dot={false} name="Ø 28d"/>
|
||||
</LineChart>
|
||||
</ResponsiveContainer>
|
||||
<div style={{marginTop:8,fontSize:10,color:'var(--text3)',textAlign:'center'}}>
|
||||
@@ -225,60 +327,107 @@ export default function NutritionCharts({ days = 28 }) {
|
||||
)
|
||||
}
|
||||
|
||||
// E5: Nutrition Consistency (Bar)
|
||||
const renderConsistency = () => {
|
||||
if (!consistencyData || consistencyData.metadata?.confidence === 'insufficient') {
|
||||
// E3: Weekly Macro Distribution (100% gestapelte Balken)
|
||||
const renderMacroWeekly = () => {
|
||||
if (!macroWeeklyData || macroWeeklyData.metadata?.confidence === 'insufficient') {
|
||||
return <div style={{padding:20,textAlign:'center',color:'var(--text3)',fontSize:12}}>
|
||||
Nicht genug Daten für Konsistenz-Analyse
|
||||
Nicht genug Daten für Wochen-Analyse (min. 7 Tage)
|
||||
</div>
|
||||
}
|
||||
|
||||
const chartData = consistencyData.data.labels.map((label, i) => ({
|
||||
name: label,
|
||||
score: consistencyData.data.datasets[0]?.data[i],
|
||||
color: consistencyData.data.datasets[0]?.backgroundColor[i]
|
||||
const chartData = macroWeeklyData.data.labels.map((label, i) => ({
|
||||
week: label,
|
||||
protein: macroWeeklyData.data.datasets[0]?.data[i],
|
||||
carbs: macroWeeklyData.data.datasets[1]?.data[i],
|
||||
fat: macroWeeklyData.data.datasets[2]?.data[i]
|
||||
}))
|
||||
|
||||
const meta = macroWeeklyData.metadata
|
||||
|
||||
return (
|
||||
<>
|
||||
<ResponsiveContainer width="100%" height={200}>
|
||||
<ResponsiveContainer width="100%" height={240}>
|
||||
<BarChart data={chartData} margin={{top:4,right:8,bottom:0,left:-20}}>
|
||||
<CartesianGrid stroke="var(--border)" strokeDasharray="3 3"/>
|
||||
<XAxis dataKey="name" tick={{fontSize:9,fill:'var(--text3)'}} tickLine={false}
|
||||
interval={0} angle={-45} textAnchor="end" height={60}/>
|
||||
<XAxis dataKey="week" tick={{fontSize:9,fill:'var(--text3)'}} tickLine={false}
|
||||
interval={Math.max(0,Math.floor(chartData.length/8)-1)}/>
|
||||
<YAxis tick={{fontSize:9,fill:'var(--text3)'}} tickLine={false} domain={[0,100]}/>
|
||||
<Tooltip contentStyle={{background:'var(--surface)',border:'1px solid var(--border)',borderRadius:8,fontSize:11}}/>
|
||||
<Bar dataKey="score" name="Score">
|
||||
{chartData.map((entry, index) => (
|
||||
<Cell key={`cell-${index}`} fill={entry.color} />
|
||||
))}
|
||||
</Bar>
|
||||
<Legend wrapperStyle={{fontSize:10}}/>
|
||||
<Bar dataKey="protein" stackId="a" fill="#1D9E75" name="Protein %"/>
|
||||
<Bar dataKey="carbs" stackId="a" fill="#F59E0B" name="Kohlenhydrate %"/>
|
||||
<Bar dataKey="fat" stackId="a" fill="#EF4444" name="Fett %"/>
|
||||
</BarChart>
|
||||
</ResponsiveContainer>
|
||||
<div style={{marginTop:8,fontSize:10,color:'var(--text3)',textAlign:'center'}}>
|
||||
Gesamt-Score: {consistencyData.metadata.consistency_score}/100
|
||||
Ø Verteilung: P {meta.avg_protein_pct}% · C {meta.avg_carbs_pct}% · F {meta.avg_fat_pct}% ·
|
||||
Konsistenz (CV): P {meta.protein_cv}% · C {meta.carbs_cv}% · F {meta.fat_cv}%
|
||||
</div>
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
||||
// E4: Nutrition Adherence Score
|
||||
const renderAdherence = () => {
|
||||
if (!adherenceData || adherenceData.metadata?.confidence === 'insufficient') {
|
||||
return (
|
||||
<ChartCard title="🎯 Ernährungs-Adhärenz Score" loading={loading.adherence} error={errors.adherence}>
|
||||
<div style={{padding:20,textAlign:'center',color:'var(--text3)',fontSize:12}}>
|
||||
Nicht genug Daten (min. 7 Tage)
|
||||
</div>
|
||||
</ChartCard>
|
||||
)
|
||||
}
|
||||
|
||||
return (
|
||||
<ScoreCard
|
||||
title="🎯 Ernährungs-Adhärenz Score"
|
||||
score={adherenceData.score}
|
||||
components={adherenceData.components}
|
||||
goal_mode={adherenceData.goal_mode}
|
||||
recommendation={adherenceData.recommendation}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
// E5: Energy Availability Warning
|
||||
const renderWarning = () => {
|
||||
if (!warningData) {
|
||||
return (
|
||||
<ChartCard title="⚡ Energieverfügbarkeit" loading={loading.warning} error={errors.warning}>
|
||||
<div style={{padding:20,textAlign:'center',color:'var(--text3)',fontSize:12}}>
|
||||
Keine Daten verfügbar
|
||||
</div>
|
||||
</ChartCard>
|
||||
)
|
||||
}
|
||||
|
||||
return (
|
||||
<WarningCard
|
||||
title="⚡ Energieverfügbarkeit"
|
||||
warning_level={warningData.warning_level}
|
||||
triggers={warningData.triggers}
|
||||
message={warningData.message}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
return (
|
||||
<div>
|
||||
<ChartCard title="📊 Energiebilanz" loading={loading.energy} error={errors.energy}>
|
||||
<ChartCard title="📊 Energiebilanz (E1)" loading={loading.energy} error={errors.energy}>
|
||||
{renderEnergyBalance()}
|
||||
</ChartCard>
|
||||
|
||||
<ChartCard title="📊 Makronährstoff-Verteilung" loading={loading.macro} error={errors.macro}>
|
||||
{renderMacroDistribution()}
|
||||
</ChartCard>
|
||||
|
||||
<ChartCard title="📊 Protein-Adequacy" loading={loading.protein} error={errors.protein}>
|
||||
<ChartCard title="📊 Protein-Adequacy (E2)" loading={loading.protein} error={errors.protein}>
|
||||
{renderProteinAdequacy()}
|
||||
</ChartCard>
|
||||
|
||||
<ChartCard title="📊 Ernährungs-Konsistenz" loading={loading.consistency} error={errors.consistency}>
|
||||
{renderConsistency()}
|
||||
<ChartCard title="📊 Wöchentliche Makro-Verteilung (E3)" loading={loading.macro} error={errors.macro}>
|
||||
{renderMacroWeekly()}
|
||||
</ChartCard>
|
||||
|
||||
{!loading.adherence && !errors.adherence && renderAdherence()}
|
||||
{!loading.warning && !errors.warning && renderWarning()}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
Reference in new issue
Block a user