Data-quality tool · Python
Rebuilding local time matches Apple's daily totals on 99.2 % of days, up from 92.6 %
Apple Health exports stamp every record with the offset from the day you exported, count steps twice and score each night three ways. This analyzer fixes each trap. Here it runs on a synthetic export whose right answers are planted.
Synthetic export, no real health dataSeed 01,095 daysOne run
Days whose active energy matches Apple's own daily total
Share of 968 days, by error against Apple's daily summary · one synthetic run
| Error | Export offset | Rebuilt local time |
|---|---|---|
| Within 5 % of Apple's total | 896 (92.6 %) | 960 (99.2 %) |
| 5–25 % off | 53 (5.5 %) | 2 (0.2 %) |
| More than 25 % off | 19 (2.0 %) | 6 (0.6 %) |
Each trap · naive vs analyzer vs planted truth
The analyzer recovers the planted answer on 6 of 7 traps; time zones reach 99.2 % of days, not 100 %
The naive answer is what you get by reading the export literally. The planted truth is what the generator put in. The time-zone row misses on 8 days; the next section shows where.
| Trap | Naive answer | Analyzer | Planted truth | Matches truth |
|---|---|---|---|---|
| iPhone and Watch count the same steps | 13,913,705 steps (plain sum) | 8,047,907 | 8,047,907 | Yes |
| Every timestamp carries the -0700 export offset | 92.6 % of days match Apple's total | 99.2 % | 100 % | No |
| Three sources score each Watch night | 8.14 h (longest source) | 6.98 h | 6.98 h | Yes |
| Days with no data at all | 5 days of 0 steps | 5 days NULL | 5 unknown days | Yes |
| Older runs keep only a few heart-rate samples | 124 runs averaged from 4 samples | 124 runs left blank | 124 runs with no reliable average | Yes |
| Zones change with a move, two trips and an alias | 1 zone (-0700 throughout) | 6 zone segments | 6 tagged eras, after 1 untagged era shown as assumed | Yes |
| Watch worn only part of the day | 113 partial days counted as worn | 113 of them excluded from worn-day series | 113 partial days | Yes |
The traps and the fixes have the same author. The generator plants the traps the analyzer was written to fix, so a match shows the fixes work on these traps. Real exports may hold traps this generator does not plant.
Time zones · where the misses are
The rebuild's remaining 8 misses all fall within 1 day of a zone change
With the export offset, the worst week averages 171 kcal a day of error (week ending Mar 17, 2024). The rebuild cuts that week to 48 kcal, but its own worst week is the next one, week ending Mar 24, 2024, at 106 kcal a day: the error moved by a week, because zone changes are placed to within about a day.
The export offset misses all year; the rebuild misses only next to a move or trip
Days more than 5 % off Apple's total, by distance to the nearest planted zone change · 6 changes · one synthetic run
| Distance | Export offset | Rebuilt local time |
|---|---|---|
| 0–2 days from a zone change | 9 | 8 |
| 3–30 days | 18 | 0 |
| More than 30 days | 45 | 0 |
Correctness evidence
Removing any one of the 14 fixes makes its test fail: 14 of 14
A mutation check reverts each fix to its naive version, one at a time, and runs the tests. A fix whose removal no test notices would be unguarded.
Every fix and the test that catches it · 14 rows
| Fix removed | File | Test that fails |
|---|---|---|
| Use the export offset for every hour | healthlab/build.py | test_local_time_is_rebuilt_from_zone_tags_not_the_export_offset |
| One fixed offset per zone, ignoring DST | healthlab/build.py | test_each_hour_uses_its_own_dst_offset |
| Treat zone aliases as different places | healthlab/build.py | test_zone_aliases_merge_into_one_place |
| Present untagged days as observed | healthlab/build.py | test_days_before_the_first_zone_tag_are_marked_assumed |
| Sum steps across sources | healthlab/build.py | test_iphone_and_watch_steps_are_not_double_counted |
| Fill missing days with zero | healthlab/build.py | test_a_day_without_samples_is_null_not_zero |
| Longest sleep source wins | healthlab/build.py | test_one_sleep_source_per_night_named_and_never_blended |
| Key a night by the date it started | healthlab/build.py | test_one_sleep_source_per_night_named_and_never_blended |
| Match device names on a plain space | healthlab/build.py | test_device_names_with_a_non_breaking_space_still_match |
| Hard-code the sleep tracking dates | healthlab/insights.py | test_sleep_tracking_and_stage_dates_come_from_the_data |
| Count any heart-rate hour as a worn day | healthlab/build.py | test_partial_wear_days_are_not_treated_as_worn |
| Average a handful of workout samples | healthlab/build.py | test_sparse_workout_heart_rate_is_left_blank |
| Count Correlation members as samples | healthlab/parse.py | test_correlation_members_are_not_counted_as_samples |
| Append every import without matching | healthlab/build.py | test_importing_an_overlapping_export_again_adds_nothing |
Methodology
How this was measured
healthlab/synth.py writes an Apple Health export zip for 1,095 days from seed 0, with each trap planted and its right answer recorded. The analyzer imports the zip the same way it imports a real one, then each trap's answer is compared with the recorded truth.
For time zones, hourly active energy is summed by calendar day in two ways and compared with Apple's own daily summary on the 968 days that have one. A day matches if the error is at most 5 % of Apple's total. Weeks run Monday to Sunday and are labeled by their last day.
What this shows
- Each fix recovers the planted answer for its trap; time zones get 99.2 % of days.
- Every fix is needed: removing any one makes a test fail.
- The rebuild's misses sit next to zone changes.
What it doesn't show
- Accuracy on real exports: no real health data was used.
- Traps this generator does not plant.
- Run-to-run spread: one seed, one run.
Reproduce
Run it yourself
git clone https://github.com/allenwang0/health-export-lab.git
cd health-export-lab
make setup # virtualenv with pinned dependencies (Python 3.11)
make test
make mutants # writes results/mutants.json
make report # rebuilds this page from a fresh synthetic run
make demo # local app on the synthetic export| Field | Value |
|---|---|
| Python | 3.11 |
| duckdb | 2.0.0 |
| pandas | 3.1.1 |
| lxml | 6.1.3 |
| Generator | healthlab/synth.py |
| Seed | 0 |
| Span | 1,095 days (2022-01-03 to 2025-01-01) |
| Days compared | 968 days with active energy in Apple's summary |
| Command | python scripts/report.py |
| Commit | 2273689 |
| Generated | 2026-11-26 21:34 UTC |