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: [] }])