Per side: log the total, show the split
Feedback on #31: a rep count that sometimes means one side and sometimes both is the ambiguity, not the fix for it. So the logged number is the total — 16 — the same as every other set in the app, and the split is derived for planning: "8 per side" on the exercise, "3 × 16 · 8/side" on the plan line and the printed sheet. Unilateral targets step in twos. 16 → 18 → 20, in the config stepper, the set-row stepper and the bodyweight rep progression, because half of an odd total is a rep one side never gets. Turning the flag on rounds an existing target up to even, and a saved target is stored even for the same reason. An odd total that arrives some other way still displays honestly, as 8.5 per side, since that is what it means. Volume loses its per-side case: both sides are already in the number logged.
This commit is contained in:
1 parent
c33ff15d9d
commit
4afffcb248
19 files changed
+103
-90
No files matched your search
+20
-15
@@ -24,18 +24,21 @@ export const isTimed = cfg => modeOf(cfg) === 'time'
|
||||
// asked for only once you say there is some. Seeded from the equipment field.
|
||||
// Spelled out rather than `bw`, which a workout already uses for the weigh-in
|
||||
// it was logged at — two different things one letter apart is a bug waiting.
|
||||
// side — the logged reps are what one side did: 8 logged is 8 per side, 16 in total.
|
||||
// side — the exercise is unilateral. You still log what you did: 16, the total across
|
||||
// both sides. The split is derived for planning ("8 per side"), never entered
|
||||
// — a number that sometimes means one side and sometimes both is the thing
|
||||
// that made this ambiguous in the first place, and one rep count that always
|
||||
// means the same thing beats two that need a legend.
|
||||
// Both are absent on every plan, workout and backup written before they existed, and absent
|
||||
// reads as false, so nothing needs migrating.
|
||||
export const isBw = cfg => (cfg && cfg.bodyweight != null ? !!cfg.bodyweight : isBodyweightEq(cfg && cfg.id))
|
||||
export const isPerSide = cfg => !!(cfg && cfg.side)
|
||||
// Reps as they are counted rather than as they are logged. Only this function knows that a
|
||||
// per-side set is worth double, so stats and volume cannot disagree with the set row.
|
||||
export const totalReps = (cfg, reps) => (isPerSide(cfg) ? 2 : 1) * (reps || 0)
|
||||
// Reps as they are written on a row: "8" bilateral, "8/side" unilateral. The total is left
|
||||
// off here — a set row is already narrow, and "8/side · 16 total" belongs in the one place
|
||||
// that has the width for it (the exercise line), not repeated down every row.
|
||||
export const repLabel = (cfg, reps) => (isPerSide(cfg) ? t('{0}/side', reps) : String(reps))
|
||||
// What one side did, for display only. Half of an odd total is shown as it falls (8.5) rather
|
||||
// than rounded away: it means the sides were not even, which is worth seeing.
|
||||
export const sideReps = reps => (reps || 0) / 2
|
||||
// Unilateral work moves in pairs, so its rep target steps by two — 16, 18, 20 — and a total
|
||||
// that stayed odd would put a rep on one side and not the other.
|
||||
export const repStep = cfg => (isPerSide(cfg) ? 2 : 1)
|
||||
|
||||
// mm:ss for a work duration — seconds alone read badly past a minute ("90 s" vs "1:30").
|
||||
export function fmtSec(sec) {
|
||||
@@ -95,7 +98,9 @@ export function setLabel(id, s, cfg) {
|
||||
if (mode === 'time') return fmtSec(s.sec) + (s.w > 0 ? ` · ${fmtNum(s.w)}` : '')
|
||||
// Bodyweight reads as what you did — "12", or "+10 × 12" once there is a belt involved —
|
||||
// rather than "0×12", which says a set was performed with no weight and means nothing.
|
||||
const reps = repLabel(c, s.r || 0)
|
||||
// A per-side set needs no mark here: the number logged is the total, the same as every
|
||||
// other set in the app.
|
||||
const reps = s.r || 0
|
||||
if (isBw({ ...c, id: c.id ?? id })) {
|
||||
const load = s.w > 0 ? `+${fmtNum(s.w)} × ` : ''
|
||||
return `${load}${reps}` + effortTail(s)
|
||||
@@ -121,9 +126,9 @@ export function exLine(cfg, unit) {
|
||||
const load = cfg.weight ? ' · ' + (isBw(cfg) ? '+' : '') + fmtNum(cfg.weight) + ' ' + unit : ''
|
||||
if (mode === 'cardio') return `${n} × ${cfg.min || 20} min @ ${fmtNum(cfg.speed || 8)} km/h`
|
||||
if (mode === 'time') return `${n} × ${fmtSec(cfg.sec || 45)}${load}`
|
||||
// This is the line with room for the arithmetic, so per side spells it out in full.
|
||||
const total = isPerSide(cfg) ? ' · ' + t('{0} in total', totalReps(cfg, cfg.reps) * n) : ''
|
||||
return `${n} × ${repLabel(cfg, cfg.reps)}${load}${total}`
|
||||
// This is the line with room for it, so the split is spelled out: "3 × 16 · 8/side".
|
||||
const split = isPerSide(cfg) ? ' · ' + t('{0}/side', fmtNum(sideReps(cfg.reps))) : ''
|
||||
return `${n} × ${cfg.reps}${load}${split}`
|
||||
}
|
||||
|
||||
// Drop superset ids that no longer have an adjacent partner (after unlink/reorder/remove).
|
||||
@@ -200,9 +205,9 @@ export function buildSets(S, cfg) {
|
||||
}
|
||||
export function workoutVolume(w) {
|
||||
let v = 0
|
||||
// A per-side set moved its load twice, so it counts twice — otherwise a routine that
|
||||
// switched to single-arm rows would show as half the work for the same session.
|
||||
w.entries.forEach(e => e.sets.forEach(s => { if (s.done) v += (s.w || 0) * totalReps(e.target, s.r) }))
|
||||
// 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.
|
||||
w.entries.forEach(e => e.sets.forEach(s => { if (s.done) v += (s.w || 0) * (s.r || 0) }))
|
||||
return v
|
||||
}
|
||||
export function setsDone(w) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { describe, it, expect } from 'vitest'
|
||||
import { modeOf, isTimed, fmtSec, setLabel, defaultConfig, buildSets, exLine, workoutVolume, effortOf, stepEffort, capEffort, isBw, isPerSide, totalReps } from './history.js'
|
||||
import { modeOf, isTimed, fmtSec, setLabel, defaultConfig, buildSets, exLine, workoutVolume, effortOf, stepEffort, capEffort, isBw, isPerSide, sideReps, repStep } from './history.js'
|
||||
import { EXDB } from './exercises.js'
|
||||
|
||||
// Real ids out of the shipped catalogue, so the body-part fallback is exercised for real.
|
||||
@@ -278,11 +278,21 @@ describe('isBw', () => {
|
||||
})
|
||||
})
|
||||
|
||||
describe('totalReps', () => {
|
||||
it('doubles a per-side set and leaves a bilateral one alone', () => {
|
||||
expect(totalReps({ side: true }, 8)).toBe(16)
|
||||
expect(totalReps({}, 8)).toBe(8)
|
||||
expect(totalReps({ side: true }, 0)).toBe(0)
|
||||
describe('sideReps', () => {
|
||||
it('halves the logged total, because the total is what was logged', () => {
|
||||
expect(sideReps(16)).toBe(8)
|
||||
expect(sideReps(0)).toBe(0)
|
||||
})
|
||||
it('shows an odd total as it falls rather than rounding the imbalance away', () => {
|
||||
expect(sideReps(17)).toBe(8.5)
|
||||
})
|
||||
})
|
||||
|
||||
describe('repStep', () => {
|
||||
it('steps unilateral work in twos so the total stays splittable', () => {
|
||||
expect(repStep({ side: true })).toBe(2)
|
||||
expect(repStep({})).toBe(1)
|
||||
expect(repStep(null)).toBe(1)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -293,9 +303,9 @@ describe('setLabel — bodyweight', () => {
|
||||
it('spells out a belt as an addition', () => {
|
||||
expect(setLabel(BW, { w: 10, r: 8 }, { id: BW })).toBe('+10 × 8')
|
||||
})
|
||||
it('marks a per-side set on both paths', () => {
|
||||
expect(setLabel(BW, { w: 0, r: 8 }, { id: BW, side: true })).toBe('8/side')
|
||||
expect(setLabel(LIFT, { w: 20, r: 8 }, { id: LIFT, side: true })).toBe('20×8/side')
|
||||
it('logs a per-side set as the plain total, like every other set in the app', () => {
|
||||
expect(setLabel(BW, { w: 0, r: 16 }, { id: BW, side: true })).toBe('16')
|
||||
expect(setLabel(LIFT, { w: 20, r: 16 }, { id: LIFT, side: true })).toBe('20×16')
|
||||
})
|
||||
it('keeps the effort tail', () => {
|
||||
expect(setLabel(BW, { w: 0, r: 12, rir: 2 }, { id: BW })).toBe('12 (RIR 2)')
|
||||
@@ -303,8 +313,8 @@ describe('setLabel — bodyweight', () => {
|
||||
})
|
||||
|
||||
describe('exLine', () => {
|
||||
it('shows the per-side arithmetic where there is room for it', () => {
|
||||
expect(exLine({ id: LIFT, sets: 3, reps: 8, side: true }, 'kg')).toBe('3 × 8/side · 48 in total')
|
||||
it('shows the split where there is room for it, next to the total you log', () => {
|
||||
expect(exLine({ id: LIFT, sets: 3, reps: 16, side: true }, 'kg')).toBe('3 × 16 · 8/side')
|
||||
})
|
||||
it('marks added weight as added', () => {
|
||||
expect(exLine({ id: BW, sets: 3, reps: 8, weight: 10 }, 'kg')).toBe('3 × 8 · +10 kg')
|
||||
@@ -370,8 +380,8 @@ describe('workoutVolume', () => {
|
||||
expect(workoutVolume(w)).toBe(600)
|
||||
})
|
||||
|
||||
it('counts a per-side set twice — the load moved twice (issue #31)', () => {
|
||||
const w = { entries: [{ id: LIFT, target: { side: true }, sets: [{ w: 20, r: 8, done: true }] }] }
|
||||
it('needs no per-side case — the logged reps are already both sides (issue #31)', () => {
|
||||
const w = { entries: [{ id: LIFT, target: { side: true }, sets: [{ w: 20, r: 16, done: true }] }] }
|
||||
expect(workoutVolume(w)).toBe(320)
|
||||
})
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
// a page break — each exercise, and each routine that fits, stays in one place.
|
||||
|
||||
import { EXIDX, isBodyweightEq } from './exercises.js'
|
||||
import { modeOf, fmtSec, isBw, repLabel } from './history.js'
|
||||
import { modeOf, fmtSec, isBw, isPerSide, sideReps } from './history.js'
|
||||
import { uid, todayISO, DAYN, fmtNum, exCount } from './format.js'
|
||||
import { t } from './i18n.js'
|
||||
|
||||
@@ -149,8 +149,10 @@ function scheme(e, unit) {
|
||||
const body = `${e.min || 20} min @ ${fmtNum(e.speed || 8)} km/h`
|
||||
return sets > 1 ? `${sets} × ${body}` : body
|
||||
}
|
||||
let s = mode === 'time' ? `${sets} × ${fmtSec(e.sec || 45)}` : `${sets} × ${repLabel(e, e.reps ?? 10)}`
|
||||
let s = mode === 'time' ? `${sets} × ${fmtSec(e.sec || 45)}` : `${sets} × ${e.reps ?? 10}`
|
||||
if (e.weight) s += ` · ${isBw(e) ? '+' : ''}${fmtNum(e.weight)} ${unit}`
|
||||
// A printed plan is read at the rack, so the split earns its four characters.
|
||||
if (mode !== 'time' && isPerSide(e)) s += ` · ${t('{0}/side', fmtNum(sideReps(e.reps ?? 10)))}`
|
||||
return s
|
||||
}
|
||||
|
||||
|
||||
@@ -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 } from './history.js'
|
||||
import { modeOf, repStep } from './history.js'
|
||||
import { EXIDX } from './exercises.js'
|
||||
|
||||
export const POLICIES = ['off', 'linear', 'greyskull', 'double', 'time']
|
||||
@@ -202,7 +202,9 @@ export function nextPrescription(S, cfg, routine) {
|
||||
// variation is — and that is a decision for a person, not a policy.
|
||||
return { policy, kind: 'hold', weight: 0, reps: goal, why: ['{0} sets of {1} — time to add weight or move to a harder variation.', sets - 1, goal] }
|
||||
}
|
||||
return { policy, kind: 'up', weight: 0, reps: goal + 1, why: ['Bodyweight — every rep last time, so go for {0} this time.', goal + 1] }
|
||||
// Unilateral work steps by two, so the total stays even and both sides get the rep.
|
||||
const next = goal + repStep(cfg)
|
||||
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
|
||||
@@ -212,7 +214,7 @@ export function nextPrescription(S, cfg, routine) {
|
||||
const dw = deloadTo(w, inc)
|
||||
return { policy, kind: 'deload', weight: dw, reps: bottom, why: ['Stalled {0} sessions — deload to {1} {2}.', stalls, dw, unit] }
|
||||
}
|
||||
const aim = Math.min(top, Math.max(bottom, last.low + 1))
|
||||
const aim = Math.min(top, Math.max(bottom, last.low + repStep(cfg)))
|
||||
return { policy, kind: 'hold', weight: w, reps: aim, why: ['Same weight — aim for {0} reps this time.', aim] }
|
||||
}
|
||||
|
||||
|
||||
@@ -222,6 +222,13 @@ describe('bodyweight exercises', () => {
|
||||
expect(p.sets).toBeUndefined()
|
||||
})
|
||||
|
||||
it('steps a unilateral total by two, so it lands on 16, 18, 20 (issue #31)', () => {
|
||||
const at16 = hist(LIFT, [[0, 16, 16, 16]], { sets: 3, reps: 16 })
|
||||
expect(nextPrescription(at16, { ...cfg, reps: 16, side: true }).reps).toBe(18)
|
||||
// and by one when it is not
|
||||
expect(nextPrescription(at16, { ...cfg, reps: 16 }).reps).toBe(17)
|
||||
})
|
||||
|
||||
it('keeps climbing reps forever when no ceiling was set — the old behaviour', () => {
|
||||
const at30 = hist(LIFT, [[0, 30, 30, 30]], { sets: 3, reps: 30 })
|
||||
const p = nextPrescription(at30, cfg)
|
||||
|
||||
Reference in new issue
Block a user