Skip to content

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.

Plates: a single stack loads both plates of every pair you own

Duarte Santos987b3eb8fe4e
diff --git a/frontend/src/lib/plates.js b/frontend/src/lib/plates.js
index a3fe9f965..f903a93b9 100644
--- a/frontend/src/lib/plates.js
+++ b/frontend/src/lib/plates.js
@@ -47,8 +47,8 @@ const sizesOf = entry => (entry && typeof entry === 'object' && !Array.isArray(e
export const ownsPlates = S => sizesOf(S?.plates?.[unitOf(S)]).length > 0
/**
- * The plates this profile can load, heaviest first: [{ w, n }] with n pairs (or plates, for a
- * single stack) of each size. S.plates[unit] is { [size]: count, _ts }; absent or without any
+ * The plates this profile can load, heaviest first: [{ w, n }] with n pairs of each size (a
+ * single stack loads both plates of a pair, see rowLoad). S.plates[unit] is { [size]: count, _ts }; absent or without any
* size → the default set.
*/
export function inventoryFor(S) {
@@ -222,7 +222,10 @@ export function rowLoad(kind, weight, base, inv) {
const b = Math.max(0, num(base))
if (w <= b) return { kind, barOnly: true, perSide: 0, plates: [], missing: 0 }
const perSide = Math.round(((w - b) / (kind === 'pairs' ? 2 : 1)) * 100) / 100
- const { plates, missing } = plateStack(perSide, inv)
+ // The inventory counts pairs. A bar takes one plate of a pair per side; a single stack can
+ // take both, so one pair of 20s is two 20s on a sled, not one.
+ const stock = kind === 'single' ? (inv || []).map(p => ({ ...p, n: p.n * 2 })) : inv
+ const { plates, missing } = plateStack(perSide, stock)
return { kind, barOnly: false, perSide, plates, missing }
}
diff --git a/frontend/src/lib/plates.test.js b/frontend/src/lib/plates.test.js
index 0e6708ef3..2fafbb9cd 100644
--- a/frontend/src/lib/plates.test.js
+++ b/frontend/src/lib/plates.test.js
@@ -195,7 +195,17 @@ describe('rowLoad', () => {
test('a single stack takes all of it beyond the base: a belt, a sled', () => {
expect(rowLoad('single', 25, 0, homeInv)).toEqual({ kind: 'single', barOnly: false, perSide: 25, plates: [25], missing: 0 })
- expect(rowLoad('single', 190, 100, homeInv).plates).toEqual([45, 35, 10])
+ // One pair of 45s is two 45s: a stack takes both plates of a pair.
+ expect(rowLoad('single', 190, 100, homeInv).plates).toEqual([45, 45])
+ })
+
+ test('a single stack counts both plates of each pair you own (QA 1.3.11)', () => {
+ const inv = inventoryFor({ unit: 'kg', plates: { kg: { 20: 1, 10: 1, _ts: 1 } } })
+ // A sled leg press at 150 kg: 20+20+10+10 = 60 on, 90 short (was "20 + 10 · 120 short").
+ expect(rowLoad('single', 150, 0, inv)).toMatchObject({ plates: [20, 20, 10, 10], missing: 90 })
+ expect(rowLoad('single', 40, 0, inv)).toMatchObject({ plates: [20, 20], missing: 0 })
+ // A bar still takes one plate of each pair per side.
+ expect(rowLoad('pairs', 80, 20, inv)).toMatchObject({ perSide: 30, plates: [20, 10], missing: 0 })
})
test('kind none never loads', () => {
@@ -230,6 +240,13 @@ describe('dropGrid', () => {
expect(snap(64)).toBe(60)
expect(snap(15)).toBe(20) // below the bar: the bar is the lightest you can load
})
+ test('a single stack drops onto both plates of each pair', () => {
+ const sled = idOf('sled machine')
+ const S = { unit: 'kg', plates: { kg: { 20: 1, 10: 1, _ts: 1 } }, barWeights: { [sled]: 0 } }
+ const snap = dropGrid(S, { id: sled })
+ expect(snap(55)).toBe(50) // 20+20+10, not 30 (one plate per pair)
+ expect(snap(100)).toBe(60) // everything owned
+ })
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)