+"""
+
+ # Heart Rate
+ heart_rate = health_metrics.get("heart_rate", {})
+ if heart_rate and isinstance(heart_rate, dict):
+ resting_hr = heart_rate.get("restingHeartRate", "N/A")
+ max_hr = heart_rate.get("maxHeartRate", "N/A")
+ html_content += f"""
+
+
💓 Heart Rate
+
{resting_hr} bpm (resting)
+
Max: {max_hr} bpm
+
+"""
+
+ # Sleep Data
+ sleep_data = health_metrics.get("sleep", {})
+ if (
+ sleep_data
+ and isinstance(sleep_data, dict)
+ and "dailySleepDTO" in sleep_data
+ ):
+ sleep_seconds = sleep_data["dailySleepDTO"].get("sleepTimeSeconds", 0)
+ sleep_hours = round(sleep_seconds / 3600, 1) if sleep_seconds else 0
+ deep_sleep = sleep_data["dailySleepDTO"].get("deepSleepSeconds", 0)
+ deep_hours = round(deep_sleep / 3600, 1) if deep_sleep else 0
+
+ html_content += f"""
+
+
😴 Sleep
+
{sleep_hours} hours
+
Deep Sleep: {deep_hours} hours
+
+"""
+
+ # Steps
+ steps_data = health_metrics.get("steps", {})
+ if steps_data and isinstance(steps_data, dict):
+ total_steps = steps_data.get("totalSteps", 0)
+ goal = steps_data.get("dailyStepGoal", 10000)
+ html_content += f"""
+
+
🎯 Step Goal
+
{total_steps:,} of {goal:,}
+
Goal: {round((total_steps/goal)*100) if goal else 0}%
+
+"""
+
+ # Stress Data
+ stress_data = health_metrics.get("stress", {})
+ if stress_data and isinstance(stress_data, dict):
+ avg_stress = stress_data.get("avgStressLevel", "N/A")
+ max_stress = stress_data.get("maxStressLevel", "N/A")
+ html_content += f"""
+
+
😰 Stress Level
+
{avg_stress} avg
+
Max: {max_stress}
+
+"""
+
+ # Body Battery
+ body_battery = health_metrics.get("body_battery", [])
+ if body_battery and isinstance(body_battery, list) and body_battery:
+ latest_bb = body_battery[-1] if body_battery else {}
+ charged = latest_bb.get("charged", "N/A")
+ drained = latest_bb.get("drained", "N/A")
+ html_content += f"""
+
+
🔋 Body Battery
+
+{charged} charged
+
-{drained} drained
+
+"""
+
+ html_content += "