Open-source gym & body-weight tracker, now in the App Store (iPhone + Apple Watch) and as an Android APK. Plan routines, log workouts, see which muscles are trained, import from Strong/Hevy/FitNotes. Self-host it or use it on the phone alone.
JavaScript apple-watchbodyweightdockerfitnessfitness-trackergymhealthiosmcpnodejspasskeysprogressive-web-applicationspwareactself-hostedself-hostingvitewebauthnweightliftingworkout-tracker
Drop-sets: each drop lands on a weight you can load, the plates you own or the exercise's step
Duarte Santosae0df4a20dda
diff --git a/frontend/src/lib/history.js b/frontend/src/lib/history.jsindex 86d7701b7..4bcf90565 100644--- a/frontend/src/lib/history.js+++ b/frontend/src/lib/history.js@@ -535,9 +535,9 @@ function seedSideFromLast(row, prev, planReps) {* Must run AFTER applyPrescription: a drop-set's chain of drops is a percentage of each row's* own `w`, so it has to be computed from the final prescribed weight, not the pre-progression* one buildSets started from — otherwise a bumped working weight would leave stale, cheaper- * drops sitting underneath it.+ * drops sitting underneath it. `grid` puts each drop on a loadable weight (nextDropWeight).*/-export function applyIntensifierPlan(sets, cfg) {+export function applyIntensifierPlan(sets, cfg, grid) {const kind = cfg && cfg.intensifier && cfg.intensifier.typeif (kind !== 'dropset' && kind !== 'restpause') return setsif (kind === 'dropset') {@@ -548,7 +548,7 @@ export function applyIntensifierPlan(sets, cfg) {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 }) }+ for (let k = 0; k < count; k++) { w = nextDropWeight(w, pct, grid); drops.push({ w, r: row.r }) }return { ...row, type: 'dropset', drops }}return sets.map(s => {diff --git a/frontend/src/lib/plates.js b/frontend/src/lib/plates.jsindex c56d31fc0..a3fe9f965 100644--- a/frontend/src/lib/plates.js+++ b/frontend/src/lib/plates.js@@ -12,6 +12,7 @@import { EXIDX } from './exercises.js'import { usesBar, defaultBarWeight } from './bar.js'import { isBw } from './history.js'+import { weightIncrement } from './progression.js'/** The plate sizes the inventory editor lists, heaviest first, per unit. */export const PLATE_SIZES = {@@ -229,3 +230,24 @@ export function rowLoad(kind, weight, base, inv) {export const sameLoad = (a, b) =>!!a && !!b && a.barOnly === b.barOnly && a.missing === b.missing&& a.plates.length === b.plates.length && a.plates.every((w, i) => w === b.plates[i])++/**+ * Where a drop-set's next weight may land (lib/workout-model.js nextDropWeight): on the plates+ * this profile owns when it has counted them and the exercise is plate-loaded — the heaviest load+ * at or below the drop that those plates make — else on the exercise's own weight step. A drop+ * rounded to .5 read 48.5 kg on a bar that loads in 2.5s (QA 1.3.9).+ */+export function dropGrid(S, cfg) {+ const kind = loadKindFor(S, cfg)+ if (ownsPlates(S) && (kind === 'pairs' || kind === 'single')) {+ const base = baseWeightFor(S, cfg?.id)+ const inv = inventoryFor(S)+ const per = kind === 'pairs' ? 2 : 1+ return w => {+ if (w <= base) return base > 0 ? base : w+ const { perSide, missing } = rowLoad(kind, w, base, inv)+ return base + per * Math.max(0, perSide - missing)+ }+ }+ return weightIncrement(cfg, S?.unit === 'lb' ? 'lb' : 'kg')+}diff --git a/frontend/src/lib/plates.test.js b/frontend/src/lib/plates.test.jsindex dfbab1d1f..0e6708ef3 100644--- a/frontend/src/lib/plates.test.js+++ b/frontend/src/lib/plates.test.js@@ -1,5 +1,5 @@import { describe, expect, test } from 'vitest'-import { PLATE_SIZES, DEFAULT_PAIRS, inventoryFor, pairsOf, ownsPlates, withPlatePairs, withStandardPlates, loadKindOf, withLoadKind, plateStack, plateDelta, loadKindFor, baseWeightFor, rowLoad, sameLoad } from './plates.js'+import { PLATE_SIZES, DEFAULT_PAIRS, inventoryFor, pairsOf, ownsPlates, withPlatePairs, withStandardPlates, loadKindOf, withLoadKind, plateStack, plateDelta, loadKindFor, baseWeightFor, rowLoad, sameLoad, dropGrid } from './plates.js'import { EXDB } from './exercises-data.js'const idOf = eq => EXDB.find(e => e.eq === eq).id@@ -213,3 +213,25 @@ describe('rowLoad', () => {expect(sameLoad(rowLoad('pairs', 325, 45, homeInv), rowLoad('pairs', 330, 45, homeInv))).toBe(false)})})++// QA 1.3.9: a drop-set's weight was rounded to .5 whatever the bar could carry.+describe('dropGrid', () => {+ const barbell = idOf('barbell'), db = idOf('dumbbell')+ test('without a plate inventory of your own: the exercise\'s weight step', () => {+ expect(dropGrid({ unit: 'kg' }, { id: db, inc: 2 })).toBe(2)+ expect(dropGrid({ unit: 'kg' }, { id: barbell, inc: 1.25 })).toBe(1.25)+ })+ test('with your own plates on a bar: the heaviest load at or below the drop that they make', () => {+ // A 20 kg bar and pairs of 10s and 5s only: loads step in 10s above the bar.+ const S = { unit: 'kg', plates: { kg: { 10: 2, 5: 1, _ts: 1 } } }+ const snap = dropGrid(S, { id: barbell })+ expect(typeof snap).toBe('function')+ expect(snap(48)).toBe(40)+ expect(snap(64)).toBe(60)+ expect(snap(15)).toBe(20) // below the bar: the bar is the lightest you can load+ })+ test('a dumbbell is not plate-loaded, so plates do not decide its drop', () => {+ const S = { unit: 'kg', plates: { kg: { 10: 2, _ts: 1 } } }+ expect(dropGrid(S, { id: db, inc: 2 })).toBe(2)+ })+})diff --git a/frontend/src/lib/session-start.js b/frontend/src/lib/session-start.jsindex 6b311e3f5..d0d2d6ec3 100644--- a/frontend/src/lib/session-start.js+++ b/frontend/src/lib/session-start.js@@ -6,6 +6,7 @@import { buildSets, applyIntensifierPlan, modeOf } from './history.js'import { isWarmupRow } from './workout-model.js'import { nextPrescription, applyPrescription, defaultIncrement, weightIncrement, plannedOf } from './progression.js'+import { dropGrid } from './plates.js'/*** Where a planned session's reps come from (Settings → During a workout). 'plan', the default:@@ -33,7 +34,7 @@ export function buildPlannedEntry(st, cfg, routine, { noProg = false } = {}) {const step = modeOf(cfg) === 'reps' ? weightIncrement(cfg, st.unit) : defaultIncrement(cfg.id, st.unit)const planReps = !startsFromLast(st)const rows = applyPrescription(buildSets(st, cfg, { step, rid: routine?.id, useTarget: plan.kind === 'off', planReps }), plan, step)- const sets = applyIntensifierPlan(rows, cfg)+ const sets = applyIntensifierPlan(rows, cfg, dropGrid(st, cfg))const target = { ...cfg }if (plan.weight != null) target.weight = plan.weightif (plan.reps != null) target.reps = plan.repsdiff --git a/frontend/src/lib/unilateral-integration.test.js b/frontend/src/lib/unilateral-integration.test.jsindex 504452dd0..7027f566c 100644--- a/frontend/src/lib/unilateral-integration.test.js+++ b/frontend/src/lib/unilateral-integration.test.js@@ -46,7 +46,8 @@ describe('unilateral sets across session boundaries', () => {const [built] = buildSessionEntries(S, { id: 'r', policy: 'linear', ex: [cfg] })expect(built.plan.kind).toBe('up')expect(built.sets[0].sides.L.w).toBe(built.plan.weight)- expect(built.sets[0].sides.L.drops[0].w).toBe(18)+ // 20% off 22.5 is 18, which a 2.5 kg step cannot load: the drop lands on 17.5.+ expect(built.sets[0].sides.L.drops[0].w).toBe(17.5)})it('converts both limbs and their drops in history and the active session', () => {diff --git a/frontend/src/lib/workout-model.js b/frontend/src/lib/workout-model.jsindex 6af77f506..9e92da058 100644--- a/frontend/src/lib/workout-model.js+++ b/frontend/src/lib/workout-model.js@@ -107,10 +107,27 @@ export function setClusterAt(set, i, patch) {return { ...objectOf(set), clusters }}-/** Suggested weight for the next drop: pct% lighter than the previous weight, rounded to .5. */-export function nextDropWeight(prevWeight, pct = 20) {+/**+ * Suggested weight for the next drop: pct% lighter than the previous weight, on a weight you can+ * actually load. `grid` is the exercise's weight step (5 → 80 kg, not 80.5) or a function that+ * snaps a weight onto the plates you own (lib/plates.js dropGrid); without one it rounds to .5,+ * the way it always did. A drop never comes out at or above the weight it drops from.+ */+export function nextDropWeight(prevWeight, pct = 20, grid) {const p = Math.min(90, Math.max(1, Number(pct) || 20))- return Math.round(Math.max(0, (Number(prevWeight) || 0) * (1 - p / 100)) * 2) / 2+ const prev = Math.max(0, Number(prevWeight) || 0)+ const raw = prev * (1 - p / 100)+ const tidy = w => Math.round(w * 1000) / 1000+ if (typeof grid === 'function') {+ const w = Number(grid(raw))+ if (Number.isFinite(w) && w >= 0) return tidy(w)+ } else if (Number(grid) > 0) {+ const step = Number(grid)+ let w = Math.round(raw / step) * step+ if (prev > 0 && w >= prev) w = prev - step+ return tidy(Math.max(0, w))+ }+ return Math.round(raw * 2) / 2}/** Suggested reps for the next rest-pause burst: roughly half the previous rep count. */@@ -263,11 +280,12 @@ function patchBothSides(row, fn) {}// Append a drop to both sides, each seeded from its own side's weight (pct lighter) and reps.-export function addSideDrop(row, pct) {+// `grid` as nextDropWeight's.+export function addSideDrop(row, pct, grid) {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 })+ return addDrop(side, { w: nextDropWeight(base, pct, grid), r: side.r })})}export function removeSideDropAt(row, i) {diff --git a/frontend/src/lib/workout-model.test.js b/frontend/src/lib/workout-model.test.jsindex 3dbfa1845..1eeb862be 100644--- a/frontend/src/lib/workout-model.test.js+++ b/frontend/src/lib/workout-model.test.js@@ -162,6 +162,19 @@ describe('nextDropWeight / nextBurstReps', () => {expect(nextDropWeight(0, 20)).toBe(0)})+ it('lands on the exercise\'s weight step when given one, and always below the weight it drops from', () => {+ expect(nextDropWeight(60, 20, 2.5)).toBe(47.5) // 48 is not loadable in 2.5s+ expect(nextDropWeight(100, 20, 5)).toBe(80)+ expect(nextDropWeight(80, 20, 5)).toBe(65) // 64 → the nearest 5+ expect(nextDropWeight(5, 5, 2.5)).toBe(2.5) // rounding back up to 5 would be no drop+ expect(nextDropWeight(2.5, 10, 2.5)).toBe(0)+ })++ it('takes a snapping function (the plates you own) as the grid', () => {+ expect(nextDropWeight(100, 20, w => Math.floor(w / 10) * 10)).toBe(80)+ expect(nextDropWeight(100, 25, w => Math.floor(w / 10) * 10)).toBe(70)+ })+it('roughly halves the previous rep count, floored at 1', () => {expect(nextBurstReps(8)).toBe(4)expect(nextBurstReps(1)).toBe(1)diff --git a/frontend/src/sheets.jsx b/frontend/src/sheets.jsxindex e675c00a8..11ba2b6b4 100644--- a/frontend/src/sheets.jsx+++ b/frontend/src/sheets.jsx@@ -6,7 +6,7 @@ import { activeProfile, exAvailable, ALL_EQUIPMENT, newProfile } from './lib/equimport { fmtDate, fmtNum, fmtPlate, exerciseNameText, fmtVol, fmtDur, durPart, todayISO, isoOf, uid, exCount, routineCount, setsWorkCount, DAYN, DAYS, weekOrder, weekStartOf, weekDayOffset, MONTHS_LONG, ACCENTS } from './lib/format.js'import { lastEntryFor, bestWeightFor, bestWeightForEntry, buildSets, effectiveRoutineIds, workoutDay, workoutVolume, setsDone, setsDoneActive, setUnitsTotal, lastBW, supersetUnits, sessionSections, unitOf, setLabel, defaultConfig, cleanupSg, modeOf, effortOf, EFFORT, capEffort, stepEffort, isBw, isPerSide, sideReps, workSetsDone, applyIntensifierPlan, MAX_PLANNED_WARMUPS, NOTE_MAX } from './lib/history.js'import { usesBar, defaultBarWeight, hasBarOverride, isNoBar } from './lib/bar.js'-import { PLATE_SIZES, pairsOf, ownsPlates, withPlatePairs, withStandardPlates, withLoadKind, loadKindFor, baseWeightFor } from './lib/plates.js'+import { PLATE_SIZES, pairsOf, ownsPlates, withPlatePairs, withStandardPlates, withLoadKind, loadKindFor, baseWeightFor, dropGrid } from './lib/plates.js'import { toScale, rirOf, EFFORT_PRESETS, effortColor } from './lib/effort.js'import { beep, vibrate } from './lib/sound.js'import { t, dateLocale, instrFor, exerciseNameFor, exerciseNameClass, getLang, INSTR_LANGS } from './lib/i18n.js'@@ -1188,7 +1188,7 @@ export function swapActiveWorkoutExercise(index) {const step = modeOf(full) === 'reps' ? weightIncrement(full, st.unit) : defaultIncrement(ex.id, st.unit)const past = sessionHistory(st)const built = freestyle- ? { target: { ...cfg }, plan: null, sets: applyIntensifierPlan(buildSets(past, full, { step, preferLast: true }), full) }+ ? { target: { ...cfg }, plan: null, sets: applyIntensifierPlan(buildSets(past, full, { step, preferLast: true }), full, dropGrid(st, full)) }: buildPlannedEntry(past, full, slotRoutine, { noProg: builtOutOfProgression(current, slotRoutine) })const replacement = {id: ex.id,diff --git a/frontend/src/views/Workout.jsx b/frontend/src/views/Workout.jsxindex 026153e82..56f8fc8a0 100644--- a/frontend/src/views/Workout.jsx+++ b/frontend/src/views/Workout.jsx@@ -6,7 +6,7 @@ import { workoutControls } from '../lib/workout-controls.js'import { useUI } from '../store/useUI.js'import { exOr, betterWeight } from '../lib/exercises.js'import { usesBar } from '../lib/bar.js'-import { loadKindFor, baseWeightFor, inventoryFor, rowLoad, sameLoad, plateDelta } from '../lib/plates.js'+import { loadKindFor, baseWeightFor, inventoryFor, rowLoad, sameLoad, plateDelta, dropGrid } from '../lib/plates.js'import { effectiveRoutines, effectiveRoutineIds, lastEntryFor, bestWeightFor, bestWeightForEntry, buildSets, freestyleConfig, defaultConfig, setsDoneActive, setUnitsTotal, supersetUnits, unitOf, setLabel, modeOf, isBw, isPerSide, repStep, EFFORT, effortOf, stepEffort, capEffort, cascadeWeight, insertWarmupRow, removeRowAt, pairAdjacent, unpairSuperset, cleanupSg, applyIntensifierPlan, pinnedNoteFor, exNoteFor, setsRepsOf } from '../lib/history.js'import { fmtNum, fmtPlate, exerciseNameText, fmtDate, todayISO, exCount, DAYN } from '../lib/format.js'import { speedUnitOf, toSpeed, fromSpeed } from '../lib/speed.js'@@ -105,12 +105,13 @@ function ExerciseBlock({ entryIdx, compact, dense, editing, onToggle, onToggleSi// A unilateral set drops per side (issue #60): addSideDrop seeds each side from its own weight.if (isSideSet(row)) {const pct = entry.target?.intensifier?.type === 'dropset' ? entry.target.intensifier.pct : undefined- return addSideDrop(row, pct)+ return addSideDrop(row, pct, dropGrid(S, { ...entry.target, id: entry.id }))}const drops = dropsOf(row)const base = drops.length ? drops[drops.length - 1].w : (row.w || 0)const pct = entry.target?.intensifier?.type === 'dropset' ? entry.target.intensifier.pct : undefined- return addDrop(row, { w: nextDropWeight(base, pct), r: row.r })+ // On a weight you can load: the plates you own, else the exercise's step (lib/plates.js).+ return addDrop(row, { w: nextDropWeight(base, pct, dropGrid(S, { ...entry.target, id: entry.id })), r: row.r })})// A rest-pause row's own reps are always the total across every burst (see// applyIntensifierPlan/history.js) — clusters are the breakdown of that total, not extra on@@ -1374,7 +1375,7 @@ function ActiveWorkout() {const built = freestyle? { target: { ...cfg }, plan: null, sets: applyIntensifierPlan(buildSets(past, full, {step: modeOf(full) === 'reps' ? weightIncrement(full, s.unit) : defaultIncrement(ex.id, s.unit), preferLast: true,- }), full) }+ }), full, dropGrid(s, full)) }: buildPlannedEntry(past, full, routine, { noProg })const insertAt = insertionIndexAfterCurrentUnit(supersetUnits(s.active.entries), s.active.cur, s.active.entries.length)s.active.entries.splice(insertAt, 0, joinSessionNoProg(s.active, { id: ex.id, ...built, ...(curRid ? { rid: curRid } : {}), ...(noProg ? { noProg: true } : {}) }))