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.

Follow-up to !140: a lift exactly at its ratio of the anchor reads as balanced

Duarte Santosea1a9f479ab0
diff --git a/frontend/src/lib/structuralBalance.js b/frontend/src/lib/structuralBalance.js
index efff880d2..768c8b2bb 100644
--- a/frontend/src/lib/structuralBalance.js
+++ b/frontend/src/lib/structuralBalance.js
@@ -1,4 +1,4 @@
-import { estimate1RM, FORMULAS } from './onerm.js'
+import { estimate1RM, FORMULAS, DEFAULT_FORMULA } from './onerm.js'
import { LB_TO_KG } from './recovery.js'
import { isBw } from './history.js'
import { EXIDX, isAssisted } from './exercises.js'
@@ -85,11 +85,22 @@ export function loadAtReps(loadKg, setReps, reps) {
return loadForReps(r === 1 ? w : FORMULAS.epley(w, r), reps)
}
+// estimate1RM()'s estimate without its 0.1 kg rounding. A load table only ever divides one
+// estimate by another, and two rounded ones of loads exactly at its ratio land either side of it:
+// a 100 kg squat and a 125 kg deadlift, both for 5, read 124.94% of Poliquin's 125% — Borderline,
+// next to "125% / 125%". Its guards, the rep cap among them, still decide what is an estimate.
+function unrounded1RM(loadKg, reps) {
+ if (estimate1RM(loadKg, reps) === null) return null
+ const w = Number(loadKg)
+ const r = Number(reps)
+ return r === 1 ? w : FORMULAS[DEFAULT_FORMULA](w, Math.round(r))
+}
+
// Best reading across a whitelist of exercise ids, in kg: the estimated 1RM (`estKg`), or with
// `reps` the load for that many reps (`repsKg`, loadAtReps). Scans the log directly instead of
// calling onerm.js's best1RM(), which reads `s.w` raw and so cannot see the body mass a dip or a
-// pull-up moves, nor a unilateral row's sides; the 1RM itself still goes through the shared
-// estimate1RM() so the formula, its rounding and its rep cap stay in one place.
+// pull-up moves, nor a unilateral row's sides; the 1RM itself still comes from the shared
+// estimate1RM()'s formula and rep cap.
export function resolveCurrent(S, exerciseIds, bodyweightKg, reps = null) {
const key = reps > 1 ? 'repsKg' : 'estKg'
let best = null
@@ -102,7 +113,7 @@ export function resolveCurrent(S, exerciseIds, bodyweightKg, reps = null) {
for (const lift of liftsOf(set)) {
const loadKg = setLoadKg(S, workout, entry, lift, bodyweightKg)
if (loadKg === null) continue
- const kg = reps > 1 ? loadAtReps(loadKg, lift.r, reps) : estimate1RM(loadKg, lift.r)
+ const kg = reps > 1 ? loadAtReps(loadKg, lift.r, reps) : unrounded1RM(loadKg, lift.r)
if (kg === null) continue
if (!best || kg > best[key]) {
best = { [key]: kg, w: Number(lift.w) || 0, r: Math.round(Number(lift.r)), d: workout.d, t: workout.start, exId }
diff --git a/frontend/src/lib/structuralBalance.test.js b/frontend/src/lib/structuralBalance.test.js
index d2be893dc..48f7aceb3 100644
--- a/frontend/src/lib/structuralBalance.test.js
+++ b/frontend/src/lib/structuralBalance.test.js
@@ -59,6 +59,38 @@ describe('computeBalance — load-ratio mode (Thibaudeau powerlifting)', () => {
expect(withoutSquat.find(r => r.roleId === 'squat').status).toBe(BALANCE_STATUSES.NO_DATA)
})
+ // Loads exactly at a table's ratio, lifted for the same reps, are exactly that ratio of each
+ // other — whatever the reps. Rounded estimates of both could land either side of it.
+ it('a lift exactly at its ratio of the anchor is balanced, at any reps', () => {
+ const poliquin = TEMPLATES.poliquin
+ const deadlift = computeBalance({ unit: 'kg', workouts: [
+ workoutAt('1436', NOW - 1000, [setDone(100, 5)]),
+ workoutAt('0032', NOW, [setDone(125, 5)]),
+ ] }, poliquin).find(r => r.roleId === 'deadlift')
+ expect(deadlift.actualPct).toBeCloseTo(125, 9)
+ expect(deadlift.status).toBe(BALANCE_STATUSES.BALANCED)
+
+ const missed = []
+ for (const tpl of [poliquin, template]) {
+ for (const role of tpl.roles.filter(r => r.anchorRoleId && !['dips', 'supinePullups'].includes(r.id))) {
+ const anchor = findRole(tpl, role.anchorRoleId)
+ for (let anchorKg = 40; anchorKg <= 250; anchorKg += 2.5) {
+ for (const reps of [1, 2, 3, 4, 5, 6, 8, 10, 12]) {
+ for (const unit of ['kg', 'lb']) {
+ const S = { unit, workouts: [
+ workoutAt(anchor.exerciseIds[0], NOW - 1000, [setDone(anchorKg, reps)]),
+ workoutAt(role.exerciseIds[0], NOW, [setDone(anchorKg * role.targetPct / 100, reps)]),
+ ] }
+ const row = computeBalance(S, tpl).find(r => r.roleId === role.id)
+ if (row.status !== BALANCE_STATUSES.BALANCED) missed.push(`${tpl.id} ${role.id} ${anchorKg} ${unit} × ${reps}: ${row.actualPct}`)
+ }
+ }
+ }
+ }
+ }
+ expect(missed).toEqual([])
+ })
+
it('a non-anchor role is no-data when the anchor itself has no data, even if the role does', () => {
const S = { unit: 'kg', workouts: [workoutAt('0025', NOW, [setDone(80, 1)])] } // bench logged, squat never
const results = computeBalance(S, template)
@@ -185,7 +217,7 @@ describe('computeBalance — bodyweight-ratio mode (ATG)', () => {
const eightAHand = { unit: 'kg', workouts: [workoutAt('0361', NOW, [
{ done: true, w: 20, r: 16, sides: { L: { w: 20, r: 8, done: true }, R: { w: 20, r: 8, done: true } } },
])] }
- expect(resolveCurrent(eightAHand, ['0361'], 80).estKg).toBeCloseTo(25.3) // 16 in total is past the rep cap
+ expect(resolveCurrent(eightAHand, ['0361'], 80).estKg).toBeCloseTo(20 * (1 + 8 / 30)) // 16 in total is past the rep cap
})
// ATG's test is to load the bar to the standard, so a lifter lands exactly on it: that has to