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: preserve per-side double progression reps

Manuel5e6c4d1a75bc
diff --git a/frontend/src/lib/progression.js b/frontend/src/lib/progression.js
index a1c8ac4c5..b9efd4109 100644
--- a/frontend/src/lib/progression.js
+++ b/frontend/src/lib/progression.js
@@ -211,7 +211,7 @@ export function nextPrescription(S, cfg, routine) {
return { policy, kind: 'up', weight: 0, reps: next, why: ['Bodyweight — every rep last time, so go for {0} this time.', next] }
}
if (policy === 'double') {
- const range = normalizeRepRange(cfg.reps || last.goal || 10, cfg.repsMin)
+ const range = normalizeRepRange(cfg.reps || last.goal || 10, cfg.repsMin, repStep(cfg))
const top = range.reps
const bottom = range.repsMin
if (last.ok) return { policy, kind: 'up', weight: snap(w + inc, inc), reps: bottom, why: ['Top of the rep range in every set — {0} {1} more, back to {2} reps.', inc, unit, bottom] }
diff --git a/frontend/src/lib/progression.test.js b/frontend/src/lib/progression.test.js
index 7cc1c5188..64a52b980 100644
--- a/frontend/src/lib/progression.test.js
+++ b/frontend/src/lib/progression.test.js
@@ -311,6 +311,13 @@ describe('double progression', () => {
expect(p.reps).toBe(8)
expect(p.weight).toBe(35) // 40 × 0.9 = 36 → nearest loadable 2.5 step
})
+
+ it('normalizes persisted per-side bounds before prescribing', () => {
+ const perSide = { ...cfg, reps: 13, repsMin: 7, side: true }
+ const p = nextPrescription(hist(LIFT, [[40, 12, 12, 12]], { sets: 3, reps: 13 }), perSide)
+ expect(p.kind).toBe('hold')
+ expect(p.reps).toBe(14)
+ })
})
describe('timed progression', () => {
diff --git a/frontend/src/lib/rep-range.js b/frontend/src/lib/rep-range.js
index b01aab133..c8646e12e 100644
--- a/frontend/src/lib/rep-range.js
+++ b/frontend/src/lib/rep-range.js
@@ -1,13 +1,18 @@
// Normalize the two bounds used by double progression.
// `reps` is the upper bound and `repsMin` is the lower bound in persisted configs.
-export function normalizeRepRange(reps, repsMin) {
- const upper = positiveInt(reps, 10)
- const lower = positiveInt(repsMin, Math.max(1, upper - 2))
+export function normalizeRepRange(reps, repsMin, stride = 1) {
+ const step = Number.isInteger(stride) && stride > 0 ? stride : 1
+ const upper = align(positiveInt(reps, 10), step)
+ const lower = align(positiveInt(repsMin, Math.max(1, upper - 2)), step)
return lower >= upper
- ? { reps: lower + 1, repsMin: lower }
+ ? { reps: lower + step, repsMin: lower }
: { reps: upper, repsMin: lower }
}
+function align(value, stride) {
+ return Math.max(stride, Math.ceil(value / stride) * stride)
+}
+
function positiveInt(value, fallback) {
const n = Number(value)
return Number.isFinite(n) && n > 0 ? Math.max(1, Math.round(n)) : fallback
diff --git a/frontend/src/lib/rep-range.test.js b/frontend/src/lib/rep-range.test.js
index 5446b2113..fc8aabcc6 100644
--- a/frontend/src/lib/rep-range.test.js
+++ b/frontend/src/lib/rep-range.test.js
@@ -26,4 +26,13 @@ describe('normalizeRepRange', () => {
it('supplies a usable default lower bound for a small upper bound', () => {
expect(normalizeRepRange(1, undefined)).toEqual({ reps: 2, repsMin: 1 })
})
+
+ it('aligns both bounds to an even stride', () => {
+ expect(normalizeRepRange(13, 7, 2)).toEqual({ reps: 14, repsMin: 8 })
+ })
+
+ it('keeps a valid gap when per-side bounds are invalid', () => {
+ expect(normalizeRepRange(8, 9, 2)).toEqual({ reps: 12, repsMin: 10 })
+ expect(normalizeRepRange(0, -2, 2)).toEqual({ reps: 10, repsMin: 8 })
+ })
})
diff --git a/frontend/src/sheets.jsx b/frontend/src/sheets.jsx
index 5f31e95cc..ba8f3663e 100644
--- a/frontend/src/sheets.jsx
+++ b/frontend/src/sheets.jsx
@@ -559,17 +559,18 @@ export const equipmentProfileSheet = profile => ui().openSheet(close => <Equipme
// Progression settings for one exercise (issue #17). Shown inside the config sheet because
// "how does this lift go up" belongs next to sets and reps, not in a separate screen. Left
// on "follow the routine" it inherits, so most people never touch it.
-function ProgressionFields({ ex, mode, c, setC, routine, unit }) {
+function ProgressionFields({ ex, mode, c, setC, routine, unit, perSide }) {
const options = POLICIES_FOR[mode] || ['off']
if (options.length < 2) return null
const inherited = policyFor({ id: ex.id }, routine, mode)
const active = policyFor({ ...c, id: ex.id }, routine, mode)
const inc = c.inc > 0 ? c.inc : (mode === 'time' ? 5 : defaultIncrement(ex.id, unit))
- const range = active === 'double' ? normalizeRepRange(c.reps, c.repsMin) : null
+ const stride = mode === 'reps' && perSide ? 2 : 1
+ const range = active === 'double' ? normalizeRepRange(c.reps, c.repsMin, stride) : null
const setRule = v => setC(x => {
const next = { ...x, prog: v || undefined }
return policyFor({ ...next, id: ex.id }, routine, mode) === 'double'
- ? { ...next, ...normalizeRepRange(next.reps, next.repsMin) }
+ ? { ...next, ...normalizeRepRange(next.reps, next.repsMin, stride) }
: next
})
return <>
@@ -584,10 +585,10 @@ function ProgressionFields({ ex, mode, c, setC, routine, unit }) {
<Stepper label={mode === 'time' ? t('Step (seconds)') : t('Step ({0})', unit)} value={inc}
step={mode === 'time' ? 5 : 1.25} decimal={mode !== 'time'} onChange={v => setC(x => ({ ...x, inc: v }))} />
{active === 'double' && <>
- <Stepper label={t('Reps from')} value={range.repsMin} step={1} decimal={false}
- onChange={v => setC(x => ({ ...x, ...normalizeRepRange(x.reps, v) }))} />
- <Stepper label={t('Reps up to')} value={range.reps} step={1} decimal={false}
- onChange={v => setC(x => ({ ...x, ...normalizeRepRange(v, x.repsMin) }))} />
+ <Stepper label={t('Reps from')} value={range.repsMin} step={stride} decimal={false}
+ onChange={v => setC(x => ({ ...x, ...normalizeRepRange(x.reps, v, stride) }))} />
+ <Stepper label={t('Reps up to')} value={range.reps} step={stride} decimal={false}
+ onChange={v => setC(x => ({ ...x, ...normalizeRepRange(v, x.repsMin, stride) }))} />
</>}
</div>}
</>
@@ -600,7 +601,7 @@ function ExConfig({ ex, existing, onSave, onDelete, close, routine, initial }) {
const [c, setC] = useState(() => {
const cfg = { ...seed }
return policyFor({ ...cfg, id: ex.id }, routine, modeOf({ ...cfg, id: ex.id })) === 'double'
- ? { ...cfg, ...normalizeRepRange(cfg.reps, cfg.repsMin) }
+ ? { ...cfg, ...normalizeRepRange(cfg.reps, cfg.repsMin, isPerSide(cfg) ? 2 : 1) }
: cfg
})
// Cardio keeps its own duration+speed form; the reps/time choice (issue #16) is offered for
@@ -615,7 +616,7 @@ function ExConfig({ ex, existing, onSave, onDelete, close, routine, initial }) {
const setMode = m => setC(x => {
const next = { ...defaultConfig(ex.id, m), ...x, mode: m }
return m === 'reps' && policyFor({ ...next, id: ex.id }, routine, 'reps') === 'double'
- ? { ...next, ...normalizeRepRange(next.reps, next.repsMin) }
+ ? { ...next, ...normalizeRepRange(next.reps, next.repsMin, isPerSide(next) ? 2 : 1) }
: next
})
const save = () => {
@@ -648,11 +649,11 @@ function ExConfig({ ex, existing, onSave, onDelete, close, routine, initial }) {
// A unilateral target is stored even: the split has to divide, and a typed 15 would
// otherwise plan seven reps on one side and eight on the other, every session.
const typed = Math.max(1, Math.round(c.reps) || 10)
- let reps = perSide ? Math.ceil(typed / 2) * 2 : typed
+ const stride = perSide ? 2 : 1
+ let reps = perSide ? Math.ceil(typed / stride) * stride : typed
let range = null
if (double) {
- range = normalizeRepRange(reps, c.repsMin)
- if (perSide) range = normalizeRepRange(Math.ceil(range.reps / 2) * 2, range.repsMin)
+ range = normalizeRepRange(reps, c.repsMin, stride)
reps = range.reps
}
const out = { sets, mode: 'reps', reps, weight: Math.max(0, c.weight || 0), ...flags, ...(perSide ? { side: true } : {}), ...prog, ...withNote, ...withWarmups }
@@ -732,7 +733,12 @@ function ExConfig({ ex, existing, onSave, onDelete, close, routine, initial }) {
subtitle={perSide ? t('You still log the total: {0} is {1} per side.', c.reps || 0, fmtNum(sideReps(c.reps))) : t('For lunges, single-arm rows and the like.')}>
{/* Turning it on rounds the target up to an even number, since half of an odd
total is a rep one side does not get. */}
- <Switch checked={perSide} onChange={v => setC(x => ({ ...x, side: v || undefined, reps: v ? Math.ceil((x.reps || 0) / 2) * 2 : x.reps }))} />
+ <Switch checked={perSide} onChange={v => setC(x => {
+ const next = { ...x, side: v || undefined, reps: v ? Math.ceil((x.reps || 0) / 2) * 2 : x.reps }
+ return policyFor({ ...next, id: ex.id }, routine, 'reps') === 'double'
+ ? { ...next, ...normalizeRepRange(next.reps, next.repsMin, v ? 2 : 1) }
+ : next
+ })} />
</Row>}
</div>}
{/* A stepper is too wide to sit in a list row next to a label — it squeezes the text to
@@ -794,7 +800,7 @@ function ExConfig({ ex, existing, onSave, onDelete, close, routine, initial }) {
: t('Every set becomes rest-pause: {0} reps to start, then {1} more split into short bursts, {2}s rest before each, roughly halving each time.', c.reps || 0, c.intensifier.totalReps, c.intensifier.restSec)}
</div>}
</>}
- <ProgressionFields ex={ex} mode={mode} c={c} setC={setC} routine={routine} unit={st.unit} />
+ <ProgressionFields ex={ex} mode={mode} c={c} setC={setC} routine={routine} unit={st.unit} perSide={perSide} />
<textarea className="input" rows={3} maxLength={500} style={{ marginBottom: 18 }}
placeholder={t('Note (optional) — loading cues, "bar only then +1 plate/side each set", anything worth remembering here')}
value={c.note || ''} onChange={e => setC(x => ({ ...x, note: e.target.value }))} />