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
frontend: a weekday pointing only at a deleted routine is not a planned day
Boris Kurktchievaedc63f59800
diff --git a/frontend/src/lib/queue.js b/frontend/src/lib/queue.jsindex 059b4051b..64248a97b 100644--- a/frontend/src/lib/queue.js+++ b/frontend/src/lib/queue.js@@ -155,8 +155,8 @@ export function queueView(S, today) {/*** The streak card's fraction, `done / planned`, for the week `today` is in. Without a queue it- * is what it always was: the calendar week's finished workouts over the weekdays that hold a- * plan (a combined day is one day, one workout). With an active queue the coach week is the+ * is the calendar week's finished workouts over the weekdays that hold a plan of routines that+ * still exist (a combined day is one day, one workout). With an active queue the coach week is the* unit, and your own training counts beside it: `planned` is the queue's sessions plus the* weekdays you plan yourself (a weekday whose routines the queue already covers adds nothing),* and `done` is the queue's finished sessions plus this calendar week's workouts on top of them@@ -171,9 +171,12 @@ export function weekTally(S, today) {const thisWeek = S.workouts.filter(w => weekKey(w.d, ws) === weekKey(today, ws))const q0 = queueOf(S)const q = q0 && today >= q0.startsOn ? q0 : null- // "Covered by the queue" is tested against the raw ids: a queue routine deleted mid-week is- // gone from `q.ids`, but a weekday pointer to it is still not a day you planned yourself.- const ownIds = ids => [].concat(ids || []).filter(id => !(q && S.queue.ids.includes(id)))+ // A weekday counts as planned only for routines that still exist (a pointer left behind by a+ // deleted routine shows as rest on the strip, and effectiveRoutineIds drops it). "Covered by+ // the queue" is tested against the raw ids: a queue routine deleted mid-week is gone from+ // `q.ids`, but a weekday pointer to it is still not a day you planned yourself.+ const unqueued = id => !(q && S.queue.ids.includes(id))+ const ownIds = ids => [].concat(ids || []).filter(id => S.routines.some(r => r.id === id) && unqueued(id))const ownDays = Object.values(S.week || {}).filter(ids => ownIds(ids).length).lengthif (!q) return { done: thisWeek.length, planned: ownDays }// The workout that earns each session its credit is the earliest one the DONE RULE accepts@@ -181,6 +184,8 @@ export function weekTally(S, today) {// workout this week is training on top, and so is a crediting workout's own half.const chrono = (a, b) => ((a.d || '') < (b.d || '') ? -1 : (a.d || '') > (b.d || '') ? 1 : (a.start || 0) - (b.start || 0))const credited = new Set(q.ids.map(id => S.workouts.filter(w => countsFor(S, q, w, id)).sort(chrono)[0]).filter(Boolean))- const other = thisWeek.filter(w => !credited.has(w) || ownIds(routineIdsOf(w)).length).length+ // (a logged workout keeps its credit even if its routine was deleted since — existence only+ // decides what is PLANNED)+ const other = thisWeek.filter(w => !credited.has(w) || routineIdsOf(w).some(unqueued)).lengthreturn { done: queueDone(S).length + other, planned: q.ids.length + ownDays }}diff --git a/frontend/src/lib/queue.test.js b/frontend/src/lib/queue.test.jsindex a865698ec..e61de4f1e 100644--- a/frontend/src/lib/queue.test.js+++ b/frontend/src/lib/queue.test.js@@ -224,6 +224,22 @@ describe('weekTally — the streak card fraction', () => {expect(weekTally(S({ queue: null }), TODAY)).toEqual({ done: 0, planned: 0 })})+ it('the own half of a merged session stays done after its routine is deleted; only the plan forgets it', () => {+ const noOwn = routines.filter(r => r.id !== 'own')+ const merged = w({ routineIds: ['d1', 'own'], name: 'US W1 D1 + Core' })+ expect(weekTally(S({ routines: noOwn, workouts: [merged] }), TODAY)).toEqual({ done: 2, planned: 3 })+ expect(weekTally(S({ routines: noOwn, week: { 3: ['own'] }, workouts: [merged] }), TODAY)).toEqual({ done: 2, planned: 3 })+ // the same training as two workouts counts 2 — merged must not count less+ const split = [w({ id: 'a', routineIds: ['d1'], name: 'US W1 D1' }), w({ id: 'b', start: SINCE + 7200000, routineIds: ['own'], name: 'Core' })]+ expect(weekTally(S({ routines: noOwn, workouts: split }), TODAY)).toEqual({ done: 2, planned: 3 })+ })++ it('a weekday pointing only at a deleted routine is not a planned day — the strip shows it as rest', () => {+ expect(weekTally(S({ queue: null, week: { 3: ['gone'] } }), TODAY)).toEqual({ done: 0, planned: 0 })+ expect(weekTally(S({ queue: null, week: { 3: ['gone', 'own'], 5: 'gone' } }), TODAY)).toEqual({ done: 0, planned: 1 })+ expect(weekTally(S({ week: { 3: ['gone'] } }), TODAY)).toEqual({ done: 0, planned: 3 })+ })+it('a coach week alone: the queue\'s sessions, done by the DONE RULE, whatever calendar week they fell in', () => {expect(weekTally(S(), TODAY)).toEqual({ done: 0, planned: 3 })expect(weekTally(S({ workouts: [w({ routineIds: ['d1'] })] }), TODAY)).toEqual({ done: 1, planned: 3 })