Apple Watch Health Data Report Generator

Portfolio

Monthly trend report generated from Apple Watch health data

I built a Python utility that turns Apple Watch health data into monthly, weekly, and long-term trend reports. It parses the export.xml file from the iOS Health app on the local machine, then creates 16:9 HTML and PDF reports with daily charts, statistical summaries, and goal achievement rates.

The project includes a CLI pipeline for Apple Health XML preprocessing, missing-value handling, intermediate CSV caching, PDF conversion, tests, and linting. I also used the cleaned daily data to examine the relationship between sleep duration and physical activity. The scripts process health data on the local machine and do not send it to external APIs.

Background

Apple Watch tracks sleep, steps, active energy, exercise, and stand hours, but the iOS Health app makes monthly summaries and weekly comparisons hard to review in one format.

I built this local-first report generator so I could review long-term lifestyle patterns without uploading personal data. The repository excludes real health data from version control, and the public PDFs and images use synthetic dummy data.

Features

The tool streams and parses the Apple Health export.xml file, then aggregates 11 health metrics across daily, weekly, monthly, and long-term views. The reports track sleep duration, step count, active energy burned, exercise time, stand hours, sleep onset time, wake-up time, and the frequency and duration of nighttime awakenings.

  • Generates monthly HTML slides with daily charts and goal-target lines.
  • Calculates average, maximum, minimum, and goal achievement rates for each metric.
  • Generates weekly reports covering the past 10 weeks.
  • Generates long-term trend charts and data tables across multiple months.
  • Supports HTML output for interactive browser viewing and PDF output for easy sharing.
Weekly trend charts and tables in the Apple Watch health report

Correlation Analysis: Sleep Duration and Activity Levels

I used a data analysis agent on the cleaned daily health data to test one question: does daytime activity affect sleep quality? The analysis covers February 1, 2026, through July 3, 2026, and focuses on step count, active energy, sleep duration, nighttime awakening count, and nighttime awakening duration.

In this dataset, daytime activity did not show a strong linear correlation with sleep duration or nighttime awakenings. The correlation coefficient between step count and sleep duration was -0.051. The coefficient between active energy and sleep duration was -0.116.

Correlation analysis charts of sleep duration, nighttime awakening count, and nighttime awakening duration against step count and active energy
Scatter plots of step count and active energy against sleep metrics. The regression lines are near horizontal, so a simple linear model does not explain the variation in sleep quality in this dataset.

The common idea that exercise improves sleep may still hold, but this dataset does not support a direct linear relationship. Future analyses can add exercise timing, workout intensity, caffeine consumption, stress levels, room temperature, and non-linear effects such as moderate exercise improving sleep more than high-intensity activity.

Technical Specifications

The system uses Python 3.12+ and uv for package and environment management. The CLI runs the full pipeline: Apple Health XML extraction, intermediate CSV generation, statistical aggregation, chart rendering, HTML compilation, and PDF conversion.

  • pandas: Handles data structuring, cleaning, and statistical calculations for daily CSVs, weekly/monthly aggregations, and multi-month trends.
  • matplotlib: Generates bar charts, line charts, and progress-to-goal visualizations for each health metric.
  • Jinja2: Renders 16:9 HTML slides from templates.
  • Playwright: Opens the rendered HTML in headless Chromium and exports it as a landscape PDF.
  • pytest / ruff: Covers testing and linting across the CLI, preprocessing, HTML generation, and trend aggregation modules.

Implementation Details and Key Considerations

An Apple Health export.xml file can grow large after years of use, so the parser uses XML streaming and extracts only the required records without loading the full file into memory. The calculations exclude missing data points, such as days when I did not wear the watch, so gaps do not skew averages or goal achievement rates.

The pipeline caches daily data from the XML as intermediate CSV files. After that first extraction, I can regenerate visual reports without rerunning the resource-heavy XML parsing step. The final reports use a 16:9 aspect ratio for consistent layout in the browser and in PDF output.

Privacy Notice

The repository ignores the real data files under input/export.xml and the generated outputs in output/. The public PDFs and images in the repository come from synthetic dummy data in output-demo/.

Local scripts run all data processing. The tool sends no health data to external APIs, cloud services, or third-party AI platforms.

Demo Outputs

The demo PDFs use synthetic dummy data and show the monthly, weekly, and daily report layouts:

Future Roadmap

Next, I plan to add more health metrics, month-over-month comparison views, and stronger visual design for the HTML templates. The project started as a personal tracking tool, but the same pipeline structure can support business intelligence and automated reporting workflows.

View GitHub Repository

Portfolio My Past Projects



See All