feat: Phase 0c - health_metrics.py module complete
Deploy Development / deploy (push) Successful in 53s
Build Test / lint-backend (push) Successful in 0s
Build Test / build-frontend (push) Successful in 14s

Data Layer:
- get_resting_heart_rate_data() - avg RHR with min/max trend
- get_heart_rate_variability_data() - avg HRV with min/max trend
- get_vo2_max_data() - latest VO2 Max with date

Placeholder Layer:
- get_vitals_avg_hr() - refactored to use data layer
- get_vitals_avg_hrv() - refactored to use data layer
- get_vitals_vo2_max() - refactored to use data layer

All 3 health data functions + 3 placeholder refactors complete.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
LarsandClaude Opus 4.6 committed 2026-03-28 19:15:31 +01:00
1 parent 432f7ba49f
commit b4558b0582
3 files changed
+238 -37

No files matched your search

+35 -36
View File
@@ -33,6 +33,11 @@ from data_layer.recovery_metrics import (
get_sleep_quality_data,
get_rest_days_data
)
from data_layer.health_metrics import (
get_resting_heart_rate_data,
get_heart_rate_variability_data,
get_vo2_max_data
)
# ── Helper Functions ──────────────────────────────────────────────────────────
@@ -351,55 +356,49 @@ def get_rest_days_count(profile_id: str, days: int = 30) -> str:
def get_vitals_avg_hr(profile_id: str, days: int = 7) -> str:
"""Calculate average resting heart rate."""
with get_db() as conn:
cur = get_cursor(conn)
cutoff = (datetime.now() - timedelta(days=days)).strftime('%Y-%m-%d')
cur.execute(
"""SELECT AVG(resting_hr) as avg FROM vitals_baseline
WHERE profile_id=%s AND date >= %s AND resting_hr IS NOT NULL""",
(profile_id, cutoff)
)
row = cur.fetchone()
"""
Calculate average resting heart rate.
if row and row['avg']:
return f"{int(row['avg'])} bpm"
Phase 0c: Refactored to use data_layer.health_metrics.get_resting_heart_rate_data()
This function now only FORMATS the data for AI consumption.
"""
data = get_resting_heart_rate_data(profile_id, days)
if data['confidence'] == 'insufficient':
return "nicht verfügbar"
return f"{data['avg_rhr']} bpm"
def get_vitals_avg_hrv(profile_id: str, days: int = 7) -> str:
"""Calculate average heart rate variability."""
with get_db() as conn:
cur = get_cursor(conn)
cutoff = (datetime.now() - timedelta(days=days)).strftime('%Y-%m-%d')
cur.execute(
"""SELECT AVG(hrv) as avg FROM vitals_baseline
WHERE profile_id=%s AND date >= %s AND hrv IS NOT NULL""",
(profile_id, cutoff)
)
row = cur.fetchone()
"""
Calculate average heart rate variability.
if row and row['avg']:
return f"{int(row['avg'])} ms"
Phase 0c: Refactored to use data_layer.health_metrics.get_heart_rate_variability_data()
This function now only FORMATS the data for AI consumption.
"""
data = get_heart_rate_variability_data(profile_id, days)
if data['confidence'] == 'insufficient':
return "nicht verfügbar"
return f"{data['avg_hrv']} ms"
def get_vitals_vo2_max(profile_id: str) -> str:
"""Get latest VO2 Max value."""
with get_db() as conn:
cur = get_cursor(conn)
cur.execute(
"""SELECT vo2_max FROM vitals_baseline
WHERE profile_id=%s AND vo2_max IS NOT NULL
ORDER BY date DESC LIMIT 1""",
(profile_id,)
)
row = cur.fetchone()
"""
Get latest VO2 Max value.
if row and row['vo2_max']:
return f"{row['vo2_max']:.1f} ml/kg/min"
Phase 0c: Refactored to use data_layer.health_metrics.get_vo2_max_data()
This function now only FORMATS the data for AI consumption.
"""
data = get_vo2_max_data(profile_id)
if data['confidence'] == 'insufficient':
return "nicht verfügbar"
return f"{data['vo2_max']:.1f} ml/kg/min"
# ── Phase 0b Calculation Engine Integration ──────────────────────────────────