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
Follow-up to #194: a typo like 99999 in a weight field no longer stalls the workout screen while the plate line works out what cannot be loaded
Duarte Santosb18801669ed2
diff --git a/frontend/src/lib/plates.js b/frontend/src/lib/plates.jsindex 0ad96df53..c56d31fc0 100644--- a/frontend/src/lib/plates.js+++ b/frontend/src/lib/plates.js@@ -121,7 +121,11 @@ export function plateStack(weight, inv) {let k = Math.min(p.n, Math.floor(left / unit))while (k-- > 0) { greedy.push(p.w); left -= unit }}- if (left === 0) return { plates: greedy, missing: 0 }+ // At or beyond everything you own, greedy has already put every plate on and the rest is+ // missing. The search below would only find that again, with a table as long as the target:+ // a typo like 9999 in a weight field built it on every keystroke.+ const all = items.reduce((sum, p) => sum + q(p.w) * p.n, 0)+ if (left === 0 || target >= all) return { plates: greedy, missing: left / Q }// 2. exact fit with the fewest plates: f[i][s] = min plates using sizes i.. to make sconst n = items.lengthconst INF = 1e9diff --git a/frontend/src/lib/plates.test.js b/frontend/src/lib/plates.test.jsindex b1c00f074..dfbab1d1f 100644--- a/frontend/src/lib/plates.test.js+++ b/frontend/src/lib/plates.test.js@@ -107,6 +107,15 @@ describe('plateStack', () => {expect(plateStack(null, homeInv)).toEqual({ plates: [], missing: 0 })expect(plateStack(30, [])).toEqual({ plates: [], missing: 30 })})++ test('beyond everything you own: every plate on, the rest missing, without a search', () => {+ expect(plateStack(200, homeInv)).toEqual({ plates: [45, 35, 25, 15, 10, 5, 2.5], missing: 62.5 })+ // A typo in a weight field is rendered on every keystroke; it must not build a table as+ // long as the number (for this one, nine arrays of four million entries).+ const t0 = performance.now()+ for (let i = 0; i < 5; i++) expect(plateStack(999999.75, homeInv).missing).toBe(999999.75 - 137.5)+ expect(performance.now() - t0).toBeLessThan(200)+ })})describe('plateDelta', () => {