From 12656479637abc17098ec95c8fa09597c045c1af Mon Sep 17 00:00:00 2001 From: Alexander Bocken Date: Fri, 10 Apr 2026 21:22:23 +0200 Subject: [PATCH] fix: use Atwater calories for consistent macro/calorie tracking MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Calorie ring and macro progress bars now both use Atwater-derived calories (P×4 + F×9 + C×4) instead of DB calories, so hitting all three macro goals guarantees hitting the calorie goal exactly. Also: show full daily TDEE (not time-based), show BMR/NEAT multiplier breakdown in info tooltip, display macro goal grams on progress bars, fix TDEE tooltip z-index on desktop. --- package.json | 2 +- .../[[date=fitnessDate]]/+page.svelte | 35 ++++++++++++------- 2 files changed, 24 insertions(+), 13 deletions(-) diff --git a/package.json b/package.json index 6b16d83..d2ccab6 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "homepage", - "version": "1.23.6", + "version": "1.23.7", "private": true, "type": "module", "scripts": { diff --git a/src/routes/fitness/[nutrition=fitnessNutrition]/[[date=fitnessDate]]/+page.svelte b/src/routes/fitness/[nutrition=fitnessNutrition]/[[date=fitnessDate]]/+page.svelte index 6d1dbc3..39dbf78 100644 --- a/src/routes/fitness/[nutrition=fitnessNutrition]/[[date=fitnessDate]]/+page.svelte +++ b/src/routes/fitness/[nutrition=fitnessNutrition]/[[date=fitnessDate]]/+page.svelte @@ -394,6 +394,9 @@ return { calories, protein, fat, carbs, fiber, sugars, saturatedFat, micros, aminos }; }); + // Atwater-derived calories (consistent with macro goals which use 4/9/4) + const atwaterCalories = $derived(dayTotals.protein * 4 + dayTotals.fat * 9 + dayTotals.carbs * 4); + // Macro percentages by calorie contribution const macroPercent = $derived.by(() => { const proteinCal = dayTotals.protein * 4; @@ -499,8 +502,9 @@ // Net calorie balance: effective goal (includes exercise) - eaten - const calorieBalance = $derived(effectiveCalorieGoal ? (effectiveCalorieGoal - dayTotals.calories) : 0); - const calorieProgressRaw = $derived(effectiveCalorieGoal ? dayTotals.calories / effectiveCalorieGoal * 100 : 0); + // Use Atwater-derived calories so the ring and macro bars always agree + const calorieBalance = $derived(effectiveCalorieGoal ? (effectiveCalorieGoal - atwaterCalories) : 0); + const calorieProgressRaw = $derived(effectiveCalorieGoal ? atwaterCalories / effectiveCalorieGoal * 100 : 0); const calorieProgress = $derived(Math.min(calorieProgressRaw, 100)); const calorieOverflow = $derived(Math.max(calorieProgressRaw - 100, 0)); @@ -1178,7 +1182,7 @@
- {fmtCal(dayTotals.calories)} + {fmtCal(atwaterCalories)} {isEn ? 'EATEN' : 'GEGESSEN'}
@@ -1213,16 +1217,17 @@ {fmtCal(exerciseKcal)} {isEn ? 'BURNED' : 'VERBRANNT'} - +{fmtCal(tdeeSoFar)} TDEE + +{fmtCal(Math.round(dailyTdee))} TDEE {#if showTdeeInfo}
- {isEn ? 'TDEE = Total Daily Energy Expenditure — calories your body burns per day at rest + daily activity.' : 'TDEE = Gesamtenergieumsatz — Kalorien, die dein Körper pro Tag in Ruhe + Alltagsaktivität verbrennt.'} + {isEn ? 'TDEE = Total Daily Energy Expenditure — calories your body burns per day at rest + daily activity (excluding tracked exercise).' : 'TDEE = Gesamtenergieumsatz — Kalorien, die dein Körper pro Tag in Ruhe + Alltagsaktivität verbrennt (ohne getracktes Training).'} + {isEn ? `BMR × ${(ACTIVITY_MULT[activityLevel] ?? 1.3).toFixed(1)} (${activityLevel.replace('_', ' ')}) = ${fmtCal(Math.round(dailyTdee))} kcal` : `BMR × ${(ACTIVITY_MULT[activityLevel] ?? 1.3).toFixed(1)} (${activityLevel.replace('_', ' ')}) = ${fmtCal(Math.round(dailyTdee))} kcal`} {#if latestWeight} {isEn ? `Based on your latest logged weight (${latestWeight} kg).` : `Basierend auf deinem letzten Gewicht (${latestWeight} kg).`} {/if} - BMR: Mifflin-St Jeor (1990) - NEAT: Levine (2002) - {isEn ? 'Multipliers reduced vs. standard Harris-Benedict factors — logged exercise kcal added separately.' : 'Multiplikatoren reduziert ggü. Harris-Benedict — geloggte Trainings-kcal werden separat addiert.'} + BMR: {fmtCal(Math.round(dailyBmr))} kcal — Mifflin-St Jeor (1990) + NEAT: ×{(ACTIVITY_MULT[activityLevel] ?? 1.3).toFixed(1)} — Levine (2002) + {isEn ? 'NEAT multiplier accounts for non-exercise activity (walking, fidgeting, daily tasks). Tracked exercise kcal are added separately on top.' : 'NEAT-Multiplikator berücksichtigt Alltagsaktivität (Gehen, Bewegung, tägliche Aufgaben). Getracktes Training wird separat oben drauf addiert.'}
{/if}
@@ -1245,7 +1250,7 @@ {@const remaining = macro.goal ? macro.goal - macro.value : 0} {@const MacroBarIcon = macro.icon}
- {macro.label} + {macro.label}{#if macro.goal} {fmt(macro.goal)}g/{isEn ? 'day' : 'Tag'}{/if}
{#if over} @@ -1871,6 +1876,7 @@ gap: 0.75rem; position: sticky; top: 1rem; + z-index: 10; } .meals-col { display: flex; @@ -1976,8 +1982,7 @@ padding: 1.25rem; box-shadow: var(--shadow-sm); position: relative; - - + z-index: 10; } .daily-summary::before { content: ''; @@ -2024,6 +2029,7 @@ } .tdee-info-wrap { position: relative; + z-index: 50; } .tdee-info-trigger { display: inline-flex; @@ -2056,7 +2062,7 @@ color: var(--color-text-secondary); white-space: nowrap; box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2); - z-index: 20; + z-index: 100; display: flex; flex-direction: column; gap: 0.15rem; @@ -2115,6 +2121,11 @@ text-transform: uppercase; color: var(--color-text-secondary); } + .macro-bar-goal { + font-weight: 400; + opacity: 0.7; + text-transform: none; + } .macro-bar-track { width: 100%; height: 6px;