Effort stepper: count up from the bottom of the scale
The first + on an empty cell jumped straight to a "typical working set" (RIR 2 / RPE 8), skipping 0 and 1 with no way to see why. A stepper that lands somewhere other than where counting would take you is just puzzling, so it now starts at the bottom of the scale and walks up in even steps like every other stepper in the app: RIR from 0, RPE from 6 — the scale is only meaningful for working sets and anything lighter is a warm-up nobody rates. Stepping back off the floor clears the cell again, so a mistap is undoable instead of sticking at 0 — which on the RIR scale claims the set went to failure. − on a cell that was never filled in still leaves it empty. The stepping moved out of the view into stepEffort/capEffort in history.js, where it can be tested: 16 new cases covering the scale walk, the floor and ceiling, the clear-on-undershoot, half-step rounding, junk settings values, the showRir overlay every load path performs, and a session's worth of logging end to end. A typed value is still only capped, never floored — clamping up would turn the "1" of "10" into the floor and fight the input. The help sheet no longer claims the highlighted row is where + starts; it is where working sets usually land. Reworded in all 11 language packs.
This commit is contained in:
1 parent
0c6c22c04b
commit
6905117352
15 files changed
+188
-29
No files matched your search
@@ -27,11 +27,32 @@ export function fmtSec(sec) {
|
||||
// their own fields: RIR counts the reps still in the tank, RPE reads the same effort off a
|
||||
// 10-point scale from the top (RPE 8 ≈ RIR 2). A set logged on one scale is never silently
|
||||
// rewritten as the other — switching the setting changes what new sets ask for, nothing else.
|
||||
// `start` is where the first + tap lands: a typical working set, not the end of the scale.
|
||||
// `min`..`max` is the range the stepper walks. RIR bottoms out at 0 (a set taken to failure);
|
||||
// RPE bottoms out at 6, since the scale is only meaningful for working sets and anything
|
||||
// lighter is a warm-up nobody rates.
|
||||
export const EFFORT = {
|
||||
rir: { f: 'rir', hd: 'RIR', step: 0.5, max: 10, start: 2 },
|
||||
rpe: { f: 'rpe', hd: 'RPE', step: 0.5, max: 10, start: 8 }
|
||||
rir: { f: 'rir', hd: 'RIR', step: 0.5, min: 0, max: 10 },
|
||||
rpe: { f: 'rpe', hd: 'RPE', step: 0.5, min: 6, max: 10 }
|
||||
}
|
||||
// One tap of an effort stepper. Empty is not 0 — an unlogged effort must not become "went to
|
||||
// failure" from one stray tap — so − on an empty cell leaves it empty, and + starts at the
|
||||
// bottom of the scale and walks up from there in even steps. Stepping back off the bottom
|
||||
// clears the cell again, so a mistap is undoable. null means "nothing logged"; the caller
|
||||
// stores that by dropping the key rather than writing a null.
|
||||
export function stepEffort(kind, cur, dir) {
|
||||
const e = EFFORT[kind]
|
||||
if (!e) return cur ?? null
|
||||
if (cur == null) return dir < 0 ? null : e.min
|
||||
const n = Math.round((cur + dir * e.step) * 100) / 100
|
||||
if (dir < 0 && n < e.min) return null
|
||||
// only the ceiling is enforced on the way up: a value typed below the floor (nothing stops
|
||||
// someone entering RPE 3) still steps in even increments instead of snapping to the floor.
|
||||
return dir > 0 ? Math.min(e.max, n) : Math.max(e.min, n)
|
||||
}
|
||||
// A typed effort is capped but not floored — clamping up while someone types "10" would turn
|
||||
// the first keystroke into the floor and fight the input.
|
||||
export const capEffort = (kind, v) =>
|
||||
(v == null || !EFFORT[kind] ? v : Math.min(EFFORT[kind].max, v))
|
||||
// Which scale a profile logs. `showRir` is the boolean this replaced and is only consulted
|
||||
// when the profile has no answer of its own — an explicit 'none' has to win over it, or a
|
||||
// backup or another device that still carries the old flag would switch the column back on.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { describe, it, expect } from 'vitest'
|
||||
import { modeOf, isTimed, fmtSec, setLabel, defaultConfig, buildSets, exLine, workoutVolume, effortOf } from './history.js'
|
||||
import { modeOf, isTimed, fmtSec, setLabel, defaultConfig, buildSets, exLine, workoutVolume, effortOf, stepEffort, capEffort } from './history.js'
|
||||
import { EXDB } from './exercises.js'
|
||||
|
||||
// Real ids out of the shipped catalogue, so the body-part fallback is exercised for real.
|
||||
@@ -108,6 +108,145 @@ describe('effortOf', () => {
|
||||
expect(effortOf({ showRir: true, effort: 'rpe' })).toBe('rpe')
|
||||
expect(effortOf({ showRir: true, effort: 'none' })).toBe('none')
|
||||
})
|
||||
|
||||
// The store cannot be imported here (it reaches for `navigator` at module load), so the
|
||||
// overlay it performs is reproduced literally: stored profile spread over the defaults.
|
||||
// DEF.effort is null precisely so this lands on the showRir fallback rather than on 'none'.
|
||||
const overlay = stored => ({ unit: 'kg', effort: null, ...stored })
|
||||
|
||||
it('survives the overlay every load path performs', () => {
|
||||
// upgrading with the column on: local state, a server pull and a restored backup all
|
||||
// arrive as a stored object spread over the defaults, and all must keep the column
|
||||
expect(effortOf(overlay({ showRir: true }))).toBe('rir')
|
||||
expect(effortOf(overlay({ showRir: false }))).toBe('none')
|
||||
// a profile predating the RIR feature entirely
|
||||
expect(effortOf(overlay({}))).toBe('none')
|
||||
// and one written by this version
|
||||
expect(effortOf(overlay({ effort: 'rpe' }))).toBe('rpe')
|
||||
// an old backup restored over a profile that had already chosen: the file wins, because
|
||||
// an import replaces state wholesale rather than merging
|
||||
expect(effortOf(overlay({ showRir: true, effort: undefined }))).toBe('rir')
|
||||
})
|
||||
|
||||
it('is not fooled by a junk value', () => {
|
||||
expect(effortOf({ effort: 'rpe10' })).toBe('none')
|
||||
expect(effortOf({ effort: 'RIR' })).toBe('none')
|
||||
expect(effortOf({ effort: 'f' })).toBe('none')
|
||||
expect(effortOf(null)).toBe('none')
|
||||
expect(effortOf(undefined)).toBe('none')
|
||||
// a junk value with the old flag still set falls back rather than showing nothing
|
||||
expect(effortOf({ effort: 'nope', showRir: true })).toBe('rir')
|
||||
})
|
||||
})
|
||||
|
||||
describe('stepEffort', () => {
|
||||
it('starts at the bottom of the scale and walks up', () => {
|
||||
// the first + on an empty cell lands on the lowest value, not on some "typical" middle:
|
||||
// the stepper counts up from the floor the way every other stepper in the app does
|
||||
expect(stepEffort('rir', null, 1)).toBe(0)
|
||||
expect(stepEffort('rpe', null, 1)).toBe(6)
|
||||
// and then in even steps
|
||||
expect(stepEffort('rir', 0, 1)).toBe(0.5)
|
||||
expect(stepEffort('rir', 0.5, 1)).toBe(1)
|
||||
expect(stepEffort('rpe', 6, 1)).toBe(6.5)
|
||||
})
|
||||
|
||||
it('leaves an untouched cell unlogged when stepped down', () => {
|
||||
// one stray − on a fresh row must not stamp "(RIR 0)" — went to failure — on the set
|
||||
expect(stepEffort('rir', null, -1)).toBe(null)
|
||||
expect(stepEffort('rpe', null, -1)).toBe(null)
|
||||
expect(stepEffort('rir', undefined, -1)).toBe(null)
|
||||
})
|
||||
|
||||
it('clears the cell again when stepped back off the floor', () => {
|
||||
// so a mistap is undoable rather than sticking at the floor for good
|
||||
expect(stepEffort('rir', 0, -1)).toBe(null)
|
||||
expect(stepEffort('rpe', 6, -1)).toBe(null)
|
||||
// but a step that stays inside the scale is an ordinary step
|
||||
expect(stepEffort('rir', 0.5, -1)).toBe(0)
|
||||
expect(stepEffort('rpe', 6.5, -1)).toBe(6)
|
||||
})
|
||||
|
||||
it('stops at the top of the scale', () => {
|
||||
expect(stepEffort('rir', 9.5, 1)).toBe(10)
|
||||
expect(stepEffort('rir', 10, 1)).toBe(10)
|
||||
expect(stepEffort('rpe', 10, 1)).toBe(10)
|
||||
})
|
||||
|
||||
it('keeps halves clean instead of drifting into float dust', () => {
|
||||
let v = null
|
||||
for (let i = 0; i < 6; i++) v = stepEffort('rpe', v, 1)
|
||||
expect(v).toBe(8.5)
|
||||
expect(stepEffort('rir', 0.1 + 0.2, 1)).toBe(0.8)
|
||||
})
|
||||
|
||||
it('steps evenly from a value typed below the floor rather than snapping', () => {
|
||||
// nothing stops someone typing RPE 3; the stepper must not jump them to 6 on one tap
|
||||
expect(stepEffort('rpe', 3, 1)).toBe(3.5)
|
||||
// stepping down out of the scale from there just clears it
|
||||
expect(stepEffort('rpe', 3, -1)).toBe(null)
|
||||
})
|
||||
|
||||
it('does nothing when the profile logs no effort at all', () => {
|
||||
expect(stepEffort('none', null, 1)).toBe(null)
|
||||
expect(stepEffort('none', 2, 1)).toBe(2)
|
||||
expect(stepEffort(undefined, 2, -1)).toBe(2)
|
||||
})
|
||||
})
|
||||
|
||||
describe('capEffort', () => {
|
||||
it('caps a typed value at the top of the scale', () => {
|
||||
expect(capEffort('rir', 12)).toBe(10)
|
||||
expect(capEffort('rpe', 99)).toBe(10)
|
||||
expect(capEffort('rpe', 8)).toBe(8)
|
||||
})
|
||||
|
||||
it('does not floor a typed value, so typing "10" survives its first keystroke', () => {
|
||||
// clamping up would turn the "1" of "10" into 6 and fight the input
|
||||
expect(capEffort('rpe', 1)).toBe(1)
|
||||
expect(capEffort('rir', 0)).toBe(0)
|
||||
})
|
||||
|
||||
it('passes an emptied field through untouched', () => {
|
||||
expect(capEffort('rir', null)).toBe(null)
|
||||
expect(capEffort('rpe', undefined)).toBe(undefined)
|
||||
expect(capEffort('none', 12)).toBe(12)
|
||||
})
|
||||
})
|
||||
|
||||
// End-to-end on the data, not the pixels: what a set carries after the taps a real session
|
||||
// makes, and what it reads back as afterwards.
|
||||
describe('logging effort across a session', () => {
|
||||
it('logs a working set on the chosen scale', () => {
|
||||
// four + taps from empty on an RPE profile: 6, 6.5, 7, 7.5
|
||||
let v = null
|
||||
for (let i = 0; i < 4; i++) v = stepEffort('rpe', v, 1)
|
||||
expect(setLabel(LIFT, { w: 80, r: 5, rpe: v })).toBe('80×5 (RPE 7.5)')
|
||||
})
|
||||
|
||||
it('a set taken to failure is logged, not left blank', () => {
|
||||
const v = stepEffort('rir', null, 1) // one + on an RIR profile
|
||||
expect(v).toBe(0)
|
||||
expect(setLabel(LIFT, { w: 100, r: 3, rir: v })).toBe('100×3 (RIR 0)')
|
||||
})
|
||||
|
||||
it('switching the setting mid-history rewrites nothing', () => {
|
||||
const old = { w: 60, r: 10, rir: 2 } // logged while the profile was on RIR
|
||||
const fresh = { w: 60, r: 10, rpe: 8 } // logged after switching to RPE
|
||||
expect(effortOf({ effort: 'rpe' })).toBe('rpe')
|
||||
expect(setLabel(LIFT, old)).toBe('60×10 (RIR 2)')
|
||||
expect(setLabel(LIFT, fresh)).toBe('60×10 (RPE 8)')
|
||||
// turning the column off entirely hides the control but keeps both sets readable
|
||||
expect(effortOf({ effort: 'none' })).toBe('none')
|
||||
expect(setLabel(LIFT, old)).toBe('60×10 (RIR 2)')
|
||||
})
|
||||
|
||||
it('never attaches effort to a mode that has no place for it', () => {
|
||||
// cardio and timed sets have no third stepper, and their labels ignore the field even
|
||||
// if an import or an old file put one there
|
||||
expect(setLabel(CARDIO, { min: 20, speed: 9, rpe: 8 })).toBe('20 min @ 9 km/h')
|
||||
expect(setLabel(LIFT, { sec: 45, rir: 2 }, { id: LIFT, mode: 'time' })).toBe('0:45')
|
||||
})
|
||||
})
|
||||
|
||||
describe('defaultConfig', () => {
|
||||
|
||||
Reference in new issue
Block a user