Open-source gym & body-weight tracker, now in the App Store (iPhone + Apple Watch) and as an Android APK. Plan routines, log workouts, see which muscles are trained, import from Strong/Hevy/FitNotes. Self-host it or use it on the phone alone.
JavaScript apple-watchbodyweightdockerfitnessfitness-trackergymhealthiosmcpnodejspasskeysprogressive-web-applicationspwareactself-hostedself-hostingvitewebauthnweightliftingworkout-tracker
feat(watch): RPE or RIR on the set page, sent with the set
Duarte Santos83a9221b9274
diff --git a/frontend/ios/App/Watch/OpenGymWatchApp.swift b/frontend/ios/App/Watch/OpenGymWatchApp.swiftindex a711202bd..c660bf21c 100644--- a/frontend/ios/App/Watch/OpenGymWatchApp.swift+++ b/frontend/ios/App/Watch/OpenGymWatchApp.swift@@ -12,6 +12,7 @@ import WidgetKit* 3-2-1 with Apple Health on, a countdown before it starts (the heart-rate sensor warms up)* set weight × reps in big rounded numerals, the round Done, the set dots; the crown turns* the reps (or the weight, after a tap on it), marked by the crown symbol under it+ * and, when the profile rates effort, RPE or RIR in a small disc beside Done* rest a full-screen ring around a huge countdown, +15 s and Skip as small round buttons* hold a timed set: the seconds on the crown, Start, then a ring counting down, Stop* finish after the last exercise, one round button@@ -328,7 +329,7 @@ struct ExercisePager: View {/// What a tap on a number opens for editing.enum EditField: String, Identifiable {- case weight, reps, seconds+ case weight, reps, seconds, effortvar id: String { rawValue }}@@ -485,7 +486,22 @@ struct ExercisePage: View {}}+ /// Done in the middle; with a profile that rates effort, the RPE / RIR button at its left (the+ /// same room again on the right keeps Done centred under the numbers).@ViewBuilder private func primaryButton(_ entry: Entry, current: Bool) -> some View {+ if let kind = store.effortKind, !entry.isCardio, let si = store.setIndex(in: index), !entry.sets[si].warmup {+ HStack(spacing: 6) {+ EffortButton(kind: kind, value: current ? store.effort : nil) { if current { editing = .effort } }+ .disabled(!current)+ doneButton(entry, current: current)+ Color.clear.frame(width: Theme.tap, height: Theme.tap).accessibilityHidden(true)+ }+ } else {+ doneButton(entry, current: current)+ }+ }++ @ViewBuilder private func doneButton(_ entry: Entry, current: Bool) -> some View {Group {if entry.isTimed {RoundButton(systemImage: "play.fill", label: Text("Start hold"), size: doneSize,@@ -525,6 +541,43 @@ struct WorkoutExtras: View {}}+/// The set's effort as a small disc beside Done: the scale's name over the number, in the phone's+/// colour for it (lib/effort.js), or a dash while it is not rated. A tap opens it on the crown.+struct EffortButton: View {+ let kind: String+ let value: Double?+ let tap: () -> Void++ var body: some View {+ let color = value.map { Effort.color(kind, $0) } ?? Color.white+ Button(action: tap) {+ VStack(spacing: -1) {+ Text(verbatim: Effort.name(kind)).font(.system(size: 9, weight: .bold, design: .rounded)).foregroundStyle(.secondary)+ Text(verbatim: value.map(formatNumber) ?? "–")+ .font(.system(size: 16, weight: .semibold, design: .rounded).monospacedDigit())+ .foregroundStyle(color)+ .lineLimit(1)+ .minimumScaleFactor(0.6)+ }+ .frame(width: Theme.tap, height: Theme.tap)+ .background(Circle().fill(value == nil ? Theme.dim : color.opacity(0.22)))+ .overlay(Circle().stroke(color.opacity(value == nil ? 0 : 0.9), lineWidth: 1.5))+ }+ .buttonStyle(.plain)+ .dynamicTypeSize(...DynamicTypeSize.large)+ .accessibilityLabel(Text("Effort"))+ .accessibilityValue(value.map { Text(verbatim: "\(Effort.name(kind)) \(formatNumber($0))") } ?? Text("None"))+ .accessibilityHint(Text("Tap to change it."))+ }+}++extension Effort {+ /// The phone's band colours (index.css --purple … --green, then the accent's soft tone).+ static func color(_ kind: String, _ value: Double) -> Color {+ [Color.purple, .red, .orange, .yellow, Theme.accent, .teal][band(kind, value)]+ }+}+/// The workout's active calories so far, redrawn only when they change (WorkoutManager throttles).struct CaloriesText: View {@ObservedObject var health: WorkoutManager@@ -588,13 +641,17 @@ struct ValueEditor: View {let entry: Entrylet unit: String@State private var value: Double = 0+ /// Effort: where the crown was when the editor opened (left untouched, nothing is rated).+ @State private var opened: Double = 0@FocusState private var focused: Bool@ScaledMetric(relativeTo: .largeTitle) private var size: CGFloat = 54+ /// The profile's effort scale; the effort editor turns a crown position (Effort.value).+ private var kind: String { store.effortKind ?? "rpe" }private var step: Double {switch field {case .weight: return entry.step.flatMap { $0 > 0 ? $0 : nil } ?? store.weightStep- case .reps: return 1+ case .reps, .effort: return 1case .seconds: return 5}}@@ -603,6 +660,7 @@ struct ValueEditor: View {case .weight: return 0...(unit == "lb" ? 1500 : 700)case .reps: return 0...200case .seconds: return 5...3600+ case .effort: return 0...Double(Effort.notches(kind)?.count ?? 0)}}private var title: Text {@@ -610,15 +668,25 @@ struct ValueEditor: View {case .weight: return entry.isBodyweight ? Text("Added weight") : Text("Weight")case .reps: return Text("Reps")case .seconds: return Text("Hold")+ case .effort: return Text(verbatim: Effort.name(kind))}}private var suffix: String? {switch field {case .weight: return unit- case .reps: return nil+ case .reps, .effort: return nilcase .seconds: return "s"}}+ /// What the big number says: the value, or for effort the rating at the crown (a dash: none).+ private var shown: String {+ guard field == .effort else { return formatNumber(value) }+ return Effort.value(kind, at: Int(value.rounded())).map(formatNumber) ?? "–"+ }+ private var shownColor: Color {+ guard field == .effort else { return Theme.accent }+ return Effort.value(kind, at: Int(value.rounded())).map { Effort.color(kind, $0) } ?? .secondary+ }var body: some View {VStack(spacing: 4) {@@ -627,9 +695,9 @@ struct ValueEditor: View {stepButton("minus", Text("Less")) { nudge(-step) }VStack(spacing: 0) {HStack(alignment: .firstTextBaseline, spacing: 2) {- Text(verbatim: formatNumber(value))+ Text(verbatim: shown).font(.system(size: size, weight: .semibold, design: .rounded).monospacedDigit())- .foregroundStyle(Theme.accent)+ .foregroundStyle(shownColor).contentTransition(.numericText())if let s = suffix { Text(verbatim: s).font(.system(size: 13, weight: .medium, design: .rounded)).foregroundStyle(.secondary) }}@@ -645,7 +713,7 @@ struct ValueEditor: View {sensitivity: field == .weight ? DigitalCrownRotationalSensitivity.medium : DigitalCrownRotationalSensitivity.low, isContinuous: false, isHapticFeedbackEnabled: true).accessibilityElement(children: .ignore).accessibilityLabel(title)- .accessibilityValue(Text(verbatim: suffix.map { "\(formatNumber(value)) \($0)" } ?? formatNumber(value)))+ .accessibilityValue(field == .effort && shown == "–" ? Text("None") : Text(verbatim: suffix.map { "\(shown) \($0)" } ?? shown)).accessibilityAdjustableAction { d inswitch d {case .increment: nudge(step)@@ -671,10 +739,14 @@ struct ValueEditor: View {case .weight: value = store.weightcase .reps: value = store.repscase .seconds: value = store.seconds+ // a set not rated yet opens on a hard working set; turned down to the dash it is none again+ case .effort: value = Double(Effort.position(kind, of: store.effort ?? Effort.start(kind)))}+ opened = valuefocused = true}- .onDisappear { save() }+ // Effort: swiped away untouched, the set stays unrated (Done rates it as shown).+ .onDisappear { if field != .effort || value != opened || store.effort != nil { save() } }}private func nudge(_ d: Double) {@@ -689,6 +761,7 @@ struct ValueEditor: View {case .weight: store.weight = max(0, value)case .reps: store.reps = max(0, value.rounded())case .seconds: store.seconds = max(5, value)+ case .effort: store.rate(Effort.value(kind, at: Int(value.rounded())))}}diff --git a/frontend/ios/App/Watch/SessionStore.swift b/frontend/ios/App/Watch/SessionStore.swiftindex c12de8f25..148c3b01c 100644--- a/frontend/ios/App/Watch/SessionStore.swift+++ b/frontend/ios/App/Watch/SessionStore.swift@@ -82,6 +82,12 @@ final class SessionStore: NSObject, ObservableObject, WCSessionDelegate, UNUserN@Published var reps: Double = 0 { didSet { if reps != oldValue { ackRestOver() } } }/// A hold's seconds, for the set up next (the crown turns it).@Published var seconds: Double = 0 { didSet { if seconds != oldValue { ackRestOver() } } }+ /// The effort rated for the set up next (RPE or RIR, the profile's scale), nil until rated.+ /// It belongs to that one set: another set coming up starts empty again (loadTargets).+ @Published private(set) var effort: Double?+ private var effortFor: String?+ /// The scale the phone's profile logs, when it logs one ("rpe" / "rir"): the set page offers it.+ var effortKind: String? { Effort.notches(state.settings.effort) != nil ? state.settings.effort : nil }/// A hold running: when it ends, and when it started.@Published private(set) var holdEndsAt: Date?@Published private(set) var holdStartedAt: Date?@@ -364,8 +370,23 @@ final class SessionStore: NSObject, ObservableObject, WCSessionDelegate, UNUserN}}+ /// The set up next, as the effort remembers it (exercise, set, side).+ private var setKey: String? {+ guard let e = entry, let si = setIndex else { return nil }+ return SessionCore.key(e.id, si, e.sets[si].sideUp)+ }++ /// The effort for the set up next, from its editor; nil clears it.+ func rate(_ v: Double?) {+ ackRestOver()+ effort = v+ effortFor = v == nil ? nil : setKey+ }+/// The weight and reps the crown starts from: the set's own target.func loadTargets() {+ // A rating stays with its set through snapshots; another set starts unrated.+ if effortFor != setKey { effort = nil; effortFor = nil }guard let e = entry else { return }let s = setIndex.map { e.sets[$0] } ?? e.sets.lastif let row = s, let side = row.sideUp, let one = row.sides?[side] {@@ -404,8 +425,9 @@ final class SessionStore: NSObject, ObservableObject, WCSessionDelegate, UNUserNtw = weighttr = reps}+ let rated = effortKind.flatMap { k in effort.map { Effort.Rating(kind: k, value: $0) } }let (next, event) = SessionCore.tick(state, entry: ei, set: si, side: side, w: tw, r: tr, sec: tsec,- at: now.timeIntervalSince1970 * 1000, id: UUID().uuidString, hr: hr)+ at: now.timeIntervalSince1970 * 1000, id: UUID().uuidString, hr: hr, effort: rated)// Sent first, saved second: killed in between, the phone still has the tick (and the next// snapshot brings it back here); the other way round the tick would be lost on the phone.if let event = event { send(event: event) }diff --git a/frontend/ios/App/Watch/ar.lproj/Localizable.strings b/frontend/ios/App/Watch/ar.lproj/Localizable.stringsindex 5896dad27..4236a0c61 100644--- a/frontend/ios/App/Watch/ar.lproj/Localizable.strings+++ b/frontend/ios/App/Watch/ar.lproj/Localizable.strings@@ -30,6 +30,8 @@"Body weight" = "وزن الجسم";"Less" = "أقل";"More" = "أكثر";+"Effort" = "الجهد";+"None" = "بدون";"Last time: %@" = "المرة السابقة: %@";"No workout running" = "لا يوجد تمرين جارٍ";"Not synced yet" = "لم تتم المزامنة بعد";diff --git a/frontend/ios/App/Watch/bn.lproj/Localizable.strings b/frontend/ios/App/Watch/bn.lproj/Localizable.stringsindex 06dc02756..ae11625e2 100644--- a/frontend/ios/App/Watch/bn.lproj/Localizable.strings+++ b/frontend/ios/App/Watch/bn.lproj/Localizable.strings@@ -30,6 +30,8 @@"Body weight" = "শরীরের ওজন";"Less" = "কম";"More" = "বেশি";+"Effort" = "পরিশ্রম";+"None" = "কিছু না";"Last time: %@" = "গতবার: %@";"No workout running" = "কোনো ওয়ার্কআউট চলছে না";"Not synced yet" = "এখনো সিঙ্ক হয়নি";diff --git a/frontend/ios/App/Watch/de.lproj/Localizable.strings b/frontend/ios/App/Watch/de.lproj/Localizable.stringsindex 4f90a62ed..db628115e 100644--- a/frontend/ios/App/Watch/de.lproj/Localizable.strings+++ b/frontend/ios/App/Watch/de.lproj/Localizable.strings@@ -30,6 +30,8 @@"Body weight" = "Körpergewicht";"Less" = "Weniger";"More" = "Mehr";+"Effort" = "Anstrengung";+"None" = "Keine";"Last time: %@" = "Letztes Mal: %@";"No workout running" = "Kein Training läuft";"Not synced yet" = "Noch nicht synchronisiert";diff --git a/frontend/ios/App/Watch/en.lproj/Localizable.strings b/frontend/ios/App/Watch/en.lproj/Localizable.stringsindex c601e40ae..69402ee14 100644--- a/frontend/ios/App/Watch/en.lproj/Localizable.strings+++ b/frontend/ios/App/Watch/en.lproj/Localizable.strings@@ -30,6 +30,8 @@"Body weight" = "Body weight";"Less" = "Less";"More" = "More";+"Effort" = "Effort";+"None" = "None";"Last time: %@" = "Last time: %@";"No workout running" = "No workout running";"Not synced yet" = "Not synced yet";diff --git a/frontend/ios/App/Watch/es.lproj/Localizable.strings b/frontend/ios/App/Watch/es.lproj/Localizable.stringsindex b5f2388e3..3717c1b0e 100644--- a/frontend/ios/App/Watch/es.lproj/Localizable.strings+++ b/frontend/ios/App/Watch/es.lproj/Localizable.strings@@ -30,6 +30,8 @@"Body weight" = "Peso corporal";"Less" = "Menos";"More" = "Más";+"Effort" = "Esfuerzo";+"None" = "Ninguno";"Last time: %@" = "La última vez: %@";"No workout running" = "Ningún entreno en curso";"Not synced yet" = "Aún sin sincronizar";diff --git a/frontend/ios/App/Watch/fr.lproj/Localizable.strings b/frontend/ios/App/Watch/fr.lproj/Localizable.stringsindex 75c63ef63..5b64cc42f 100644--- a/frontend/ios/App/Watch/fr.lproj/Localizable.strings+++ b/frontend/ios/App/Watch/fr.lproj/Localizable.strings@@ -30,6 +30,8 @@"Body weight" = "Poids corporel";"Less" = "Moins";"More" = "Plus";+"Effort" = "Effort";+"None" = "Aucun";"Last time: %@" = "La dernière fois: %@";"No workout running" = "Aucune séance en cours";"Not synced yet" = "Pas encore synchronisé";diff --git a/frontend/ios/App/Watch/hi.lproj/Localizable.strings b/frontend/ios/App/Watch/hi.lproj/Localizable.stringsindex 1c11b88f3..d8b05df33 100644--- a/frontend/ios/App/Watch/hi.lproj/Localizable.strings+++ b/frontend/ios/App/Watch/hi.lproj/Localizable.strings@@ -30,6 +30,8 @@"Body weight" = "शरीर का वज़न";"Less" = "कम";"More" = "अधिक";+"Effort" = "मेहनत";+"None" = "कोई नहीं";"Last time: %@" = "पिछली बार: %@";"No workout running" = "कोई वर्कआउट नहीं चल रहा";"Not synced yet" = "अभी सिंक नहीं हुआ";diff --git a/frontend/ios/App/Watch/hu.lproj/Localizable.strings b/frontend/ios/App/Watch/hu.lproj/Localizable.stringsindex 6ef2527a1..b1d2d3e61 100644--- a/frontend/ios/App/Watch/hu.lproj/Localizable.strings+++ b/frontend/ios/App/Watch/hu.lproj/Localizable.strings@@ -30,6 +30,8 @@"Body weight" = "Testsúly";"Less" = "Kevesebb";"More" = "Több";+"Effort" = "Megerőltetés";+"None" = "Nincs";"Last time: %@" = "Legutóbb: %@";"No workout running" = "Nincs folyamatban edzés";"Not synced yet" = "Még nincs szinkronizálva";diff --git a/frontend/ios/App/Watch/it.lproj/Localizable.strings b/frontend/ios/App/Watch/it.lproj/Localizable.stringsindex 2c4b7f642..820750cbd 100644--- a/frontend/ios/App/Watch/it.lproj/Localizable.strings+++ b/frontend/ios/App/Watch/it.lproj/Localizable.strings@@ -30,6 +30,8 @@"Body weight" = "Peso corporeo";"Less" = "Meno";"More" = "Più";+"Effort" = "Sforzo";+"None" = "Nessuno";"Last time: %@" = "L'ultima volta: %@";"No workout running" = "Nessun allenamento in corso";"Not synced yet" = "Non ancora sincronizzato";diff --git a/frontend/ios/App/Watch/ko.lproj/Localizable.strings b/frontend/ios/App/Watch/ko.lproj/Localizable.stringsindex 948ba7619..f1eceb9ec 100644--- a/frontend/ios/App/Watch/ko.lproj/Localizable.strings+++ b/frontend/ios/App/Watch/ko.lproj/Localizable.strings@@ -30,6 +30,8 @@"Body weight" = "체중";"Less" = "적음";"More" = "많음";+"Effort" = "강도";+"None" = "없음";"Last time: %@" = "지난번: %@";"No workout running" = "진행 중인 운동이 없어요";"Not synced yet" = "아직 동기화되지 않았어요";diff --git a/frontend/ios/App/Watch/pl.lproj/Localizable.strings b/frontend/ios/App/Watch/pl.lproj/Localizable.stringsindex 0fb802bd9..950dab253 100644--- a/frontend/ios/App/Watch/pl.lproj/Localizable.strings+++ b/frontend/ios/App/Watch/pl.lproj/Localizable.strings@@ -30,6 +30,8 @@"Body weight" = "Masa ciała";"Less" = "Mniej";"More" = "Więcej";+"Effort" = "Wysiłek";+"None" = "Brak";"Last time: %@" = "Ostatnio: %@";"No workout running" = "Żaden trening nie trwa";"Not synced yet" = "Jeszcze nie zsynchronizowano";diff --git a/frontend/ios/App/Watch/pt-BR.lproj/Localizable.strings b/frontend/ios/App/Watch/pt-BR.lproj/Localizable.stringsindex 4eae452da..42703c414 100644--- a/frontend/ios/App/Watch/pt-BR.lproj/Localizable.strings+++ b/frontend/ios/App/Watch/pt-BR.lproj/Localizable.strings@@ -30,6 +30,8 @@"Body weight" = "Peso corporal";"Less" = "Menos";"More" = "Mais";+"Effort" = "Esforço";+"None" = "Nenhum";"Last time: %@" = "Da última vez: %@";"No workout running" = "Nenhum treino em andamento";"Not synced yet" = "Ainda não sincronizado";diff --git a/frontend/ios/App/Watch/pt-PT.lproj/Localizable.strings b/frontend/ios/App/Watch/pt-PT.lproj/Localizable.stringsindex 15eb8d90d..df4f2d0bb 100644--- a/frontend/ios/App/Watch/pt-PT.lproj/Localizable.strings+++ b/frontend/ios/App/Watch/pt-PT.lproj/Localizable.strings@@ -30,6 +30,8 @@"Body weight" = "Peso corporal";"Less" = "Menos";"More" = "Mais";+"Effort" = "Esforço";+"None" = "Nenhum";"Last time: %@" = "Da última vez: %@";"No workout running" = "Nenhum treino a decorrer";"Not synced yet" = "Ainda não sincronizado";diff --git a/frontend/ios/App/Watch/ru.lproj/Localizable.strings b/frontend/ios/App/Watch/ru.lproj/Localizable.stringsindex 635aedc4c..75f1663bd 100644--- a/frontend/ios/App/Watch/ru.lproj/Localizable.strings+++ b/frontend/ios/App/Watch/ru.lproj/Localizable.strings@@ -30,6 +30,8 @@"Body weight" = "Вес тела";"Less" = "Меньше";"More" = "Больше";+"Effort" = "Усилие";+"None" = "Нет";"Last time: %@" = "В прошлый раз: %@";"No workout running" = "Тренировка не идёт";"Not synced yet" = "Ещё не синхронизировано";diff --git a/frontend/ios/App/Watch/th.lproj/Localizable.strings b/frontend/ios/App/Watch/th.lproj/Localizable.stringsindex 2eb7e35ae..175d28afd 100644--- a/frontend/ios/App/Watch/th.lproj/Localizable.strings+++ b/frontend/ios/App/Watch/th.lproj/Localizable.strings@@ -30,6 +30,8 @@"Body weight" = "น้ำหนักตัว";"Less" = "น้อย";"More" = "มาก";+"Effort" = "ความหนัก";+"None" = "ไม่มี";"Last time: %@" = "ครั้งก่อน: %@";"No workout running" = "ไม่มีการฝึกที่กำลังทำอยู่";"Not synced yet" = "ยังไม่ได้ซิงค์";diff --git a/frontend/ios/App/Watch/tr.lproj/Localizable.strings b/frontend/ios/App/Watch/tr.lproj/Localizable.stringsindex 1d1daec3b..11cd99b01 100644--- a/frontend/ios/App/Watch/tr.lproj/Localizable.strings+++ b/frontend/ios/App/Watch/tr.lproj/Localizable.strings@@ -30,6 +30,8 @@"Body weight" = "Vücut ağırlığı";"Less" = "Az";"More" = "Çok";+"Effort" = "Zorluk";+"None" = "Yok";"Last time: %@" = "Geçen sefer: %@";"No workout running" = "Devam eden antrenman yok";"Not synced yet" = "Henüz eşitlenmedi";diff --git a/frontend/ios/App/Watch/uk.lproj/Localizable.strings b/frontend/ios/App/Watch/uk.lproj/Localizable.stringsindex de0e5caf5..3a2dd68fb 100644--- a/frontend/ios/App/Watch/uk.lproj/Localizable.strings+++ b/frontend/ios/App/Watch/uk.lproj/Localizable.strings@@ -30,6 +30,8 @@"Body weight" = "Вага тіла";"Less" = "Менше";"More" = "Більше";+"Effort" = "Зусилля";+"None" = "Немає";"Last time: %@" = "Минулого разу: %@";"No workout running" = "Тренування не триває";"Not synced yet" = "Ще не синхронізовано";diff --git a/frontend/ios/App/Watch/zh-Hans.lproj/Localizable.strings b/frontend/ios/App/Watch/zh-Hans.lproj/Localizable.stringsindex 6351770db..8550d5ed0 100644--- a/frontend/ios/App/Watch/zh-Hans.lproj/Localizable.strings+++ b/frontend/ios/App/Watch/zh-Hans.lproj/Localizable.strings@@ -30,6 +30,8 @@"Body weight" = "体重";"Less" = "更少";"More" = "更多";+"Effort" = "强度";+"None" = "无";"Last time: %@" = "上次: %@";"No workout running" = "没有进行中的训练";"Not synced yet" = "尚未同步";diff --git a/frontend/ios/App/Watch/zh-Hant.lproj/Localizable.strings b/frontend/ios/App/Watch/zh-Hant.lproj/Localizable.stringsindex 82e2306f6..815cc3fec 100644--- a/frontend/ios/App/Watch/zh-Hant.lproj/Localizable.strings+++ b/frontend/ios/App/Watch/zh-Hant.lproj/Localizable.strings@@ -30,6 +30,8 @@"Body weight" = "體重";"Less" = "較少";"More" = "較多";+"Effort" = "強度表現";+"None" = "無";"Last time: %@" = "上次: %@";"No workout running" = "沒有進行中的訓練";"Not synced yet" = "尚未同步";diff --git a/frontend/ios/App/WatchCore/Sources/WatchCore/Model.swift b/frontend/ios/App/WatchCore/Sources/WatchCore/Model.swiftindex e668ab8e7..8c4a40352 100644--- a/frontend/ios/App/WatchCore/Sources/WatchCore/Model.swift+++ b/frontend/ios/App/WatchCore/Sources/WatchCore/Model.swift@@ -138,6 +138,8 @@ struct WatchSettings: Codable, Equatable {var lastBw: Double?/// What the watch shows during a workout (Settings → Apple Watch); nil is the default.var show: WatchShow?+ /// The effort the profile logs per set, "rpe" or "rir"; nil: none (no effort tile).+ var effort: String?}/// What a workout screen shows. Each nil means its default.diff --git a/frontend/ios/App/WatchCore/Sources/WatchCore/SessionCore.swift b/frontend/ios/App/WatchCore/Sources/WatchCore/SessionCore.swiftindex 3896d93b6..7fab1dc9a 100644--- a/frontend/ios/App/WatchCore/Sources/WatchCore/SessionCore.swift+++ b/frontend/ios/App/WatchCore/Sources/WatchCore/SessionCore.swift@@ -153,7 +153,7 @@ enum SessionCore {/// A set ticked here: the state with it done, and the event for the phone. `side` ticks one/// side of a per-side set; `sec` is a hold's seconds; a cardio tick carries no numbers.static func tick(_ s0: SessionState, entry ei: Int, set si: Int, side: String? = nil, w: Double?, r: Double?, sec: Double? = nil,- at: Double, id: String, hr: [String: Double]? = nil) -> (SessionState, Event?) {+ at: Double, id: String, hr: [String: Double]? = nil, effort: Effort.Rating? = nil) -> (SessionState, Event?) {guard var workout = s0.workout, workout.entries.indices.contains(ei), workout.entries[ei].sets.indices.contains(si) else { return (s0, nil) }var s = s0let e = workout.entries[ei]@@ -178,6 +178,8 @@ enum SessionCore {if let sec = sec { event["sec"] = sec }if let side = oneSide { event["side"] = side }if let hr = hr { event["hr"] = hr }+ // "rpe": 8.5 or "rir": 2, never both; the phone puts it on the set (watch-sync.js effortFrom)+ if let e = effort, Effort.notches(e.kind) != nil { event[e.kind] = e.value }return (s, event)}@@ -438,3 +440,53 @@ enum Idle: Equatable {return idle >= endAfter ? .end : idle >= askAfter ? .ask : .active}}++/*+ * RPE or RIR on a set, in the scale the phone's profile logs (lib/history.js EFFORT). Empty by+ * default: a set nobody rated sends no effort. The crown walks notches from "not rated" through+ * the scale from easy to hard, so turning up always means harder, whichever the scale:+ * RPE –, 6, 6.5, … 10 (half points, as on the phone)+ * RIR –, 5, 4, 3, 2, 1, 0 (whole reps left; 0 = failure, the far end of the crown)+ */+enum Effort {+ struct Rating: Equatable {+ var kind: String+ var value: Double+ }++ /// The scale's values from easy to hard, nil for a scale the watch does not know.+ static func notches(_ kind: String?) -> [Double]? {+ switch kind {+ case "rpe": return stride(from: 6.0, through: 10.0, by: 0.5).map { $0 }+ case "rir": return [5, 4, 3, 2, 1, 0]+ default: return nil+ }+ }++ /// "RPE" / "RIR": the phone's own column heading, the same word in every language.+ static func name(_ kind: String) -> String { kind == "rpe" ? "RPE" : "RIR" }++ /// The value at a crown position: 0 is not rated, 1… the scale; past either end it stops there.+ static func value(_ kind: String, at position: Int) -> Double? {+ guard let n = notches(kind), position > 0 else { return nil }+ return n[min(position, n.count) - 1]+ }++ /// Where a value sits on the crown (the nearest notch); 0 for not rated.+ static func position(_ kind: String, of value: Double?) -> Int {+ guard let n = notches(kind), let v = value else { return 0 }+ var best = 0+ for i in n.indices where abs(n[i] - v) < abs(n[best] - v) { best = i }+ return best + 1+ }++ /// Where the editor opens on a set not rated yet: a hard working set, RPE 8 / RIR 2.+ static func start(_ kind: String) -> Double { kind == "rpe" ? 8 : 2 }++ /// The phone's colour band (lib/effort.js EFFORT_BANDS), by RIR: 0 nothing left … 5 easy.+ static func band(_ kind: String, _ value: Double) -> Int {+ let rir = kind == "rpe" ? 10 - value : value+ let tops: [Double] = [0.25, 0.75, 1.5, 2.5, 3.5]+ return tops.firstIndex { rir <= $0 } ?? tops.count+ }+}diff --git a/frontend/ios/App/WatchCore/Tests/WatchCoreTests/EffortTests.swift b/frontend/ios/App/WatchCore/Tests/WatchCoreTests/EffortTests.swiftnew file mode 100644index 000000000..684f4c91b--- /dev/null+++ b/frontend/ios/App/WatchCore/Tests/WatchCoreTests/EffortTests.swift@@ -0,0 +1,56 @@+import XCTest+@testable import WatchCore++/// RPE / RIR on the watch: the crown's notches, the event, the phone's colour bands.+final class EffortTests: XCTestCase {+ func testTheCrownGoesFromNotRatedThroughTheScaleEasyToHard() {+ XCTAssertNil(Effort.value("rpe", at: 0), "position 0 is not rated")+ XCTAssertEqual(Effort.value("rpe", at: 1), 6)+ XCTAssertEqual(Effort.value("rpe", at: 2), 6.5)+ XCTAssertEqual(Effort.value("rpe", at: 9), 10)+ XCTAssertEqual(Effort.value("rpe", at: 40), 10, "past the end it stays at the top")+ XCTAssertEqual(Effort.value("rir", at: 1), 5, "RIR starts easy too")+ XCTAssertEqual(Effort.value("rir", at: 6), 0)+ XCTAssertNil(Effort.value("none", at: 3))+ }++ func testAValueFindsItsNotchBack() {+ XCTAssertEqual(Effort.position("rpe", of: nil), 0)+ XCTAssertEqual(Effort.position("rpe", of: 8), 5)+ XCTAssertEqual(Effort.position("rpe", of: 8.4), 6, "the nearest notch, 8.5")+ XCTAssertEqual(Effort.position("rir", of: 2), 4)+ XCTAssertEqual(Effort.position("rir", of: 9), 1, "a phone value above the watch's RIR 5 lands on 5")+ for k in ["rpe", "rir"] {+ XCTAssertEqual(Effort.value(k, at: Effort.position(k, of: Effort.start(k))), Effort.start(k))+ }+ }++ func testTheRatingGoesOutOnTheTickAndOnlyWhenThereIsOne() {+ let set = SetRow(w: 60, r: 8, sec: nil, done: false, warmup: false, at: nil)+ var s = SessionState()+ s.workout = ActiveWorkout(id: "w1", name: "Push", unit: "kg", cur: 0, restSec: 90, rest: nil,+ entries: [Entry(id: "0025", name: "Bench Press", mode: "reps", restSec: nil, last: nil, sets: [set, set])])+ let (_, rated) = SessionCore.tick(s, entry: 0, set: 0, w: 60, r: 8, at: 1, id: "e1", effort: Effort.Rating(kind: "rpe", value: 8.5))+ XCTAssertEqual(rated?["rpe"] as? Double, 8.5)+ XCTAssertNil(rated?["rir"])+ let (_, plain) = SessionCore.tick(s, entry: 0, set: 1, w: 60, r: 8, at: 2, id: "e2")+ XCTAssertNil(plain?["rpe"])+ XCTAssertNil(plain?["rir"])+ let (_, odd) = SessionCore.tick(s, entry: 0, set: 1, w: 60, r: 8, at: 2, id: "e3", effort: Effort.Rating(kind: "x", value: 3))+ XCTAssertNil(odd?["x"], "a scale the phone does not know is not sent")+ }++ func testColoursFollowThePhonesBandsInEitherScale() {+ XCTAssertEqual(Effort.band("rir", 0), 0)+ XCTAssertEqual(Effort.band("rpe", 10), 0, "RPE 10 is RIR 0")+ XCTAssertEqual(Effort.band("rpe", 8), Effort.band("rir", 2))+ XCTAssertEqual(Effort.band("rir", 5), 5)+ }++ func testTheProfilesScaleArrivesInTheSettings() throws {+ let snap = try JSONDecoder().decode(Snapshot.self, from: Data(#"{"v":1,"settings":{"effort":"rir"}}"#.utf8))+ XCTAssertEqual(snap.settings?.effort, "rir")+ let old = try JSONDecoder().decode(Snapshot.self, from: Data(#"{"v":1,"settings":{}}"#.utf8))+ XCTAssertNil(old.settings?.effort)+ }+}diff --git a/frontend/ios/App/WatchWidgets/ar.lproj/Localizable.strings b/frontend/ios/App/WatchWidgets/ar.lproj/Localizable.stringsindex 5896dad27..4236a0c61 100644--- a/frontend/ios/App/WatchWidgets/ar.lproj/Localizable.strings+++ b/frontend/ios/App/WatchWidgets/ar.lproj/Localizable.strings@@ -30,6 +30,8 @@"Body weight" = "وزن الجسم";"Less" = "أقل";"More" = "أكثر";+"Effort" = "الجهد";+"None" = "بدون";"Last time: %@" = "المرة السابقة: %@";"No workout running" = "لا يوجد تمرين جارٍ";"Not synced yet" = "لم تتم المزامنة بعد";diff --git a/frontend/ios/App/WatchWidgets/bn.lproj/Localizable.strings b/frontend/ios/App/WatchWidgets/bn.lproj/Localizable.stringsindex 06dc02756..ae11625e2 100644--- a/frontend/ios/App/WatchWidgets/bn.lproj/Localizable.strings+++ b/frontend/ios/App/WatchWidgets/bn.lproj/Localizable.strings@@ -30,6 +30,8 @@"Body weight" = "শরীরের ওজন";"Less" = "কম";"More" = "বেশি";+"Effort" = "পরিশ্রম";+"None" = "কিছু না";"Last time: %@" = "গতবার: %@";"No workout running" = "কোনো ওয়ার্কআউট চলছে না";"Not synced yet" = "এখনো সিঙ্ক হয়নি";diff --git a/frontend/ios/App/WatchWidgets/de.lproj/Localizable.strings b/frontend/ios/App/WatchWidgets/de.lproj/Localizable.stringsindex 4f90a62ed..db628115e 100644--- a/frontend/ios/App/WatchWidgets/de.lproj/Localizable.strings+++ b/frontend/ios/App/WatchWidgets/de.lproj/Localizable.strings@@ -30,6 +30,8 @@"Body weight" = "Körpergewicht";"Less" = "Weniger";"More" = "Mehr";+"Effort" = "Anstrengung";+"None" = "Keine";"Last time: %@" = "Letztes Mal: %@";"No workout running" = "Kein Training läuft";"Not synced yet" = "Noch nicht synchronisiert";diff --git a/frontend/ios/App/WatchWidgets/en.lproj/Localizable.strings b/frontend/ios/App/WatchWidgets/en.lproj/Localizable.stringsindex c601e40ae..69402ee14 100644--- a/frontend/ios/App/WatchWidgets/en.lproj/Localizable.strings+++ b/frontend/ios/App/WatchWidgets/en.lproj/Localizable.strings@@ -30,6 +30,8 @@"Body weight" = "Body weight";"Less" = "Less";"More" = "More";+"Effort" = "Effort";+"None" = "None";"Last time: %@" = "Last time: %@";"No workout running" = "No workout running";"Not synced yet" = "Not synced yet";diff --git a/frontend/ios/App/WatchWidgets/es.lproj/Localizable.strings b/frontend/ios/App/WatchWidgets/es.lproj/Localizable.stringsindex b5f2388e3..3717c1b0e 100644--- a/frontend/ios/App/WatchWidgets/es.lproj/Localizable.strings+++ b/frontend/ios/App/WatchWidgets/es.lproj/Localizable.strings@@ -30,6 +30,8 @@"Body weight" = "Peso corporal";"Less" = "Menos";"More" = "Más";+"Effort" = "Esfuerzo";+"None" = "Ninguno";"Last time: %@" = "La última vez: %@";"No workout running" = "Ningún entreno en curso";"Not synced yet" = "Aún sin sincronizar";diff --git a/frontend/ios/App/WatchWidgets/fr.lproj/Localizable.strings b/frontend/ios/App/WatchWidgets/fr.lproj/Localizable.stringsindex 75c63ef63..5b64cc42f 100644--- a/frontend/ios/App/WatchWidgets/fr.lproj/Localizable.strings+++ b/frontend/ios/App/WatchWidgets/fr.lproj/Localizable.strings@@ -30,6 +30,8 @@"Body weight" = "Poids corporel";"Less" = "Moins";"More" = "Plus";+"Effort" = "Effort";+"None" = "Aucun";"Last time: %@" = "La dernière fois: %@";"No workout running" = "Aucune séance en cours";"Not synced yet" = "Pas encore synchronisé";diff --git a/frontend/ios/App/WatchWidgets/hi.lproj/Localizable.strings b/frontend/ios/App/WatchWidgets/hi.lproj/Localizable.stringsindex 1c11b88f3..d8b05df33 100644--- a/frontend/ios/App/WatchWidgets/hi.lproj/Localizable.strings+++ b/frontend/ios/App/WatchWidgets/hi.lproj/Localizable.strings@@ -30,6 +30,8 @@"Body weight" = "शरीर का वज़न";"Less" = "कम";"More" = "अधिक";+"Effort" = "मेहनत";+"None" = "कोई नहीं";"Last time: %@" = "पिछली बार: %@";"No workout running" = "कोई वर्कआउट नहीं चल रहा";"Not synced yet" = "अभी सिंक नहीं हुआ";diff --git a/frontend/ios/App/WatchWidgets/hu.lproj/Localizable.strings b/frontend/ios/App/WatchWidgets/hu.lproj/Localizable.stringsindex 6ef2527a1..b1d2d3e61 100644--- a/frontend/ios/App/WatchWidgets/hu.lproj/Localizable.strings+++ b/frontend/ios/App/WatchWidgets/hu.lproj/Localizable.strings@@ -30,6 +30,8 @@"Body weight" = "Testsúly";"Less" = "Kevesebb";"More" = "Több";+"Effort" = "Megerőltetés";+"None" = "Nincs";"Last time: %@" = "Legutóbb: %@";"No workout running" = "Nincs folyamatban edzés";"Not synced yet" = "Még nincs szinkronizálva";diff --git a/frontend/ios/App/WatchWidgets/it.lproj/Localizable.strings b/frontend/ios/App/WatchWidgets/it.lproj/Localizable.stringsindex 2c4b7f642..820750cbd 100644--- a/frontend/ios/App/WatchWidgets/it.lproj/Localizable.strings+++ b/frontend/ios/App/WatchWidgets/it.lproj/Localizable.strings@@ -30,6 +30,8 @@"Body weight" = "Peso corporeo";"Less" = "Meno";"More" = "Più";+"Effort" = "Sforzo";+"None" = "Nessuno";"Last time: %@" = "L'ultima volta: %@";"No workout running" = "Nessun allenamento in corso";"Not synced yet" = "Non ancora sincronizzato";diff --git a/frontend/ios/App/WatchWidgets/ko.lproj/Localizable.strings b/frontend/ios/App/WatchWidgets/ko.lproj/Localizable.stringsindex 948ba7619..f1eceb9ec 100644--- a/frontend/ios/App/WatchWidgets/ko.lproj/Localizable.strings+++ b/frontend/ios/App/WatchWidgets/ko.lproj/Localizable.strings@@ -30,6 +30,8 @@"Body weight" = "체중";"Less" = "적음";"More" = "많음";+"Effort" = "강도";+"None" = "없음";"Last time: %@" = "지난번: %@";"No workout running" = "진행 중인 운동이 없어요";"Not synced yet" = "아직 동기화되지 않았어요";diff --git a/frontend/ios/App/WatchWidgets/pl.lproj/Localizable.strings b/frontend/ios/App/WatchWidgets/pl.lproj/Localizable.stringsindex 0fb802bd9..950dab253 100644--- a/frontend/ios/App/WatchWidgets/pl.lproj/Localizable.strings+++ b/frontend/ios/App/WatchWidgets/pl.lproj/Localizable.strings@@ -30,6 +30,8 @@"Body weight" = "Masa ciała";"Less" = "Mniej";"More" = "Więcej";+"Effort" = "Wysiłek";+"None" = "Brak";"Last time: %@" = "Ostatnio: %@";"No workout running" = "Żaden trening nie trwa";"Not synced yet" = "Jeszcze nie zsynchronizowano";diff --git a/frontend/ios/App/WatchWidgets/pt-BR.lproj/Localizable.strings b/frontend/ios/App/WatchWidgets/pt-BR.lproj/Localizable.stringsindex 4eae452da..42703c414 100644--- a/frontend/ios/App/WatchWidgets/pt-BR.lproj/Localizable.strings+++ b/frontend/ios/App/WatchWidgets/pt-BR.lproj/Localizable.strings@@ -30,6 +30,8 @@"Body weight" = "Peso corporal";"Less" = "Menos";"More" = "Mais";+"Effort" = "Esforço";+"None" = "Nenhum";"Last time: %@" = "Da última vez: %@";"No workout running" = "Nenhum treino em andamento";"Not synced yet" = "Ainda não sincronizado";diff --git a/frontend/ios/App/WatchWidgets/pt-PT.lproj/Localizable.strings b/frontend/ios/App/WatchWidgets/pt-PT.lproj/Localizable.stringsindex 15eb8d90d..df4f2d0bb 100644--- a/frontend/ios/App/WatchWidgets/pt-PT.lproj/Localizable.strings+++ b/frontend/ios/App/WatchWidgets/pt-PT.lproj/Localizable.strings@@ -30,6 +30,8 @@"Body weight" = "Peso corporal";"Less" = "Menos";"More" = "Mais";+"Effort" = "Esforço";+"None" = "Nenhum";"Last time: %@" = "Da última vez: %@";"No workout running" = "Nenhum treino a decorrer";"Not synced yet" = "Ainda não sincronizado";diff --git a/frontend/ios/App/WatchWidgets/ru.lproj/Localizable.strings b/frontend/ios/App/WatchWidgets/ru.lproj/Localizable.stringsindex 635aedc4c..75f1663bd 100644--- a/frontend/ios/App/WatchWidgets/ru.lproj/Localizable.strings+++ b/frontend/ios/App/WatchWidgets/ru.lproj/Localizable.strings@@ -30,6 +30,8 @@"Body weight" = "Вес тела";"Less" = "Меньше";"More" = "Больше";+"Effort" = "Усилие";+"None" = "Нет";"Last time: %@" = "В прошлый раз: %@";"No workout running" = "Тренировка не идёт";"Not synced yet" = "Ещё не синхронизировано";diff --git a/frontend/ios/App/WatchWidgets/th.lproj/Localizable.strings b/frontend/ios/App/WatchWidgets/th.lproj/Localizable.stringsindex 2eb7e35ae..175d28afd 100644--- a/frontend/ios/App/WatchWidgets/th.lproj/Localizable.strings+++ b/frontend/ios/App/WatchWidgets/th.lproj/Localizable.strings@@ -30,6 +30,8 @@"Body weight" = "น้ำหนักตัว";"Less" = "น้อย";"More" = "มาก";+"Effort" = "ความหนัก";+"None" = "ไม่มี";"Last time: %@" = "ครั้งก่อน: %@";"No workout running" = "ไม่มีการฝึกที่กำลังทำอยู่";"Not synced yet" = "ยังไม่ได้ซิงค์";diff --git a/frontend/ios/App/WatchWidgets/tr.lproj/Localizable.strings b/frontend/ios/App/WatchWidgets/tr.lproj/Localizable.stringsindex 1d1daec3b..11cd99b01 100644--- a/frontend/ios/App/WatchWidgets/tr.lproj/Localizable.strings+++ b/frontend/ios/App/WatchWidgets/tr.lproj/Localizable.strings@@ -30,6 +30,8 @@"Body weight" = "Vücut ağırlığı";"Less" = "Az";"More" = "Çok";+"Effort" = "Zorluk";+"None" = "Yok";"Last time: %@" = "Geçen sefer: %@";"No workout running" = "Devam eden antrenman yok";"Not synced yet" = "Henüz eşitlenmedi";diff --git a/frontend/ios/App/WatchWidgets/uk.lproj/Localizable.strings b/frontend/ios/App/WatchWidgets/uk.lproj/Localizable.stringsindex de0e5caf5..3a2dd68fb 100644--- a/frontend/ios/App/WatchWidgets/uk.lproj/Localizable.strings+++ b/frontend/ios/App/WatchWidgets/uk.lproj/Localizable.strings@@ -30,6 +30,8 @@"Body weight" = "Вага тіла";"Less" = "Менше";"More" = "Більше";+"Effort" = "Зусилля";+"None" = "Немає";"Last time: %@" = "Минулого разу: %@";"No workout running" = "Тренування не триває";"Not synced yet" = "Ще не синхронізовано";diff --git a/frontend/ios/App/WatchWidgets/zh-Hans.lproj/Localizable.strings b/frontend/ios/App/WatchWidgets/zh-Hans.lproj/Localizable.stringsindex 6351770db..8550d5ed0 100644--- a/frontend/ios/App/WatchWidgets/zh-Hans.lproj/Localizable.strings+++ b/frontend/ios/App/WatchWidgets/zh-Hans.lproj/Localizable.strings@@ -30,6 +30,8 @@"Body weight" = "体重";"Less" = "更少";"More" = "更多";+"Effort" = "强度";+"None" = "无";"Last time: %@" = "上次: %@";"No workout running" = "没有进行中的训练";"Not synced yet" = "尚未同步";diff --git a/frontend/ios/App/WatchWidgets/zh-Hant.lproj/Localizable.strings b/frontend/ios/App/WatchWidgets/zh-Hant.lproj/Localizable.stringsindex 82e2306f6..815cc3fec 100644--- a/frontend/ios/App/WatchWidgets/zh-Hant.lproj/Localizable.strings+++ b/frontend/ios/App/WatchWidgets/zh-Hant.lproj/Localizable.strings@@ -30,6 +30,8 @@"Body weight" = "體重";"Less" = "較少";"More" = "較多";+"Effort" = "強度表現";+"None" = "無";"Last time: %@" = "上次: %@";"No workout running" = "沒有進行中的訓練";"Not synced yet" = "尚未同步";diff --git a/frontend/ios/ci/watch-strings.mjs b/frontend/ios/ci/watch-strings.mjsindex c5d0bc194..4aca8979d 100644--- a/frontend/ios/ci/watch-strings.mjs+++ b/frontend/ios/ci/watch-strings.mjs@@ -51,6 +51,8 @@ const FROM_APP = {'Body weight': 'Body weight','Less': 'Less','More': 'More',+ 'Effort': 'Effort',+ 'None': 'None',}// Built from an app word: "Last time: %@".const COMPOSED = { 'Last time: %@': ['Last time', w => `${w}: %@`] }diff --git a/frontend/src/lib/watch-sync.effort.test.js b/frontend/src/lib/watch-sync.effort.test.jsnew file mode 100644index 000000000..10ee8f955--- /dev/null+++ b/frontend/src/lib/watch-sync.effort.test.js@@ -0,0 +1,63 @@+// @vitest-environment happy-dom+// RPE / RIR from the Apple Watch: the phone says which scale the profile logs, the watch's set+// page offers it, and the rating rides along on the setDone event into the set.+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'+import { applyEvents, bindWatchActions, bindWatchAppActions, effortFrom, patchSetIn, watchExtras, _resetWatchSync } from './watch-sync.js'++beforeEach(() => { localStorage.clear(); _resetWatchSync() })+afterEach(() => _resetWatchSync())++describe('the scale the watch is told about', () => {+ it('only a profile that tracks effort gets the effort tile', () => {+ expect(watchExtras({ effort: 'rpe' }).effort).toBe('rpe')+ expect(watchExtras({ effort: 'rir' }).effort).toBe('rir')+ expect(watchExtras({ showRir: true }).effort).toBe('rir')+ expect('effort' in watchExtras({ effort: 'none' })).toBe(false)+ expect('effort' in watchExtras({})).toBe(false)+ })+})++describe('the rating on a watch event', () => {+ it('takes RPE or RIR on the half-point grid and drops what does not hold up', () => {+ expect(effortFrom({ rpe: 8.5 })).toEqual({ rpe: 8.5 })+ expect(effortFrom({ rir: 2 })).toEqual({ rir: 2 })+ expect(effortFrom({ rpe: 7.74 })).toEqual({ rpe: 7.5 })+ expect(effortFrom({ rir: 0 })).toEqual({ rir: 0 })+ expect(effortFrom({ rpe: 11 })).toEqual({})+ expect(effortFrom({ rir: -1 })).toEqual({})+ expect(effortFrom({ rpe: 'x' })).toEqual({})+ expect(effortFrom({})).toEqual({})+ })++ it('goes to the workout screen\'s tick with the numbers', () => {+ const setDone = vi.fn()+ bindWatchActions({ setDone, finish: vi.fn() })+ const S = { active: { id: 'w', entries: [{ id: '0025', sets: [{ w: 60, r: 8, done: false }] }] } }+ applyEvents([{ id: 'e1', type: 'setDone', wid: 'w', exId: '0025', entryIdx: 0, setIdx: 0, w: 60, r: 8, at: 5, rpe: 9 }], () => ({ S }))+ expect(setDone).toHaveBeenCalledWith(0, 0, expect.objectContaining({ w: 60, r: 8, rpe: 9 }))+ applyEvents([{ id: 'e2', type: 'setDone', wid: 'w', exId: '0025', entryIdx: 0, setIdx: 0, w: 60, r: 8, at: 6 }], () => ({ S }))+ expect(setDone.mock.calls[1][2]).not.toHaveProperty('rpe')+ })++ it('lands in a workout already saved, and on a set rated on the phone only when it has none', () => {+ const patchSet = vi.fn()+ bindWatchAppActions({ start: vi.fn(), patchSet })+ const S = { active: null, workouts: [{ id: 'w-old', entries: [{ id: '0025', sets: [{ w: 60, r: 8, done: false }] }] }] }+ applyEvents([{ id: 'late', type: 'setDone', wid: 'w-old', exId: '0025', entryIdx: 0, setIdx: 0, w: 60, r: 8, at: 900, rir: 1 }], () => ({ S }))+ expect(patchSet.mock.calls[0][1]).toMatchObject({ done: true, rir: 1 })++ const s = { active: null, workouts: [{ id: 'w', entries: [{ id: '0025', sets: [{ w: 60, r: 8, done: true, at: 2000 }, { w: 60, r: 8, done: true, at: 2000, rpe: 7 }] }] }] }+ // the phone's edit is later: its numbers stay, the watch's rating fills the empty set+ patchSetIn(s, { wid: 'w', exId: '0025', entryIdx: 0, setIdx: 0 }, { done: true, w: 50, r: 5, at: 1000, rpe: 9 }, vi.fn(), { ifNewer: 1000 })+ expect(s.workouts[0].entries[0].sets[0]).toEqual({ w: 60, r: 8, done: true, at: 2000, rpe: 9 })+ patchSetIn(s, { wid: 'w', exId: '0025', entryIdx: 0, setIdx: 1 }, { done: true, w: 50, r: 5, at: 1000, rpe: 9 }, vi.fn(), { ifNewer: 1000 })+ expect(s.workouts[0].entries[0].sets[1].rpe).toBe(7)+ })++ it('a per-side set keeps the rating on its side', () => {+ const s = { active: { id: 'w', entries: [{ id: '0025', sets: [{ w: 20, r: 8, done: false, sides: { L: { w: 20, r: 8, done: false }, R: { w: 20, r: 8, done: false } } }] }] } }+ patchSetIn(s, { wid: 'w', exId: '0025', entryIdx: 0, setIdx: 0, side: 'L' }, { done: true, w: 20, r: 8, rir: 2 }, vi.fn())+ expect(s.active.entries[0].sets[0].sides.L).toMatchObject({ done: true, rir: 2 })+ expect(s.active.entries[0].sets[0].sides.R.rir).toBeUndefined()+ })+})diff --git a/frontend/src/lib/watch-sync.js b/frontend/src/lib/watch-sync.jsindex ab6309417..f03ebdd2c 100644--- a/frontend/src/lib/watch-sync.js+++ b/frontend/src/lib/watch-sync.js@@ -19,7 +19,7 @@ import { EXIDX, gifSrc, figureOf, isAssisted } from './exercises.js'import { packId, packDrawingId } from './anim-quality.js'import { getState as animPacks } from './anim-packs.js'import { getLang, baseLang, onLangChange } from './i18n.js'-import { modeOf, setLabel, lastEntryFor, effectiveRoutineIds, isBw, isPerSide } from './history.js'+import { modeOf, setLabel, lastEntryFor, effectiveRoutineIds, isBw, isPerSide, EFFORT, effortOf } from './history.js'import { isWarmupRow, isSideSet, syncSideAggregate } from './workout-model.js'import { bestSetFor } from './exercise-history.js'import { weightIncrement } from './progression.js'@@ -43,7 +43,19 @@ const okBw = v => { const n = num(v); return n != null && n > 0 && n < 700 }// One side of a per-side set, from the watch: 'L', 'R', or none (the whole set).const sideOf = v => (v === 'L' || v === 'R' ? v : null)// What a tick of a hold (`sec`) or of one side carries besides the numbers; nothing for a plain set.-const extraOf = ev => ({ ...(num(ev.sec) != null ? { sec: num(ev.sec) } : {}), ...(sideOf(ev.side) ? { side: sideOf(ev.side) } : {}) })+const extraOf = ev => ({ ...(num(ev.sec) != null ? { sec: num(ev.sec) } : {}), ...(sideOf(ev.side) ? { side: sideOf(ev.side) } : {}), ...effortFrom(ev) })+// The effort the watch logged on a set: { rpe } or { rir } on the half-point grid, inside the+// phone's own scale (lib/history.js EFFORT); nothing for none, or for a number that does not hold up.+export function effortFrom (ev) {+ for (const k of ['rpe', 'rir']) {+ const v = num(ev?.[k])+ if (v == null) continue+ const e = EFFORT[k]+ const snapped = Math.round(v * 2) / 2+ return snapped >= (k === 'rpe' ? 1 : e.min) && snapped <= e.max ? { [k]: snapped } : {}+ }+ return {}+}/* ---------- the snapshot ---------- */@@ -222,7 +234,7 @@ function entryIndexOf (A, ev) {* stay queued, in order, for the next drain.** start { routineIds, wid, at } the app starts that session with the watch's id and start- * setDone { wid, exId, entryIdx, setIdx, w, r, at } the workout screen's own tick+ * setDone { wid, exId, entryIdx, setIdx, w, r, at, rpe?|rir? } the workout screen's own tick* finish { wid, at } the workout screen's own Finish and save* discard { wid, at } the workout screen's own Discard (confirmed on the watch)* setHr { wid, exId, entryIdx, setIdx, hr?, restHr? } heart rate on a set (lib/heart-rate.js)@@ -254,7 +266,7 @@ export function applyEvents (events, getState) {// A workout already running on the phone is kept; one with the watch's id is this one.} else if (ev.type === 'setDone' && saved) {if (!appHandlers) break- const fields = { done: true, ...(num(ev.w) != null ? { w: num(ev.w) } : {}), ...(num(ev.r) != null ? { r: num(ev.r) } : {}), ...(num(ev.sec) != null ? { sec: num(ev.sec) } : {}), ...(num(ev.at) ? { at: num(ev.at) } : {}) }+ const fields = { done: true, ...(num(ev.w) != null ? { w: num(ev.w) } : {}), ...(num(ev.r) != null ? { r: num(ev.r) } : {}), ...(num(ev.sec) != null ? { sec: num(ev.sec) } : {}), ...(num(ev.at) ? { at: num(ev.at) } : {}), ...effortFrom(ev) }const hr = sanitizeHr(ev.hr)if (hr) fields.hr = hrappHandlers.patchSet({ wid: ev.wid, exId: ev.exId, entryIdx: ev.entryIdx, setIdx: ev.setIdx, ...(sideOf(ev.side) ? { side: sideOf(ev.side) } : {}) }, fields, { ifNewer: num(ev.at) })@@ -468,6 +480,8 @@ export function watchExtras (S) {lang,weighIn: S?.weighIn !== false,...(bw && num(bw.w) ? { lastBw: num(bw.w) } : {}),+ // the effort scale the profile logs ('rpe' or 'rir'): the watch's set page offers it then+ ...(EFFORT[effortOf(S)] ? { effort: effortOf(S) } : {}),}}@@ -588,11 +602,14 @@ export function patchSetIn (s, { wid, exId, entryIdx, setIdx, side = null }, fie// follow from both sides (lib/workout-model.js syncSideAggregate).const write = (set, f) => {if (side && isSideSet(set)) {- const { w, r, done, ...rest } = f+ const { w, r, done, rpe, rir, ...rest } = fconst one = { ...set.sides[side] }if (w != null) one.w = wif (r != null) one.r = rif (done) one.done = true+ // a side's effort is that side's (the row's follows from both, as on the phone)+ if (rpe != null) one.rpe = rpe+ if (rir != null) one.rir = rirset.sides = { ...set.sides, [side]: one }const agg = syncSideAggregate(set)for (const k of Object.keys(set)) if (!(k in agg)) delete set[k]@@ -619,6 +636,8 @@ export function patchSetIn (s, { wid, exId, entryIdx, setIdx, side = null }, fief = {}if (fields.hr) f.hr = fields.hrif (fields.restHr) f.restHr = fields.restHr+ // the watch's effort still lands on a set that has none+ if (set.rpe == null && set.rir == null) Object.assign(f, effortFrom(fields))if (!Object.keys(f).length) return false}write(set, f)diff --git a/frontend/src/views/Workout.jsx b/frontend/src/views/Workout.jsxindex 3374793c0..5a509f897 100644--- a/frontend/src/views/Workout.jsx+++ b/frontend/src/views/Workout.jsx@@ -1909,15 +1909,19 @@ function ActiveWorkout() {// The time is the watch's: the phone may hear of the set much later (lib/finish-workout.js// sessionEnd reads the sets' times). The watch's Finish runs the phone's Finish and save.useEffect(() => bindWatchActions({- setDone: (idx, i, { w, r, sec, side, at, hr }) => {+ setDone: (idx, i, { w, r, sec, side, at, hr, rpe, rir }) => {if (useStore.getState().S.active?.editingWorkoutId) return // a saved workout being edited is not the sessionconst now = useStore.getState().S.active?.entries?.[idx]?.sets?.[i]// One side of a per-side set (a unilateral exercise): that side's numbers and its own tick.const oneSide = side && isSideSet(now) ? side : nullconst wasDone = oneSide ? now.sides[oneSide].done : now?.done// The same set ticked here after the watch did: the later tick wins, the heart rate still lands.+ // The effort the watch logged (lib/watch-sync.js effortFrom): RPE or RIR, never both.+ const eff = rpe != null ? ['rpe', rpe] : rir != null ? ['rir', rir] : nullif (wasDone && at && Number(now.at) > at) {if (hr) mutEntry(idx, en => { if (en.sets[i]) en.sets[i].hr = hr })+ // the phone's rating wins, the watch's only fills a set that has none+ if (eff && !oneSide && now.rpe == null && now.rir == null) mutEntry(idx, en => { if (en.sets[i]) en.sets[i][eff[0]] = eff[1] })return}mutEntry(idx, en => {@@ -1926,11 +1930,13 @@ function ActiveWorkout() {if (oneSide) {if (w != null) en.sets[i] = setSideField(en.sets[i], oneSide, 'w', w)if (r != null) en.sets[i] = setSideField(en.sets[i], oneSide, 'r', r)+ if (eff) en.sets[i] = setSideField(en.sets[i], oneSide, eff[0], eff[1])return}if (w != null) set.w = wif (r != null) set.r = rif (sec != null) set.sec = sec // a hold: the seconds it lasted on the watch+ if (eff) { delete set.rpe; delete set.rir; set[eff[0]] = eff[1] }})if (!wasDone) toggleRef.current(idx, i, oneSide || undefined)if (at || hr) mutEntry(idx, en => { const set = en.sets[i]; if (!(oneSide ? set?.sides?.[oneSide]?.done : set?.done)) return; if (at) set.at = at; if (hr) set.hr = hr })diff --git a/frontend/src/views/Workout.watch.test.jsx b/frontend/src/views/Workout.watch.test.jsxindex b508d45a5..0f5bba5b4 100644--- a/frontend/src/views/Workout.watch.test.jsx+++ b/frontend/src/views/Workout.watch.test.jsx@@ -69,6 +69,15 @@ describe('a set ticked on the watch', () => {expect(S.workouts.at(-1).entries[0].sets[0]).toMatchObject({ w: 60, r: 8, done: true, at })})+ it('the watch\'s RPE goes on the set it ticked, and a later phone rating is not overwritten', () => {+ act(() => { applyEvents([{ id: 'r1', type: 'setDone', wid: 'w-watch', exId: '0025', entryIdx: 0, setIdx: 0, w: 60, r: 8, at: Date.now(), rpe: 8.5 }], () => useStore.getState()) })+ expect(useStore.getState().S.active.entries[0].sets[0]).toMatchObject({ done: true, rpe: 8.5 })+ expect(useStore.getState().S.active.entries[0].sets[0].rir).toBeUndefined()+ act(() => { useStore.getState().update(s => { Object.assign(s.active.entries[0].sets[1], { done: true, at: 9e12, rpe: 7 }) }) })+ act(() => { applyEvents([{ id: 'r2', type: 'setDone', wid: 'w-watch', exId: '0025', entryIdx: 0, setIdx: 1, w: 60, r: 8, at: 1000, rpe: 10 }], () => useStore.getState()) })+ expect(useStore.getState().S.active.entries[0].sets[1].rpe).toBe(7)+ })+it('the watch\'s Discard drops the workout without saving it', () => {const before = useStore.getState().S.workouts.lengthact(() => { applyEvents([{ id: 'x1', type: 'discard', wid: 'w-watch', at: Date.now() }], () => useStore.getState()) })