Add extended health metrics and trends UI

This commit is contained in:
Alex
2026-05-26 16:28:07 +03:00
parent a70439194e
commit d52a2d6d1d
13 changed files with 1387 additions and 380 deletions
+63 -1
View File
@@ -32,7 +32,54 @@ def test_init_health_db_is_idempotent(tmp_path: Path) -> None:
row["name"]
for row in conn.execute("SELECT name FROM sqlite_master WHERE type = 'table'").fetchall()
}
assert {"steps_daily", "sleep_daily", "heart_rate", "blood_oxygen"}.issubset(tables)
assert {
"steps_daily",
"sleep_daily",
"heart_rate",
"blood_oxygen",
"stress",
"calories_daily",
"weight",
"workouts",
}.issubset(tables)
def test_extended_health_tables_have_expected_columns(tmp_path: Path) -> None:
db_path = tmp_path / "miband_123.db"
storage.init_health_db(db_path)
with storage.sqlite_conn(db_path, row_factory=False) as conn:
columns = {
table: {
row[1]
for row in conn.execute(f"PRAGMA table_info({table})").fetchall()
}
for table in ("stress", "calories_daily", "weight", "workouts")
}
assert columns["stress"] == {"timestamp", "value"}
assert {
"date",
"total_cal",
"active_cal",
"valid_stand_hours",
"intensity_minutes",
"last_sync",
}.issubset(columns["calories_daily"])
assert {"timestamp", "weight_kg", "bmi", "body_fat_pct"}.issubset(columns["weight"])
assert {
"workout_id",
"sport_type",
"start_time",
"end_time",
"duration_sec",
"calories",
"avg_hr",
"max_hr",
"min_hr",
"watermark",
"raw_json",
}.issubset(columns["workouts"])
def test_zip_export_includes_non_empty_tables_only(tmp_path: Path) -> None:
@@ -44,9 +91,24 @@ def test_zip_export_includes_non_empty_tables_only(tmp_path: Path) -> None:
"INSERT INTO steps_daily (date, total_steps, calories, distance_m, last_sync) VALUES (?, ?, ?, ?, ?)",
("2026-05-24", 1000, 10.0, 800.0, 1),
)
conn.execute(
"INSERT INTO stress (timestamp, value) VALUES (?, ?)",
(1779760000, 42),
)
conn.execute(
"""
INSERT INTO workouts
(workout_id, sport_type, start_time, end_time, duration_sec,
calories, avg_hr, max_hr, min_hr, watermark, raw_json)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
""",
("w1", "free_training", 1779760000, 1779760600, 600, 55.0, 110, 130, 90, 1, "{}"),
)
conn.commit()
archive = storage.zip_export(settings)
assert archive.getbuffer().nbytes > 0
assert b"steps_daily.csv" in archive.getvalue()
assert b"stress.csv" in archive.getvalue()
assert b"workouts.csv" in archive.getvalue()