fix: Phase 0b - complete Decimal/float conversion in nutrition_metrics
All checks were successful
Deploy Development / deploy (push) Successful in 51s
Build Test / lint-backend (push) Successful in 0s
Build Test / build-frontend (push) Successful in 14s

Previous commit only converted weight values, but missed:
- avg_intake (calories from DB)
- avg_protein (protein_g from DB)
- protein_per_kg calculations in loops

All DB numeric values now converted to float BEFORE arithmetic.

Fixed locations:
- Line 44: avg_intake conversion
- Line 126: avg_protein conversion
- Line 175: protein_per_kg in loop
- Line 213: protein_values list comprehension

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Lars 2026-03-28 11:32:07 +01:00
parent 78437b649f
commit 05d15264c8

View File

@ -41,7 +41,7 @@ def calculate_energy_balance_7d(profile_id: str) -> Optional[float]:
if len(calories) < 4: # Need at least 4 days
return None
avg_intake = sum(calories) / len(calories)
avg_intake = float(sum(calories) / len(calories))
# Get estimated TDEE (simplified - could use Harris-Benedict)
# For now, use weight-based estimate
@ -123,7 +123,7 @@ def calculate_protein_g_per_kg(profile_id: str) -> Optional[float]:
if len(protein_values) < 4:
return None
avg_protein = sum(protein_values) / len(protein_values)
avg_protein = float(sum(protein_values) / len(protein_values))
protein_per_kg = avg_protein / weight
return round(protein_per_kg, 2)
@ -172,7 +172,7 @@ def calculate_protein_days_in_target(profile_id: str, target_low: float = 1.6, t
total_days = len(protein_data)
for row in protein_data:
protein_per_kg = row['protein_g'] / weight
protein_per_kg = float(row['protein_g']) / weight
if target_low <= protein_per_kg <= target_high:
days_in_target += 1
@ -210,7 +210,7 @@ def calculate_protein_adequacy_28d(profile_id: str) -> Optional[int]:
AND protein_g IS NOT NULL
""", (profile_id,))
protein_values = [row['protein_g'] for row in cur.fetchall()]
protein_values = [float(row['protein_g']) for row in cur.fetchall()]
if len(protein_values) < 18: # 60% coverage
return None