Apple Health Architecture

Daily exports → analytics → visual memory for sleep, recovery, and coaching insights

Overview

AI-Steve’s Apple Health stack turns daily CSV exports into a structured time series, runs correlation and lag analysis, and trains a sleep-concentration model. The resulting plots are stored as visual artifacts and ingested into the same visual memory layer as images, so health insights are queryable inside the assistant.

Apple Health CSV Correlation Engine Sleep Modeling Visualization Artifacts AI-Steve Recall

Data Ingest + Normalization

Daily Exports

Health Auto Export produces HealthMetrics-YYYY-MM-DD.csv snapshots that are pulled nightly.

Normalization

Column names are normalized across export versions; duplicate dates are de-duped to a single daily row.

Sleep Concentration

Derived metric computed as (REM + Deep) / Asleep to capture quality signals.

Core modules: health_csv_loader.py for parsing and normalization, plus shared helpers for metric selection and completeness filtering.

Analytics + Modeling

Correlation Engine

Computes full correlation matrices, top correlates, and statistical significance for sleep metrics.

Lag Effects

Lag correlation checks delayed effects (e.g., exercise → deep sleep) across multi-day windows.

Sleep Quality Model

Random Forest regression highlights which daily behaviors best predict sleep concentration.

# Simplified health pipeline df = HealthCSVLoader(data_dir).load_all_csvs() df = HealthCSVLoader(data_dir).select_metrics(df, max_null_pct=70) df = compute_sleep_concentration(df) corr = HealthCorrelationEngine(df).compute_correlation_matrix() model = SleepQualityPredictor().train_model(X, y)

Visualization Outputs

Plots are generated nightly and stored for dashboard review, then ingested into AI-Steve’s visual memory for searchable recall.

Full Apple Health correlation heatmap

Full correlation heatmap across all available metrics.

Feature importance for sleep concentration prediction

Top 20 features for sleep concentration prediction.

Top correlates with deep sleep

Top correlates with deep sleep to isolate recovery drivers.

Top correlates with REM sleep

Top correlates with REM sleep for cognitive recovery signals.

Sleep-focused correlation heatmap

Sleep-focused correlation matrix for the top 30 predictors.

Integration in AI-Steve

Dashboard

Health plots and summaries are shown on the /health dashboard for fast review.

Visual Memory Ingest

Visualization PNGs and JSON annotations are embedded and indexed with content type health_visualization.

Nightly Refresh

Cron jobs recompute stats, regenerate plots, and optionally send summary emails.

Health visualizations are stored alongside other image assets so they can be searched, clustered, and recalled just like photos.