Skip to content

Export the four ring metrics that stopped short of Apple Health - #122

Open
ak710 wants to merge 1 commit into
saksham2001:mainfrom
ak710:feat/healthkit-export-completion
Open

Export the four ring metrics that stopped short of Apple Health#122
ak710 wants to merge 1 commit into
saksham2001:mainfrom
ak710:feat/healthkit-export-completion

Conversation

@ak710

@ak710 ak710 commented Aug 3, 2026

Copy link
Copy Markdown

Closes #113

Merge order: 3 of 9. Branches off main, independent of #120 and #121.

What

Respiratory rate, VO₂max and blood glucose join the quantity path with the units HealthKit expects and the same plausibility bounds RingEventBridge already applies on the way into the store.

Blood pressure gets its own pass, because Health only recognises a reading when systolic and diastolic are saved together in an HKCorrelation — saved separately they are stored but never surface, which is indistinguishable from a silent failure.

Design notes

  • The two BP halves are written from one packet at one instant, so that shared timestamp is the pairing key. A half without its partner is skipped rather than guessed at, and a pair with systolic ≤ diastolic is rejected as a misframed packet.
  • The BP watermark reuses the bloodPressureSystolic slot in measurementWatermarks, which the quantity path never touches — so backfill and resetWatermarks keep working unchanged.
  • Stress and fatigue stay unmapped, and the comment now says why properly. This isn't a follow-up: HealthKit has no type for a device-derived wellness score, and HKStateOfMind is a self-reported mood log that would misrepresent both. One existing test asserted these mapped to nil and needed updating for glucose — I left the two that are genuinely permanent.
  • New toggles appear only for rings that can produce the metric, or that already have data for it. A jring owner never sees a VO₂max switch that couldn't write anything.

Testing

PulseLoopTests/HealthSyncNewTypesTests.swift — 11 tests on units, bounds, BP pairing and sync-ID stability. Full suite green (882).

Not verifiable in CI beyond the pure mappings — HKHealthStore isn't reachable from the test bundle, which is why this file follows the existing HealthSyncTests convention of testing the mapping tables only.

Respiratory rate, VO2max, blood glucose and blood pressure were all decoded,
stored and displayed in-app, but the export path mapped every one of them to
nil. Three were a genuine follow-up; blood pressure needed a different shape
entirely.

Respiratory rate, VO2max and glucose join the quantity path with the units
HealthKit expects (count/min, mL/(kg*min), mg/dL) and the same plausibility
bounds RingEventBridge already applies on the way into the store.

Blood pressure gets its own pass, because Health only recognises a reading when
systolic and diastolic are saved together in an HKCorrelation — saved separately
they are stored but never surface in the Health app, which is indistinguishable
from a silent failure. The two halves are written from one packet at one
instant, so that shared timestamp is the pairing key; a half without its partner
is skipped rather than guessed at, and a pair with systolic at or below
diastolic is rejected as a misframed packet. Its watermark reuses the
bloodPressureSystolic slot, which the quantity path never touches, so backfill
and reset keep working unchanged.

Stress and fatigue stay unmapped, and the comment now says why properly: this
isn't a follow-up, HealthKit has no type for a device-derived wellness score.
HKStateOfMind is a self-reported mood log and would misrepresent both.

The four new toggles only appear for rings that can produce the metric — or that
already have — since respiratory rate and VO2max come only from the YCBT
records and glucose and BP only from jring and some YCBT units. A jring owner
never sees a VO2max switch that could not write anything.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature]: Four tracked metrics never reach Apple Health

1 participant