Files
ia-fit/app/domain/kit.js
T

93 lines
4.0 KiB
JavaScript

// 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)]);