Repository navigation
Pairing 6/6: compare daily and workout capabilities #696
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
abdulsaheel
merged 56 commits into
OpenStrap:main
from
mikenrafter:split/669-comparison
Nov 14, 2026
Merged
Changes from all commits
Commits
Show all changes
56 commits
Select commit
Hold shift + click to select a range
e2826e7
feat(pairing): offer only supported main bands on first run
mikenrafter c1057ac
feat(pairing): show device capabilities by daily and workout use
mikenrafter 5d5d966
merge main
abdulsaheel a700ad3
first run: the whoop description only shows under whoop rows
abdulsaheel a65fe39
merge main
abdulsaheel 9959734
my sources: no-band card says what that costs, one import for pair_te…
abdulsaheel b7cfe7d
merge main
abdulsaheel a6ac04f
merge main
abdulsaheel dc101ed
merge main
abdulsaheel bb76e29
merge main
abdulsaheel 547d368
Merge branch 'split/669-add-device' into split/669-first-run
mikenrafter b7e4595
Merge branch 'split/669-add-device' into split/669-first-run
mikenrafter 6373435
Merge branch 'split/669-first-run' into split/669-comparison
mikenrafter 1b2dd42
Merge branch 'split/669-first-run' into split/669-comparison
mikenrafter a3ba119
Distinguish generation comparisons from default assignments
mikenrafter 5f5c84c
Scroll pairing-sheet controls into view in flow tests
mikenrafter 8ef1c1e
Scroll first-run skip into view in its widget test
mikenrafter 9f95b8d
Merge branch 'split/669-add-device' into split/669-first-run
mikenrafter 66d7a10
Merge branch 'split/669-first-run' into split/669-comparison
mikenrafter 3ac5229
Merge branch 'split/669-add-device' into split/669-first-run
mikenrafter 437c438
Exercise the scan race from the sensor picker
mikenrafter 7b2f654
Merge branch 'split/669-first-run' into split/669-comparison
mikenrafter d66387b
Keep provisional and unknown device capabilities explicit
mikenrafter b1e0e13
merge split/669-add-device
abdulsaheel 866588b
merge split/669-first-run
abdulsaheel 38dc1e1
Merge branch 'split/669-add-device' into split/669-first-run
mikenrafter 1639192
Merge branch 'split/669-add-device' into split/669-first-run
mikenrafter 81f3691
Merge branch 'split/669-first-run' into split/669-comparison
mikenrafter c39cc36
Merge branch 'split/669-add-device' into split/669-first-run
mikenrafter b666726
Merge branch 'split/669-first-run' into split/669-comparison
mikenrafter afb1f98
Merge branch 'split/669-add-device' into split/669-first-run
mikenrafter 9504152
Merge branch 'split/669-first-run' into split/669-comparison
mikenrafter f74044a
merge split/669-add-device
abdulsaheel c7fd1d0
merge split/669-first-run
abdulsaheel 00ded4e
merge split/669-add-device
abdulsaheel 7394444
merge main
abdulsaheel 83d6a51
replacement and forget: refuse a candidate that is already a sensor, …
abdulsaheel 7a2b585
merge split/669-first-run
abdulsaheel 8763ef4
choice sheet safe-area test: pass the comparison this branch's sheet …
abdulsaheel fa22807
merge split/669-add-device
abdulsaheel 9d8c9e4
merge main
abdulsaheel bf7bfa4
replacement: refuse a sensor candidate inside the guarded section, dr…
abdulsaheel f8d39fa
merge split/669-first-run
abdulsaheel 7e01587
merge split/669-add-device
abdulsaheel a8fcf35
merge split/669-first-run
abdulsaheel e87a4b4
merge split/669-add-device
abdulsaheel 8b4c02b
merge split/669-first-run
abdulsaheel e0147f3
merge split/669-add-device
abdulsaheel 808d044
merge split/669-first-run
abdulsaheel 7c5796d
merge main
abdulsaheel 3857ea8
alarm arms: drop a pending arm for a band that is no longer paired, r…
abdulsaheel e489855
merge split/669-first-run
abdulsaheel d2c24a4
merge main
abdulsaheel 519fbca
pairing: stop replacing when the old sync burst outlives the wait, ke…
abdulsaheel 5b42dde
merge main
abdulsaheel 41e4719
merge split/669-first-run
abdulsaheel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,345 @@ | ||
| // What a device gives in each of the two columns the pairing screens draw: | ||
| // "Every day" (the main band, or the active wearable that fills the days the | ||
| // band left empty) and "Workouts only" (a workout-armed sensor). Capabilities | ||
| // come from the compute layer's eligibility rules, never from raw-signal | ||
| // membership. | ||
| import '../compute/inputs/canonical.dart' | ||
| show Cell, MetricClass, capabilities, columnFor, kWorkoutArmedSensors; | ||
| import 'adapters/_registry.dart'; | ||
|
|
||
| /// The two columns. A WHOOP fills [everyDay] as the main band; a ring or a | ||
| /// watch fills it as the active wearable (canonical.dart `activeWearable`, | ||
| /// `wearableSubstrate`); a workout-armed sensor fills [workoutsOnly]. | ||
| enum DeviceSlot { everyDay, workoutsOnly } | ||
|
|
||
| enum DeviceCapability { | ||
| sleep, | ||
| recovery, | ||
| strain, | ||
|
|
||
| /// Heart rate and resting heart rate (the column's `resting_hr` row). | ||
| heartRate, | ||
| hrv, | ||
| respiration, | ||
| skinTemperature, | ||
| steps, | ||
| bloodOxygen, | ||
| workoutHeartRate, | ||
| workoutBeatToBeat, | ||
| } | ||
|
|
||
| /// How a capability is delivered. | ||
| /// native: this app computes it. conditional: only when [CapabilityStatus.reasonKey] | ||
| /// holds (an l10n-able key). vendorReported: the device's own number, shown as | ||
| /// the device's (never passed off as native). | ||
| enum CapabilityKind { native, conditional, vendorReported } | ||
|
|
||
| class CapabilityStatus { | ||
| final CapabilityKind kind; | ||
|
|
||
| /// Required (nonblank) when [kind] is conditional, else null. | ||
| final String? reasonKey; | ||
| const CapabilityStatus(this.kind, {this.reasonKey}); | ||
| } | ||
|
|
||
| class SlotSide { | ||
| final Map<DeviceCapability, CapabilityStatus> sends; | ||
|
|
||
| /// The table's rows ([kTableRows]) this side does not send. | ||
| final Set<DeviceCapability> doesNotSend; | ||
| const SlotSide({required this.sends, required this.doesNotSend}); | ||
| } | ||
|
|
||
| class SlotComparison { | ||
| /// What the entry gives every day: as the main band (a WHOOP) or as the | ||
| /// active wearable (a columned ring or watch). Empty for a chest strap. | ||
| final SlotSide everyDay; | ||
|
|
||
| /// What the entry gives during workouts as a workout-armed sensor (a WHOOP | ||
| /// kept for workouts is read as one). Empty for a ring. | ||
| final SlotSide workoutsOnly; | ||
|
|
||
| /// The column the device goes into, or null when it fits neither (a Coros | ||
| /// watch, a scale). | ||
| final DeviceSlot? slot; | ||
| const SlotComparison( | ||
| {required this.everyDay, required this.workoutsOnly, this.slot}); | ||
|
|
||
| SlotSide side(DeviceSlot s) => switch (s) { | ||
| DeviceSlot.everyDay => everyDay, | ||
| DeviceSlot.workoutsOnly => workoutsOnly, | ||
| }; | ||
| } | ||
|
|
||
| /// The whole-day rows of the table, in the order they are drawn. | ||
| const List<DeviceCapability> kDayCapabilities = <DeviceCapability>[ | ||
| DeviceCapability.sleep, | ||
| DeviceCapability.recovery, | ||
| DeviceCapability.strain, | ||
| DeviceCapability.heartRate, | ||
| DeviceCapability.hrv, | ||
| DeviceCapability.respiration, | ||
| DeviceCapability.skinTemperature, | ||
| DeviceCapability.steps, | ||
| ]; | ||
|
|
||
| /// Capabilities decided per workout session, not per day: the band records a | ||
| /// workout itself; a sensor only through the sensor path | ||
| /// (`kWorkoutArmedSensors`, canonical.dart; `HrsLink.deriveTier`). | ||
| const Set<DeviceCapability> kSessionCapabilities = <DeviceCapability>{ | ||
| DeviceCapability.workoutHeartRate, | ||
| DeviceCapability.workoutBeatToBeat, | ||
| }; | ||
|
|
||
| /// Every row the table draws: the whole-day rows, then the workout rows. | ||
| /// Blood oxygen is never one of them. | ||
| const List<DeviceCapability> kTableRows = <DeviceCapability>[ | ||
| ...kDayCapabilities, | ||
| DeviceCapability.workoutHeartRate, | ||
| DeviceCapability.workoutBeatToBeat, | ||
| ]; | ||
|
|
||
| /// THE mapping from a whole-day capability to its row in the compute layer's | ||
| /// metric x device columns (`columnFor`, compute/inputs/canonical.dart). A | ||
| /// capability's status for a wearable is read off `capabilities(column)[row]`. | ||
| const Map<DeviceCapability, String> kCapabilityRow = <DeviceCapability, String>{ | ||
| DeviceCapability.sleep: 'sleep_window', | ||
| DeviceCapability.recovery: 'readiness', | ||
| DeviceCapability.strain: 'strain', | ||
| DeviceCapability.heartRate: 'resting_hr', | ||
| DeviceCapability.hrv: 'hrv', | ||
| DeviceCapability.respiration: 'respiratory_rate', | ||
| DeviceCapability.skinTemperature: 'skin_temp', | ||
| DeviceCapability.steps: 'steps', | ||
| }; | ||
|
|
||
| // Blood oxygen is never claimed by a pairing comparison, for any device: the | ||
| // app refuses its own SpO2 (onehz_pipeline.dart kSpo2Refusal), and a vendor's | ||
| // reading is not a promise made at pairing. It is not in [kCapabilityRow]. | ||
| // (The enum value and its label stay so the absence can be asserted.) | ||
|
|
||
| /// Where a claimed capability comes from: [rule] names the eligibility rule, | ||
| /// [source] is the repo file that holds it. | ||
| typedef CapabilityTrace = ({String rule, String source}); | ||
|
|
||
| /// l10n keys (lib/l10n/app_*.arb) of the one-line captions a conditional | ||
| /// capability carries. | ||
| const String kReasonSkinTempNights = 'capReasonSkinTempNights'; | ||
|
|
||
| // Ring settle bands use synthetic nights (oura_inputs.dart), so waiting | ||
| // for the minimum nights does not remove their provisional status. | ||
| const String kReasonSkinTempProvisional = 'capReasonSkinTempProvisional'; | ||
| const String kReasonEstimated = 'capReasonEstimated'; | ||
| const String kReasonEarly = 'capReasonEarly'; | ||
|
|
||
| /// A wearable's readiness is provisional until its inputs have 14 nights of | ||
| /// baseline (oura_inputs.dart `readiness`, onehz_pipeline.dart | ||
| /// kSkinTempDevMinNights). | ||
| const String kReasonFirstNights = 'capReasonFirstNights'; | ||
|
|
||
| /// A wearable's sleep window is ours, its stages the device's own | ||
| /// (`sleep_stages` is a device-only row). | ||
| const String kReasonOwnStagesRing = 'capReasonOwnStagesRing'; | ||
| const String kReasonOwnStages = 'capReasonOwnStages'; | ||
|
|
||
| /// WHOOP 4 has no step counter: its steps come from the strap's 100 Hz | ||
| /// pedometer over a live link only (live_step_runs.dart). | ||
| const String kReasonLiveSessions = 'capReasonLiveSessions'; | ||
|
|
||
| /// A row that depends on whether the device sends it, where nobody has | ||
| /// confirmed it does: RR intervals are optional in the Heart Rate Service, so | ||
| /// a generic strap's (or a WHOOP read as one) beat timing is unconfirmed. A | ||
| /// device people use and send it (Polar's PPI stream) carries no caption. | ||
| const String kReasonUnconfirmed = 'capReasonUnconfirmed'; | ||
|
|
||
| /// Pebble 2 SE has no HR sensor; only Pebble 2 can supply HR-based rows. | ||
| const String kReasonPebble2Only = 'capReasonPebble2Only'; | ||
|
|
||
| /// [kReasonPebble2Only] on a row that is also an estimate on Pebble 2. | ||
| const String kReasonPebble2OnlyEstimated = 'capReasonPebble2OnlyEstimated'; | ||
|
|
||
| /// l10n key of each capability's user-facing name. | ||
| const Map<DeviceCapability, String> kCapabilityLabelKey = <DeviceCapability, String>{ | ||
| DeviceCapability.sleep: 'capLabelSleep', | ||
| DeviceCapability.recovery: 'capLabelRecovery', | ||
| DeviceCapability.strain: 'capLabelStrain', | ||
| DeviceCapability.heartRate: 'capLabelHeartRate', | ||
| DeviceCapability.hrv: 'capLabelHrv', | ||
| DeviceCapability.respiration: 'capLabelRespiration', | ||
| DeviceCapability.skinTemperature: 'capLabelSkinTemperature', | ||
| DeviceCapability.steps: 'capLabelSteps', | ||
| DeviceCapability.bloodOxygen: 'capLabelBloodOxygen', | ||
| DeviceCapability.workoutHeartRate: 'capLabelWorkoutHeartRate', | ||
| DeviceCapability.workoutBeatToBeat: 'capLabelWorkoutBeatToBeat', | ||
| }; | ||
|
|
||
| typedef _Claim = ({CapabilityStatus status, CapabilityTrace trace}); | ||
|
|
||
| const String _canonical = 'lib/compute/inputs/canonical.dart'; | ||
| const String _pipeline = 'lib/compute/onehz_pipeline.dart'; | ||
| const String _engine = 'lib/compute/derivation_engine.dart'; | ||
|
|
||
| const CapabilityStatus _native = CapabilityStatus(CapabilityKind.native); | ||
|
|
||
| CapabilityStatus _when(String reasonKey) => | ||
| CapabilityStatus(CapabilityKind.conditional, reasonKey: reasonKey); | ||
|
|
||
| bool _nativeWhoop(BandEntry e) => kWhoopGen4.id == e.id || kWhoopGen5.id == e.id; | ||
|
|
||
| /// The column [e] goes into, or null when it fits neither. | ||
| DeviceSlot? _slotOf(BandEntry e) { | ||
| if (_nativeWhoop(e)) return DeviceSlot.everyDay; | ||
| if (e.category == DeviceCategory.wearable && columnFor(e.id) != null) { | ||
| return DeviceSlot.everyDay; | ||
| } | ||
| if (kWorkoutArmedSensors.contains(e.id)) return DeviceSlot.workoutsOnly; | ||
| return null; | ||
| } | ||
|
|
||
| /// Every capability [e] gives in [slot], each with the rule behind it. The one | ||
| /// place claims are made, so a claim cannot exist without its trace. | ||
| Map<DeviceCapability, _Claim> _claims(BandEntry e, DeviceSlot slot, | ||
| {bool modelKnown = true}) => | ||
| switch (slot) { | ||
| DeviceSlot.everyDay => _everyDayClaims(e, modelKnown: modelKnown), | ||
| DeviceSlot.workoutsOnly => _workoutClaims(e), | ||
| }; | ||
|
|
||
| Map<DeviceCapability, _Claim> _everyDayClaims(BandEntry e, | ||
| {bool modelKnown = true}) { | ||
| if (!_nativeWhoop(e)) { | ||
| // The active wearable: its column's rows, behind its own switch. Coros has | ||
| // no column (and wearableEnabled() is false for it): nothing. | ||
| return e.category == DeviceCategory.wearable ? _columnClaims(e) : {}; | ||
| } | ||
| // The native pipeline (onehz_pipeline.dart): sleep, rmssd, resting HR, | ||
| // respiration, strain, readiness. Skin temperature needs a nightly mean, | ||
| // >= 3 prior nights and a baseline spread >= 1; WHOOP 5's deg C needs 14. | ||
| final out = <DeviceCapability, _Claim>{ | ||
| for (final c in kDayCapabilities) | ||
| c: ( | ||
| status: c == DeviceCapability.skinTemperature | ||
| ? _when(kReasonSkinTempNights) | ||
| : _native, | ||
| trace: (rule: 'native WHOOP pipeline (${c.name})', source: _pipeline), | ||
| ), | ||
| }; | ||
| // Steps: WHOOP 5's cumulative on-chip counter rides every synced row; | ||
| // WHOOP 4 has none (derivation_engine.dart _stepCounterModulus), so only | ||
| // the live link's 100 Hz pedometer counts for it. | ||
| out[DeviceCapability.steps] = ( | ||
| status: !modelKnown | ||
| ? _when(kReasonUnconfirmed) | ||
| : e.id == kWhoopGen5.id ? _native : _when(kReasonLiveSessions), | ||
| trace: (rule: 'band steps (counter or live pedometer)', source: _engine), | ||
| ); | ||
| // The band records a workout itself. | ||
| for (final c in kSessionCapabilities) { | ||
| out[c] = (status: _native, trace: (rule: 'band workout session', source: _pipeline)); | ||
| } | ||
| return out; | ||
| } | ||
|
|
||
| Map<DeviceCapability, _Claim> _workoutClaims(BandEntry e) { | ||
| // Only the sensors in kWorkoutArmedSensors (ble_hrs, polar_pmd) are session | ||
| // sources, and only with their switch on. A WHOOP kept for workouts is | ||
| // paired under ble_hrs, so it gets ble_hrs's claims. Anything else (a ring, | ||
| // Coros) sends nothing here. | ||
| final slotId = _nativeWhoop(e) ? kBleHrs.id : e.id; | ||
| if (!kWorkoutArmedSensors.contains(slotId)) return {}; | ||
| final out = <DeviceCapability, _Claim>{}; | ||
| final sig = declaredSignals(slotId).map((s) => s.name).toSet(); | ||
| const trace = ( | ||
| rule: 'workout session sensor (kWorkoutArmedSensors, flag on)', | ||
| source: _canonical, | ||
| ); | ||
| if (sig.contains('hr1Hz') || sig.contains('hrSparse')) { | ||
| out[DeviceCapability.workoutHeartRate] = (status: _native, trace: trace); | ||
| } | ||
| if (sig.contains('rrIntervals')) { | ||
| out[DeviceCapability.workoutBeatToBeat] = ( | ||
| status: slotId != kBleHrs.id ? _native : _when(kReasonUnconfirmed), | ||
| trace: trace, | ||
| ); | ||
| } | ||
| return out; | ||
| } | ||
|
|
||
| /// [e]'s rows of the metric x device table, or none without a column. | ||
| Map<DeviceCapability, _Claim> _columnClaims(BandEntry e) { | ||
| final out = <DeviceCapability, _Claim>{}; | ||
| final col = columnFor(e.id); | ||
| if (col == null) return out; // Coros, sensors, scales: no column, no claim. | ||
| final cls = capabilities(col); | ||
| for (final m in kCapabilityRow.entries) { | ||
| var status = _statusOf(cls[m.value], col[m.value]); | ||
| if (status == null) continue; | ||
| if (status.kind == CapabilityKind.native) { | ||
| status = switch (m.key) { | ||
| // Ours is the window; the stages are the device's own. | ||
| DeviceCapability.sleep when cls['sleep_stages'] == MetricClass.device => | ||
| _when(e.kind == DeviceKind.ring | ||
| ? kReasonOwnStagesRing | ||
| : kReasonOwnStages), | ||
| _ => status, | ||
| }; | ||
| } | ||
| if (status.reasonKey == kReasonEarly) { | ||
| status = switch (m.key) { | ||
| DeviceCapability.recovery => _when(kReasonFirstNights), | ||
| DeviceCapability.skinTemperature => _when(kReasonSkinTempProvisional), | ||
| _ => status, | ||
| }; | ||
| } | ||
| // The shared Pebble entry covers the 2 SE too. It still serves the | ||
| // watch's reported sleep and steps without HR (dayCells), but cannot | ||
| // derive resting HR, strain or the resting-HR recovery estimate. | ||
| final pebbleHr = e.id == kPebble.id && | ||
| const {DeviceCapability.recovery, DeviceCapability.strain, | ||
| DeviceCapability.heartRate}.contains(m.key); | ||
| out[m.key] = ( | ||
| status: !pebbleHr | ||
| ? status | ||
| : _when(status.reasonKey == kReasonEstimated | ||
| ? kReasonPebble2OnlyEstimated | ||
| : kReasonPebble2Only), | ||
| trace: pebbleHr | ||
| ? (rule: 'Pebble 2 HR required for ${m.value}; SE has no HR sensor', | ||
| source: 'lib/compute/inputs/pebble_inputs.dart') | ||
| : (rule: 'metric x device column row ${m.value}', source: _canonical), | ||
| ); | ||
| } | ||
| return out; | ||
| } | ||
|
|
||
| CapabilityStatus? _statusOf(MetricClass? cls, Cell? cell) => switch (cls) { | ||
| null || MetricClass.unavailable => null, | ||
| MetricClass.device => const CapabilityStatus(CapabilityKind.vendorReported), | ||
| MetricClass.estimated => _when(kReasonEstimated), | ||
| MetricClass.ours => cell?.provisionalAt != null ? _when(kReasonEarly) : _native, | ||
| }; | ||
|
|
||
| /// The rule behind [c] for [e] in [slot], or null when no eligibility rule | ||
| /// supports the claim. | ||
| CapabilityTrace? capabilityTrace( | ||
| BandEntry e, | ||
| DeviceCapability c, { | ||
| required DeviceSlot slot, | ||
| bool modelKnown = true, | ||
| }) => _claims(e, slot, modelKnown: modelKnown)[c]?.trace; | ||
|
|
||
| SlotSide _side(BandEntry e, DeviceSlot slot, {bool modelKnown = true}) { | ||
| final sends = { | ||
| for (final m in _claims(e, slot, modelKnown: modelKnown).entries) m.key: m.value.status, | ||
| }; | ||
| return SlotSide( | ||
| sends: sends, | ||
| doesNotSend: kTableRows.toSet().difference(sends.keys.toSet()), | ||
| ); | ||
| } | ||
|
|
||
| SlotComparison slotComparisonFor(BandEntry e, {bool modelKnown = true}) => SlotComparison( | ||
| everyDay: _side(e, DeviceSlot.everyDay, modelKnown: modelKnown), | ||
| workoutsOnly: _side(e, DeviceSlot.workoutsOnly, modelKnown: modelKnown), | ||
| slot: _slotOf(e), | ||
| ); | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Keep mature ring recovery marked provisional.
For an Ultrahuman recovery composite that uses temperature, the pipeline still sets
provisional: trueafter 14 baseline nights. This branch replaces that condition with “Estimated for the first 14 nights,” which implies that the limitation ends. Preserve the continuing provisional status and describe the initial baseline requirement separately. The skin-temperature caption fix does not cover this recovery branch. (raw.githubusercontent.com)