Stangengewicht: Scheiben-Rechnung pro Seite, pro Uebung einstellbar

Wer an der Stange arbeitet, rechnet vor jedem Satz dasselbe im Kopf: was muss
pro Seite drauf. Die App kennt beide Zahlen laengst — das Gesamtgewicht steht
im Satz, der Stangentyp in der Uebung — und hat sie nie zusammengebracht.

Neu: lib/bar.js mit den ueblichen Stangen (Olympia 20 kg, EZ 10, Multipresse 9,
Trap 25) und den Markierungen, die ein lb-Profil wirklich im Rack hat (45, 25,
20, 55) — keine umgerechneten 44,1 lb, die auf keiner Stange stehen. Das
Stangengewicht liegt in S.barWeights pro Uebung und in der Profil-Einheit, wie
jedes andere Gewicht im State: ein Einheitenwechsel beschriftet um und rechnet
nicht, sonst waere die Stange die eine Zahl, die unter dem Nutzer wegrutscht,
waehrend die Totale drumherum stehen bleiben.

Eingetragen wird weiterhin das Gesamtgewicht. Historie, Progression und 1RM
bedeuten exakt das, was sie vorher bedeutet haben — die Stange ist reine
Anzeige-Metadatei und speist nur die Rechnung "(Total − Stange) / 2".

Im Workout haengt der Chip "Stange 20 kg · 30 kg pro Seite" am Satz, der als
naechstes dran ist (erster offener; ist alles abgehakt, der schwerste). Ein
Tipp darauf oeffnet dieselbe Stepper-Zeile, die auch in Uebungsdetail und
Konfiguration steht — auf 0 gestellt faellt die Uebung auf den Standard ihres
Stangentyps zurueck, dieselbe "0 loescht den Schluessel"-Form wie bei den
nullbaren Satzfeldern.

Strings in allen vierzehn Sprachen; der pt-BR-Vererbungs-Fingerabdruck ist
nachgezogen (4 Overrides, 3 geerbt).
This commit is contained in:
Duarte Santos committed 2026-09-01 14:11:51 +02:00
1 parent 75fb168a03
commit 45c4756cd0
20 files changed
+334 -4

No files matched your search

+56
View File
@@ -0,0 +1,56 @@
// Per-exercise bar weight (issue: plate math for barbell work). Logged weights stay the
// TOTAL on the bar — history, progression and 1RM keep meaning exactly what they always
// did. The bar weight is display metadata: it feeds the "X per side" plate math and
// nothing else.
//
// Unit: stored in the profile unit (S.unit), like every other weight in state — set
// weights, exWeights, bodyweight are all written in whatever unit the profile logs and a
// unit switch re-labels them without converting. A canonical-kg bar would be the one
// number that shifts under the user on a unit switch while the totals around it stay
// put, so the override follows the same rule. The equipment *defaults* therefore exist
// per unit too: a kg profile gets the 20 kg olympic bar, a lb profile the 45 lb bar its
// gym actually racks — not a 44.1 lb conversion no bar is stamped with.
import { EXIDX } from './exercises.js'
/** Equipment values (e.eq) that put a bar in your hands. */
export const BAR_EQ = new Set(['barbell', 'olympic barbell', 'ez barbell', 'smith machine', 'trap bar'])
/** Typical bar weights per equipment type, for a kg profile. */
export const DEFAULT_BAR_KG = { barbell: 20, 'olympic barbell': 20, 'ez barbell': 10, 'smith machine': 9, 'trap bar': 25 }
/** The same bars as a lb profile knows them — real markings, not converted kg. */
export const DEFAULT_BAR_LB = { barbell: 45, 'olympic barbell': 45, 'ez barbell': 25, 'smith machine': 20, 'trap bar': 55 }
const exOf = exOrId => (typeof exOrId === 'string' ? EXIDX[exOrId] : exOrId)
/** Whether this exercise (object or id) is done with a bar. */
export const usesBar = exOrId => BAR_EQ.has(exOf(exOrId)?.eq)
/** The default bar weight for an equipment type, in the given unit. null off the list. */
export const defaultBarWeight = (eq, unit) =>
(unit === 'lb' ? DEFAULT_BAR_LB : DEFAULT_BAR_KG)[eq] ?? null
/** True when the user has set their own bar weight for this exercise. */
export const hasBarOverride = (S, exId) => ((S?.barWeights || {})[exId] || 0) > 0
/**
* Effective bar weight for one exercise, in the profile unit: the explicit
* S.barWeights[exId] if set, else the default for the bar type. null for anything
* that is not a bar exercise.
*/
export function barWeightFor(S, exOrId) {
const ex = exOf(exOrId)
if (!BAR_EQ.has(ex?.eq)) return null
const own = (S?.barWeights || {})[ex.id]
if (own > 0) return own
return defaultBarWeight(ex.eq, S?.unit)
}
/**
* Plates per side: (total − bar) / 2, rounded to 2 decimals. null when there is nothing
* sensible to show — a missing number, or a total at or below the bar itself.
*/
export function plateSplit(total, bar) {
if (!(total > 0) || !(bar > 0) || total <= bar) return null
return Math.round(((total - bar) / 2) * 100) / 100
}
+94
View File
@@ -0,0 +1,94 @@
import { describe, expect, test } from 'vitest'
import { BAR_EQ, DEFAULT_BAR_KG, DEFAULT_BAR_LB, usesBar, defaultBarWeight, barWeightFor, hasBarOverride, plateSplit } from './bar.js'
import { EXDB } from './exercises-data.js'
const idOf = eq => EXDB.find(e => e.eq === eq).id
describe('bar equipment', () => {
test('covers the five bar types and the 228 catalogue exercises they carry', () => {
expect([...BAR_EQ].sort()).toEqual(['barbell', 'ez barbell', 'olympic barbell', 'smith machine', 'trap bar'])
expect(EXDB.filter(e => BAR_EQ.has(e.eq)).length).toBe(228)
})
test('usesBar answers for ids and exercise objects alike', () => {
for (const eq of BAR_EQ) {
expect(usesBar(idOf(eq)), eq).toBe(true)
expect(usesBar({ eq }), eq).toBe(true)
}
expect(usesBar({ eq: 'dumbbell' })).toBe(false)
expect(usesBar({ eq: 'body weight' })).toBe(false)
expect(usesBar('no-such-id')).toBe(false)
expect(usesBar(null)).toBe(false)
})
})
describe('per-unit defaults', () => {
test('every bar type has a default in both units', () => {
for (const eq of BAR_EQ) {
expect(DEFAULT_BAR_KG[eq], eq).toBeGreaterThan(0)
expect(DEFAULT_BAR_LB[eq], eq).toBeGreaterThan(0)
}
expect(defaultBarWeight('ez barbell', 'kg')).toBe(10)
expect(defaultBarWeight('ez barbell', 'lb')).toBe(25)
expect(defaultBarWeight('olympic barbell', 'kg')).toBe(20)
// A lb profile gets the bar its gym actually racks, not a 44.1 lb conversion.
expect(defaultBarWeight('barbell', 'lb')).toBe(45)
expect(defaultBarWeight('dumbbell', 'kg')).toBeNull()
})
})
describe('barWeightFor', () => {
const barbell = idOf('barbell')
const ez = idOf('ez barbell')
test('falls back to the equipment default in the profile unit', () => {
expect(barWeightFor({ unit: 'kg', barWeights: {} }, barbell)).toBe(20)
expect(barWeightFor({ unit: 'lb', barWeights: {} }, barbell)).toBe(45)
expect(barWeightFor({ unit: 'kg' }, ez)).toBe(10)
})
test('an explicit override wins over the default', () => {
const S = { unit: 'kg', barWeights: { [ez]: 7.5 } }
expect(barWeightFor(S, ez)).toBe(7.5)
expect(hasBarOverride(S, ez)).toBe(true)
expect(barWeightFor(S, barbell)).toBe(20) // other exercises keep their default
expect(hasBarOverride(S, barbell)).toBe(false)
})
test('a cleared (deleted or zeroed) override falls back to the default', () => {
const S = { unit: 'kg', barWeights: { [ez]: 12.5 } }
delete S.barWeights[ez]
expect(barWeightFor(S, ez)).toBe(10)
expect(barWeightFor({ unit: 'kg', barWeights: { [ez]: 0 } }, ez)).toBe(10)
expect(hasBarOverride({ unit: 'kg', barWeights: { [ez]: 0 } }, ez)).toBe(false)
})
test('is null for anything without a bar', () => {
const dumbbell = EXDB.find(e => e.eq === 'dumbbell')
expect(barWeightFor({ unit: 'kg', barWeights: {} }, dumbbell.id)).toBeNull()
expect(barWeightFor({ unit: 'kg', barWeights: {} }, 'no-such-id')).toBeNull()
})
})
describe('plateSplit', () => {
test('splits what is beyond the bar evenly per side', () => {
expect(plateSplit(62.5, 20)).toBe(21.25)
expect(plateSplit(100, 20)).toBe(40)
expect(plateSplit(30, 10)).toBe(10)
})
test('rounds to 2 decimals', () => {
expect(plateSplit(65.55, 20)).toBe(22.78)
expect(plateSplit(21.2, 20)).toBe(0.6)
})
test('is null when there is nothing sensible to show', () => {
expect(plateSplit(20, 20)).toBe(null) // bar only
expect(plateSplit(15, 20)).toBe(null) // below the bar
expect(plateSplit(0, 20)).toBe(null)
expect(plateSplit(100, 0)).toBe(null)
expect(plateSplit(null, 20)).toBe(null)
expect(plateSplit(100, null)).toBe(null)
expect(plateSplit(undefined, undefined)).toBe(null)
})
})
+3 -3
View File
@@ -27,11 +27,11 @@ describe('Brazilian Portuguese locale', () => {
.sort(byCodeUnit)
const fingerprint = createHash('sha256').update(JSON.stringify(inherited)).digest('hex')
expect(Object.keys(PT_BR_OVERRIDES)).toHaveLength(338)
expect(inherited).toHaveLength(458)
expect(Object.keys(PT_BR_OVERRIDES)).toHaveLength(342)
expect(inherited).toHaveLength(461)
// If this fails, review the changed keys and wording before accepting a new hash. From
// frontend/: node scripts/pt-br-inheritance-fingerprint.mjs --list
expect(fingerprint, 'pt-PT inheritance changed; review the inherited pt-BR wording').toBe('67edc754880ed2a392eee8839549a36bd8bf55b16f889b655b40fc6c493fc6dd')
expect(fingerprint, 'pt-PT inheritance changed; review the inherited pt-BR wording').toBe('1b6f52ab4152f95d7fca75fb79f12f582be228f6388b292b75932bfd09b427b2')
})
test('does not leak European Portuguese UI terms', () => {