feat(workout): colour-coded RIR/RPE quick picker
This commit is contained in:
1 parent
272bf785ee
commit
5e42bd29d6
21 files changed
+411
-29
No files matched your search
@@ -132,3 +132,43 @@ export function effortHistogram(S, days) {
|
||||
|
||||
/** A set that counts as hard — the filter behind the muscle map's "hard sets" mode. */
|
||||
export const isHardSet = s => { const r = rirOf(s); return r != null && r <= HARD_RIR }
|
||||
|
||||
// ---------------------------------------------------------------- colour bands --
|
||||
//
|
||||
// A set's effort read as a colour, so a glance down a workout tells you how hard it ran
|
||||
// without reading every number. Bands are defined once, in RIR (the internal scale), and
|
||||
// apply unchanged whether the profile logs RIR or RPE — RPE 8 and RIR 2 are the same set and
|
||||
// get the same colour. The scale runs from "nothing left" (purple, past red — the far end,
|
||||
// not just "very hard") through to "easy, warm-up range" (green).
|
||||
//
|
||||
// The named buckets are also the quick-pick presets: one tap logs the middle of a band. They
|
||||
// are deliberately coarse where estimation is coarse — nobody reliably tells 5 RIR from 7, so
|
||||
// everything from 4 up shares one bucket — and fine near failure, where the difference between
|
||||
// 0, 0.5 and 1 actually changes the training. A typed value between presets still colours by
|
||||
// the band it falls in, so the flexibility of a free number is never lost.
|
||||
export const EFFORT_BANDS = [
|
||||
{ rir: 0, max: 0.25, color: 'var(--purple)', feel: 'Nothing left — went to failure' },
|
||||
{ rir: 0.5, max: 0.75, color: 'var(--red)', feel: 'Maybe half a rep left' },
|
||||
{ rir: 1, max: 1.5, color: 'var(--orange)', feel: 'One more rep in the tank' },
|
||||
{ rir: 2, max: 2.5, color: 'var(--yellow)', feel: 'Two more reps' },
|
||||
{ rir: 3, max: 3.5, color: 'var(--green)', feel: 'Three more reps' },
|
||||
{ rir: 4, max: Infinity, color: 'var(--acc-2)', feel: 'Easy — warm-up territory' }
|
||||
]
|
||||
// The presets shown in the picker, hardest first — the order they read on the scale and the
|
||||
// order the colours run. `tail` is the collapsed top bucket ("4+"): its value is the floor it
|
||||
// stands for, so a tap logs a concrete 4, not a range nothing downstream could average.
|
||||
export const EFFORT_PRESETS = EFFORT_BANDS.map((b, i) => ({
|
||||
rir: b.rir, color: b.color, feel: b.feel, tail: i === EFFORT_BANDS.length - 1
|
||||
}))
|
||||
|
||||
/**
|
||||
* The colour for one effort value, given in RIR (use rirOf to convert a set first). Picks the
|
||||
* band the value falls into: an exact preset lands on its own band, a typed in-between value
|
||||
* (RIR 1.5) takes the band it sits within so it is never left uncoloured. null (unrated) has
|
||||
* no colour — the caller shows a neutral control, not a green one.
|
||||
*/
|
||||
export const effortColor = rir => {
|
||||
if (rir == null) return null
|
||||
for (const b of EFFORT_BANDS) if (rir <= b.max) return b.color
|
||||
return EFFORT_BANDS[EFFORT_BANDS.length - 1].color
|
||||
}
|
||||
@@ -1,7 +1,8 @@
|
||||
import { describe, it, expect } from 'vitest'
|
||||
import {
|
||||
rirOf, toScale, displayScale, avgRir, effortSummary, hasEffort, effortWeeks,
|
||||
effortHistogram, isHardSet, HARD_RIR, MIN_RATED
|
||||
effortHistogram, isHardSet, HARD_RIR, MIN_RATED,
|
||||
effortColor, EFFORT_BANDS, EFFORT_PRESETS
|
||||
} from './effort.js'
|
||||
import { isoOf } from './format.js'
|
||||
|
||||
@@ -184,3 +185,78 @@ describe('isHardSet', () => {
|
||||
expect(isHardSet({})).toBe(false) // unrated is not hard, and not easy either
|
||||
})
|
||||
})
|
||||
|
||||
describe('EFFORT_BANDS / EFFORT_PRESETS', () => {
|
||||
it('runs hardest-first and covers the whole scale with no gap', () => {
|
||||
// presets are the quick-pick buttons, top of the scale (0 RIR = failure) first
|
||||
expect(EFFORT_PRESETS.map(p => p.rir)).toEqual([0, 0.5, 1, 2, 3, 4])
|
||||
// only the last bucket is the collapsed "4+" tail
|
||||
expect(EFFORT_PRESETS.map(p => p.tail)).toEqual([false, false, false, false, false, true])
|
||||
// the bands are contiguous: each band's ceiling is below the next band's floor, and the
|
||||
// last reaches infinity so no rating is ever left without a colour
|
||||
expect(EFFORT_BANDS[EFFORT_BANDS.length - 1].max).toBe(Infinity)
|
||||
for (let i = 1; i < EFFORT_BANDS.length; i++) {
|
||||
expect(EFFORT_BANDS[i].rir).toBeGreaterThan(EFFORT_BANDS[i - 1].max)
|
||||
}
|
||||
})
|
||||
|
||||
it('every preset carries a colour and a human description', () => {
|
||||
for (const p of EFFORT_PRESETS) {
|
||||
expect(p.color).toMatch(/^var\(--/)
|
||||
expect(typeof p.feel).toBe('string')
|
||||
expect(p.feel.length).toBeGreaterThan(0)
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
describe('effortColor', () => {
|
||||
it('gives each preset value its own band colour', () => {
|
||||
// hardest to easiest — the colours the picker shows on its buttons
|
||||
expect(effortColor(0)).toBe('var(--purple)')
|
||||
expect(effortColor(0.5)).toBe('var(--red)')
|
||||
expect(effortColor(1)).toBe('var(--orange)')
|
||||
expect(effortColor(2)).toBe('var(--yellow)')
|
||||
expect(effortColor(3)).toBe('var(--green)')
|
||||
expect(effortColor(4)).toBe('var(--acc-2)')
|
||||
})
|
||||
|
||||
it('colours a typed in-between value by the band it falls in, never leaving it blank', () => {
|
||||
// a half-step belongs to the harder band below it — the band ceilings are inclusive, so
|
||||
// 1.5 (between "one left" and "two left") reads as the tougher of the two, its band 1 colour
|
||||
expect(effortColor(1.5)).toBe(effortColor(1)) // orange, not yellow
|
||||
expect(effortColor(2.5)).toBe(effortColor(2)) // yellow, not green
|
||||
// 0.25 sits between failure (0) and the half-rep band (0.5); by the same inclusive-ceiling
|
||||
// rule it reads as the harder one — the failure colour, never uncoloured
|
||||
expect(effortColor(0.25)).toBe(effortColor(0))
|
||||
})
|
||||
|
||||
it('collapses everything past the top bucket into one colour', () => {
|
||||
// nobody reliably tells 5 from 7 reps in reserve — they are all "easy"
|
||||
expect(effortColor(4)).toBe(effortColor(7))
|
||||
expect(effortColor(4)).toBe(effortColor(10))
|
||||
})
|
||||
|
||||
it('is null for an unrated set — colour means a rating, empty has none', () => {
|
||||
expect(effortColor(null)).toBe(null)
|
||||
expect(effortColor(undefined)).toBe(null)
|
||||
})
|
||||
|
||||
it('reads the same colour whether the set was logged as RIR or RPE', () => {
|
||||
// the picker colours by internal RIR (via rirOf), so 0 RIR and 10 RPE match, 2 and 8 match
|
||||
expect(effortColor(rirOf({ rir: 0 }))).toBe(effortColor(rirOf({ rpe: 10 })))
|
||||
expect(effortColor(rirOf({ rir: 2 }))).toBe(effortColor(rirOf({ rpe: 8 })))
|
||||
expect(effortColor(rirOf({ rir: 0.5 }))).toBe(effortColor(rirOf({ rpe: 9.5 })))
|
||||
})
|
||||
})
|
||||
|
||||
describe('picker preset labels', () => {
|
||||
// The picker labels each preset with its value on the active scale — the RIR presets shown
|
||||
// to an RPE profile read as 10, 9.5, 9, 8, 7, 6. This is what toScale computes per button.
|
||||
it('labels presets on the RIR scale unchanged', () => {
|
||||
expect(EFFORT_PRESETS.map(p => toScale('rir', p.rir))).toEqual([0, 0.5, 1, 2, 3, 4])
|
||||
})
|
||||
|
||||
it('labels the same presets as their RPE mirror for an RPE profile', () => {
|
||||
expect(EFFORT_PRESETS.map(p => toScale('rpe', p.rir))).toEqual([10, 9.5, 9, 8, 7, 6])
|
||||
})
|
||||
})
|
||||
@@ -27,11 +27,11 @@ describe('Brazilian Portuguese locale', () => {
|
||||
.sort(byCodeUnit)
|
||||
const fingerprint = createHash('sha256').update(JSON.stringify(inherited)).digest('hex')
|
||||
|
||||
expect(Object.keys(PT_BR_OVERRIDES)).toHaveLength(342)
|
||||
expect(inherited).toHaveLength(463)
|
||||
expect(Object.keys(PT_BR_OVERRIDES)).toHaveLength(343)
|
||||
expect(inherited).toHaveLength(467)
|
||||
// If this fails, review the changed keys and wording before accepting a new hash. From
|
||||
// frontend/: node scripts/pt-br-inheritance-fingerprint.mjs --list
|
||||
expect(fingerprint, 'pt-PT inheritance changed; review the inherited pt-BR wording').toBe('cafd0b6fde9f8261563b5040aa6e1278f5b469dc2d6b9c81d7d5554bb6825a05')
|
||||
expect(fingerprint, 'pt-PT inheritance changed; review the inherited pt-BR wording').toBe('091fdc0f54dd211f04986afd906513a906989cbc241f0aafca6fc69570f3c70b')
|
||||
})
|
||||
|
||||
test('does not leak European Portuguese UI terms', () => {
|
||||
|
||||
Reference in new issue
Block a user