fix: smaller same-area items from the review - future-dated clamp, LB_TO_KG export, value-based bodyweight guard

This commit is contained in:
Space-Hermes committed 2026-08-12 17:43:20 +02:00
1 parent ed666df237
commit 23a5b6c228
3 files changed
+17 -5

No files matched your search

+3 -3
View File
@@ -66,7 +66,7 @@ function emptyMuscleMap(value) {
const REP_CAP = 12
const epley1RM = (load, reps) => load * (1 + Math.min(reps || 1, REP_CAP) / 30)
const LB_TO_KG = 0.45359237
export const LB_TO_KG = 0.45359237
function numeric(value) {
if (value === null || value === undefined || value === '' || typeof value === 'boolean') return null
@@ -139,7 +139,7 @@ function bodyweightConfigured(ex, entry, set, workout, opts = {}) {
const added = kgOf(set?.w, unitOf(set, entry?.target, entry, workout, opts))
const hasBodyweightContext = numeric(workout?.bw) !== null
|| numeric(workout?.bodyweight) !== null
|| Object.prototype.hasOwnProperty.call(opts, 'bodyweightKg')
|| numeric(opts.bodyweightKg) !== null
|| numeric(opts.bodyweight) !== null
|| hasUnitStamp(set, entry?.target, entry, workout)
return ex?.eq === 'body weight' && (added === 0 || hasBodyweightContext)
@@ -253,7 +253,7 @@ function fatigueValue(events, now) {
value += event.stimulus
lastTimestamp = event.timestamp
}
value *= halfLifeDecay(now - lastTimestamp, FATIGUE_HALF_LIFE_MS)
value *= halfLifeDecay(Math.max(0, now - lastTimestamp), FATIGUE_HALF_LIFE_MS)
// Normalise the accumulated stimulus to a saturating fatigue level: more volume starts
// higher but never pins, and the value fades asymptotically - no window-edge cliff.
return 1 - Math.exp(-value)
+12
View File
@@ -476,6 +476,18 @@ describe('canonical loads and configured bodyweight', () => {
}
})
it('treats a future-dated workout as its own timestamp, never amplified', () => {
// A CSV import with a bad timezone can date a workout 10 days in the future. The final
// decay clamps the age to zero instead of exponentiating, so the session counts exactly
// like the same workout dated now - no 2^(10d/36h) ~ 102x amplification.
const future = doneWorkoutAt(SINGLE.id, NOW + 10 * DAY, 5)
const now = doneWorkoutAt(SINGLE.id, NOW, 5)
const futureValue = fatigueOf([future], NOW)[SINGLE_SLUG]
const nowValue = fatigueOf([now], NOW)[SINGLE_SLUG]
expect(futureValue).toBeCloseTo(nowValue, 10)
expect(futureValue).toBeLessThan(1)
})
it('counts a default custom zero-load ring push-up for fatigue and load-blind strength', () => {
const id = 'recovery-ring-push-up'
registerCustom([{ id, n: 'Ring push-up', bp: 'chest', tg: 'chest', eq: 'custom', sm: [] }])
+2 -2
View File
@@ -11,7 +11,7 @@ import Heatmap from '../components/Heatmap.jsx'
import Icon from '../components/Icon.jsx'
import BodyMap, { BodyMapLegend } from '../components/BodyMap.jsx'
import { loadOfWorkouts, rankOf, MUSCLE_NAME, musclesOf } from '../lib/muscles.js'
import { fatigueOf, strengthOf, STRENGTH_FLOOR } from '../lib/recovery.js'
import { fatigueOf, strengthOf, STRENGTH_FLOOR, LB_TO_KG } from '../lib/recovery.js'
import { fatigueStateOf } from '../lib/recovery-view.js'
import { e1rmSeries, best1RM } from '../lib/onerm.js'
import {
@@ -106,7 +106,7 @@ function MuscleBalance({ S }) {
if (!entries.length) return null
const last = entries.slice().sort((a, b) => String(a.d).localeCompare(String(b.d))).at(-1)
if (!last || !(last.w > 0)) return null
return S.unit === 'lb' ? last.w * 0.45359237 : last.w
return S.unit === 'lb' ? last.w * LB_TO_KG : last.w
}, [S.bodyweight, S.unit])
const fatigue = useMemo(() => fatigueOf(workouts, now, { bodyweightKg, unit: S.unit }), [workouts, now, bodyweightKg, S.unit])
const strength = useMemo(() => strengthOf(workouts, now, { bodyweightKg, unit: S.unit }), [workouts, now, bodyweightKg, S.unit])