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.

Stangengewicht: Bibliothek und Store — pro Uebung, in der Profil-Einheit, Defaults je Stangentyp (kg und lb)

Duarte Santos9892f735d369
diff --git a/frontend/src/lib/bar.js b/frontend/src/lib/bar.js
new file mode 100644
index 000000000..fa75348c6
--- /dev/null
+++ b/frontend/src/lib/bar.js
@@ -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
+}
diff --git a/frontend/src/store/useStore.js b/frontend/src/store/useStore.js
index 7a85ccdf3..6dc85245f 100644
--- a/frontend/src/store/useStore.js
+++ b/frontend/src/store/useStore.js
@@ -26,6 +26,10 @@ export const DEF = {
// every time you do the movement ("seat 4, pin 7"). Distinct from a routine's `note`, which
// belongs to one exercise in one plan, and from a session note, which belongs to one day.
exNotes: {},
+ // Per-exercise bar weight overrides, keyed by exercise id, in the profile unit (see
+ // lib/bar.js). Personal equipment, so it syncs with the account but never travels in a
+ // shared plan. Logged weights stay the total — this only feeds the plate math.
+ barWeights: {},
}
const clone = o => JSON.parse(JSON.stringify(o))