Skip to content

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.

fix(recovery): calibrate the 90-day anchor with logged RIR via effective reps

Сергей Горбатенко533ae2f9173a
diff --git a/docs/dev/FATIGUE_SETS_MODEL.md b/docs/dev/FATIGUE_SETS_MODEL.md
index fd4a0ccd7..ac0cd59e5 100644
--- a/docs/dev/FATIGUE_SETS_MODEL.md
+++ b/docs/dev/FATIGUE_SETS_MODEL.md
@@ -92,7 +92,10 @@ Two orthogonal multipliers on top of the phase-1 sets, both causal and bounded:
(via `effort.js`, `HARD_RIR = 3`) always wins; otherwise RIR is estimated by
Epley inverse against the exercise's 90-day rolling best anchor
(`30*(anchor/w-1)-r`, clamped 0..10, null above `REP_CAP = 12`, for
- load-less rows, or assisted work). Weight is 1.0 at RIR <= 3, linear down to
+ load-less rows, or assisted work). The anchor itself is RIR-calibrated: each
+ session's best runs on effective reps (done plus logged RIR, a set taken to
+ failure adding nothing), so a rated set reads its own rating back and an
+ unrated twin of it reads the same. Weight is 1.0 at RIR <= 3, linear down to
the 0.3 floor at RIR >= 6. Loads canonicalise to kg through the
set -> target -> entry -> workout -> opts chain, so mixed-unit imports anchor
correctly (176 lb anchors like 80 kg). A ramp-up row therefore costs a
diff --git a/frontend/src/lib/recovery.js b/frontend/src/lib/recovery.js
index 1beb6c920..fac57d37e 100644
--- a/frontend/src/lib/recovery.js
+++ b/frontend/src/lib/recovery.js
@@ -287,13 +287,24 @@ function sessionEffSets(workout, anchors, opts = {}) {
// 90-day-old import can never reweight today's anchor - only sessions inside the
// anchor window ending at the scored session contribute. Assistance work has no
// 1RM (the load is help received) and stays out, matching onerm.js.
+//
+// A logged rating calibrates the anchor: done plus left is the set's true rep
+// capacity, so the estimate runs on effective reps (a set taken to failure adds
+// nothing; an unrated set keeps its raw reps, exactly as before). The inversion
+// stays consistent, so the set that set the anchor reads its logged RIR back -
+// and an unrated twin of a rated set reads the same RIR. Past the rep cap an
+// easy rated set anchors nothing, which is the honest answer (work capacity,
+// not strength), matching estimate1RM.
function sessionBests(workout, opts = {}) {
const best = new Map()
const consider = (ex, set, entry, exId) => {
if (set?.done !== true) return
const sides = isSideSet(set) ? [set.sides.L, set.sides.R].filter(s => s?.done === true) : [set]
for (const side of sides) {
- const est = estimate1RM(loadKgFor(ex, entry, set, workout, opts, side), numeric(side?.r))
+ const reps = numeric(side?.r)
+ const logged = rirOf(side) ?? rirOf(set)
+ const effective = reps != null && logged != null ? reps + logged : reps
+ const est = estimate1RM(loadKgFor(ex, entry, set, workout, opts, side), effective)
if (est !== null && (!best.has(exId) || est > best.get(exId))) best.set(exId, est)
}
}
diff --git a/frontend/src/lib/recovery.test.js b/frontend/src/lib/recovery.test.js
index 13cfff804..93de68418 100644
--- a/frontend/src/lib/recovery.test.js
+++ b/frontend/src/lib/recovery.test.js
@@ -766,6 +766,40 @@ describe('anchorsByWorkout and resolveSetRir', () => {
expect(anchors.get(now).get(SINGLE.id)).toBeCloseTo(100 * (1 + 5 / 30), 1)
})
+ it('calibrates the anchor with a logged rating: done plus left is the capacity', () => {
+ const rated = at(SINGLE.id, NOW, [{ done: true, w: 80, r: 8, rir: 2 }])
+ const plain = at(SINGLE.id, NOW, [{ done: true, w: 80, r: 8 }])
+ const failed = at(SINGLE.id, NOW, [{ done: true, w: 80, r: 8, failure: true }])
+ // 80x8 at RIR 2 is a 10RM effort, so it anchors like 80x10.
+ expect(anchorsByWorkout([rated]).get(rated).get(SINGLE.id)).toBeCloseTo(80 * (1 + 10 / 30), 1)
+ expect(anchorsByWorkout([plain]).get(plain).get(SINGLE.id)).toBeCloseTo(80 * (1 + 8 / 30), 1)
+ // A set taken to failure adds nothing - it anchors exactly like an unrated set.
+ expect(anchorsByWorkout([failed]).get(failed).get(SINGLE.id))
+ .toBeCloseTo(anchorsByWorkout([plain]).get(plain).get(SINGLE.id), 5)
+ })
+
+ it('reads an unrated twin of a rated set back at the same RIR', () => {
+ const w = at(SINGLE.id, NOW, [{ done: true, w: 80, r: 8, rir: 2 }, { done: true, w: 80, r: 8 }])
+ const anchors = anchorsByWorkout([w])
+ const twin = resolveSetRir({ done: true, w: 80, r: 8 }, null, { id: SINGLE.id }, w, anchors.get(w), {})
+ expect(twin.source).toBe('estimated')
+ expect(twin.rir).toBeCloseTo(2, 1)
+ })
+
+ it('anchors nothing for an easy rated set past the rep cap', () => {
+ // 60x8 at RIR 6 is a 14RM effort: work capacity, not strength.
+ const w = at(SINGLE.id, NOW, [{ done: true, w: 60, r: 8, rir: 6 }])
+ expect(anchorsByWorkout([w]).get(w).has(SINGLE.id)).toBe(false)
+ })
+
+ it('falls back to the shared rating for unrated sides of a side set', () => {
+ const w = at(SINGLE.id, NOW, [{
+ w: 20, r: 16, done: true, rir: 2,
+ sides: { L: { w: 20, r: 8, done: true }, R: { w: 20, r: 8, done: true } },
+ }])
+ expect(anchorsByWorkout([w]).get(w).get(SINGLE.id)).toBeCloseTo(20 * (1 + 10 / 30), 1)
+ })
+
it('resolves logged effort first, estimates second, null when unknowable', () => {
const anchors = new Map([['e1', 110]])
const entry = { id: 'e1' }