Skip to content

Open-source gym & body-weight tracker, now in the App Store (iPhone + Apple Watch) and as an Android APK. Plan routines, log workouts, see which muscles are trained, import from Strong/Hevy/FitNotes. Self-host it or use it on the phone alone.

Merge #311: Fix Coach routine icons and balance exercise candidates (ameer-khan-ashraf)

Duarte Santos3573eb4b64fa
diff --cc api/coach/core/library.js
index 1d47e3ee8,cdc392533..00947f1aa
--- a/api/coach/core/library.js
+++ b/api/coach/core/library.js
@@@ -26,15 -26,39 +26,45 @@@ export const MAX_LIBRARY = 160
// fields beyond body part never appear in a rationale and cost ~30 tokens an entry.
const slim = e => ({ id: e.id, n: e.n, bp: e.bp, ...(e.custom ? { custom: true } : {}) });
+ /* Mobility work is not what a plan is built from, and at an even share per body part the
+ catalogue's 57 stretches crowded out the lifts that are: a first plan for someone who
+ stated no equipment arrived with "upper legs" as five stretches, a balance board and some
+ band work — no squat, no hinge, no lunge anywhere in the lane.
+
+ Dropped from the candidate pool, never from the catalogue. One already in someone's plan or
+ history is pinned by `keep` below and still travels, because a review has to be able to name
+ what it is talking about, and the validator still accepts every id the catalogue holds.
+
+ The word boundary is what stops this being a silent data bug: "single leg bridge with
+ outstretched leg" is a glute exercise, not a stretch. */
+ export const isStretch = e => /\bstretch(es|ing)?\b/i.test((e && e.n) || '');
+
+ /* ---------- what each body part is worth in candidates ----------
+ An equal lane per body part reads fair and is not: it spent as many of the 160 slots on
+ "lower arms" (37 rows, wrist curls to a one) as on "chest", and gave "neck" (two rows, both
+ stretches) a lane of its own. A plan is not drawn from an even spread of the catalogue's
+ taxonomy, so the lanes are weighted by how much programming actually draws on them.
+
+ These are shares, not quotas — a lane that runs out hands its remainder to the others, which
+ is what keeps a narrow equipment filter from returning a short slice. Anything not listed
+ gets 1, so a body part added to the catalogue later still appears rather than vanishing. */
+ const LANE_WEIGHT = {
+ 'back': 4, 'chest': 4, 'upper legs': 4,
+ 'shoulders': 3,
+ 'upper arms': 2, 'waist': 2,
+ 'cardio': 1, 'lower arms': 1, 'lower legs': 1, 'neck': 1
+ };
+ const laneWeight = bp => LANE_WEIGHT[bp] ?? 1;
+
export function librarySlice(S, equipment, { keep = [], max = MAX_LIBRARY } = {}) {
const wanted = (equipment || []).map(x => String(x).toLowerCase());
- const customs = (S.customEx || []).map(c => ({ id: c.id, n: c.n, bp: c.bp, tg: null, eq: 'custom', custom: true }));
+ // A custom exercise's name and body part are whatever the person typed, and its id is
+ // whatever the client wrote; all three ride into every prompt. Cut to the bounds payload.js
+ // gives every other name (NAME_MAX, 80) and id (ID_MAX, 64); a non-string reads as absent.
+ const cut = (v, n) => (typeof v === 'string' ? v.slice(0, n) : undefined);
+ const customs = (Array.isArray(S.customEx) ? S.customEx : [])
+ .filter(c => c && typeof c === 'object' && typeof c.id === 'string' && c.id)
+ .map(c => ({ id: cut(c.id, 64), n: cut(c.n, 80), bp: cut(c.bp, 40), tg: null, eq: 'custom', custom: true }));
// No equipment stated (or "everything") ⇒ the whole catalogue. Filtering to nothing would
// leave the Coach unable to propose anything at all, which is a worse failure than a
// slightly larger payload.
diff --cc frontend/src/views/CoachChat.jsx
index 96441c1f9,bd4b76085..bfa56d0e5
--- a/frontend/src/views/CoachChat.jsx
+++ b/frontend/src/views/CoachChat.jsx
@@@ -328,10 -328,10 +329,10 @@@ function PlanCard({ p, S, update, toast
<WeekStrip days={weekDays} />
{b.routines.length > 1 && <div className="pcard-tabs">
- {b.routines.map((x, i) => <button key={x.id || i} className={'pcard-tab' + (i === tab ? ' on' : '')} onClick={() => setTab(i)}>{x.emoji} {x.name}</button>)}
+ {b.routines.map((x, i) => <button key={x.id || i} className={'pcard-tab' + (i === tab ? ' on' : '')} onClick={() => setTab(i)}><Icon name={glyphOf(x.emoji)} />{x.name}</button>)}
</div>}
- {r && <RoutineBlock r={r} unit={S.unit} />}
+ {r && <RoutineBlock r={r} unit={S.unit} speedUnit={speedUnitOf(S)} />}
<div className="pcard-row">
<span className="lrow-m"><span className="lrow-t">{t('Use this weekly schedule')}</span><span className="lrow-s">{t('Replaces your current week. Days this plan leaves empty become rest days.')}</span></span>
@@@ -351,11 -351,11 +352,11 @@@ const WeekStrip = ({ days }) => <div cl
{[1, 2, 3, 4, 5, 6, 0].map(d => <div key={d} className={'pcard-wd' + (days.has(d) ? ' on' : '')}>{t(DAYS[d])}</div>)}
</div>
-const RoutineBlock = ({ r, unit }) => <div className="pcard-rt">
+const RoutineBlock = ({ r, unit, speedUnit }) => <div className="pcard-rt">
- <div className="pcard-rt-h"><b>{r.emoji} {r.name}</b><span>{t('{0} exercises', r.ex.length)}</span></div>
+ <div className="pcard-rt-h"><b><Icon name={glyphOf(r.emoji)} />{r.name}</b><span>{t('{0} exercises', r.ex.length)}</span></div>
{!!r.why && <div className="pcard-why">{r.why}</div>}
{r.ex.map((e, i) => <div key={i} className="pcard-ex">
- <div className="pcard-ex-r"><span className="pcard-ex-n">{exName(e.id)}</span><span className="pcard-ex-l">{exLine(e, unit)}</span></div>
+ <div className="pcard-ex-r"><span className="pcard-ex-n">{exName(e.id)}</span><span className="pcard-ex-l">{exLine(e, unit, speedUnit)}</span></div>
{!!e.why && <div className="pcard-ex-w">{e.why}</div>}
</div>)}
</div>
@@@ -626,10 -626,10 +627,10 @@@ function ProposalDetail({ entry, S })
{kind === 'create' && b && <>
<WeekStrip days={weekDays} />
- {b.routines.length > 1 && <div className="pcard-tabs" style={{ paddingLeft: 0, paddingRight: 0 }}>
+ {b.routines.length > 1 && <div className="pcard-tabs" style={{ paddingInline: 0 }}>
- {b.routines.map((x, i) => <button key={x.id || i} className={'pcard-tab' + (i === tab ? ' on' : '')} onClick={() => setTab(i)}>{x.emoji} {x.name}</button>)}
+ {b.routines.map((x, i) => <button key={x.id || i} className={'pcard-tab' + (i === tab ? ' on' : '')} onClick={() => setTab(i)}><Icon name={glyphOf(x.emoji)} />{x.name}</button>)}
</div>}
- {r && <RoutineBlock r={r} unit={S.unit} />}
+ {r && <RoutineBlock r={r} unit={S.unit} speedUnit={speedUnitOf(S)} />}
<p className="pcard-sum" style={{ fontSize: 13 }}>{entry.scheduled ? t('Your week was set to this schedule.') : t('Imported without changing your week.')}</p>
</>}
{kind === 'create' && !b && <p className="pcard-sum">{t('This plan was imported before the app kept proposals; only its summary is left.')}</p>}