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
Routine editor: Replace drops an assistance machine's help and a per-side setting instead of carrying them onto an exercise they do not fit (#110)
Duarte Santosc72085a48ede
diff --git a/frontend/src/lib/routines.js b/frontend/src/lib/routines.jsindex a3d97a892..e540dade7 100644--- a/frontend/src/lib/routines.js+++ b/frontend/src/lib/routines.js@@ -1,6 +1,6 @@import { uid } from './format.js'import { defaultConfig, isBw, modeOf } from './history.js'-import { isBodyweightEq, isCardio } from './exercises.js'+import { isAssisted, isBodyweightEq, isCardio } from './exercises.js'import { sessionsFor } from './progression.js'/**@@ -23,13 +23,15 @@ export function copyRoutine(routine, suffix = 'Copy') {* it — sets, reps, weight, rest, warm-ups, the progression rule, the note, its superset — and only* the exercise changes. The old way (remove, add, configure again) lost all of that.*- * Two things cannot come along. A cardio slot is minutes at a speed and a lifting slot is sets of- * reps at a load, so between the two only the note, the rest and the superset carry over and the- * rest starts from the new exercise's defaults. And a load means something else once the new+ * Some things cannot come along. A cardio slot is minutes at a speed and a lifting slot is sets+ * of reps at a load, so between the two only the note, the rest and the superset carry over and+ * the rest starts from the new exercise's defaults. A load means something else once the new* exercise is bodyweight where the old one was not, or the other way round: 60 kg on a bench is- * not 60 kg added to a push-up. There the weight goes back to 0. The bodyweight flag is stored- * only where it overrides an exercise's equipment, so it is always dropped and the new exercise- * follows its own.+ * not 60 kg added to a push-up. The same goes for an assistance machine, where the number is+ * help rather than load: 40 kg off a pull-up is not 40 kg on a pulldown. There the weight goes+ * back to 0. The bodyweight, assisted and per-side flags describe the movement, not the+ * prescription, so they are dropped and the new exercise follows its own, the way the Coach's+ * swap does (lib/coach.js): a split squat's "per side" would split a back squat's reps into L/R.** What is not carried is history. Progress belongs to a routine and an exercise together (#216),* so the new exercise starts on its own line — its own sessions in this routine, and until there@@ -52,7 +54,7 @@ export function replaceSlotExercise(slot, id, S, rid) {const kept = ['sg', 'note', 'restSec'].filter(key => old[key] != null)return { id, ...defaultConfig(id), ...Object.fromEntries(kept.map(key => [key, old[key]])) }}- const { id: _replaced, bodyweight: _flag, ...carried } = old+ const { id: _replaced, bodyweight: _flag, assisted: _assisted, side: _side, ...carried } = oldconst out = { id, ...carried }if (isCardio(id)) return outif (isBw(old) !== isBodyweightEq(id)) {@@ -60,6 +62,7 @@ export function replaceSlotExercise(slot, id, S, rid) {// A rep ceiling belongs to bodyweight work: it adds sets where there is no load to add.delete out.repsMax}+ if (isAssisted(old) !== isAssisted(id)) out.weight = 0// The session the next prescription will read for this slot (nextPrescription), so the weight// put here is the one that session was planned at: the restart rule then sees no edit and// holds at what was lifted, or the plan carries on from it. A session saved before plans werediff --git a/frontend/src/lib/routines.replace.test.js b/frontend/src/lib/routines.replace.test.jsindex d674c9449..407b877a6 100644--- a/frontend/src/lib/routines.replace.test.js+++ b/frontend/src/lib/routines.replace.test.js@@ -12,12 +12,14 @@ const DB_BENCH = '0289' // dumbbell bench pressconst PUSH_UP = '0662' // push-up, body weightconst PULL_UP = '0652' // pull-up, body weightconst BIKE = '2138' // stationary bike, cardio+const ASSISTED_PULL_UP = '0015' // assisted pull-up, a leverage machine: the weight is help+const PULLDOWN = '0150' // lat pulldown, cabledescribe('replaceSlotExercise', () => {it('keeps the slot\'s sets, reps, weight, rule, rest, warm-ups, note and superset', () => {const slot = {id: BENCH, sg: 'sgA', sets: 4, mode: 'reps', reps: 8, repsMin: 6, weight: 60, prog: 'double', inc: 1.25,- deloadFactor: 0.85, note: 'pause on the chest', warmupSets: 2, restSec: 150, side: true,+ deloadFactor: 0.85, note: 'pause on the chest', warmupSets: 2, restSec: 150,intensifier: { type: 'dropset', count: 1, pct: 20 },}const next = replaceSlotExercise(slot, DB_BENCH)@@ -26,6 +28,12 @@ describe('replaceSlotExercise', () => {expect(slot.id).toBe(BENCH)})+ it('drops the flags that describe the old movement, so the new exercise follows its own', () => {+ // A split squat's "per side" would turn a back squat's 16 reps into 8 a side with L/R rows.+ expect(replaceSlotExercise({ id: BENCH, sets: 3, mode: 'reps', reps: 16, weight: 40, side: true, assisted: false }, DB_BENCH))+ .toEqual({ id: DB_BENCH, sets: 3, mode: 'reps', reps: 16, weight: 40 })+ })+it('changes nothing when the pick is the exercise already in the slot', () => {// A push-up the user loaded with 20 kg and marked as not bodyweight, picked again from "Chosen".const slot = { id: PUSH_UP, sg: 'sgA', sets: 3, mode: 'reps', reps: 8, weight: 20, bodyweight: false, side: true }@@ -34,6 +42,15 @@ describe('replaceSlotExercise', () => {expect(same).not.toBe(slot)})+ it('drops a weight that is help on one side of the swap and load on the other', () => {+ // 40 kg of help on an assisted pull-up is not a 40 kg pulldown …+ expect(replaceSlotExercise({ id: ASSISTED_PULL_UP, sets: 3, mode: 'reps', reps: 8, weight: 40 }, PULLDOWN))+ .toEqual({ id: PULLDOWN, sets: 3, mode: 'reps', reps: 8, weight: 0 })+ // … and a 50 kg pulldown is not 50 kg taken off a pull-up.+ expect(replaceSlotExercise({ id: PULLDOWN, sets: 3, mode: 'reps', reps: 8, weight: 50 }, ASSISTED_PULL_UP))+ .toEqual({ id: ASSISTED_PULL_UP, sets: 3, mode: 'reps', reps: 8, weight: 0 })+ })+it('keeps a timed slot timed', () => {const next = replaceSlotExercise({ id: BENCH, sets: 3, mode: 'time', sec: 40, weight: 20 }, DB_BENCH)expect(next).toEqual({ id: DB_BENCH, sets: 3, mode: 'time', sec: 40, weight: 20 })