Feature: Alter fließt in Kalorienbedarf ein (Lebensphasen-Faktoren)

Welpe <4 Mon ×3.0, Junghund 4-12 Mon ×2.0 (Wachstum, überschreibt Aktivität),
Senior 7+ ×0.90, Hochbetagt 11+ ×0.85 des Erwachsenen-Faktors. Lebensphase wird
im Ergebnis angezeigt. SW v1172
This commit is contained in:
rene 2026-06-04 18:04:16 +02:00
parent cca9a9c70f
commit 258ccf84ee
6 changed files with 37 additions and 17 deletions

View file

@ -3,7 +3,7 @@
Router, State-Management, Navigation, Initialisierung.
============================================================ */
const APP_VER = '1171'; // ← bei jedem Deploy mit Frontend-Änderungen erhöhen
const APP_VER = '1172'; // ← bei jedem Deploy mit Frontend-Änderungen erhöhen
const APP_VERSION = '1.6.0'; // ← semantische Version, wird bei make release gesetzt
window.APP_VER = APP_VER; // global verfügbar für andere Module (z.B. offline-indicator)
window.APP_VERSION = APP_VERSION;

View file

@ -122,6 +122,18 @@ window.Page_ernaehrung = (() => {
return (years > 0 && years < 30) ? Math.round(years * 10) / 10 : '';
}
// Lebensphase aus Alter (Jahre): Welpen/Junghunde brauchen mehr (Wachstum),
// Senioren weniger. `growth` (absoluter RER-Faktor) überschreibt den
// Aktivitäts-Faktor; `mult` skaliert den Erwachsenen-Faktor.
function _lifeStage(alter) {
if (!alter || alter <= 0) return { label: '', mult: 1, growth: null };
if (alter < 0.34) return { label: '🍼 Welpe (< 4 Mon.) — hoher Wachstumsbedarf', mult: 1, growth: 3.0 };
if (alter < 1) return { label: '🐶 Junghund (412 Mon.) — erhöhter Bedarf', mult: 1, growth: 2.0 };
if (alter >= 11) return { label: '🐕 Hochbetagt (11+ J.) — reduzierter Bedarf', mult: 0.85, growth: null };
if (alter >= 7) return { label: '🐕 Senior (7+ J.) — leicht reduzierter Bedarf', mult: 0.90, growth: null };
return { label: '', mult: 1, growth: null };
}
function _renderRechner(el) {
const dog = _appState.activeDog;
@ -269,6 +281,7 @@ window.Page_ernaehrung = (() => {
function _berechne(el) {
const gewicht = parseFloat(el.querySelector('#ern-gewicht').value);
const alter = parseFloat(el.querySelector('#ern-alter').value) || 0;
const aktivitaet = el.querySelector('[data-akt].active')?.dataset.akt || 'normal';
const kastriert = el.querySelector('[data-kas].active')?.dataset.kas === 'ja';
@ -284,7 +297,12 @@ window.Page_ernaehrung = (() => {
aktiv: { intakt: 1.8, kastriert: 1.6 },
sport: { intakt: 2.1, kastriert: 1.9 },
};
const kcal = Math.round(rer * faktoren[aktivitaet][kastriert ? 'kastriert' : 'intakt']);
// Lebensphase einrechnen: Welpe/Junghund = Wachstumsfaktor (überschreibt
// Aktivität), Senior = reduzierter Faktor.
const baseFactor = faktoren[aktivitaet][kastriert ? 'kastriert' : 'intakt'];
const stage = _lifeStage(alter);
const factor = stage.growth != null ? stage.growth : baseFactor * stage.mult;
const kcal = Math.round(rer * factor);
_showResult(el, kcal);
}
@ -297,6 +315,7 @@ window.Page_ernaehrung = (() => {
const barf = Math.round(kcal / 1.5); // ~150 kcal/100g
const kcalFormatted = kcal.toLocaleString('de-DE');
const stageLabel = _lifeStage(parseFloat(el.querySelector('#ern-alter')?.value) || 0).label;
const resultEl = el.querySelector('#ern-rechner-result');
resultEl.style.display = '';
@ -306,6 +325,7 @@ window.Page_ernaehrung = (() => {
border-radius:var(--radius-lg);margin-bottom:var(--space-4)">
<div style="font-size:var(--text-2xl);font-weight:700">ca. ${kcalFormatted} kcal</div>
<div style="font-size:var(--text-sm);opacity:0.85">pro Tag</div>
${stageLabel ? `<div style="font-size:var(--text-xs);opacity:0.9;margin-top:6px">${stageLabel}</div>` : ''}
</div>
<div style="display:grid;gap:var(--space-3)">