Add per-routine target heart rate with live in-run indicator
Endurance routines (HIIT, cardio, cycling) can carry an optional target bpm (RoutineDocument.targetHeartRate, not schema-bumped — same preference-field rationale as restSeconds/autoAdvance), snapshotted onto the WorkoutDocument at plan time like the other pacing fields. During a run, the watch streams its live HR sample to the phone over a new best-effort liveHeartRate message — deliberately outside the LiveProgress machinery (no version bump, no staging/retry; a gauge, not a record), throttled to changed-bpm-or-10s in the watch bridge. LiveRunState holds the sample with a 30s staleness auto-clear so a dead stream never shows a frozen number. Both run screens show the reading only when the run carries a target: the phone's ExerciseProgressView as a top pill, the watch's in the top-trailing toolbar slot, each tinted by a shared ±5 bpm HeartRateBand with an arrow cue to push harder (low) or ease off (high) — e.g. dialing in a treadmill incline to hold a steady effort. Claude-Session: https://claude.ai/code/session_01Y7ZhkCYWNiTSAFhFCGnJ8n
This commit is contained in:
@@ -28,7 +28,8 @@ extension RoutineDocument {
|
||||
createdAt: routine.createdAt, updatedAt: routine.updatedAt,
|
||||
exercises: routine.exercisesArray.map(ExerciseDocument.init(from:)),
|
||||
activityType: routine.activityTypeRaw,
|
||||
restSeconds: routine.restSeconds, autoAdvance: routine.autoAdvance)
|
||||
restSeconds: routine.restSeconds, autoAdvance: routine.autoAdvance,
|
||||
targetHeartRate: routine.targetHeartRate)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -52,7 +53,8 @@ extension WorkoutDocument {
|
||||
logs: workout.logsArray.map(WorkoutLogDocument.init(from:)),
|
||||
metrics: workout.metrics,
|
||||
deletedLogIDs: workout.deletedLogIDs,
|
||||
restSeconds: workout.restSeconds, autoAdvance: workout.autoAdvance)
|
||||
restSeconds: workout.restSeconds, autoAdvance: workout.autoAdvance,
|
||||
targetHeartRate: workout.targetHeartRate)
|
||||
}
|
||||
|
||||
/// Maps a *live* cache entity to a document, or `nil` when that entity has already
|
||||
@@ -69,7 +71,7 @@ extension WorkoutDocument {
|
||||
/// read still traps. A `@Model` retained across time (not freshly fetched) can reach
|
||||
/// this map in that state, so check both.
|
||||
init?(fromLive workout: Workout) {
|
||||
guard !workout.isDeleted, workout.modelContext != nil else { return nil }
|
||||
guard workout.isLive else { return nil }
|
||||
self.init(from: workout)
|
||||
}
|
||||
|
||||
@@ -140,6 +142,7 @@ enum CacheMapper {
|
||||
routine.activityTypeRaw = doc.activityType ?? 0
|
||||
routine.restSeconds = doc.restSeconds
|
||||
routine.autoAdvance = doc.autoAdvance
|
||||
routine.targetHeartRate = doc.targetHeartRate
|
||||
|
||||
let existing = Dictionary(routine.exercises.map { ($0.id, $0) }, uniquingKeysWith: { a, _ in a })
|
||||
var keep = Set<String>()
|
||||
@@ -200,6 +203,7 @@ enum CacheMapper {
|
||||
workout.deletedLogIDs = doc.deletedLogIDs
|
||||
workout.restSeconds = doc.restSeconds
|
||||
workout.autoAdvance = doc.autoAdvance
|
||||
workout.targetHeartRate = doc.targetHeartRate
|
||||
|
||||
let existing = Dictionary(workout.logs.map { ($0.id, $0) }, uniquingKeysWith: { a, _ in a })
|
||||
var keep = Set<String>()
|
||||
|
||||
Reference in New Issue
Block a user