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
Follow-up to !140: an assistance machine counts the help against the lifter
Duarte Santos2ef4be1f924b
diff --git a/frontend/src/lib/structuralBalance.js b/frontend/src/lib/structuralBalance.jsindex ab09806a3..805d940dc 100644--- a/frontend/src/lib/structuralBalance.js+++ b/frontend/src/lib/structuralBalance.js@@ -1,6 +1,7 @@import { estimate1RM } from './onerm.js'import { LB_TO_KG } from './recovery.js'import { isBw } from './history.js'+import { isAssisted } from './exercises.js'import { isSideSet, isWarmupRow } from './workout-model.js'import { BALANCE_STATUSES, BORDERLINE_BAND_PCT, EVALUATION_MODES } from './structuralBalanceTemplates.js'@@ -16,19 +17,34 @@ export function bodyweightKgOf(S) {return kgOf(last.w, S.unit)}+// An assistance machine (exercises.js isAssisted, issue #232), read the way onerm.js and+// history.js read a logged entry — by the exercise, so the same machine counts the same way on+// every screen.+const isAssistedEntry = entry => isAssisted(entry?.id ? { id: entry.id } : entry)+// What one completed set actually moved, in kg. On a bodyweight-configured entry `w` holds only// what was *added* (history.js: "`w` means *added* weight"), so the lifter's own mass has to be// added back: a chin-up with +10 kg is not a 10 kg lift, and Poliquin's dip/pull-up ratios are// against bodyweight + load. The weigh-in stamped on that session is the honest figure for an// old workout, with the profile's latest as the fallback; with neither, the set is left unscored// rather than scored against an invented body mass.+//+// On an assistance machine `w` is the help the stack gave, so it comes off the lifter's mass+// instead: 20 kg of help at 80 kg is a 60 kg pull-up. Counting it as load — or adding it to the+// body when the entry is flagged bodyweight — would score more help as a stronger lift. A 0+// there is a row with no help entered, not a set done without any (history.js), and help at or+// above body mass moved nothing: both are left unscored.function setLoadKg(S, workout, entry, set, bodyweightKg) {- const added = kgOf(set.w || 0, S.unit)- const bodyweight = entry.target?.bodyweight ?? entry.bodyweight- if (!isBw({ id: entry.id, bodyweight })) return added+ const logged = kgOf(set.w || 0, S.unit)const stamped = workout?.bw > 0 ? kgOf(workout.bw, S.unit) : nullconst body = stamped ?? bodyweightKg- return body > 0 ? body + added : null+ if (isAssistedEntry(entry)) {+ if (!(logged > 0) || !(body > 0)) return null+ return body - logged > 0 ? body - logged : null+ }+ const bodyweight = entry.target?.bodyweight ?? entry.bodyweight+ if (!isBw({ id: entry.id, bodyweight })) return logged+ return body > 0 ? body + logged : null}// Best estimated 1RM across a whitelist of exercise ids, in kg. Scans the log directly instead of@@ -77,12 +93,14 @@ function bestRepsOf(entry) {return best}+// A rep target is reps at body weight: reps the machine helped with are not those reps, so an+// assistance machine a role was pointed at reads as no data here rather than as a pass.export function resolveCurrentReps(S, exerciseIds) {let best = nullfor (const exId of exerciseIds) {for (const workout of S.workouts || []) {const entry = (workout.entries || []).find(e => e.id === exId)- const found = entry && bestRepsOf(entry)+ const found = entry && !isAssistedEntry(entry) && bestRepsOf(entry)if (found && (!best || found.r > best.r)) best = { ...found, d: workout.d, t: workout.start, exId }}}diff --git a/frontend/src/lib/structuralBalance.test.js b/frontend/src/lib/structuralBalance.test.jsindex 45517ecc0..4ef712227 100644--- a/frontend/src/lib/structuralBalance.test.js+++ b/frontend/src/lib/structuralBalance.test.js@@ -237,6 +237,67 @@ describe('bodyweight exercises count the lifter, not just the belt', () => {})})+// A role pointed at an assistance machine through the exercise picker (0017 assisted pull-up):+// the logged number is the help, so it comes off the lifter instead of going on top.+describe('an assistance machine counts the help against the lifter', () => {+ const ASSISTED = '0017' // assisted pull-up, a leverage machine+ const poliquin = TEMPLATES.poliquin+ const pullRole = findRole(poliquin, 'supinePullups')+ const lifter = (entry, extra = {}) => ({+ unit: 'kg',+ bodyweight: [{ d: '2026-01-01', w: 80 }],+ balanceOverrides: { [overrideKey(poliquin, pullRole)]: ASSISTED },+ workouts: [{ d: '2026-01-10', start: NOW, entries: [{ id: '0030', sets: [setDone(100, 1)] }, entry] }],+ ...extra,+ })+ const pullups = S => computeBalance(S, poliquin).find(r => r.roleId === 'supinePullups')++ it('scores body weight minus the help', () => {+ const row = pullups(lifter({ id: ASSISTED, sets: [setDone(20, 1)] }))+ expect(row.mappedExerciseId).toBe(ASSISTED)+ expect(row.current.estKg).toBeCloseTo(60) // 80 kg lifter, 20 kg of help+ expect(row.actualPct).toBeCloseTo(60)+ expect(row.status).toBe(BALANCE_STATUSES.WEAK) // 87% target+ })++ it('reads less help as the stronger set, not more', () => {+ const row = pullups(lifter({ id: ASSISTED, sets: [setDone(40, 1), setDone(10, 1)] }))+ expect(row.current.estKg).toBeCloseTo(70)+ expect(row.current.w).toBe(10)+ })++ it('still subtracts when the entry is flagged bodyweight', () => {+ const row = pullups(lifter({ id: ASSISTED, target: { bodyweight: true }, sets: [setDone(20, 1)] }))+ expect(row.current.estKg).toBeCloseTo(60) // not 80 + 20+ })++ it('uses the weigh-in stamped on the session, and converts a lb profile', () => {+ const stamped = lifter({ id: ASSISTED, sets: [setDone(20, 1)] })+ stamped.workouts[0].bw = 70+ expect(pullups(stamped).current.estKg).toBeCloseTo(50)++ const lb = lifter({ id: ASSISTED, sets: [setDone(44.09, 1)] }, { unit: 'lb', bodyweight: [{ d: '2026-01-01', w: 176.37 }] })+ lb.workouts[0].entries[0].sets = [setDone(220.46, 1)] // the 100 kg anchor in lb+ expect(pullups(lb).actualPct).toBeCloseTo(60, 0)+ })++ it('leaves a set unscored with no help entered, help at or above body weight, or no body weight', () => {+ expect(pullups(lifter({ id: ASSISTED, sets: [setDone(0, 5)] })).status).toBe(BALANCE_STATUSES.NO_DATA)+ expect(pullups(lifter({ id: ASSISTED, sets: [setDone(80, 5)] })).status).toBe(BALANCE_STATUSES.NO_DATA)+ expect(pullups(lifter({ id: ASSISTED, sets: [setDone(20, 1)] }, { bodyweight: [] })).status).toBe(BALANCE_STATUSES.NO_DATA)+ })++ it('does not count helped reps toward a body-weight rep target', () => {+ const atg = TEMPLATES.atg+ const key = overrideKey(atg, findRole(atg, 'pullups'))+ const S = { unit: 'kg', balanceOverrides: { [key]: ASSISTED }, workouts: [workoutAt(ASSISTED, NOW, [setDone(30, 12)])] }+ const row = computeBalance(S, atg).find(r => r.roleId === 'pullups')+ expect(row.isOverridden).toBe(true)+ expect(row.status).toBe(BALANCE_STATUSES.NO_DATA)+ expect(resolveCurrentReps(S, [ASSISTED])).toBe(null)+ })+})+describe('rep-count on a unilateral set', () => {it('reads the better side, not the both-sides total', () => {// workout-model.js keeps `r` as L.r + R.r on a per-side row; a "10 reps" target is per limb.