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
Finish: a long cardio finisher or hold no longer cuts the workout's duration short
Duarte Santos39b1fd7ce5aa
diff --git a/frontend/src/lib/finish-workout.js b/frontend/src/lib/finish-workout.jsindex 7c30f6255..44cd5e6e6 100644--- a/frontend/src/lib/finish-workout.js+++ b/frontend/src/lib/finish-workout.js@@ -37,16 +37,25 @@ function finishedRow(set) {// builds that did not stamp sets keep the old behaviour.export const FORGOTTEN_GAP_MS = 20 * 60 * 1000+// How long a ticked row itself took: a cardio row its minutes, a hold its seconds (both sides of+// a per-side hold). A 30-minute treadmill finisher ticked at its end follows the last lift by+// more than the gap without the session being over, so that time is not counted as a break.+function rowLengthMs(set) {+ const n = v => (Number(v) > 0 ? Number(v) : 0)+ if (isSideSet(set)) return (n(set.sides.L?.sec) + n(set.sides.R?.sec)) * 1000+ return n(set.min) * 60000 + n(set.sec) * 1000+}+export function sessionEnd(active, now = Date.now(), gap = FORGOTTEN_GAP_MS) {const ticks = (active?.entries || []).flatMap(e => e.sets || []).filter(s => hasCompletedWork(s) && Number.isFinite(s.at))- .map(s => s.at)- .sort((a, b) => a - b)+ .map(s => ({ at: s.at, len: rowLengthMs(s) }))+ .sort((a, b) => a.at - b.at)if (!ticks.length) return now- let end = ticks[0]- for (const at of ticks.slice(1)) {- if (at - end > gap) break+ let end = ticks[0].at+ for (const { at, len } of ticks.slice(1)) {+ if (at - len - end > gap) breakend = at}return now - end > gap ? end : nowdiff --git a/frontend/src/lib/finish-workout.test.js b/frontend/src/lib/finish-workout.test.jsindex 9b0fed082..eacc6f5d9 100644--- a/frontend/src/lib/finish-workout.test.js+++ b/frontend/src/lib/finish-workout.test.js@@ -290,6 +290,24 @@ describe('sessionEnd: a workout finished long after its last set', () => {expect(sessionEnd({ entries: [{ id: 'x', sets: [{ done: true, w: 50, r: 8 }] }] }, 42)).toBe(42)})+ it('does not cut a long cardio finisher or hold off as a forgotten break', () => {+ // Bench 0 to 40 min, a 30-minute treadmill row ticked at 72, Finish at 73.+ const active = { entries: [+ { id: 'x', sets: [0, 20, 40].map(m => ({ done: true, w: 50, r: 8, at: T0 + m * MIN })) },+ { id: 'run', sets: [{ done: true, min: 30, speed: 10, at: T0 + 72 * MIN }] },+ ] }+ expect(sessionEnd(active, T0 + 73 * MIN)).toBe(T0 + 73 * MIN)+ // Its own length is all it is credited: the same row ticked the next morning still is a break.+ active.entries[1].sets[0].at = T0 + 24 * 60 * MIN+ expect(sessionEnd(active, T0 + 24 * 60 * MIN + 1)).toBe(T0 + 40 * MIN)+ // A long per-side hold counts both sides.+ const hold = { entries: [+ { id: 'x', sets: [{ done: true, w: 50, r: 8, at: T0 }] },+ { id: 'plank', sets: [{ done: true, at: T0 + 30 * MIN, sides: { L: { sec: 330, done: true }, R: { sec: 330, done: true } } }] },+ ] }+ expect(sessionEnd(hold, T0 + 31 * MIN)).toBe(T0 + 31 * MIN)+ })+it('counts a per-side set once one side is done', () => {const active = { entries: [{ id: 'x', sets: [{w: 20, r: 8, done: false, at: T0,