# `health@1`: daily body metrics, sleep sessions with stages, and workouts

Version **1.4.0** · published 2026-12-01 · MIT · boards: sleep-recovery, training-log, nutrition-weight, athlete, neverchill-athlete

One row of `sleep_sessions` is one sleep (a night or a nap) as one device recorded it; one row of `daily_metrics` is one
value of one metric code on one local day from one device; one row of `workouts` is one workout; one row of `nutrition`
(1.2) is one diary day of food from one app; one row of `body` is one day's weigh-in (and body fat, waist) from one scale or app. The Apple Health
export fills all three (it also carries Apple Watch data and every app that writes to Apple Health: Oura, WHOOP,
AutoSleep and others); a folder of health@1 CSV files is the generic lane-1 format any tool can write.

This standard holds **information about the body, not medical advice**. It stores what devices measured; it never
holds a diagnosis.

## Conventions
- Units: durations in seconds, distances in metres, energy in kilocalories, temperature in degrees Celsius, shares
  and rates as decimals (SpO2 0.97, efficiency 0.91). Values are converted on import (`degF`, `kJ`, a percent written as
  `97`); `metric_codes.unit` is the one unit every value of a code is in.
- Dates are the person's local `YYYY-MM-DD`; instants are ISO 8601 UTC (`...Z`) with a `tz` column: an IANA name when
  the source gives or implies one, otherwise a fixed offset (`+01:00`). `start_local` / `end_local` hold the local
  wall-clock times, so bedtimes need no time-zone database in SQL.
- IDs: the source's own id when it has one, otherwise sha1 of the natural key, first 16 hex
  (`source|device|night_of|is_nap|start_utc` for sleep, `source|device|start_utc|sport` for workouts).
- Provenance on every fact table: `source` (connector id, vocab `sources`), `device` (the device or app as the source
  names it), `source_ref` (file and record type, or file:line), `imported_at` (left out of `data_hash`).
- **HRV is two codes**: `hrv_sdnn` (Apple Watch) and `hrv_rmssd` (Oura, WHOOP). They measure different things and are
  never mixed, averaged together or compared with each other's baselines. HRV another app wrote to Apple Health under the
  SDNN type is `hrv_unverified` (its kind is not certain), never `hrv_sdnn`.

## The night rules (every connector follows these)
1. **One device at a time.** Each device keeps its own session rows. Two devices recording one night give two rows; a
   board chooses one per night by the person's source priority. Rows from two devices are never added.
2. **Interval union within a device.** A device's samples for a night are laid on one timeline. Where samples of the
   same device overlap, the time is counted once: awake wins (an Awake sample on top of a long Asleep one is time awake),
   then the most specific stage (deep > REM > light > unspecified asleep), then in bed. So `asleep_s = light_s + deep_s + rem_s +
   asleep_unspecified_s`, and nothing is ever a plain sum of overlapping samples. Exact repeats of a sample (the same
   type, device, times and value) are counted once and reported as duplicates.
3. **In bed** is the union of every in-bed, asleep and awake interval of the device. A device that writes stages but no
   in-bed samples (an Apple Watch on iOS 16+) gets in bed = the union of its stage and awake samples; a device that
   writes only in bed (an iPhone sleep schedule) has `asleep_s` NULL, never a guess.
4. **night_of, noon to noon.** On each device's own timeline, samples less than the session gap apart (default 2 hours)
   form one sleep period. A period belongs to the night whose local noon-to-noon window it starts in:
   `night_of = date(start_local - 12 hours)`, so a sleep that runs past noon stays one sleep. Local time comes from the sample's own time zone when the source records
   one (Apple's `HKTimeZone` metadata), else the person's time-zone history in the board's inputs, else the offset
   written on the sample.
5. **Sessions and naps.** Within a device and night, samples more than 15 minutes apart are separate pieces. A piece with
   under 4 hours asleep is a **nap** (`is_nap = 1`, its own row) when it starts between 10:00 and 20:00 local time; a
   piece under 2 hours that starts between 10:00 and 22:00 and ends before the night's longest piece starts is an evening
   doze, also a nap. All other pieces are the night's main sleep:
   one row, its in-bed time the union of its pieces (a long wake in the middle is not counted as in bed).
6. **Durations are UTC.** Seconds are differences of UTC instants, so a night across a daylight-saving change is its
   true length (7 hours asleep is 25200 seconds whichever way the clocks moved). Bedtime uses the start's local time,
   wake time the end's.
7. **Daily metrics**: a day's value is the code's `agg` (avg, sum, last, min, max) over that device's samples whose start
   falls on that local date. One row per day, code, device and source; a board picks one device per day and code.

## The workout rules (every connector and board follows these) (1.1)
1. **One row per source.** Each source (and each device within Apple Health) keeps its own workout rows. The same run
   recorded by an Apple Watch and also held in the Strava archive is two rows. Exact repeats within one source (the same
   external id, or the same device, start and sport) are counted once and reported as duplicates.
2. **A board counts one row per real workout.** Rows from different sources (or devices) whose starts are within a
   tolerance (default 2 minutes), whose sports are the same and whose durations agree (default within 10% or 3 minutes)
   are one real workout; the board counts the row from the source highest in the person's source priority, keeps the
   others visible as "recorded too, not counted", and lists every match. Rows are never added or merged field by field.
   Two rows from the same source are never matched to each other this way. The matching is one-to-one: a row is matched
   to at most one row of each other source.
3. **Units at the door.** Distances are metres, durations seconds, energy kilocalories, heart rate bpm, whatever the
   source wrote (Strava's summary distance in km, Garmin's centimetres and milliseconds are converted on import).
   An impossible speed for the sport (checked at warn by `workouts_plausible`) means a unit was read wrong.
4. **Zones and laps are the source's.** `workout_zones` holds time in heart-rate zones only when the source measured it
   from heart-rate samples. A board that estimates zones (from a workout's average heart rate) keeps that in its own
   `d_` tables and says so on screen.
5. **The sport vocabulary is small on purpose** (`vocab/sports.csv`); `sport_raw` keeps the source's own type and
   `vocab/sport_map.csv` lists how each source's types map.
6. **Streams are summarised, never stored (1.3).** A reader that sees a workout's samples (a FIT, GPX or TCX activity
   file, Apple Health heart-rate and power samples) keeps only what they measured: per stream the covered seconds,
   average, maximum and weighted power (`workout_streams`), best efforts (`workout_efforts`) and seconds per bin
   (`workout_histograms`). No sample and no position (latitude, longitude) is ever written; distances from positions are
   worked out in memory. The clock is the workout's own: a gap between samples longer than the reader's `max_gap_s` is a
   pause and counts in no stream's seconds; inside an effort's window a pause counts as standing still (no power, no
   distance), so a pause can lower an effort but never raise it. Efforts and histograms belong to the row of the source
   whose file they came from (a Strava archive activity's own file stays with `strava:<id>`, never a second workout).

## The food and body rules (every connector and board follows these) (1.2)
1. **The diary date is the day.** A food day is the local date the person logged it for in the app (MyFitnessPal's and
   Cronometer's Date column, the local date of an Apple Health dietary sample's start). Time zones and daylight saving
   never move food to another day: the app already chose the date.
2. **An unlogged day has no row.** `nutrition` never holds a day of zeros for a day nothing was logged. A board treats a
   missing day as unknown, never as zero intake, and averages intake over logged days only.
3. **One source per day, never added.** MyFitnessPal's own export and the copy MyFitnessPal wrote to Apple Health are two
   rows for the same day; so are two apps writing to Apple Health. A board counts one row per day (the whole day from one
   source, never protein from one and energy from another) by the person's source priority and shows the others as
   "recorded too, not counted". Within one source, the same day read twice (two overlapping downloads) is kept once and
   counted as a duplicate.
4. **The day's first weigh-in.** `body` holds one row per local day, device and source: the first measurement of each
   kind that day (the morning weigh-in is the comparable one), with `n_samples` counting every measurement that day. Later
   weigh-ins are never averaged in. A board picks one source per day by the person's priority (a Withings scale's own
   export and the copy in Apple Health are the same weigh-in).
5. **Units at the door.** Weight in kilograms (pounds x 0.45359237, stone x 6.35029318), body fat as a share (21 % is
   0.21), waist in metres, energy in kilocalories (kilojoules / 4.184). A file whose unit cannot be read from its header or
   from the board's inputs stops the import; a value is never guessed into a unit. `nutrition_plausible` and
   `body_plausible` (warn) catch a unit read wrong.
6. **Food names and notes are not stored.** Only the day's totals: what was eaten stays in the person's app.

## Sources that fill it
| Source | Lane | Tables and columns it fills |
|---|---|---|
| Apple Health `export.zip` (Health app > your profile > Export All Health Data), `apple_health_export/export.xml` | 1 | `sleep_sessions` from `HKCategoryTypeIdentifierSleepAnalysis` (values InBed, Asleep, AsleepUnspecified, AsleepCore, AsleepDeep, AsleepREM, Awake), `daily_metrics` (rhr, hrv_sdnn, resp_rate, spo2, wrist_temp), `workouts` (`<Workout>`), `import_counts`. The file layout is not documented by Apple (community knowledge, checked 2026-11-29). |
| A folder of health@1 CSV files (`sleep_sessions.csv`, `daily_metrics.csv`, `workouts.csv`, optional `body.csv`, `workout_zones.csv`, `workout_laps.csv`) | 1 | the same columns, one CSV per table, header = column names |
| Strava archive (the person requests it in Strava's settings and downloads it): `activities.csv` (+ `activities/*.fit.gz`, `.gpx`, `.tcx` files) | 1 | `workouts` (one per activity; `external_id` = Activity ID, distance converted from km, `sport_raw` = Activity Type); from each activity's own file (1.3): `workout_streams`, `workout_efforts`, `workout_histograms` |
| Garmin Connect account export (Export Your Data, by email): `DI_CONNECT/DI-Connect-Fitness/*summarizedActivities.json` | 1 | `workouts`, `workout_zones` (hrTimeInZone). Layout from third-party parsers, UNVERIFIED: Garmin does not document it |
| FIT activity files (`.fit`, `.fit.gz`) | 1 | `workouts` from the session message, `workout_laps` from lap messages, `workout_zones` from heart-rate records; `workout_streams`, `workout_efforts`, `workout_histograms` from records (power, heart rate, speed, distance, cadence; positions never decoded) (1.3) |
| Apple Health, 1.2 (only for a board that asks for food and body) | 1 | `nutrition` from `HKQuantityTypeIdentifierDietaryEnergyConsumed`, `DietaryProtein`, `DietaryCarbohydrates`, `DietaryFatTotal`, `DietaryFiber` (summed per local day and app; kJ converted); `body` from `BodyMass`, `BodyFatPercentage`, `WaistCircumference` (first of the day per device; lb, %, cm, in converted) |
| MyFitnessPal export (Settings > Export Data; a zip of CSV files) | 1 | `nutrition` from `Nutrition-Summary-*.csv` (one row per diary date and meal, summed per date), `body` from `Measurement-Summary-*.csv` (the weight unit is not in the file: the board's inputs name it). Layout from community readers, UNVERIFIED |
| Cronometer export (Settings > Account > Export Data) | 1 | `nutrition` from `dailysummary.csv` (`Energy (kcal)` or `Energy (kJ)`, `Completed` when present), `body` from `biometrics.csv` (Metric Weight, Body Fat, Waist with their Unit) |
| Withings export (Download my data) | 1 | `body` from `weight.csv` (`Weight (kg)` or `Weight (lb)`, fat mass divided by weight for body fat; local date-times) |
| A weigh-ins CSV (`date,weight,unit`, or `weight_kg` / `weight_lb`; optional `time`, `body_fat`, `waist`) | 1 | `body` |
| NeverChill account export (1.4): the ZIP parts `account-export-part-NNN.zip` and `manifest-<id>.json`, read in place (never extracted) | 1 | `workouts` from `activities` (TSS as `load`, `sport_raw` = sport/sub_sport), `workout_streams` (power: average, maximum and NeverChill's normalized power as `weighted`; heart rate), `workout_efforts` from `activity_power_efforts` (else the ride's `power_curve`), `workout_zones` (heart rate, 5-zone models), `body` from `weight_logs`, `daily_metrics` (readiness, hrv_rmssd, rhr, spo2) from `health_readiness_days`, `sleep_sessions` from `health_sleep_sessions`. NeverChill's own concepts (its fitness model and freshness, durability, Rider DNA, plan, baselines) stay in the reading board's `x_neverchill_` tables |
| Oura API v2, WHOOP API v2, Google Health API (Fitbit) | 2 | not available at launch: documented stubs in `connectors/health/` (OAuth with the person's own app) |

Not used: the Fitbit Web API (turned down in late 2026), Oura personal access tokens (removed), Google Fit REST
(deprecated), the Strava API (its API agreement forbids using data obtained through the API in AI models, and an
assistant reading it could count as that; the archive the person downloads from Strava is their own copy of their own
data and goes through lane 1), and Garmin's Health and Activity APIs (partner programmes, not open to individuals).

## Compatibility
- A board that declares `health@1 >=1.0` keeps working on any later 1.x database.
- Remixes that add only metrics, pages and `x_<owner>_` tables survive every minor.
- Breaking changes go to `health@2` with a migration and `metrics-codemod.py` (see `../../README.md`, Semver).

## Fields

<!-- fields:begin (generated from schema.sql by spec/build.py; edit the DDL comments) -->

### `meta` (required table)

Key/value facts about this database. Required: schema, schema_version, as_of, data_hash. Recommended (checked at warn): source_built_at (ISO 8601 UTC instant the importer wrote it).

| Field | Type | Required | Meaning |
|---|---|---|---|
| `key` | TEXT | no |  |
| `value` | TEXT | no |  |

### `metric_codes` (required table)

The metric codes this database uses, copied from vocab/metric_codes.csv (the controlled list), so metrics can read units and aggregation rules with a join. HRV is two codes that are never mixed: hrv_sdnn (Apple) and hrv_rmssd (Oura, WHOOP).

| Field | Type | Required | Meaning |
|---|---|---|---|
| `code` | TEXT (vocab `metric_codes`) | **yes** | e.g. rhr, hrv_sdnn, hrv_rmssd, resp_rate, spo2, wrist_temp, steps |
| `name` | TEXT | **yes** | display name, e.g. Resting heart rate |
| `unit` | TEXT (vocab `units`) | **yes** | the unit every value of this code is stored in: bpm \| ms \| breaths_min \| share \| degC \| count \| kcal \| s \| kg \| ml_kg_min |
| `agg` | TEXT | **yes** | how samples within one day become the day's value: sum \| avg \| last \| min \| max |
| `sources` | TEXT | no | source identifiers that map to this code, separated by spaces (HKQuantityTypeIdentifierRestingHeartRate ...) |

### `daily_metrics` (required table)

One metric value per local day, code and device. A board's source priority picks one device per day and code.

| Field | Type | Required | Meaning |
|---|---|---|---|
| `date` | TEXT (date) | **yes** | the local calendar date the samples were taken (YYYY-MM-DD) |
| `code` | TEXT (vocab `metric_codes`) | **yes** | metric code (vocab metric_codes) |
| `value` | REAL | **yes** | in metric_codes.unit, after the code's agg over that day's samples |
| `unit` | TEXT | no | the unit, repeated for readers that do not join metric_codes |
| `device` | TEXT | **yes** | the device or app that measured it, as the source names it (Sam's Apple Watch, Oura); '' when unknown |
| `n_samples` | INTEGER | no | how many source samples made the value (1 for a source that reports daily values) |
| `source` | TEXT (vocab `sources`) | **yes** | connector id that wrote the row (vocab sources): apple-health \| health-csv \| oura \| whoop ... |
| `source_ref` | TEXT | no | where it came from: the file (and record type), or the API object id |
| `imported_at` | TEXT (instant) | no | ISO 8601 UTC instant of the import (left out of meta.data_hash) |

### `sleep_sessions` (required table)

One sleep as one device recorded it: the night's main sleep, or a nap. Stage seconds are measured on a timeline in which overlapping samples from the same device are merged (an interval union), never added: asleep_s = light_s + deep_s + rem_s + asleep_unspecified_s, and in_bed_s >= asleep_s. night_of is the local date of the evening the night began: a sleep belongs to the noon-to-noon window it starts in, in local time.

| Field | Type | Required | Meaning |
|---|---|---|---|
| `sleep_id` | TEXT | **yes** | the source's id when it has one, else sha1 of source\|device\|night_of\|is_nap\|start_utc (first 16 hex) |
| `start_utc` | TEXT (instant) | **yes** | first moment in bed or asleep (ISO 8601 UTC) |
| `end_utc` | TEXT (instant) | **yes** | last moment in bed or asleep (ISO 8601 UTC) |
| `tz` | TEXT | **yes** | the local time zone: an IANA name (Europe/London), or a fixed offset (+01:00) when the source gives only an offset |
| `start_local` | TEXT | no | local wall-clock time it started (YYYY-MM-DDTHH:MM:SS, no zone), for bedtimes |
| `end_local` | TEXT | no | local wall-clock time it ended (YYYY-MM-DDTHH:MM:SS), for wake times; across a DST change the two zones differ |
| `night_of` | TEXT (date) | **yes** | the local date of the evening the sleep belongs to (noon-to-noon window) |
| `in_bed_s` | INTEGER | no | seconds in bed: the union of every in-bed, asleep and awake interval of this device |
| `asleep_s` | INTEGER | no | seconds asleep (any stage); NULL when the device only knows in bed |
| `awake_s` | INTEGER | no | seconds awake in bed (in_bed_s - asleep_s) |
| `light_s` | INTEGER | no | light sleep seconds (Apple calls it Core) |
| `deep_s` | INTEGER | no | deep sleep seconds |
| `rem_s` | INTEGER | no | REM sleep seconds |
| `asleep_unspecified_s` | INTEGER | no | asleep seconds with no stage (older devices and apps, Apple before iOS 16) |
| `latency_s` | INTEGER | no | seconds from getting into bed to first sleep, when the device knows both |
| `efficiency` | REAL | no | asleep_s / in_bed_s (0..1) |
| `hr_min` | REAL | no | lowest heart rate during the sleep, bpm |
| `hrv_sdnn_ms` | REAL | no | average HRV as SDNN during the sleep, ms (Apple); never an RMSSD value |
| `hrv_rmssd_ms` | REAL | no | average HRV as RMSSD during the sleep, ms (Oura, WHOOP); never an SDNN value |
| `rhr` | REAL | no | resting heart rate the device gave for this sleep, bpm |
| `resp_rate` | REAL | no | average breaths per minute during the sleep |
| `score` | REAL | no | the device's own sleep score (0..100) when it gives one; boards never compute it |
| `is_nap` | INTEGER | **yes** | 1 for a nap (a short daytime sleep apart from the night's main sleep) |
| `n_segments` | INTEGER | no | how many source samples made the session (Apple sleep records) |
| `device` | TEXT | **yes** | the device or app that recorded it, as the source names it |
| `source` | TEXT (vocab `sources`) | **yes** | connector id (vocab sources) |
| `source_ref` | TEXT | no | where it came from: file (and record type), or file:line, or API id |
| `imported_at` | TEXT (instant) | no | ISO 8601 UTC instant of the import (left out of meta.data_hash) |

### `workouts` (required table)

One workout as one source recorded it. Training Log reads this table; Sleep & Recovery uses it to compare nights after workout days. The same real workout often arrives from two sources (an Apple Watch run that Strava also holds): every source keeps its own row, and a board counts one row per real workout by the person's source priority (the workout rules in README.md). Rows from two sources are never added or merged field by field.

| Field | Type | Required | Meaning |
|---|---|---|---|
| `workout_id` | TEXT | **yes** | the source's id, else sha1 of source\|device\|start_utc\|sport (first 16 hex) |
| `start_utc` | TEXT (instant) | **yes** | ISO 8601 UTC |
| `end_utc` | TEXT (instant) | no | ISO 8601 UTC |
| `tz` | TEXT | **yes** | IANA name or fixed offset, as sleep_sessions.tz |
| `date` | TEXT (date) | no | local date it started (YYYY-MM-DD) |
| `sport` | TEXT (vocab `sports`) | **yes** | run \| ride \| swim \| walk \| hike \| strength \| yoga \| row \| ski \| other (vocab sports) |
| `duration_s` | INTEGER | **yes** | elapsed seconds |
| `moving_s` | INTEGER | no | moving seconds when the source gives them |
| `distance_m` | REAL | no | metres |
| `elev_gain_m` | REAL | no | metres climbed |
| `kcal` | REAL | no | active kilocalories |
| `avg_hr` | REAL | no | bpm |
| `max_hr` | REAL | no | bpm |
| `load` | REAL | no | training load (TRIMP or the source's own), unitless |
| `rpe` | REAL | no | perceived effort 1..10 |
| `name` | TEXT | no | the source's title |
| `gear` | TEXT | no | shoes, bike |
| `is_race` | INTEGER | no | 1 for a race |
| `route_ref` | TEXT | no | path to a GPX/FIT file for the route (never embedded) |
| `external_id` | TEXT | no | the source's own activity id (Strava Activity ID, Garmin activityId, a FIT file's serial + time) (1.1) |
| `sport_raw` | TEXT | no | the source's activity type as written (Running, Run, running, Weight Training) (1.1) |
| `indoor` | INTEGER | no | 1 indoors (treadmill, trainer, pool), 0 outdoors, NULL unknown (1.1) |
| `laps_n` | INTEGER | no | laps the source recorded (1.1) |
| `device` | TEXT | **yes** | the device or app that recorded it |
| `source` | TEXT (vocab `sources`) | **yes** | connector id (vocab sources) |
| `source_ref` | TEXT | no | where it came from |
| `imported_at` | TEXT (instant) | no | ISO 8601 UTC instant of the import |

### `workout_zones`

Optional (1.1): seconds in each heart-rate zone of one workout, as the source measured them from its own heart-rate samples (a Garmin summary, a FIT file's records). Zones are numbered 1 (easiest) to 5. A board that works zones out itself (from avg_hr) keeps that in its own d_ tables, never here.

| Field | Type | Required | Meaning |
|---|---|---|---|
| `workout_id` | TEXT | **yes** | workouts.workout_id |
| `zone` | INTEGER | **yes** | 1..5 |
| `seconds` | INTEGER | **yes** | seconds in this zone |
| `lo_bpm` | REAL | no | the zone's lower bound in bpm, when the source says |
| `hi_bpm` | REAL | no | the zone's upper bound in bpm, when the source says |
| `source` | TEXT (vocab `sources`) | **yes** | connector id (vocab sources) |
| `source_ref` | TEXT | no | where it came from |
| `imported_at` | TEXT (instant) | no | ISO 8601 UTC instant of the import |

### `workout_laps`

Optional (1.1): the laps (or splits) of one workout, when the source records them.

| Field | Type | Required | Meaning |
|---|---|---|---|
| `workout_id` | TEXT | **yes** | workouts.workout_id |
| `lap_n` | INTEGER | **yes** | 1, 2, ... in order |
| `start_utc` | TEXT (instant) | no | ISO 8601 UTC |
| `duration_s` | INTEGER | **yes** | elapsed seconds of the lap |
| `distance_m` | REAL | no | metres |
| `avg_hr` | REAL | no | bpm |
| `max_hr` | REAL | no | bpm |
| `elev_gain_m` | REAL | no | metres climbed |
| `source` | TEXT (vocab `sources`) | **yes** | connector id (vocab sources) |
| `source_ref` | TEXT | no | where it came from |
| `imported_at` | TEXT (instant) | no | ISO 8601 UTC instant of the import |

### `workout_streams`

Optional (1.3): what one stream of a workout's samples measured (power, heart rate, speed or cadence, second by second, from a FIT, GPX or TCX activity file or from Apple Health samples), summarised. The samples themselves are never stored, and neither is any position: a reader works distances out in memory and keeps only these summaries (workout rule 6). Time is measured on the workout's own clock: a gap between samples longer than the reader's max gap is a pause, counted in no stream's seconds.

| Field | Type | Required | Meaning |
|---|---|---|---|
| `workout_id` | TEXT | **yes** | workouts.workout_id |
| `stream` | TEXT (vocab `streams`) | **yes** | power \| heart_rate \| speed \| cadence (vocab streams) |
| `seconds` | INTEGER | no | seconds of the workout covered by samples (pauses left out); NULL when the source gave only a summary |
| `avg` | REAL | no | time-weighted average over those seconds, in the stream's unit (W, bpm, m/s, rpm) |
| `max` | REAL | no | highest sample, in the stream's unit |
| `weighted` | REAL | no | power only: the 4th root of the mean of the 30-second rolling average to the 4th power (W); NULL for other streams |
| `max_gap_s` | INTEGER | no | the longest gap between samples the reader held a value across (longer gaps are pauses) |
| `source` | TEXT (vocab `sources`) | **yes** | connector id (vocab sources) |
| `source_ref` | TEXT | no | where it came from (the activity file) |
| `imported_at` | TEXT (instant) | no | ISO 8601 UTC instant of the import |

### `workout_efforts`

Optional (1.3): a workout's best efforts, worked out from its streams by the reader: the highest average power, speed or heart rate held for `span` seconds, and the fewest seconds needed to cover `span` metres. The window runs on the elapsed clock: a pause inside it counts as standing still (no power, no distance), so a pause never improves an effort.

| Field | Type | Required | Meaning |
|---|---|---|---|
| `workout_id` | TEXT | **yes** | workouts.workout_id |
| `measure` | TEXT (vocab `effort_measures`) | **yes** | power \| speed \| heart_rate (best average over span seconds) \| time (fewest seconds over span metres) (vocab effort_measures) |
| `span` | REAL | **yes** | seconds (power, speed, heart_rate) or metres (time), e.g. 1200 or 5000 |
| `value` | REAL | **yes** | W (power), m/s (speed), bpm (heart_rate) or seconds (time) |
| `offset_s` | INTEGER | no | seconds from the workout's start to the start of the effort |
| `source` | TEXT (vocab `sources`) | **yes** | connector id (vocab sources) |
| `source_ref` | TEXT | no | where it came from (the activity file) |
| `imported_at` | TEXT (instant) | no | ISO 8601 UTC instant of the import |

### `workout_histograms`

Optional (1.3): seconds a workout spent in each bin of one stream (power in 5 W bins, heart rate in 1 bpm bins, speed in 0.1 m/s bins, or wider bins a source chose), so a board can count time in zones of any threshold without the samples. A bin holds lo <= value < lo + width. A workout's seconds over all bins of a stream equal workout_streams.seconds.

| Field | Type | Required | Meaning |
|---|---|---|---|
| `workout_id` | TEXT | **yes** | workouts.workout_id |
| `stream` | TEXT (vocab `streams`) | **yes** | power \| heart_rate \| speed \| cadence (vocab streams) |
| `lo` | REAL | **yes** | the bin's lower bound, in the stream's unit |
| `width` | REAL | **yes** | the bin's width, in the stream's unit (> 0) |
| `seconds` | INTEGER | **yes** | seconds in this bin |
| `source` | TEXT (vocab `sources`) | **yes** | connector id (vocab sources) |
| `source_ref` | TEXT | no | where it came from (the activity file) |
| `imported_at` | TEXT (instant) | no | ISO 8601 UTC instant of the import |

### `body`

Optional body measurements: one row per local day, device and source. The row holds the day's FIRST measurement of each kind (the morning weigh-in is the comparable one); later measurements that day are counted in n_samples, never averaged or added. Stored in kilograms, shares and metres whatever the scale or app showed (lb, st, %, cm, in converted on import).

| Field | Type | Required | Meaning |
|---|---|---|---|
| `date` | TEXT (date) | **yes** | local date (YYYY-MM-DD) |
| `weight_kg` | REAL | no | kilograms |
| `body_fat` | REAL | no | share (0.21) |
| `waist_m` | REAL | no | metres |
| `device` | TEXT | **yes** | scale or app |
| `source` | TEXT (vocab `sources`) | **yes** | connector id |
| `source_ref` | TEXT | no | where it came from |
| `imported_at` | TEXT | no | ISO 8601 UTC instant of the import |
| `measured_at` | TEXT (instant) | no | 1.2: ISO 8601 UTC instant of the day's first measurement, when the source gives a time |
| `n_samples` | INTEGER | no | 1.2: measurements this device and source took that day (the row holds the first of each kind) |

### `nutrition`

1.2, optional: food eaten, one row per local day, device (the app) and source. A day's totals as the app logged them for that diary date. A day with nothing logged has NO row (never a row of zeros): an unlogged day is unknown, not zero intake. Two apps or files holding the same day (MyFitnessPal's own export and the copy it wrote to Apple Health) give two rows; a board counts one per day by the person's source priority and never adds them. Food names and notes are never stored.

| Field | Type | Required | Meaning |
|---|---|---|---|
| `date` | TEXT (date) | **yes** | the diary date (local YYYY-MM-DD) the food was logged for |
| `kcal` | REAL | no | energy eaten, kilocalories (kilojoules / 4.184 on import) |
| `protein_g` | REAL | no | protein, grams |
| `carbs_g` | REAL | no | carbohydrates (total, not net), grams |
| `fat_g` | REAL | no | fat (total), grams |
| `fiber_g` | REAL | no | fibre, grams |
| `n_entries` | INTEGER | **yes** | source rows or records that made the day (meals, servings, daily rows, Apple dietary samples) |
| `completed` | INTEGER | no | 1 when the person marked the diary day complete in the app, 0 when the app says not complete, NULL when the app has no such flag |
| `device` | TEXT | **yes** | the app that logged it (MyFitnessPal, Cronometer; for Apple Health the app that wrote the samples) |
| `source` | TEXT (vocab `sources`) | **yes** | connector id (vocab sources): myfitnesspal \| cronometer \| apple-health \| health-csv ... |
| `source_ref` | TEXT | no | where it came from: the file (and record type) |
| `imported_at` | TEXT (instant) | no | ISO 8601 UTC instant of the import |

### `import_counts`

Source accounting: for every input file and record type, how many rows or records were read and what happened to each. n_read = n_used + n_duplicate + n_skipped + n_out_of_scope always. raw_sum is the sum over every record read of its value (quantities) or its seconds (sleep), so an independent reader can confirm nothing vanished.

| Field | Type | Required | Meaning |
|---|---|---|---|
| `file` | TEXT | **yes** | the input file as written in the board's inputs (data/files/export.zip) |
| `record_type` | TEXT | **yes** | HKCategoryTypeIdentifierSleepAnalysis, a CSV file's table, ... |
| `source` | TEXT (vocab `sources`) | **yes** | connector id (vocab sources) |
| `n_read` | INTEGER | **yes** | records or rows read |
| `n_used` | INTEGER | **yes** | that went into a row of this database |
| `n_duplicate` | INTEGER | **yes** | exact repeats of a record already read (same type, device, times and value) |
| `n_skipped` | INTEGER | **yes** | that could not be read (a bad date, value or unit): counted, never guessed |
| `n_out_of_scope` | INTEGER | **yes** | of a type this importer does not use |
| `raw_sum` | REAL | no | sum of value (quantity records) or seconds (sleep records) over all n_read |

### `data_issues`

What the importer could not read or decided: skipped records, unknown values, gaps, files it could not open.

| Field | Type | Required | Meaning |
|---|---|---|---|
| `issue_id` | TEXT | **yes** | stable id |
| `severity` | TEXT (vocab `severities`) | **yes** | info \| warn \| error (vocab severities) |
| `kind` | TEXT | **yes** | rows_skipped \| unknown_value \| unknown_unit \| duplicates \| file \| ... |
| `title` | TEXT | **yes** | one line |
| `detail` | TEXT | **yes** | what and where (file, record type), never a value from the person's data |
| `source_ref` | TEXT | no | file, or file:line |
| `handling` | TEXT | **yes** | what the importer did about it |

### `annotations`

Notes on metrics and pages (platform table). Numbers only through {{metric:...}} placeholders.

| Field | Type | Required | Meaning |
|---|---|---|---|
| `annotation_id` | TEXT | **yes** | stable id |
| `target` | TEXT | **yes** | metric id or page id |
| `kind` | TEXT | **yes** | note \| caveat \| flag \| decision \| open_item |
| `body` | TEXT | **yes** | the note text |
| `author` | TEXT | no | person or assistant |
| `source_ref` | TEXT | no | where it came from |
| `created_at` | TEXT | no | ISO 8601 instant |
| `data_hash` | TEXT | no | hash of the cited metric values when written (stale when they change) |
| `status` | TEXT | no | active \| stale \| retired |

### `metric_registry`

| Field | Type | Required | Meaning |
|---|---|---|---|
| `metric_id` | TEXT | **yes** | e.g. sleep.nightly |
| `version` | INTEGER | no | the metric's own version |
| `unit` | TEXT | no | rows \| pct \| count \| hours ... |
| `params` | TEXT | no | comma list of parameters it honours |
| `description` | TEXT | no | the @desc line |
| `sql` | TEXT | no | expanded SQL |
| `test` | TEXT | no | the @test line (check that covers it) |

<!-- fields:end -->

## Vocabularies
- `metric_codes.csv`: the metric codes, their unit, how a day's samples combine (`agg`) and the source identifiers that
  map to each (Apple `HKQuantityTypeIdentifier...`; Oura and WHOOP field names for future lane-2 connectors, unverified).
- `sleep_stages.csv`: the sleep stages and the Apple sleep-analysis values that map to each.
- `sports.csv`: workout sports.
- `sport_map.csv` (1.1): each source's own activity types (Apple `HKWorkoutActivityType...` without the prefix, Strava
  archive labels, Garmin export type keys, FIT sport or sport/sub_sport), the sport they map to and whether they are
  indoors. Types not listed are `other`. The Strava and Garmin labels are UNVERIFIED (community readers, not the
  services' documentation).
- `sources.csv`: connector ids and their lane (1.2 adds `myfitnesspal`, `cronometer`, `withings`, `weigh-ins-csv`).
- `units.csv`: the stored units.
- `severities.csv`: data issue severities.

## Conformance checks
See `checks.yaml`. `dashremix spec check <db> health@1` runs them after the DDL diff, the meta keys and the JSON Schema.
