mitai-jinkendo/backend/data_layer
Lars 0c19e0c0ed
All checks were successful
Deploy Development / deploy (push) Successful in 45s
Build Test / lint-backend (push) Successful in 0s
Build Test / build-frontend (push) Successful in 15s
fix: Part B protein placeholders - aggregate by date
Fixes calculate_protein_g_per_kg and calculate_protein_days_in_target:

**Problem:**
Both functions were treating individual nutrition_log entries as days,
causing incorrect calculations when multiple entries exist per day
(e.g., from CSV imports: 233 entries across 7 days).

**Solution:**
1. calculate_protein_g_per_kg:
   - Added GROUP BY date, SUM(protein_g) to aggregate by day
   - Now averages daily totals, not individual entries
   - Correct: 7 days → 7 values, not 233 entries → 233 values

2. calculate_protein_days_in_target:
   - Added GROUP BY date, SUM(protein_g) to aggregate by day
   - Calculates target range in absolute grams (not g/kg per entry)
   - Counts unique DAYS in range, not entries
   - Correct format: "5/7" (5 of 7 days), not "150/233" (entries)

**Impact:**
- protein_g_per_kg: was returning "nicht verfügbar" → now returns correct value
- protein_days_in_target: was returning "nicht verfügbar" → now returns correct format

**Root Cause:**
Functions expected 7 unique dates but got 233 entries.
With export date 2026-04-02 and last data 2026-03-26,
the 7-day window had insufficient unique dates.

Issue reported by user: Part B placeholders not showing correct values
in extended export (registry metadata was correct, but computed values failed).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-02 12:43:33 +02:00
..
__init__.py feat: Phase 0c - migrate correlation_metrics to data_layer/correlations (11 functions) 2026-03-28 20:28:26 +01:00
activity_metrics.py fix: add missing statistics import and update focus_weights function 2026-03-28 20:46:21 +01:00
body_metrics.py fix: add missing statistics import and update focus_weights function 2026-03-28 20:46:21 +01:00
correlations.py fix: Phase 0c - update all in-function imports to use data_layer 2026-03-28 20:36:50 +01:00
health_metrics.py feat: Phase 0c - health_metrics.py module complete 2026-03-28 19:15:31 +01:00
nutrition_metrics.py fix: Part B protein placeholders - aggregate by date 2026-04-02 12:43:33 +02:00
recovery_metrics.py fix: Phase 0c - update all in-function imports to use data_layer 2026-03-28 20:36:50 +01:00
scores.py fix: Phase 0c - update all in-function imports to use data_layer 2026-03-28 20:36:50 +01:00
utils.py fix: correct confidence thresholds for 30-89 day range 2026-03-28 21:03:22 +01:00