Effort per set: RIR or RPE, whichever scale you think in

The RIR column becomes a three-way setting (Off / RIR / RPE). Both scales
measure the same judgement from opposite ends — RPE 8 is RIR 2 — so they
share one column and one stepper, but keep their own field on the set.

A set is never silently rewritten into the other scale: switching the
setting changes what new sets ask for, and old sets still read back with
the scale they were logged with.

Profiles carrying the old showRir boolean keep their column (effortOf
falls back to it until the new setting is chosen), so a backup or another
device that still has the flag does not lose the column.

The steppers now know the scale: the first + lands on a typical working
set (RIR 2 / RPE 8) instead of the end of the scale, and typed values are
capped at 10 — there is no RPE 12.
This commit is contained in:
Duarte Santos committed 2026-07-30 23:35:47 +02:00
1 parent fa978a1bb4
commit 4e27461b7e
17 files changed
+210 -51

No files matched your search

+23 -1
View File
@@ -23,13 +23,35 @@ export function fmtSec(sec) {
return Math.floor(n / 60) + ':' + String(n % 60).padStart(2, '0')
}
// How hard a set felt, if the profile logs it at all. Two scales for the same thing, kept in
// 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.
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 }
}
// 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.
export const effortOf = S => {
const e = S && S.effort
return e === 'none' || EFFORT[e] ? e : (S && S.showRir ? 'rir' : 'none')
}
// The "(RIR 2)" / "(RPE 8)" tail on a set summary, empty when nothing was logged.
const effortTail = s => {
const k = s.rir != null ? 'rir' : s.rpe != null ? 'rpe' : null
return k ? ` (${EFFORT[k].hd} ${fmtNum(s[k])})` : ''
}
// One-line summary of a logged set. `cfg` carries the mode when the caller has it (a routine
// entry or a workout entry); passing an id alone keeps the old body-part behaviour.
export function setLabel(id, s, cfg) {
const mode = modeOf(cfg || { id })
if (mode === 'cardio') return `${s.min || 0} min @ ${fmtNum(s.speed || 0)} km/h`
if (mode === 'time') return fmtSec(s.sec) + (s.w > 0 ? ` · ${fmtNum(s.w)}` : '')
return `${fmtNum(s.w || 0)}×${s.r || 0}` + (s.rir != null ? ` (RIR ${fmtNum(s.rir)})` : '')
return `${fmtNum(s.w || 0)}×${s.r || 0}` + effortTail(s)
}
// Default config for a freshly added exercise.
export function defaultConfig(id, mode) {
+34 -1
View File
@@ -1,5 +1,5 @@
import { describe, it, expect } from 'vitest'
import { modeOf, isTimed, fmtSec, setLabel, defaultConfig, buildSets, exLine, workoutVolume } from './history.js'
import { modeOf, isTimed, fmtSec, setLabel, defaultConfig, buildSets, exLine, workoutVolume, effortOf } from './history.js'
import { EXDB } from './exercises.js'
// Real ids out of the shipped catalogue, so the body-part fallback is exercised for real.
@@ -75,6 +75,39 @@ describe('setLabel', () => {
// cleared in the UI: the key is dropped, but a null must read the same as absent
expect(setLabel(LIFT, { w: 60, r: 10, rir: null })).toBe('60×10')
})
it('appends RPE for a set logged on that scale', () => {
expect(setLabel(LIFT, { w: 60, r: 10, rpe: 8 })).toBe('60×10 (RPE 8)')
expect(setLabel(LIFT, { w: 60, r: 10, rpe: 9.5 })).toBe('60×10 (RPE 9.5)')
expect(setLabel(LIFT, { w: 60, r: 10, rpe: null })).toBe('60×10')
})
it('keeps each set on the scale it was logged with', () => {
// switching the setting must not rewrite history: an old RIR set still reads as RIR
expect(setLabel(LIFT, { w: 60, r: 10, rir: 2 })).toBe('60×10 (RIR 2)')
// and a set that somehow carries both is described once, by the one it was logged with
expect(setLabel(LIFT, { w: 60, r: 10, rir: 2, rpe: 8 })).toBe('60×10 (RIR 2)')
})
})
describe('effortOf', () => {
it('reads the scale a profile logs', () => {
expect(effortOf({ effort: 'rpe' })).toBe('rpe')
expect(effortOf({ effort: 'rir' })).toBe('rir')
expect(effortOf({ effort: 'none' })).toBe('none')
expect(effortOf({})).toBe('none')
})
it('keeps the column for a profile still carrying the old showRir flag', () => {
expect(effortOf({ showRir: true })).toBe('rir')
// what a stored profile actually looks like once it is overlaid on DEF
expect(effortOf({ effort: null, showRir: true })).toBe('rir')
expect(effortOf({ effort: null })).toBe('none')
expect(effortOf({ showRir: false })).toBe('none')
// once the new setting is chosen it wins, whatever the old flag said
expect(effortOf({ showRir: true, effort: 'rpe' })).toBe('rpe')
expect(effortOf({ showRir: true, effort: 'none' })).toBe('none')
})
})
describe('defaultConfig', () => {