Matériel coché dans le profil, bibliothèque « ce que mon matériel permet » (5a)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Pierre MARTIN
2026-11-23 02:12:25 +01:00
co-authored by Claude Opus 5.5
parent 938d6cf198
commit 72adffb613
15 changed files with 281 additions and 20 deletions
+5 -2
View File
@@ -6,6 +6,7 @@
// - buildEvolutionBrief : faire évoluer le programme existant, à partir de l'état.
// Les clés des formats sont en anglais (ce sont celles du code), le texte en français.
import { KIT, kitLabels } from "./kit.js";
import { WOD_TYPES, scoreLabel } from "./wod.js";
import { BENCHMARKS } from "./benchmarks.js";
import { EXERCISES, FAMILIES, MUSCLES } from "./exercises.js";
@@ -143,7 +144,8 @@ Une séance WOD porte un \`format\`. L'app affiche alors un chrono adapté (comp
Profile {
goal: l'objectif, en une phrase
context: pratique passée, niveau, lieu d'entraînement
equipment: [matériel disponible]
equipment: [matériel disponible, en texte libre : ce que kit ne dit pas]
kit?: [matériel coché, parmi ${Object.keys(KIT).map((k) => `"${k}"`).join(", ")}] ; omis : pas renseigné
constraints: [contraintes de sécurité et d'organisation]
heightCm: taille en centimètres, ou null
sessionMinutes: durée visée d'une séance, de 10 à 240
@@ -275,7 +277,8 @@ Tu es le coach qui fait évoluer mon programme de musculation. IA-Fit (${appUrl(
- Contexte : ${text(p.context)}
- Taille : ${p.heightCm ? p.heightCm + " cm" : "non renseignée"} ; poids : ${weightLine(state.weights)}
- Durée visée d'une séance : ${p.sessionMinutes} minutes
- Matériel :
- Matériel coché : ${p.kit ? (p.kit.length ? kitLabels(p.kit).join(", ") : "aucun (poids du corps seulement)") : "non renseigné"}
- Autre matériel :
${list(p.equipment)}
- Contraintes (à respecter absolument) :
${list(p.constraints)}
+92
View File
@@ -0,0 +1,92 @@
// Le matériel, en cases à cocher (lot 5a) : ce que le profil possède (Profile.kit) et
// ce que demande chaque exercice de la bibliothèque. Sert au filtre « Ce que je peux
// faire » de la bibliothèque, à la vérification des propositions (5b) et au
// générateur de WOD (5c). Glossaire : docs/glossaire/materiel.md
// Ces clés font partie du format des événements (ProfileUpdated) : en ajouter est
// possible, en renommer demande une migration.
import { EXERCISES } from "./exercises.js";
/** Le matériel qu'on peut cocher, dans l'ordre d'affichage. */
export const KIT = Object.freeze({
barbell: "Barre et disques",
rack: "Rack ou supports de squat",
bench: "Banc",
dumbbells: "Haltères",
kettlebell: "Kettlebell",
"pullup-bar": "Barre de traction",
"dip-bars": "Barres parallèles",
rings: "Anneaux",
bands: "Élastiques",
machines: "Machines guidées",
cable: "Poulie",
rower: "Rameur",
bike: "Vélo ou air bike",
"ski-erg": "SkiErg",
"jump-rope": "Corde à sauter",
box: "Box ou plateforme",
"medicine-ball": "Médecine-ball, wall ball",
"ab-wheel": "Roue abdominale",
"battle-rope": "Corde ondulatoire",
sled: "Traîneau",
ghd: "Banc GHD",
"climbing-rope": "Corde à grimper",
});
/** @typedef {keyof typeof KIT} Kit */
/** Ce que demande chaque catégorie de matériel de la bibliothèque. */
const BY_EQUIPMENT = /** @type {Record<string, Kit[]>} */ ({
barbell: ["barbell"], dumbbell: ["dumbbells"], dumbbells: ["dumbbells"], kettlebell: ["kettlebell"],
machine: ["machines"], cable: ["cable"], band: ["bands"],
});
/** Ce que la catégorie ne dit pas : un support, un banc, un petit matériel. */
const EXTRA = /** @type {Record<string, Kit[]>} */ ({
squat: ["rack"], "front-squat": ["rack"], "bench-press": ["rack", "bench"], "incline-bench-press": ["rack", "bench"],
"dumbbell-bench-press": ["bench"], "incline-dumbbell-press": ["bench"], "dumbbell-fly": ["bench"],
"seated-dumbbell-press": ["bench"], "one-arm-dumbbell-row": ["bench"], "dumbbell-pullover": ["bench"],
"skull-crusher": ["bench"], "hip-thrust": ["bench"], "bulgarian-split-squat": ["bench"], "step-up": ["bench"],
"bench-dips": ["bench"],
"pull-up": ["pullup-bar"], "chin-up": ["pullup-bar"], "kipping-pull-up": ["pullup-bar"], "hanging-leg-raise": ["pullup-bar"],
"toes-to-bar": ["pullup-bar"], "knees-to-elbow": ["pullup-bar"], "muscle-up": ["pullup-bar"],
"band-assisted-pull-up": ["pullup-bar"],
"parallel-bar-dips": ["dip-bars"], "ring-dip": ["rings"], "ring-row": ["rings"],
"ab-wheel-rollout": ["ab-wheel"], "jump-rope": ["jump-rope"], "double-under": ["jump-rope"], "box-jump": ["box"],
"wall-ball": ["medicine-ball"], "ball-slam": ["medicine-ball"], "battle-rope": ["battle-rope"], "sled-push": ["sled"],
"ghd-sit-up": ["ghd"], "rope-climb": ["climbing-rope"],
"rowing-machine": ["rower"], "assault-bike": ["bike"], "ski-erg": ["ski-erg"],
});
/**
* Le matériel que demande un exercice de la bibliothèque. Vide : rien (poids du
* corps, ou exercice hors bibliothèque, dont on ne sait rien).
* @param {string} ref
* @returns {Kit[]}
*/
export function requiredKit(ref) {
const x = EXERCISES[ref];
if (!x) return [];
return [...new Set([...(BY_EQUIPMENT[x.equipment] ?? []), ...(EXTRA[ref] ?? [])])];
}
/**
* Le matériel qui manque pour un exercice. Rien ne manque tant que le profil n'a
* pas coché son matériel (`kit` absent).
* @param {string} ref
* @param {readonly string[]|undefined} kit
* @returns {Kit[]}
*/
export function missingKit(ref, kit) {
if (!kit) return [];
const have = new Set(kit);
return requiredKit(ref).filter((k) => !have.has(k));
}
/** @param {string} ref @param {readonly string[]|undefined} kit */
export const canDo = (ref, kit) => missingKit(ref, kit).length === 0;
/** @param {unknown} x */
export const isKit = (x) => typeof x === "string" && Object.hasOwn(KIT, x);
/** Libellés lisibles, dans l'ordre de KIT. @param {readonly string[]} kit */
export const kitLabels = (kit) => Object.keys(KIT).filter((k) => kit.includes(k)).map((k) => KIT[/** @type {Kit} */ (k)]);
+10 -3
View File
@@ -3,6 +3,7 @@
// Les critères vivent dans l'adresse (ADR 0009) : `#/bibliotheque?zone=lower&muscle=glutes`.
// Glossaire : docs/glossaire/bibliotheque.md
import { canDo } from "./kit.js";
import { EXERCISES, FAMILIES, MUSCLES } from "./exercises.js";
import { exerciseKey, resolveExercise } from "./program.js";
import { exerciseHistory } from "./analysis.js";
@@ -36,10 +37,11 @@ export const ZONE_LABELS = { upper: "Haut du corps", lower: "Bas du corps", core
* @property {Zone} [zone]
* @property {string} [muscle] clé de MUSCLES, dans la zone choisie
* @property {EquipmentGroup} [equipment]
* @property {boolean} [possible] seulement ce que le matériel du profil permet (lot 5a)
*/
/** Noms des paramètres dans l'adresse. */
const PARAMS = /** @type {const} */ ({ q: "q", family: "famille", zone: "zone", muscle: "muscle", equipment: "materiel" });
const PARAMS = /** @type {const} */ ({ q: "q", family: "famille", zone: "zone", muscle: "muscle", equipment: "materiel", possible: "possible" });
/**
* Lit les critères dans la requête de l'adresse. Une valeur inconnue est ignorée ;
@@ -64,6 +66,7 @@ export function parseCriteria(query) {
}
const equipment = p.get(PARAMS.equipment);
if (equipment && equipment in EQUIPMENT_GROUPS) c.equipment = /** @type {EquipmentGroup} */ (equipment);
if (p.get(PARAMS.possible) === "1") c.possible = true;
return c;
}
@@ -75,6 +78,7 @@ export function formatCriteria(c) {
const p = new URLSearchParams();
for (const key of /** @type {(keyof LibraryCriteria)[]} */ (["q", "family", "zone", "muscle", "equipment"]))
if (c[key]) p.set(PARAMS[key], /** @type {string} */ (c[key]));
if (c.possible) p.set(PARAMS.possible, "1");
return p.toString();
}
@@ -84,15 +88,18 @@ export const fold = (s) => s.normalize("NFD").replace(/[̀-ͯ]/g, "").toLowerCas
/**
* Les exercices de la bibliothèque qui répondent aux critères, groupés par
* famille dans l'ordre de FAMILIES, triés par nom. Le filtre de zone et de
* muscle porte sur les muscles principaux.
* muscle porte sur les muscles principaux. `possible` ne garde que ce que permet
* `kit`, le matériel coché du profil (sans effet tant qu'il n'est pas renseigné).
* @param {LibraryCriteria} c
* @param {readonly string[]} [kit]
* @returns {{family: Family, label: string, items: {ref: string, exercise: LibraryExercise}[]}[]}
*/
export function filterLibrary(c) {
export function filterLibrary(c, kit) {
const words = c.q ? fold(c.q).split(/\s+/).filter(Boolean) : [];
const equipment = c.equipment ? /** @type {readonly string[]} */ (EQUIPMENT_GROUPS[c.equipment].equipment) : null;
const match = (/** @type {string} */ ref, /** @type {LibraryExercise} */ x) =>
(!c.family || x.family === c.family) &&
(!c.possible || canDo(ref, kit)) &&
(!equipment || equipment.includes(x.equipment)) &&
(!c.muscle || x.primary.includes(c.muscle)) &&
(!c.zone || x.primary.some((m) => MUSCLES[m].zone === c.zone)) &&
+6 -1
View File
@@ -1,11 +1,14 @@
// Le profil : ce que l'IA doit savoir pour construire le programme.
// Glossaire : docs/glossaire/profil.md
import { isKit } from "./kit.js";
/**
* @typedef {object} Profile
* @property {string} goal objectif, en une phrase
* @property {string} context pratique passée, lieu d'entraînement
* @property {string[]} equipment matériel disponible
* @property {string[]} equipment matériel disponible, en texte libre (ce que les cases ne disent pas)
* @property {import("./kit.js").Kit[]} [kit] matériel coché (lot 5a) ; absent : pas encore renseigné
* @property {string[]} constraints contraintes de sécurité et d'organisation
* @property {number|null} heightCm
* @property {number} sessionMinutes durée visée d'une séance
@@ -33,6 +36,8 @@ export function validateProfile(profile) {
for (const k of ["goal", "context"]) if (typeof p[k] !== "string") errors.push(`'${k}' doit être un texte.`);
for (const k of ["equipment", "constraints"])
if (!Array.isArray(p[k]) || !p[k].every((/** @type {unknown} */ s) => typeof s === "string")) errors.push(`'${k}' doit être une liste de textes.`);
if (p.kit !== undefined && !(Array.isArray(p.kit) && p.kit.every(isKit) && new Set(p.kit).size === p.kit.length))
errors.push("'kit' doit être une liste de clés de matériel connues, sans doublon (voir le format du profil).");
if (p.heightCm !== null && !(typeof p.heightCm === "number" && p.heightCm > 50 && p.heightCm < 260))
errors.push("'heightCm' doit être une taille en centimètres, ou null.");
if (!(typeof p.sessionMinutes === "number" && p.sessionMinutes >= 10 && p.sessionMinutes <= 240))
+2 -1
View File
@@ -97,7 +97,8 @@ WodFormat {
<pre><code>Profile {
goal: l'objectif, en une phrase
context: pratique passée, niveau, lieu d'entraînement
equipment: [matériel disponible]
equipment: [matériel disponible, en texte libre : ce que kit ne dit pas]
kit?: [matériel coché, parmi &quot;barbell&quot;, &quot;rack&quot;, &quot;bench&quot;, &quot;dumbbells&quot;, &quot;kettlebell&quot;, &quot;pullup-bar&quot;, &quot;dip-bars&quot;, &quot;rings&quot;, &quot;bands&quot;, &quot;machines&quot;, &quot;cable&quot;, &quot;rower&quot;, &quot;bike&quot;, &quot;ski-erg&quot;, &quot;jump-rope&quot;, &quot;box&quot;, &quot;medicine-ball&quot;, &quot;ab-wheel&quot;, &quot;battle-rope&quot;, &quot;sled&quot;, &quot;ghd&quot;, &quot;climbing-rope&quot;] ; omis : pas renseigné
constraints: [contraintes de sécurité et d'organisation]
heightCm: taille en centimètres, ou null
sessionMinutes: durée visée d'une séance, de 10 à 240
+2 -1
View File
@@ -99,7 +99,8 @@ Une séance WOD porte un `format`. L'app affiche alors un chrono adapté (compte
Profile {
goal: l'objectif, en une phrase
context: pratique passée, niveau, lieu d'entraînement
equipment: [matériel disponible]
equipment: [matériel disponible, en texte libre : ce que kit ne dit pas]
kit?: [matériel coché, parmi "barbell", "rack", "bench", "dumbbells", "kettlebell", "pullup-bar", "dip-bars", "rings", "bands", "machines", "cable", "rower", "bike", "ski-erg", "jump-rope", "box", "medicine-ball", "ab-wheel", "battle-rope", "sled", "ghd", "climbing-rope"] ; omis : pas renseigné
constraints: [contraintes de sécurité et d'organisation]
heightCm: taille en centimètres, ou null
sessionMinutes: durée visée d'une séance, de 10 à 240
+2
View File
@@ -117,6 +117,8 @@
.lib-more { margin-top: var(--space-3); }
.lib-more > summary { list-style: none; gap: var(--space-2); cursor: pointer; font-family: var(--font-mark); font-size: var(--fs-mark); font-weight: 700; text-transform: uppercase; min-height: var(--tap); display: flex; align-items: center; }
.lib-count { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); font-family: var(--font-mark); font-size: var(--fs-mark); font-weight: 700; text-transform: uppercase; }
.lib-possible { width: 100%; border: var(--b) solid var(--ink); }
.lib-kit strong { display: block; margin-top: var(--space-1); }
.lib-usage { font-size: var(--fs-sm); margin: var(--space-3) 0; }
.lib-more > summary::-webkit-details-marker { display: none; }
.lib-more > summary::before { content: "+"; font-family: var(--font-mark); }
+26 -5
View File
@@ -2,6 +2,7 @@
// filtres dans l'adresse (ADR 0009), et la fiche d'un exercice. Calculs du
// domaine : domain/library.js.
import { KIT, canDo, missingKit, requiredKit } from "../../domain/kit.js";
import { h, replace } from "../dom.js";
import { EXERCISES, FAMILIES, MUSCLES } from "../../domain/exercises.js";
import { resolveExercise } from "../../domain/program.js";
@@ -84,7 +85,13 @@ export function libraryScreen({ store, nav, query }) {
const c = criteria;
const muscles = c.zone ? Object.entries(MUSCLES).filter(([, m]) => m.zone === c.zone) : [];
const more = !!(c.family || c.equipment);
const kit = store.getState().profile.kit;
replace(filters,
// Le matériel coché du profil (lot 5a) : un seul geste pour ne voir que le faisable.
kit && h("button", {
type: "button", class: "choice lib-possible", "aria-pressed": String(!!c.possible),
on: { click: () => update({ ...c, possible: !c.possible || undefined }) },
}, "Seulement ce que mon matériel permet"),
h("p", { class: "mini-label" }, "Zone"),
segmented("Zone", ZONES.map((z) => [z, ZONE_LABELS[z]]), c.zone, (zone) => update({ ...c, zone: /** @type {any} */ (zone), muscle: undefined })),
muscles.length > 1 && [
@@ -97,13 +104,13 @@ export function libraryScreen({ store, nav, query }) {
h("p", { class: "mini-label" }, "Matériel"),
segmented("Matériel", Object.entries(EQUIPMENT_GROUPS).map(([k, v]) => [k, v.label]), c.equipment, (equipment) => update({ ...c, equipment: /** @type {any} */ (equipment) }))));
const groups = filterLibrary(c);
const groups = filterLibrary(c, kit);
const count = groups.reduce((n, g) => n + g.items.length, 0);
// Les exercices génériques n'ont pas de muscles : ils ne suivent que la recherche.
const words = c.q ? fold(c.q).split(/\s+/).filter(Boolean) : [];
const generic = c.zone || c.muscle || c.family || c.equipment ? []
const generic = c.zone || c.muscle || c.family || c.equipment || c.possible ? []
: genericExercises(store.getState()).filter((x) => words.every((w) => fold(x.name).includes(w)));
const filtered = !!(c.q || c.zone || c.muscle || c.family || c.equipment);
const filtered = !!(c.q || c.zone || c.muscle || c.family || c.equipment || c.possible);
replace(results,
h("p", { class: "lib-count" }, filtered ? `${plural(count, "exercice")} sur ${total}` : `${total} exercices`,
filtered && h("button", { type: "button", class: "btn btn--ghost btn--sm", on: { click: () => { search.value = ""; update({}); } } }, "Tout effacer")),
@@ -125,8 +132,9 @@ export function libraryScreen({ store, nav, query }) {
paint();
const near = pick ? [
...(pick.planned.id !== pick.currentId && EXERCISES[pick.planned.id] ? [pick.planned.id] : []),
// Pas un exercice déjà dans la séance : on ne remplace pas par un doublon.
...similarExercises(pick.planned.id, 12).filter((r) => !pick.draft.exercises.some((x) => x.id === r)).slice(0, 8),
// Ni un exercice déjà dans la séance (un doublon), ni un que le matériel coché ne permet pas.
...similarExercises(pick.planned.id, 16)
.filter((r) => !pick.draft.exercises.some((x) => x.id === r) && canDo(r, store.getState().profile.kit)).slice(0, 8),
] : [];
const node = h("div", { class: "screen" },
pick
@@ -181,6 +189,7 @@ export function libraryItemScreen({ store, nav, today, id }) {
library && h("ul", { class: "chips", "aria-label": "Muscles" },
library.primary.map((m) => h("li", { class: "chip" }, MUSCLES[m].name)),
library.secondary.map((m) => h("li", { class: "chip chip--secondary" }, MUSCLES[m].name))),
library && kitLine(id, state.profile.kit),
h("h2", { class: "tape" }, "Dans ton programme"),
use.sessions.length
@@ -229,6 +238,18 @@ function pickContext(state, query) {
}
/** Ligne d'une liste : matériel et muscles principaux. @param {import("../../domain/exercises.js").LibraryExercise} x */
/**
* Le matériel que demande l'exercice, et ce qui manque au profil (lot 5a).
* @param {string} ref @param {readonly string[]|undefined} kit
*/
function kitLine(ref, kit) {
const needs = requiredKit(ref);
if (!needs.length) return null;
const missing = missingKit(ref, kit);
return h("p", { class: "lib-kit" }, `Matériel : ${needs.map((k) => KIT[k]).join(", ")}.`,
missing.length > 0 && h("strong", null, ` Il te manque : ${missing.map((k) => KIT[k].toLowerCase()).join(", ")}.`));
}
const metaOf = (x) => `${EQUIPMENT_LABELS[x.equipment]} · ${x.primary.map((m) => MUSCLES[m].name).join(", ")}`;
/** @param {string} link @param {string} title @param {string} meta */
+29 -3
View File
@@ -6,6 +6,7 @@
import { h } from "../dom.js";
import { MODES } from "../../domain/vocabulary.js";
import { validateProfile } from "../../domain/profile.js";
import { KIT } from "../../domain/kit.js";
import { screenHeader } from "../layout.js";
import { href } from "../router.js";
import { toast } from "../feedback.js";
@@ -21,7 +22,8 @@ export const MODE_LABELS = {
/**
* Lit le formulaire. Les listes s'écrivent une ligne par élément.
* @param {{goal: string, context: string, equipment: string, constraints: string, heightCm: string, sessionMinutes: string}} form
* @param {{goal: string, context: string, equipment: string, constraints: string, heightCm: string, sessionMinutes: string, kit?: string[]}} form
* kit : le matériel coché, omis s'il n'a jamais été renseigné
* @returns {{profile: import("../../domain/profile.js").Profile, errors: string[]}}
*/
export function profileFromForm(form) {
@@ -33,6 +35,7 @@ export function profileFromForm(form) {
context: form.context.trim(),
equipment: lines(form.equipment),
constraints: lines(form.constraints),
...(form.kit ? { kit: /** @type {import("../../domain/kit.js").Kit[]} */ (Object.keys(KIT).filter((k) => form.kit?.includes(k))) } : {}),
heightCm: height,
sessionMinutes: Math.round(Number(form.sessionMinutes.replace(",", "."))),
};
@@ -63,10 +66,26 @@ export function profileScreen({ store, nav }) {
const minutes = h("input", { id: "p-minutes", class: "field__input", type: "text", inputmode: "numeric", value: String(p.sessionMinutes) });
const status = h("p", { class: "status", role: "status", "aria-live": "polite" });
// Matériel coché (lot 5a) : absent tant qu'on n'a rien touché, pour ne rien filtrer à tort.
/** @type {Set<string>|null} */
let kit = p.kit ? new Set(p.kit) : null;
const kitBtns = Object.entries(KIT).map(([k, label]) => h("button", {
type: "button", class: "segmented__opt", data: { kit: k },
on: { click: () => { kit ??= new Set(); if (kit.has(k)) kit.delete(k); else kit.add(k); paintKit(); } },
}, label));
const kitNote = h("p", { class: "field__hint" });
const paintKit = () => {
kitBtns.forEach((b) => b.setAttribute("aria-pressed", String(!!kit?.has(/** @type {string} */ (b.dataset.kit)))));
kitNote.textContent = kit === null ? "Pas encore renseigné : la bibliothèque montre tout."
: kit.size === 0 ? "Rien de coché : poids du corps seulement." : `${kit.size} coché${kit.size > 1 ? "s" : ""}.`;
};
const setKit = (/** @type {string[]} */ keys) => { kit = new Set(keys); paintKit(); };
paintKit();
const save = () => {
const { profile, errors } = profileFromForm({
goal: goal.value, context: context.value, equipment: equipment.value, constraints: constraints.value,
heightCm: height.value, sessionMinutes: minutes.value,
heightCm: height.value, sessionMinutes: minutes.value, kit: kit ? [...kit] : undefined,
});
if (errors.length) {
status.className = "status status--err";
@@ -109,7 +128,14 @@ export function profileScreen({ store, nav }) {
h("h2", { class: "tape" }, "Toi"),
field("p-goal", "Objectif", goal, "En une phrase."),
field("p-context", "Contexte", context, "Pratique passée, lieu d'entraînement."),
field("p-equipment", "Matériel", equipment, "Un élément par ligne."),
h("div", { class: "field" },
h("p", { class: "field__label", id: "p-kit" }, "Matériel"),
h("div", { class: "segmented segmented--wrap", role: "group", "aria-labelledby": "p-kit" }, kitBtns),
kitNote,
h("div", { class: "btn-row" },
h("button", { type: "button", class: "btn btn--ghost btn--sm", on: { click: () => setKit(Object.keys(KIT)) } }, "Salle complète"),
h("button", { type: "button", class: "btn btn--ghost btn--sm", on: { click: () => setKit([]) } }, "Poids du corps seulement"))),
field("p-equipment", "Autre matériel", equipment, "Ce que les cases ne disent pas (charges des haltères, hauteur du plafond…). Un élément par ligne."),
field("p-constraints", "Contraintes", constraints, "Sécurité, blessures, organisation. Une par ligne."),
h("div", { class: "field-pair" },
field("p-height", "Taille (cm)", height),