HealthDock icon HealthDock
Browser Parser Specification · Single-File Web Worker · Zero Telemetry

How HealthDock Processes Apple Health Data — Methodology & Data Dictionary

This page documents the exact parsing, de-duplication, aggregation, and export rules implemented in HealthDock’s browser-local Apple Health converter. Every rule below matches the code running on this site.

📄 Source: assets/health-worker.js ⚡ 4 MB streaming chunks 🔒 100% browser-local execution

1. Input Handling (ZIP & XML Streaming)

The parser accepts either Apple Health’s compressed export.zip (detected when the filename ends in .zip or the MIME type is application/zip) or an unzipped export.xml. It never builds an XML DOM in memory.

Code references: CHUNK_BYTES, findExportXmlInZip, parseFile, feedTextChunk, extractAttr.

2. Record Types Read vs. Not Exported

HealthDock reads 13 HealthKit <Record> types plus <Workout> and selected nested <WorkoutStatistics> elements. Unit conversions happen during ingestion.

Apple Health Identifier Output Metric Key Aggregation & Unit Normalization
HKQuantityTypeIdentifierRestingHeartRateresting_hr_avgDaily arithmetic mean (bpm)
HKQuantityTypeIdentifierHeartRateVariabilitySDNNhrv_sdnn_msDaily arithmetic mean; s converted to ms (×1000)
HKQuantityTypeIdentifierWalkingHeartRateAveragewalking_hr_avgDaily arithmetic mean (bpm)
HKQuantityTypeIdentifierStepCountstepsPer-source daily sum, then chooseCumulativeSum
HKQuantityTypeIdentifierActiveEnergyBurnedactive_kcalPer-source daily sum, then chooseCumulativeSum; kJ ÷ 4.184
HKQuantityTypeIdentifierAppleExerciseTimeexercise_minPer-source daily sum, then chooseCumulativeSum; s ÷ 60
HKQuantityTypeIdentifierOxygenSaturationspo2_pctDaily arithmetic mean; values ≤ 1.5 multiplied by 100
HKQuantityTypeIdentifierRespiratoryRateresp_rateDaily arithmetic mean (/min)
HKQuantityTypeIdentifierVO2Maxvo2maxDaily arithmetic mean (ml/kg·min)
HKQuantityTypeIdentifierBloodPressureSystolicbp_sysDaily arithmetic mean (mmHg)
HKQuantityTypeIdentifierBloodPressureDiastolicbp_diaDaily arithmetic mean (mmHg)
HKQuantityTypeIdentifierBodyMassweight_kgDaily arithmetic mean; lb × 0.45359237, g ÷ 1000
HKCategoryTypeIdentifierSleepAnalysissleep_min, deep_min, rem_minNight-window interval union (asleep stages only)

Workouts: Reads <Workout> attributes (workoutActivityType, startDate, endDate, duration/durationUnit, totalEnergyBurned, totalDistance, sourceName) and nested <WorkoutStatistics> for HKQuantityTypeIdentifierActiveEnergyBurned (sum), HKQuantityTypeIdentifierHeartRate (average), and DistanceWalkingRunning / DistanceCycling / DistanceSwimming (sum, converting mi × 1.609344 and m ÷ 1000).

Not exported (ignored by the browser parser): All other XML elements and record types are skipped, including per-sample HKQuantityTypeIdentifierHeartRate records outside <WorkoutStatistics>, InBed and Awake sleep records, BasalEnergyBurned, AppleStandTime, distance <Record> entries, body fat / height / body temperature / blood glucose / mindfulness records, <Electrocardiogram> and electrocardiograms/ CSVs, <WorkoutRoute> and workout-routes/ GPX files, <ClinicalRecord>, <ActivitySummary>, <Correlation>, <MetadataEntry>, and <Me>.

Code references: RECORD_TYPE_MAP, WORKOUT_NAMES, processRecordTag, processWorkoutStart, processWorkoutStatsTag.

3. Steps, Active Energy & Exercise De-duplication

When you wear an Apple Watch and carry an iPhone, both devices write overlapping cumulative records for the same walk. HealthDock applies per-source daily selection to the three cumulative metrics (PARTIAL_KEYS: steps, active_kcal, exercise_min):

  1. During parsing, each cumulative record is summed into a bucket keyed by (date, metricKey, sourceName).
  2. At finalization, if only one source recorded values on that date, its sum is used.
  3. If multiple sources recorded values on that date, chooseCumulativeSum checks whether any sourceName matches the case-insensitive regular expression /watch/i.
    • If one or more sources match /watch/i, the parser returns the highest single Watch source total and discards all non-Watch sources for that day.
    • If no source matches /watch/i, the parser returns the highest single source total across all sources for that day.
Known trade-offs: This avoids 2× double-counting without needing per-second interval overlap math, but it picks one source per day. If you left your Apple Watch charging for part of the day and walked with your iPhone, iPhone-only steps/energy/exercise on that day are dropped whenever any Watch record exists for that date—even if the Watch total is smaller than the iPhone total. Also, because device matching relies on /watch/i in sourceName, an Apple Watch renamed without the word “watch” falls back to the highest single source total.

Code references: PARTIAL_KEYS, processRecordTag, chooseCumulativeSum, finalizeDataset.

4. Sleep Night Window & Interval Merging

Code references: ASLEEP_VALUES, mergeIntervalsMinutes, applySleepNights.

5. HRV, Resting Heart Rate & Other Daily Metrics

All nine non-cumulative quantity metrics—resting_hr_avg, hrv_sdnn_ms, walking_hr_avg, spo2_pct, resp_rate, vo2max, bp_sys, bp_dia, and weight_kg—are aggregated as the simple arithmetic mean (sum / count) of every valid record sharing the same calendar date across all sources. The parser does not take the last reading, median, or per-source priority for these metrics.

Code references: processRecordTag, finalizeDataset.

6. Time Zones, Dates, Travel & DST

Code references: parseAppleDateMs, formatLocalDate, parseYMD, addDaysYMD, formatClock.

7. Missing Data: Blank vs. Zero

Code references: buildExportPayload, formatNumber, deltaText.

8. Baselines & Unusual Days in context.md

Code references: METRICS, windowRows, metricMean, renderContextMarkdown.

9. CSV & JSON Column Dictionary

Daily Summary CSV (daily-csv) & JSON (daily-json)

In Daily Summary CSV, every row is one calendar date in ascending order. In Daily Summary JSON, the same metric keys live inside days[].values (with sleep_min in integer minutes, unlike context.md which divides sleep_min by 60 to display hours).

Column Unit Format Meaning
date—YYYY-MM-DDCalendar date from Apple Health startDate (or sleep morning date).
resting_hr_avgbpmintegerDaily mean resting heart rate.
hrv_sdnn_msmsintegerDaily mean heart rate variability (SDNN).
walking_hr_avgbpmintegerDaily mean walking heart rate average.
sleep_minminintegerMerged total asleep minutes in the 18:00–12:00 night window (all asleep stages).
deep_minminintegerMerged deep sleep minutes in the night window (blank if no deep segments).
rem_minminintegerMerged REM sleep minutes in the night window (blank if no REM segments).
stepscountintegerDaily cumulative steps from the source selected by chooseCumulativeSum.
active_kcalkcalintegerDaily cumulative active energy burned from the selected source.
exercise_minminintegerDaily cumulative Apple Exercise minutes from the selected source.
spo2_pct%1 decimalDaily mean blood oxygen saturation in percent.
resp_rate/min1 decimalDaily mean respiratory rate in breaths per minute.
vo2maxml/kg·min1 decimalDaily mean cardio fitness (VO₂max).
bp_sysmmHgintegerDaily mean systolic blood pressure.
bp_diammHgintegerDaily mean diastolic blood pressure.
weight_kgkg1 decimalDaily mean body mass in kilograms.
workout_countcountintegerNumber of <Workout> entries on this date (0 if none; CSV only).
workout_minmin1 decimal or 0Sum of workout durations on this date (0 if none; CSV only).

Workouts CSV (workouts-csv)

Sorted newest-first by workout start timestamp.

Column Unit Format Meaning
date—YYYY-MM-DDWorkout start calendar date.
start—YYYY-MM-DD HH:MM:SSFirst 19 characters of the workout’s recorded startDate.
activity_type—textHuman-readable activity name mapped from workoutActivityType.
duration_minmin1 decimalWorkout duration (falls back to endDate − startDate if duration is missing).
active_kcalkcalintegerWorkout active energy from totalEnergyBurned or nested <WorkoutStatistics>; blank if absent.
avg_hr_bpmbpmintegerAverage workout heart rate from nested <WorkoutStatistics>; blank if absent.
distance_kmkm2 decimalsWorkout distance in kilometers from totalDistance or nested <WorkoutStatistics>; blank if absent.
source—textsourceName attribute of the <Workout> element (or Unknown).

Code references: METRICS, buildExportPayload, csvCell.

10. Privacy Boundary, Offline Verification & Parser Source

All file reading, ZIP decompression, aggregation, and CSV/JSON/Markdown generation run strictly inside your browser tab via a local Web Worker. HealthDock sends zero health bytes to any server and loads no third-party analytics or tracking scripts.

Privacy boundary: Once you copy context.md or upload a generated CSV/JSON file into a cloud AI service (such as ChatGPT, Claude, Gemini, Grok, or Perplexity), that AI provider receives the text you share under its own privacy policy.

How to verify offline: Load any converter page (for example XML → CSV or Apple Health to ChatGPT), disconnect your computer from the internet (or check Offline in browser DevTools → Network), and then drop your export.zip or export.xml file. Conversion completes normally with zero network activity.

Parser source: The parser is a single file, assets/health-worker.js, served with this site. You can also inspect real synthetic input and output files in Sample input and output (samples/README.txt).

Methodology FAQ

How does HealthDock deduplicate steps, active energy, and exercise minutes between Apple Watch and iPhone?

For steps, active_kcal, and exercise_min, HealthDock sums records separately by sourceName per day. When multiple sources exist on the same day, chooseCumulativeSum checks whether any source matches /watch/i; if so, it keeps the largest single Watch source total, otherwise the largest single source total. That prevents 2× double-counting, with the trade-off that iPhone-only activity while the Watch was off is dropped on any day that also has Watch data.

How are overlapping sleep segments and sleep stages calculated?

Only asleep values (Asleep, AsleepUnspecified, AsleepCore, AsleepDeep, and AsleepREM) are included; InBed and Awake are ignored. Segments are grouped into 18:00–12:00 night windows anchored to the offset in startDate and unioned via mergeIntervalsMinutes so overlapping sources are not double-counted.

How are HRV, resting heart rate, and other daily metrics aggregated when there are multiple readings per day?

All nine non-cumulative quantity metrics (resting_hr_avg, hrv_sdnn_ms, walking_hr_avg, spo2_pct, resp_rate, vo2max, bp_sys, bp_dia, and weight_kg) are aggregated as the simple arithmetic mean across all records on that calendar date.

How are unusual days (≥2 SD) calculated in context.md?

Each of the last 14 calendar days is compared against the baseline window (windowDays excluding the most recent 14 days). A metric is evaluated only if it is one of the 10 flagged physiological metrics and has at least 14 days in that baseline with a non-zero population standard deviation. Days with |value − mean| / SD >= 2 are flagged.

How can I verify that HealthDock processes my export.zip completely offline?

Open any converter page on gethealthdock.com, disconnect from Wi-Fi (or toggle Offline in DevTools), and drop your export.zip or export.xml. Everything runs locally in assets/health-worker.js with zero network calls.