feat(checkin): per-side drop-sets and rest-pause bursts

Drops and rest-pause bursts on a one-sided exercise are now logged per limb, matching the L/R main sets: each side carries its own {type, drops, clusters}, edited independently but kept symmetric, while the row's aggregate (type + summed extra volume) stays correct for volume/1RM/history. Also restores the Drop/Burst set-menu options that were wrongly hidden on per-side exercises. Refs #60.
This commit is contained in:
Sebastian G committed 2026-09-07 13:34:14 +02:00
1 parent 0cae9867a1
commit a284017a84
4 files changed
+202 -13

No files matched your search

+11 -4
View File
@@ -412,12 +412,19 @@ export function applyIntensifierPlan(sets, cfg) {
if (kind === 'dropset') {
const count = Math.max(1, Math.round(cfg.intensifier.count) || 1)
const pct = cfg.intensifier.pct
// Stamp a descending chain of drops onto a row (or one side of a per-side row): each drop is
// pct% lighter than the last, at that row/side's own rep count.
const withDrops = row => {
const drops = []
let w = row.w || 0
for (let k = 0; k < count; k++) { w = nextDropWeight(w, pct); drops.push({ w, r: row.r }) }
return { ...row, type: 'dropset', drops }
}
return sets.map(s => {
if (isWarmupRow(s)) return s
const drops = []
let w = s.w || 0
for (let k = 0; k < count; k++) { w = nextDropWeight(w, pct); drops.push({ w, r: s.r }) }
return { ...s, type: 'dropset', drops }
// A unilateral set drops per side (issue #60): stamp each side, then resync the aggregate.
if (isSideSet(s)) return syncSideAggregate({ ...s, sides: { L: withDrops(s.sides.L), R: withDrops(s.sides.R) } })
return withDrops(s)
})
}
// Rest-pause trains as exactly two sets, not one per configured `sets` count: a warm-up at
+78 -1
View File
@@ -56,7 +56,14 @@ export function clustersOf(set) {
* `clustersOf(set)` here as well would double-count the same reps twice.
*/
export function extraVolumeOf(set) {
const drops = dropsOf(set)
const source = objectOf(set)
// A per-side set carries its drops on each side (issue #60), so the extra volume is the sum of
// both sides' drops — the row itself has no `drops`. dropsOf reads a side's own {type,drops}.
if (isSideSet(source)) {
return [source.sides.L, source.sides.R].reduce(
(v, side) => v + dropsOf(side).reduce((n, d) => n + (Number(d?.w) || 0) * (Number(d?.r) || 0), 0), 0)
}
const drops = dropsOf(source)
return drops.reduce((v, d) => v + (Number(d?.w) || 0) * (Number(d?.r) || 0), 0)
}
@@ -153,6 +160,12 @@ const sideOf = value => {
const out = { w: Number(v.w) || 0, r: Number(v.r) || 0, done: v.done === true }
if (v.rir != null) out.rir = v.rir
if (v.rpe != null) out.rpe = v.rpe
// A side can carry its own intensifier (issue #60): drop-sets and rest-pause bursts are logged
// per limb, exactly like the main set, so the same {type, drops, clusters} shape rides on the
// side. Reuses the row-level helpers below (addDrop/dropsOf/…), which read this very shape.
if (v.type === 'dropset' || v.type === 'restpause') out.type = v.type
if (Array.isArray(v.drops)) out.drops = v.drops
if (Array.isArray(v.clusters)) out.clusters = v.clusters
return out
}
@@ -185,6 +198,11 @@ export function syncSideAggregate(row) {
const rpes = [L.rpe, R.rpe].filter(v => v != null)
if (rirs.length) out.rir = Math.min(...rirs)
else if (rpes.length) out.rpe = Math.max(...rpes)
// Drops/clusters live on the sides now, so the row itself never carries them — only the shared
// `type` so isDropSet/isRestPauseSet still classify the set. extraVolumeOf reads the sides.
delete out.drops; delete out.clusters; delete out.type
const sideType = setType(L) !== 'straight' ? setType(L) : setType(R)
if (sideType !== 'straight') out.type = sideType
return out
}
@@ -207,6 +225,65 @@ export function toggleSide(row, side) {
return syncSideAggregate({ ...base, sides: { ...base.sides, [side]: cur } })
}
// --- per-side intensifiers (drop-sets / rest-pause) --------------------------------------------
//
// On a unilateral set the intensifier is logged per limb too. The structure stays symmetric —
// both sides always carry the same number of drops/bursts — while each side's weights and reps
// are edited independently, mirroring how the main set works. These reuse the side-agnostic
// helpers above (addDrop/dropsOf/setDropAt/…) on each side object, then resync the aggregate.
// Apply an editing fn to a single side and resync (used to edit one side's drop/burst).
function patchSide(row, side, fn) {
const base = objectOf(row)
if (!isSideSet(base) || (side !== 'L' && side !== 'R')) return { ...base }
return syncSideAggregate({ ...base, sides: { ...base.sides, [side]: fn(sideOf(base.sides[side])) } })
}
// Apply an editing fn to both sides and resync (used to add/remove a drop/burst symmetrically).
function patchBothSides(row, fn) {
const base = objectOf(row)
if (!isSideSet(base)) return { ...base }
return syncSideAggregate({ ...base, sides: { L: fn(sideOf(base.sides.L), 'L'), R: fn(sideOf(base.sides.R), 'R') } })
}
// Append a drop to both sides, each seeded from its own side's weight (pct lighter) and reps.
export function addSideDrop(row, pct) {
return patchBothSides(row, side => {
const drops = dropsOf(side)
const base = drops.length ? drops[drops.length - 1].w : (side.w || 0)
return addDrop(side, { w: nextDropWeight(base, pct), r: side.r })
})
}
export function removeSideDropAt(row, i) {
return patchBothSides(row, side => removeDropAt(side, i))
}
export function setSideDropAt(row, side, i, patch) {
return patchSide(row, side, sd => setDropAt(sd, i, patch))
}
// Append a rest-pause burst to both sides, each seeded from its own side's rep count. The side's
// own `r` grows by the added burst, mirroring the non-per-side rule that a rest-pause row's `r`
// is the running total across its bursts.
export function addSideCluster(row, restSec) {
return patchBothSides(row, side => {
const clusters = clustersOf(side)
const base = clusters.length ? clusters[clusters.length - 1].r : (side.r || 0)
const added = nextBurstReps(base)
return { ...addCluster(side, { r: added, restSec }), r: (side.r || 0) + added }
})
}
export function removeSideClusterAt(row, i) {
return patchBothSides(row, side => {
const removed = clustersOf(side)[i]?.r || 0
return { ...removeClusterAt(side, i), r: Math.max(0, (side.r || 0) - removed) }
})
}
export function setSideClusterAt(row, side, i, r) {
return patchSide(row, side, sd => {
const delta = (Number(r) || 0) - (clustersOf(sd)[i]?.r || 0)
return { ...setClusterAt(sd, i, { r }), r: Math.max(0, (sd.r || 0) + delta) }
})
}
export function normalizeMode(value, fallback = 'reps') {
const token = typeof value === 'string' ? value.trim().toLowerCase() : ''
if (MODES.includes(token)) return token
+68
View File
@@ -5,6 +5,7 @@ import {
addDrop, addCluster, removeDropAt, removeClusterAt, setDropAt, setClusterAt,
nextDropWeight, nextBurstReps, splitBurstReps,
isSideSet, makeSideSet, syncSideAggregate, setSideField, toggleSide,
addSideDrop, removeSideDropAt, setSideDropAt, addSideCluster, removeSideClusterAt, setSideClusterAt,
} from './workout-model.js'
describe('phaseForSet / isWarmupRow', () => {
@@ -70,6 +71,14 @@ describe('extraVolumeOf', () => {
expect(extraVolumeOf({ w: 100, r: 5 })).toBe(0)
expect(extraVolumeOf({ phase: 'warmup', w: 20, r: 8 })).toBe(0)
})
it('sums both sides drops for a per-side drop-set (issue #60)', () => {
let s = addSideDrop(makeSideSet({ w: 20, r: 16 }), 20) // each side: one 16×8 drop
expect(extraVolumeOf(s)).toBe(16 * 8 * 2) // L + R
// an asymmetric edit is reflected
s = setSideDropAt(s, 'R', 0, { w: 10, r: 6 })
expect(extraVolumeOf(s)).toBe(16 * 8 + 10 * 6)
})
})
describe('addDrop / addCluster', () => {
@@ -277,3 +286,62 @@ describe('toggleSide', () => {
expect(s.done).toBe(false) // un-tick one side → row no longer done
})
})
// Per-side intensifiers: a unilateral set's drop-sets and rest-pause bursts are logged per limb
// too (issue #60). The structure stays symmetric (both sides carry the same count) while each
// side's numbers are edited independently; drops/clusters live on the sides, and the aggregate's
// extra volume sums both.
describe('addSideDrop / removeSideDropAt / setSideDropAt', () => {
it('adds a drop to both sides, each seeded from its own side weight and reps', () => {
let s = makeSideSet({ w: 20, r: 16 }) // sides: 20×8 each
s = setSideField(s, 'R', 'w', 18) // make the sides asymmetric first
s = addSideDrop(s, 20) // 20% lighter
expect(s.sides.L.drops).toEqual([{ w: 16, r: 8 }]) // 20 → 16
expect(s.sides.R.drops).toEqual([{ w: 14.5, r: 8 }]) // 18 → 14.4 → rounds to 14.5
expect(s.type).toBe('dropset') // aggregate mirrors the intensifier type
expect(s.drops).toBeUndefined() // drops live on the sides, not the row
})
it('edits one side drop independently, leaving the other side untouched', () => {
let s = addSideDrop(makeSideSet({ w: 20, r: 16 }), 20)
s = setSideDropAt(s, 'L', 0, { w: 12 })
expect(s.sides.L.drops[0].w).toBe(12)
expect(s.sides.R.drops[0].w).toBe(16)
})
it('removes a drop from both sides, reverting to straight when the last goes', () => {
let s = addSideDrop(makeSideSet({ w: 20, r: 16 }), 20)
s = removeSideDropAt(s, 0)
expect(s.sides.L.drops).toEqual([])
expect(s.sides.R.drops).toEqual([])
expect(s.type).toBeUndefined() // no side is a drop-set anymore
})
})
describe('addSideCluster / removeSideClusterAt / setSideClusterAt', () => {
it('adds a burst to both sides and grows each side reps by its own added burst', () => {
let s = makeSideSet({ w: 20, r: 16 }) // 8 per side
s = addSideCluster(s, 15) // nextBurstReps(8) = 4
expect(s.sides.L.clusters).toEqual([{ r: 4, restSec: 15 }])
expect(s.sides.L.r).toBe(12) // 8 + 4
expect(s.sides.R.r).toBe(12)
expect(s.r).toBe(24) // aggregate total across both sides
expect(s.type).toBe('restpause')
})
it('editing one side burst keeps that side reps in step and leaves the other alone', () => {
let s = addSideCluster(makeSideSet({ w: 20, r: 16 }), 15) // L/R: r 12, burst 4
s = setSideClusterAt(s, 'L', 0, 6) // +2 on L
expect(s.sides.L.clusters[0].r).toBe(6)
expect(s.sides.L.r).toBe(14) // 12 + 2
expect(s.sides.R.r).toBe(12) // untouched
})
it('removing a burst subtracts its reps from that side', () => {
let s = addSideCluster(makeSideSet({ w: 20, r: 16 }), 15) // r 12 each
s = removeSideClusterAt(s, 0)
expect(s.sides.L.clusters).toEqual([])
expect(s.sides.L.r).toBe(8) // back to the base
expect(s.type).toBeUndefined()
})
})