feat: expose the double progression rep range
This commit is contained in:
1 parent
cb24bf12d7
commit
c71cb09515
16 files changed
+98
-10
No files matched your search
@@ -19,6 +19,7 @@
|
||||
import { modeOf, repStep, rerampWarmups } from './history.js'
|
||||
import { EXIDX } from './exercises.js'
|
||||
import { isWarmupRow } from './workout-model.js'
|
||||
import { normalizeRepRange } from './rep-range.js'
|
||||
|
||||
export const POLICIES = ['off', 'linear', 'greyskull', 'double', 'time']
|
||||
|
||||
@@ -210,8 +211,9 @@ 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 top = cfg.reps || last.goal || 10
|
||||
const bottom = Math.min(cfg.repsMin || Math.max(1, top - 2), top)
|
||||
const range = normalizeRepRange(cfg.reps || last.goal || 10, cfg.repsMin)
|
||||
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] }
|
||||
if (stalls >= deloadAt) {
|
||||
const dw = deloadTo(w, inc)
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
// 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))
|
||||
return lower >= upper
|
||||
? { reps: lower + 1, repsMin: lower }
|
||||
: { reps: upper, repsMin: lower }
|
||||
}
|
||||
|
||||
function positiveInt(value, fallback) {
|
||||
const n = Number(value)
|
||||
return Number.isFinite(n) && n > 0 ? Math.max(1, Math.round(n)) : fallback
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import { normalizeRepRange } from './rep-range.js'
|
||||
|
||||
describe('normalizeRepRange', () => {
|
||||
it('keeps valid positive integer bounds unchanged', () => {
|
||||
expect(normalizeRepRange(12, 8)).toEqual({ reps: 12, repsMin: 8 })
|
||||
})
|
||||
|
||||
it('rounds bounds to positive integers', () => {
|
||||
expect(normalizeRepRange(12.4, 7.6)).toEqual({ reps: 12, repsMin: 8 })
|
||||
expect(normalizeRepRange(0, -2)).toEqual({ reps: 10, repsMin: 8 })
|
||||
})
|
||||
|
||||
it('raises the upper bound when the lower bound reaches it', () => {
|
||||
expect(normalizeRepRange(8, 8)).toEqual({ reps: 9, repsMin: 8 })
|
||||
})
|
||||
|
||||
it('raises the upper bound when the lower bound exceeds it', () => {
|
||||
expect(normalizeRepRange(8, 12)).toEqual({ reps: 13, repsMin: 12 })
|
||||
})
|
||||
|
||||
it('keeps the lower bound at least one below a lowered upper bound', () => {
|
||||
expect(normalizeRepRange(6, 8)).toEqual({ reps: 9, repsMin: 8 })
|
||||
})
|
||||
|
||||
it('supplies a usable default lower bound for a small upper bound', () => {
|
||||
expect(normalizeRepRange(1, undefined)).toEqual({ reps: 2, repsMin: 1 })
|
||||
})
|
||||
})
|
||||
Reference in new issue
Block a user