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
Progression reads the sets the plan asked for, not the extra ones logged on top (#233)
Duarte Santosb5d55467d076
diff --git a/frontend/src/lib/progression.extra-sets.test.js b/frontend/src/lib/progression.extra-sets.test.jsnew file mode 100644index 000000000..25ba4fe5a--- /dev/null+++ b/frontend/src/lib/progression.extra-sets.test.js@@ -0,0 +1,53 @@+// Issue #233: a set logged on top of the plan is extra work, not part of the prescription.+// Before this, one heavier bonus set pulled the next session's weight up with it, and a bonus+// set taken short of the target reps reported the whole session as missed.+import { describe, it, expect } from 'vitest'+import { readSession } from './progression.js'++const set = (w, r, done = true) => ({ w, r, done })+const entry = (target, sets) => ({ id: '0025', target, sets })+const plan = { mode: 'reps', sets: 3, reps: 8, weight: 60 }++describe('extra sets stay out of the progression read', () => {+ it('ignores a heavier bonus set when reading the weight', () => {+ const done = readSession(entry(plan, [set(60, 8), set(60, 8), set(60, 8), set(80, 8)]))+ expect(done.weight).toBe(60)+ expect(done.ok).toBe(true)+ })++ it('does not call the session missed because a bonus set fell short', () => {+ const done = readSession(entry(plan, [set(60, 8), set(60, 8), set(60, 8), set(80, 3)]))+ expect(done.ok).toBe(true)+ expect(done.low).toBe(8)+ expect(done.count).toBe(3)+ // Greyskull reads the last set of the plan, not whatever was tacked on after it+ expect(done.amrap).toBe(8)+ })++ it('still reports a short session as short, and still reads every planned set', () => {+ const short = readSession(entry(plan, [set(60, 8), set(60, 5), set(60, 8)]))+ expect(short.ok).toBe(false)+ expect(short.low).toBe(5)+ const missing = readSession(entry(plan, [set(60, 8), set(60, 8)]))+ expect(missing.ok).toBe(false)+ })++ it('reads everything when the plan names no set count (freestyle)', () => {+ const free = readSession(entry({ mode: 'reps', reps: 8 }, [set(60, 8), set(80, 8)]))+ expect(free.weight).toBe(80)+ expect(free.count).toBe(2)+ })++ it('leaves warm-ups out before counting, so a warm-up does not eat a planned slot', () => {+ const warm = readSession(entry(plan, [{ w: 20, r: 10, done: true, phase: 'warmup' }, set(60, 8), set(60, 8), set(60, 8), set(90, 8)]))+ expect(warm.weight).toBe(60)+ expect(warm.ok).toBe(true)+ })++ it('applies the same rule to a timed hold', () => {+ const timed = { mode: 'time', sets: 2, sec: 30, weight: 0 }+ const held = readSession(entry(timed, [{ sec: 30, done: true }, { sec: 30, done: true }, { sec: 12, done: true }]))+ expect(held.ok).toBe(true)+ expect(held.best).toBe(30)+ })+})diff --git a/frontend/src/lib/progression.js b/frontend/src/lib/progression.jsindex 8e4d818e2..48d94b08b 100644--- a/frontend/src/lib/progression.js+++ b/frontend/src/lib/progression.js@@ -219,9 +219,16 @@ export function readSession(entry, fallback) {const mode = modeOf({ ...target, id: entry && entry.id })// Warm-up rows are prep, not the session: one filtered read beats guarding every consumer// below (an undone warm-up otherwise poisons `ok` forever and its reps drag `low`/`count`).- const sets = ((entry && entry.sets) || []).filter(s => !isWarmupRow(s))- const planned = target.sets || sets.length- const enough = sets.length >= planned+ const logged = ((entry && entry.sets) || []).filter(s => !isWarmupRow(s))+ const planned = target.sets || logged.length+ const enough = logged.length >= planned+ // Only the sets the plan asked for decide what happens next (issue #233). A set added on top+ // is extra work, and it used to be read as part of the prescription: one heavier bonus set+ // raised the weight for next time, and a hard one taken short of the target reps reported the+ // whole session as missed. Extra sets still count everywhere else — volume, PRs, history —+ // they just do not move the plan. The plan's own sets are the ones it laid out first, so the+ // read stops at that many; a session with fewer than planned is short either way (`enough`).+ const sets = logged.slice(0, Math.max(1, planned))if (mode === 'time') {const goal = target.sec || 0