warm-ups: keep them out of volume, and make the ramp follow the weight
Three defects, all of them latent before v1.2.10 and live the moment a routine started planning warm-ups by default. workoutVolume counted warm-up rows. It was the only consumer that did — onerm, muscles, recovery and progression all filter them — while the config sheet tells users in so many words that warm-ups are "left out of volume, records and progression", and a comment in this very file asserts it. Three planned warm-ups on a 3x5 at 100kg reported 2562.5 instead of 1500, and that number is written into the finished workout, so it would have stayed wrong forever. The ramp aimed at last session's weight. buildSets prepends the warm-ups and applyPrescription rewrites work rows only, by design — so nothing ever re-derived the ramp once progression moved the target. Deload 100 -> 50 produced warm-ups of 50 and 75 under work sets of 50: the second "warm-up" heavier than everything it was warming up for. applyPrescription now finishes by re-ramping, which is where the invariant cannot be forgotten, rather than at the two call sites where it already was. A logged warm-up keeps its weight and becomes what the next one ramps from — it happened, and rewriting performed work is data loss. insertWarmupRow's early return was unclamped. Once a warm-up sat above the work weight, every warm-up added after it inherited that number. The clamp guarded only the other branch. A hand-edited row stays as typed; what stops is the inheritance.
This commit is contained in:
1 parent
8104539932
commit
287550df6c
5 files changed
+129
-8
No files matched your search
@@ -388,7 +388,14 @@ export function workoutVolume(w) {
|
||||
// No special case for unilateral work: a per-side set logs its total, so both sides are
|
||||
// already in the rep count that arrives here. Drop-set drops and rest-pause bursts add their
|
||||
// own weight x reps on top of the row's main/activation set (see extraVolumeOf).
|
||||
w.entries.forEach(e => e.sets.forEach(s => { if (s.done) v += (s.w || 0) * (s.r || 0) + extraVolumeOf(s) }))
|
||||
// Warm-ups are excluded here as everywhere else. The config sheet promises it in so many
|
||||
// words ("left out of volume, records and progression") and every other consumer already
|
||||
// does it; this line was the one that did not, which only stopped being harmless when a
|
||||
// routine started planning warm-ups by default. The number is written into the saved
|
||||
// workout, so an inflated one would stay wrong forever.
|
||||
w.entries.forEach(e => e.sets.forEach(s => {
|
||||
if (s.done && !isWarmupRow(s)) v += (s.w || 0) * (s.r || 0) + extraVolumeOf(s)
|
||||
}))
|
||||
return v
|
||||
}
|
||||
export function setsDone(w) {
|
||||
@@ -460,6 +467,36 @@ export function cascadeWeight(rows, from, value) {
|
||||
* `at` is 0, and reading `rows[-1]` used to fall through to the *last* row — the heaviest
|
||||
* work set — so "add warm-up set" handed you a full-weight set to correct by hand.
|
||||
*/
|
||||
/**
|
||||
* Recompute the warm-up block so it ramps toward the weight the work rows ACTUALLY carry.
|
||||
*
|
||||
* buildSets prepends the warm-ups before a prescription is applied, and applyPrescription
|
||||
* deliberately rewrites work rows only — so without this the ramp still aims at last
|
||||
* session's weight. On a deload that put the last warm-up above every work set, which is
|
||||
* the exact opposite of what a warm-up is for.
|
||||
*
|
||||
* A warm-up already logged keeps its weight and becomes what the next one ramps from: it
|
||||
* happened, and rewriting performed work is data loss. Entries with nothing to ramp toward
|
||||
* — cardio, bodyweight, an unloaded hold — are returned untouched.
|
||||
*/
|
||||
export function rerampWarmups(rows, step = 2.5) {
|
||||
const firstWork = rows.findIndex(x => !isWarmupRow(x))
|
||||
if (firstWork <= 0) return rows
|
||||
const target = rows[firstWork].w || 0
|
||||
if (!(target > 0)) return rows
|
||||
const out = rows.slice()
|
||||
let from = 0
|
||||
for (let i = 0; i < firstWork; i++) {
|
||||
if (out[i].done) { from = out[i].w || 0; continue }
|
||||
const w = target > from
|
||||
? Math.max(0, Math.min(target, Math.floor((from + (target - from) / 2) / step) * step))
|
||||
: target
|
||||
out[i] = { ...out[i], w }
|
||||
from = w
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
export function insertWarmupRow(rows, mode, target, step = 2.5) {
|
||||
const firstWork = rows.findIndex(x => !isWarmupRow(x))
|
||||
const at = firstWork === -1 ? rows.length : firstWork
|
||||
@@ -467,7 +504,12 @@ export function insertWarmupRow(rows, mode, target, step = 2.5) {
|
||||
const work = firstWork === -1 ? null : rows[firstWork]
|
||||
const rampTo = to => {
|
||||
const from = prev ? (prev.w || 0) : 0
|
||||
if (!(to > 0) || to <= from) return from
|
||||
// Nothing to ramp toward: bodyweight, cardio, a timed hold with no load.
|
||||
if (!(to > 0)) return 0
|
||||
// Already at or past the work weight — which happens when a warm-up was edited by hand
|
||||
// above it. Returning `from` here handed the next warm-up that same too-heavy number and
|
||||
// let it propagate down the block. A warm-up is never heavier than the set it warms up for.
|
||||
if (to <= from) return to
|
||||
// Rounded DOWN to the step: a warm-up that lands a notch light costs nothing, one that
|
||||
// lands a notch heavy is a set you have to strip plates off before you can use it.
|
||||
return Math.max(0, Math.min(to, Math.floor((from + (to - from) / 2) / step) * step))
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
// · fewer sets than prescribed → miss
|
||||
// So a session that fell apart can never advance the load as though it had succeeded.
|
||||
|
||||
import { modeOf, repStep } from './history.js'
|
||||
import { modeOf, repStep, rerampWarmups } from './history.js'
|
||||
import { EXIDX } from './exercises.js'
|
||||
import { isWarmupRow } from './workout-model.js'
|
||||
|
||||
@@ -250,7 +250,7 @@ export function nextPrescription(S, cfg, routine) {
|
||||
* Apply a prescription to freshly built sets. Only the fields the policy actually decided
|
||||
* are touched, and only on sets that have not been logged yet.
|
||||
*/
|
||||
export function applyPrescription(sets, p) {
|
||||
export function applyPrescription(sets, p, step = 2.5) {
|
||||
if (!p || p.kind === 'off' || p.kind === 'first') return sets
|
||||
const out = sets.map(s => {
|
||||
// Never rewrite a logged set, and never rewrite a warm-up: the prescription speaks to
|
||||
@@ -270,7 +270,7 @@ export function applyPrescription(sets, p) {
|
||||
if (p.sets > workRows.length) {
|
||||
// An all-warm-up entry has no work row to seed growth from - growing warm-up copies
|
||||
// would both invent work and never terminate the loop. Leave the entry untouched.
|
||||
if (!workRows.length) return out
|
||||
if (!workRows.length) return rerampWarmups(out, step)
|
||||
const seed = workRows[workRows.length - 1]
|
||||
// A freshly appended row hasn't been performed, so it never inherits a seed's already-
|
||||
// logged drops/clusters — that would invent extra work the row never actually did. Its
|
||||
@@ -279,5 +279,7 @@ export function applyPrescription(sets, p) {
|
||||
const { drops, clusters, ...plainSeed } = seed
|
||||
while (out.filter(s => !isWarmupRow(s)).length < p.sets) out.push({ ...plainSeed, done: false })
|
||||
}
|
||||
return out
|
||||
// Last, because the work rows now carry their final weight: the warm-up block ramps toward
|
||||
// what you are actually about to lift, not toward what you lifted last time.
|
||||
return rerampWarmups(out, step)
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import { workoutVolume, insertWarmupRow, buildSets } from './history.js'
|
||||
import { applyPrescription } from './progression.js'
|
||||
|
||||
// The config sheet tells users warm-ups are "left out of volume, records and progression",
|
||||
// and history.js repeats that as an invariant in a comment. Volume was the one place it
|
||||
// was false — harmless while warm-ups were hand-added and rare, wrong now that a routine
|
||||
// plans them by default and the number is written into the saved workout for good.
|
||||
describe('warm-ups and volume', () => {
|
||||
const w = {
|
||||
entries: [{
|
||||
id: 'bench',
|
||||
sets: [
|
||||
{ w: 50, r: 5, done: true, phase: 'warmup', warmup: true },
|
||||
{ w: 75, r: 5, done: true, phase: 'warmup', warmup: true },
|
||||
{ w: 87.5, r: 5, done: true, phase: 'warmup', warmup: true },
|
||||
{ w: 100, r: 5, done: true },
|
||||
{ w: 100, r: 5, done: true },
|
||||
{ w: 100, r: 5, done: true },
|
||||
],
|
||||
}],
|
||||
}
|
||||
|
||||
it('counts only the work sets', () => {
|
||||
expect(workoutVolume(w)).toBe(1500)
|
||||
})
|
||||
|
||||
it('a warm-up adds nothing, whatever it weighs', () => {
|
||||
const heavy = { entries: [{ id: 'b', sets: [{ w: 200, r: 10, done: true, phase: 'warmup', warmup: true }] }] }
|
||||
expect(workoutVolume(heavy)).toBe(0)
|
||||
})
|
||||
})
|
||||
|
||||
// A warm-up must never be heavier than the set it warms you up for. The ramp branch clamps
|
||||
// to the work weight; the early-return branch did not, so a hand-edited warm-up above the
|
||||
// work weight propagated into every warm-up added after it.
|
||||
describe('a warm-up never outweighs the work set', () => {
|
||||
// The 120 is something the user typed, and it stays: silently rewriting their own edit
|
||||
// would be worse than leaving it. What must not happen is the NEW row inheriting it, which
|
||||
// is how one bad number used to spread through the whole warm-up block.
|
||||
it('does not copy a hand-edited warm-up that sits above the work weight', () => {
|
||||
const rows = [{ warmup: true, phase: 'warmup', w: 120, r: 5 }, { w: 100, r: 5 }]
|
||||
const out = insertWarmupRow(rows, 'reps', { reps: 5 }, 2.5)
|
||||
expect(out.map(r => r.w)).toEqual([120, 100, 100])
|
||||
expect(out[1].phase).toBe('warmup')
|
||||
})
|
||||
|
||||
it('still ramps normally when the previous warm-up is below the work weight', () => {
|
||||
const rows = [{ warmup: true, phase: 'warmup', w: 50, r: 5 }, { w: 100, r: 5 }]
|
||||
const out = insertWarmupRow(rows, 'reps', { reps: 5 }, 2.5)
|
||||
expect(out.filter(r => r.phase === 'warmup').map(r => r.w)).toEqual([50, 75])
|
||||
})
|
||||
})
|
||||
|
||||
// buildSets prepends the warm-ups, then applyPrescription rewrites the WORK rows only — so a
|
||||
// ramp built against last session's weight is stale the moment progression moves. On a deload
|
||||
// that put the last warm-up above every work set.
|
||||
describe('the ramp follows the prescribed weight', () => {
|
||||
const S = { workouts: [], exWeights: {}, routines: [] }
|
||||
const cfg = { id: 'bench', sets: 3, reps: 5, weight: 100, warmupSets: 2 }
|
||||
|
||||
it('re-ramps after a deload instead of aiming at the old weight', () => {
|
||||
const rows = applyPrescription(buildSets(S, cfg, { step: 2.5 }), { kind: 'deload', weight: 50 })
|
||||
const warm = rows.filter(r => r.phase === 'warmup').map(r => r.w)
|
||||
const work = rows.filter(r => r.phase !== 'warmup').map(r => r.w)
|
||||
expect(work).toEqual([50, 50, 50])
|
||||
for (const x of warm) expect(x).toBeLessThanOrEqual(50)
|
||||
expect(warm).toEqual([25, 37.5])
|
||||
})
|
||||
|
||||
it('re-ramps after a bump', () => {
|
||||
const rows = applyPrescription(buildSets(S, cfg, { step: 2.5 }), { kind: 'up', weight: 150 })
|
||||
expect(rows.filter(r => r.phase !== 'warmup').map(r => r.w)).toEqual([150, 150, 150])
|
||||
expect(rows.filter(r => r.phase === 'warmup').map(r => r.w)).toEqual([75, 112.5])
|
||||
})
|
||||
})
|
||||
@@ -1014,7 +1014,8 @@ export function beginWorkout(routineId, bw) {
|
||||
// kept on the entry purely so the workout can explain the number it chose.
|
||||
const entries = (r ? r.ex : []).map(cfg => {
|
||||
const plan = nextPrescription(st, cfg, r)
|
||||
const sets = applyIntensifierPlan(applyPrescription(buildSets(st, cfg, { step: defaultIncrement(cfg.id, st.unit) }), plan), cfg)
|
||||
const step = defaultIncrement(cfg.id, st.unit)
|
||||
const sets = applyIntensifierPlan(applyPrescription(buildSets(st, cfg, { step }), plan, step), cfg)
|
||||
return { id: cfg.id, sg: cfg.sg, target: { ...cfg }, plan, sets }
|
||||
})
|
||||
update(s => {
|
||||
|
||||
@@ -520,7 +520,7 @@ function ActiveWorkout() {
|
||||
const full = { ...cfg, id: ex.id }
|
||||
const plan = freestyle ? null : nextPrescription(s, full, s.routines.find(r => r.id === s.active.routineId))
|
||||
const sets = buildSets(s, full, { step: defaultIncrement(ex.id, s.unit), ...(freestyle ? { preferLast: true } : {}) })
|
||||
const progressed = freestyle ? sets : applyPrescription(sets, plan)
|
||||
const progressed = freestyle ? sets : applyPrescription(sets, plan, defaultIncrement(ex.id, s.unit))
|
||||
s.active.entries.push({ id: ex.id, target: { ...cfg }, plan, sets: applyIntensifierPlan(progressed, full) })
|
||||
s.active.cur = s.active.entries.length - 1
|
||||
}), null, routine, seed)
|
||||
|
||||
Reference in new issue
Block a user