Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion frontend/src/lib/failure-sets.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,8 @@ describe('"Last set to failure" in a plan', () => {

it('marks the rest-pause work set of a rest-pause plan', () => {
const rows = applyIntensifierPlan([{ w: 60, r: 8 }], { id: '0025', reps: 8, intensifier: { type: 'restpause', totalReps: 12, restSec: 15 }, lastToFailure: true })
expect(rows.map(s => !!s.failure)).toEqual([false, true])
// one work row, the activation set and its bursts (lib/rest-pause.js), and that is the one marked
expect(rows.map(s => !!s.failure)).toEqual([true])
})

it('travels with a shared plan and reads on its printout', () => {
Expand Down
56 changes: 26 additions & 30 deletions frontend/src/lib/history.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ import { setBandsOf, bandText, bandsOf, usesBands, withSetBands, nextBandsUp } f
import { hasIncline, inclineFrom, hasLevel, levelFrom } from './incline.js'
import { isCardio, isHold, isDistanceEx, isOneLimb, isBodyweightEq, isAssisted, betterWeight, exerciseOf } from './exercises.js'
import { barWeightFor } from './bar.js'
import { phaseForSet, modeForSet, modeForEntry, isWarmupRow, isFailureSet, isDropSet, isRestPauseSet, normalizeMode, completedVolumeOf, hasCompletedWork, nextDropWeight, splitBurstReps, splitClusterReps, makeSideSet, isSideSet, syncSideAggregate, WEIGHT_ORIGIN_MANUAL, dropsOf, clustersOf } from './workout-model.js'
import { phaseForSet, modeForSet, modeForEntry, isWarmupRow, isFailureSet, isDropSet, isRestPauseSet, normalizeMode, completedVolumeOf, hasCompletedWork, nextDropWeight, splitClusterReps, makeSideSet, isSideSet, syncSideAggregate, WEIGHT_ORIGIN_MANUAL, dropsOf, clustersOf } from './workout-model.js'
import { backoffAt, backoffStepOf, backoffWeights } from './backoff.js'
import { restPausePlan, restPauseAim, restPauseRow } from './rest-pause.js'
import { dbLoadOf, bellsIn, volumeFactor, historyAs, ownedFloor } from './dumbbells.js'
import { isRungRow, rungWeight } from './warmup-snap.js'
import { bodyLoadOf, bodyweightFor, countsBodyweight } from './bw-load.js'
Expand Down Expand Up @@ -203,7 +204,7 @@ function setLabelText(id, s, cfg, speedUnit) {
// down. The row's own `r` is the total either way; a planned set's bursts already add up to it
// (applyIntensifierPlan), while bursts added live sit on top of the activation set, which is
// then whatever the total leaves over. Bursts that do not fit the total are not shown.
// A planned set has no activation set in front of its bursts, so when its total was raised by
// A planned set from before 1.4.6 has no activation set in front of its bursts, so when its total was raised by
// hand the leftover is not one: "60×2+6+3+2+1" read as a two-rep set nobody did. Which burst
// the extra reps belong to is not known, so such a set reads as its plain total. The target
// says whether the exercise plans rest-pause; a row added to it and given bursts live can only
Expand All @@ -213,7 +214,9 @@ function setLabelText(id, s, cfg, speedUnit) {
const reps = side.r || 0
const bursts = clustersOf(side).map(b => Number(b?.r) || 0).filter(r => r > 0)
const sum = bursts.reduce((a, b) => a + b, 0)
if (!bursts.length || sum > reps || (planned && sum !== reps)) return reps
// A row planned since 1.4.6 carries its activation set in `r` (`act`, lib/rest-pause.js), so
// what the bursts leave over is that set, however it was edited.
if (!bursts.length || sum > reps || (planned && side.act !== true && sum !== reps)) return reps
return (reps > sum ? [reps - sum, ...bursts] : bursts).join('+')
}
// One side's "weight×reps" (or bodyweight "reps" / "+belt × reps"), the same shape a whole
Expand Down Expand Up @@ -902,33 +905,26 @@ function shapeRows(sets, cfg, grid) {
return withDrops(s)
})
}
// Rest-pause trains as exactly two sets, not one per configured `sets` count: a warm-up at
// the exercise's own configured reps, then a single rest-pause work set. Doing the full
// activation+bursts protocol several times over isn't how rest-pause is actually trained, so
// planning it replaces whatever buildSets built rather than stamping each of those rows.
// The work row's own reps are the total — not "the total minus what the bursts carry" — and
// the bursts are the full breakdown of that same total, down to the last one. See
// extraVolumeOf/setTonnage: a rest-pause row's `clusters` are read-only display of how `r`
// breaks down, not extra volume on top of it, precisely so this doesn't double-count.
const restSec = Math.max(5, cfg.intensifier.restSec || 15)
const totalReps = Math.max(1, Math.round(cfg.intensifier.totalReps) || 1)
const w = (sets.find(s => !isWarmupRow(s)) || sets[0] || {}).w || 0
const warmup = { w, r: Math.max(1, Math.round(cfg.reps) || 1), done: false, phase: 'warmup' }
const work = { w, r: totalReps, done: false, type: 'restpause', clusters: splitBurstReps(totalReps).map(r => ({ r, restSec })) }
if (isPerSide(cfg)) {
const source = sets.find(s => !isWarmupRow(s))
// The configured total covers both limbs; preserve it even for an odd total.
const side = (key, reps) => ({
w: source?.sides?.[key]?.w ?? w, r: reps, done: false, type: 'restpause',
clusters: splitBurstReps(reps).map(r => ({ r, restSec })),
})
// The warm-up is per side too (issue #60): makeSideSet splits its combined reps the same
// way the work set's are, each side its own reps/weight/effort and done tick.
return [makeSideSet(warmup), syncSideAggregate({ ...work, sides: {
L: side('L', Math.ceil(totalReps / 2)), R: side('R', Math.floor(totalReps / 2)),
} })]
}
return [warmup, work]
// Rest-pause trains as one work set, not one per configured `sets` count: the activation set
// and its bursts, all on one row (lib/rest-pause.js). Doing the whole protocol several times
// over isn't how rest-pause is trained, so planning it replaces whatever buildSets built
// rather than stamping each of those rows. Warm-ups stay what they are (the generated or saved
// block goes in front later, session-start.js), so only the work rows are replaced.
// The row's own reps are the total, activation set included, and `clusters` are the bursts
// alone; see extraVolumeOf/setTonnage: the bursts are a breakdown of `r`, not volume on top.
// `cfg.intensifier.aim` is the total this session asks for (the progression's, stamped on the
// target); without one, where the plan starts.
const plan = restPausePlan(cfg)
const aim = restPauseAim(cfg)
const warm = sets.filter(isWarmupRow)
const source = sets.find(s => !isWarmupRow(s)) || {}
const w = source.w || 0
const row = restPauseRow(plan, aim, w, {
perSide: isPerSide(cfg),
sideW: isSideSet(source) ? { L: source.sides.L?.w, R: source.sides.R?.w } : null,
sides: (base, L, R) => syncSideAggregate({ ...base, sides: { L, R } }),
})
return [...warm, row]
}
export function workoutVolume(w, { warmups = false, bodyweight = 0 } = {}) {
let v = 0
Expand Down
58 changes: 39 additions & 19 deletions frontend/src/lib/history.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,22 +135,30 @@ describe('setLabel', () => {

// A planned rest-pause set has no activation set: its bursts are the whole total. Raising the
// total by hand put the difference in front, "60×2+6+3+2+1", a two-rep set nobody did.
it('reads a planned rest-pause set whose total was raised by hand as its plain total', () => {
it('reads a pre-1.4.6 planned rest-pause set whose total was raised by hand as its plain total', () => {
// Rows planned before the activation set lived in the row: the bursts were the whole total.
const cfg = { id: LIFT, reps: 8, intensifier: { type: 'restpause', totalReps: 12, restSec: 15 } }
const [, work] = applyIntensifierPlan([{ w: 60, r: 8, done: false }], cfg)
const work = { w: 60, r: 12, done: false, type: 'restpause', clusters: [6, 3, 2, 1].map(r => ({ r, restSec: 15 })) }
expect(setLabel(LIFT, work, cfg)).toBe('60×6+3+2+1')
expect(setLabel(LIFT, { ...work, r: 14 }, cfg)).toBe('60×14')
// a burst added live on top keeps the breakdown, since the total follows it
const added = { ...work, r: 13, clusters: [...work.clusters, { r: 1, restSec: 15 }] }
expect(setLabel(LIFT, added, cfg)).toBe('60×6+3+2+1+1')
// per side, each side is read the same way
const sided = applyIntensifierPlan([makeSideSet({ w: 20, r: 8, done: false })], { ...cfg, side: true })[1]
sided.sides.L = { ...sided.sides.L, r: sided.sides.L.r + 2 }
expect(setLabel(LIFT, sided, { ...cfg, side: true })).toBe('L 20×8 · R 20×3+2+1')
// an unplanned set with live bursts still shows its activation set first
expect(setLabel(LIFT, { w: 60, r: 16, type: 'restpause', clusters: [{ r: 4 }, { r: 2 }] }, { id: LIFT, reps: 10 })).toBe('60×10+4+2')
})

it('reads a planned rest-pause set as its activation set and its bursts, however it was edited', () => {
const cfg = { id: LIFT, reps: 10, intensifier: { type: 'restpause', bursts: 3, total: 20, totalMax: 24, restSec: 15 } }
const [work] = applyIntensifierPlan([{ w: 60, r: 10, done: false }], cfg)
expect(setLabel(LIFT, work, cfg)).toBe('60×10+4+3+3')
// two more reps on the activation set raise the total, and it reads as such
expect(setLabel(LIFT, { ...work, r: 22 }, cfg)).toBe('60×12+4+3+3')
// per side, each side is read the same way
const [sided] = applyIntensifierPlan([makeSideSet({ w: 20, r: 10, done: false })], { ...cfg, side: true })
expect(setLabel(LIFT, sided, { ...cfg, side: true })).toBe('L 20×5+2+2+1 · R 20×5+2+2+1')
})

it('reads drops and bursts of a bodyweight exercise as reps and added weight', () => {
const cfg = { id: BW, bodyweight: true }
expect(setLabel(BW, { w: 10, r: 8, type: 'dropset', drops: [{ w: 0, r: 5 }] }, cfg)).toBe('+10 × 8 ↘ 5')
Expand Down Expand Up @@ -823,28 +831,40 @@ describe('applyIntensifierPlan', () => {
])
})

it('collapses rest-pause to exactly two rows regardless of how many sets were configured: a warm-up at the exercise\'s own reps, then one work set whose own reps ARE the total', () => {
const sets = [{ w: 60, r: 8, done: false }, { w: 60, r: 8, done: false }, { w: 60, r: 8, done: false }]
const out = applyIntensifierPlan(sets, { reps: 8, intensifier: { type: 'restpause', totalReps: 12, restSec: 15 } })
it('plans rest-pause as one work row whatever the sets say: the activation set plus its bursts, the row\'s own reps the total', () => {
const sets = [{ w: 60, r: 10, done: false }, { w: 60, r: 10, done: false }, { w: 60, r: 10, done: false }]
const out = applyIntensifierPlan(sets, { reps: 10, intensifier: { type: 'restpause', bursts: 3, total: 20, restSec: 15 } })
expect(out).toEqual([
{ w: 60, r: 8, done: false, phase: 'warmup' },
{ w: 60, r: 12, done: false, type: 'restpause', clusters: [{ r: 6, restSec: 15 }, { r: 3, restSec: 15 }, { r: 2, restSec: 15 }, { r: 1, restSec: 15 }] },
{ w: 60, r: 20, done: false, type: 'restpause', act: true, clusters: [{ r: 4, restSec: 15 }, { r: 3, restSec: 15 }, { r: 3, restSec: 15 }] },
])
// the full breakdown always sums back to the row's own r — no reps missing, none double-counted
expect(out[1].clusters.reduce((sum, c) => sum + c.r, 0)).toBe(out[1].r)
// what the bursts leave over is the activation set, at the exercise's own reps
expect(out[0].r - out[0].clusters.reduce((sum, c) => sum + c.r, 0)).toBe(10)
})

it('keeps the warm-up rows in front, and the activation set is never one of them', () => {
const sets = [{ w: 30, r: 5, done: false, phase: 'warmup' }, { w: 60, r: 8, done: false }]
const out = applyIntensifierPlan(sets, { reps: 8, intensifier: { type: 'restpause', bursts: 2, total: 12, restSec: 15 } })
expect(out[0]).toEqual({ w: 30, r: 5, done: false, phase: 'warmup' })
expect(out).toHaveLength(2)
expect(out[1]).toMatchObject({ w: 60, r: 12, type: 'restpause', act: true })
})

it('reads a pre-1.4.6 plan (totalReps past the activation set) as that many halving bursts and that total', () => {
const out = applyIntensifierPlan([{ w: 60, r: 8, done: false }], { reps: 8, intensifier: { type: 'restpause', totalReps: 12, restSec: 15 } })
// 12 past the activation set halved into 6+3+2+1: four bursts, 20 in total
expect(out).toEqual([{ w: 60, r: 20, done: false, type: 'restpause', act: true, clusters: [3, 3, 3, 3].map(r => ({ r, restSec: 15 })) }])
})

it('the warm-up reps come from the exercise\'s own configured reps, not the rest-pause total', () => {
const sets = [{ w: 60, r: 8, done: false }]
const out = applyIntensifierPlan(sets, { reps: 5, intensifier: { type: 'restpause', totalReps: 20, restSec: 15 } })
expect(out[0]).toEqual({ w: 60, r: 5, done: false, phase: 'warmup' })
it('builds the total a progression aimed for', () => {
const out = applyIntensifierPlan([{ w: 60, r: 8, done: false }], { reps: 8, intensifier: { type: 'restpause', bursts: 3, total: 14, totalMax: 18, aim: 16, restSec: 20 } })
expect(out[0].r).toBe(16)
expect(out[0].clusters).toEqual([{ r: 3, restSec: 20 }, { r: 3, restSec: 20 }, { r: 2, restSec: 20 }])
})

it('carries the prescribed weight from the built sets onto both new rows', () => {
it('carries the prescribed weight from the built sets onto the work row', () => {
const sets = [{ w: 82.5, r: 8, done: false }]
const out = applyIntensifierPlan(sets, { reps: 8, intensifier: { type: 'restpause', totalReps: 4, restSec: 15 } })
expect(out[0].w).toBe(82.5)
expect(out[1].w).toBe(82.5)
})

it('never touches a warm-up row', () => {
Expand Down
5 changes: 5 additions & 0 deletions frontend/src/lib/plan-print.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,11 @@ describe('planPrintHTML prints the exercise as it is prescribed', () => {
expect(body).toContain('1 × 8 · 40 kg · Rest-pause 20 reps')
})

it('prints a rest-pause plan with its total range, bursts and rest', () => {
const S3 = { ...S2, routines: [{ ...S2.routines[0], ex: [{ id: '0027', sets: 1, mode: 'reps', reps: 8, weight: 40, intensifier: { type: 'restpause', bursts: 3, total: 14, totalMax: 18, restSec: 20 } }] }] }
expect(text(planPrintHTML(S3, '', { routineId: 'r' }))).toContain('Rest-pause 14–18 reps · 3× 20s')
})

it('translates the body part and keeps it a separate word', () => {
_setLangState('de', { chest: 'Brust', 'Drop-set': 'Dropsatz' }, null, null)
const html = planPrintHTML(S2, '', { routineId: 'r' })
Expand Down
14 changes: 12 additions & 2 deletions frontend/src/lib/plan-share.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { isPyramid, normalizePyramid, normalizePyramidRest, normalizePyramidWeig
import { isBackoff } from './backoff.js'
import { dbLoadOf } from './dumbbells.js'
import { MAX_TRIPLE_SETS } from './progression.js'
import { RP_BURSTS_MAX } from './rest-pause.js'
import { uid, todayISO, DAYN, weekOrder, weekStartOf, exCount, routineCount } from './format.js'
import { t, exerciseNameFor, exerciseNameClass } from './i18n-core.js'
import { convertStep, convertWeight } from './units.js'
Expand Down Expand Up @@ -218,7 +219,14 @@ function cleanIntensifier(x) {
return { type, count: Math.max(1, Math.round(Number(x.count)) || 1), pct: Math.max(5, Math.round(Number(x.pct)) || 20), ...(x.on === 'last' ? { on: 'last' } : {}) }
}
if (type === 'restpause') {
return { type, totalReps: Math.max(1, Math.round(Number(x.totalReps)) || 1), restSec: Math.max(5, Math.round(Number(x.restSec)) || 15) }
const restSec = Math.max(5, Math.round(Number(x.restSec)) || 15)
// The shape since 1.4.6 (lib/rest-pause.js); a plan file from before keeps its `totalReps`,
// which the app still reads, rather than being guessed into the new one without its reps.
if (Number(x.total) > 0) {
const total = Math.max(1, Math.round(Number(x.total)))
return { type, bursts: Math.min(RP_BURSTS_MAX, Math.max(1, Math.round(Number(x.bursts)) || 1)), total, totalMax: Math.max(total, Math.round(Number(x.totalMax)) || 0), restSec }
}
return { type, totalReps: Math.max(1, Math.round(Number(x.totalReps)) || 1), restSec }
}
if (type === 'cluster') {
return { type, size: Math.min(50, Math.max(1, Math.round(Number(x.size)) || 3)), restSec: Math.max(5, Math.round(Number(x.restSec)) || 20) }
Expand Down Expand Up @@ -483,7 +491,9 @@ function intensifierLine(x) {
? `${t('Drop-set')} ${intens.count}× −${intens.pct}%` + (intens.on === 'last' ? ` (${t('last set')})` : '')
: intens.type === 'cluster'
? `${t('Cluster')} ${intens.size} ${t('reps')} · ${intens.restSec}s`
: `${t('Rest-pause')} ${intens.totalReps} ${t('reps')}`
: intens.total
? `${t('Rest-pause')} ${intens.total}${intens.totalMax > intens.total ? '–' + intens.totalMax : ''} ${t('reps')} · ${intens.bursts}× ${intens.restSec}s`
: `${t('Rest-pause')} ${intens.totalReps} ${t('reps')}`
}

// Group consecutive exercises sharing a superset id into rendered units.
Expand Down
7 changes: 7 additions & 0 deletions frontend/src/lib/plan-share.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,13 @@ describe('what survives a shared plan', () => {
.toEqual({ type: 'restpause', totalReps: 12, restSec: 15 })
})

it('carries a rest-pause plan with its bursts and total range, held to what trains', () => {
expect(roundTrip({ intensifier: { type: 'restpause', bursts: 3, total: 16, totalMax: 20, restSec: 20, aim: 18 } }).intensifier)
.toEqual({ type: 'restpause', bursts: 3, total: 16, totalMax: 20, restSec: 20 })
expect(roundTrip({ intensifier: { type: 'restpause', bursts: 99, total: 16, totalMax: 2, restSec: 1 } }).intensifier)
.toEqual({ type: 'restpause', bursts: 6, total: 16, totalMax: 16, restSec: 5 })
})

it('carries planned warm-ups', () => {
expect(roundTrip({ warmupSets: 3 }).warmupSets).toBe(3)
})
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/lib/progression-copy.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ export function progressionGuidance(plan) {
// A deload week of your own (lib/deload-cycle.js) says so, whatever the policy.
if (plan?.kind === 'deloadweek' && plan.why) return { policyLabel: 'Deload week', why: plan.why, prog: plan.prog || null }
if (!plan?.why || plan.kind === 'off' || plan.policy === 'off') return null
// A planned rest-pause set progresses by its own rule whatever the policy (lib/rest-pause.js).
if (plan.rpAim != null) return { policyLabel: 'Rest-pause', why: plan.why }
const policyLabel = POLICY_NAME[plan.policy]
if (!policyLabel) return null
return { policyLabel, why: plan.why }
Expand Down
7 changes: 7 additions & 0 deletions frontend/src/lib/progression-copy.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@ describe('policy-labelled progression guidance', () => {
.toEqual({ policyLabel: 'Greyskull LP', why: deload })
})

it('labels a rest-pause outcome as rest-pause, the rule that decided it', () => {
const why = ['{0} reps in total last time. Go for {1} at the same weight.', 20, 21]
expect(progressionGuidance({ policy: 'linear', kind: 'up', rpAim: 21, why }))
.toEqual({ policyLabel: 'Rest-pause', why })
expect(progressionGuidance({ policy: 'off', kind: 'off', rpAim: 20 })).toBeNull()
})

it('labels a baseline outcome and omits policies with no visible outcome', () => {
const baseline = ['Nothing logged yet, so this session sets the baseline.']
expect(progressionGuidance({ policy: 'linear', kind: 'first', why: baseline }))
Expand Down
Loading
Loading