WOD du jour composé par l'app, hors ligne (5c)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
442b3f0a56
commit
7194530b38
@@ -0,0 +1,175 @@
|
||||
// Le générateur de « WOD du jour », hors ligne (lot 5c, ADR 0011) : un WOD composé
|
||||
// par des règles, sans IA. Déterministe : le même jour, le même matériel et le même
|
||||
// tirage donnent le même WOD (« Un autre » passe au tirage suivant).
|
||||
// Règles de composition :
|
||||
// - un format tiré parmi AMRAP, EMOM, For Time en tours, et 21-15-9 ;
|
||||
// - deux ou trois mouvements, de modalités différentes autant que le matériel le
|
||||
// permet : cardio (M), gymnastique (G), charges (W) ;
|
||||
// - seulement ce que le matériel coché permet (sans matériel renseigné : poids du
|
||||
// corps et course) ;
|
||||
// - pas un mouvement fait dans les deux derniers jours, tant qu'il en reste d'autres ;
|
||||
// - des répétitions à l'échelle du format (moins par intervalle d'EMOM, plus par tour
|
||||
// d'un For Time court ; 12-9-6 plutôt que 21-15-9 pour un mouvement lourd) ;
|
||||
// - pas de mouvement de gymnastique avancé (pompes en équilibre, muscle-up) : le profil
|
||||
// ne dit pas encore le niveau.
|
||||
// Glossaire : docs/glossaire/wod.md
|
||||
|
||||
import { EXERCISES } from "./exercises.js";
|
||||
import { canDo } from "./kit.js";
|
||||
import { addDays } from "./dates.js";
|
||||
|
||||
/** @typedef {"M"|"G"|"W"} Modality */
|
||||
/** @typedef {import("./program.js").ProgramSession} ProgramSession */
|
||||
|
||||
/**
|
||||
* Les mouvements du générateur : leur modalité, les répétitions d'un tour d'AMRAP
|
||||
* (ou une distance, des calories), et la charge conseillée.
|
||||
* @type {readonly {ref: string, m: Modality, reps: number, unit?: string, note?: string}[]}
|
||||
*/
|
||||
export const WOD_MOVES = Object.freeze([
|
||||
{ ref: "run", m: "M", reps: 200, unit: "m" },
|
||||
{ ref: "rowing-machine", m: "M", reps: 250, unit: "m" },
|
||||
{ ref: "assault-bike", m: "M", reps: 12, unit: "cal" },
|
||||
{ ref: "ski-erg", m: "M", reps: 12, unit: "cal" },
|
||||
{ ref: "jump-rope", m: "M", reps: 50 },
|
||||
{ ref: "double-under", m: "M", reps: 30 },
|
||||
{ ref: "pull-up", m: "G", reps: 7 },
|
||||
{ ref: "push-up", m: "G", reps: 10 },
|
||||
{ ref: "burpee", m: "G", reps: 8 },
|
||||
{ ref: "sit-up", m: "G", reps: 15 },
|
||||
{ ref: "bodyweight-squat", m: "G", reps: 15 },
|
||||
{ ref: "box-jump", m: "G", reps: 10, note: "Box de 60 / 50 cm" },
|
||||
{ ref: "toes-to-bar", m: "G", reps: 8 },
|
||||
{ ref: "forward-lunge", m: "G", reps: 12, note: "En alternant les jambes" },
|
||||
{ ref: "mountain-climber", m: "G", reps: 20 },
|
||||
{ ref: "ring-row", m: "G", reps: 10 },
|
||||
{ ref: "ring-dip", m: "G", reps: 7 },
|
||||
{ ref: "kettlebell-swing", m: "W", reps: 15, note: "Kettlebell 24 / 16 kg" },
|
||||
{ ref: "wall-ball", m: "W", reps: 12, note: "Ballon de 9 / 6 kg" },
|
||||
{ ref: "dumbbell-snatch", m: "W", reps: 10, note: "Haltère 22,5 / 15 kg, en alternant les bras" },
|
||||
{ ref: "thruster", m: "W", reps: 10, note: "Haltères 2 × 15 / 10 kg" },
|
||||
{ ref: "devil-press", m: "W", reps: 6, note: "Haltères 2 × 15 / 10 kg" },
|
||||
{ ref: "goblet-squat", m: "W", reps: 12, note: "Haltère ou kettlebell 24 / 16 kg" },
|
||||
{ ref: "ball-slam", m: "W", reps: 12, note: "Ballon de 9 / 6 kg" },
|
||||
{ ref: "barbell-thruster", m: "W", reps: 9, note: "Barre légère : 43 / 29 kg" },
|
||||
{ ref: "power-clean", m: "W", reps: 6, note: "Barre moyenne : 61 / 43 kg" },
|
||||
{ ref: "deadlift", m: "W", reps: 9, note: "Barre moyenne : 84 / 57 kg" },
|
||||
{ ref: "front-squat", m: "W", reps: 8, note: "Barre moyenne : 52 / 35 kg" },
|
||||
{ ref: "push-press", m: "W", reps: 8, note: "Barre légère : 43 / 29 kg" },
|
||||
{ ref: "sumo-deadlift-high-pull", m: "W", reps: 10, note: "Barre légère : 34 / 25 kg" },
|
||||
]);
|
||||
|
||||
/** Les mouvements qui ne demandent rien : sans matériel renseigné, on reste là. */
|
||||
const NO_KIT = /** @type {string[]} */ ([]);
|
||||
|
||||
/**
|
||||
* Générateur pseudo-aléatoire à graine (mulberry32) : le même tirage pour la même graine.
|
||||
* @param {number} seed
|
||||
*/
|
||||
function random(seed) {
|
||||
let a = seed >>> 0;
|
||||
return () => {
|
||||
a = (a + 0x6d2b79f5) >>> 0;
|
||||
let t = a;
|
||||
t = Math.imul(t ^ (t >>> 15), t | 1);
|
||||
t ^= t + Math.imul(t ^ (t >>> 7), t | 61);
|
||||
return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
|
||||
};
|
||||
}
|
||||
|
||||
/** Une graine stable pour un texte (FNV-1a). @param {string} text */
|
||||
function hash(text) {
|
||||
let h = 0x811c9dc5;
|
||||
for (const c of text) h = Math.imul(h ^ c.charCodeAt(0), 0x01000193) >>> 0;
|
||||
return h;
|
||||
}
|
||||
|
||||
/** @template T @param {() => number} rnd @param {readonly T[]} list @returns {T} */
|
||||
const pick = (rnd, list) => list[Math.floor(rnd() * list.length)];
|
||||
|
||||
/**
|
||||
* @typedef {object} GeneratorInput
|
||||
* @property {string} today AAAA-MM-JJ
|
||||
* @property {number} [draw] tirage du jour, à partir de 1
|
||||
* @property {readonly string[]} [kit] matériel coché ; absent : poids du corps et course
|
||||
* @property {{date: string, exercises: {id: string}[]}[]} [sessions] l'historique, pour éviter les mouvements récents
|
||||
*/
|
||||
|
||||
/**
|
||||
* Le WOD du jour : une séance WOD ponctuelle, valide (validateProgram) et faisable
|
||||
* avec le matériel.
|
||||
* @param {GeneratorInput} input
|
||||
* @returns {Omit<ProgramSession, "key">}
|
||||
*/
|
||||
export function generateWod({ today, draw = 1, kit, sessions = [] }) {
|
||||
const rnd = random(hash(`${today}|${draw}|${[...(kit ?? ["-"])].sort().join(",")}`));
|
||||
const since = addDays(today, -2);
|
||||
// Les deux jours d'avant, pas aujourd'hui : faire le WOD du jour ne doit pas le changer.
|
||||
const recent = new Set(sessions.filter((s) => s.date >= since && s.date < today).flatMap((s) => s.exercises.map((x) => x.id)));
|
||||
const possible = WOD_MOVES.filter((x) => EXERCISES[x.ref] && canDo(x.ref, kit ?? NO_KIT));
|
||||
const fresh = possible.filter((x) => !recent.has(x.ref));
|
||||
const pool = fresh.length >= 3 ? fresh : possible;
|
||||
|
||||
// Le format, puis le nombre de mouvements qu'il demande.
|
||||
const kind = pick(rnd, /** @type {const} */ (["amrap", "amrap", "emom", "rounds", "couplet"]));
|
||||
const count = kind === "couplet" ? 2 : kind === "emom" ? pick(rnd, [2, 3]) : 3;
|
||||
|
||||
// Les modalités : toutes différentes tant qu'il y en a assez ; un couplet 21-15-9
|
||||
// préfère charges + gymnastique.
|
||||
const byM = /** @type {Record<Modality, typeof pool>} */ ({ M: [], G: [], W: [] });
|
||||
for (const x of pool) byM[x.m].push(x);
|
||||
const order = /** @type {Modality[]} */ (kind === "couplet" ? ["W", "G", "M"] : shuffle(rnd, ["M", "G", "W"]));
|
||||
/** @type {typeof pool} */
|
||||
const chosen = [];
|
||||
for (const m of order) if (chosen.length < count && byM[m].length) chosen.push(pick(rnd, byM[m]));
|
||||
// Pas assez de modalités (poids du corps seul) : on complète, sans doublon ni même muscle principal.
|
||||
const rest = shuffle(rnd, pool.filter((x) => !chosen.includes(x)));
|
||||
for (const x of rest) {
|
||||
if (chosen.length >= count) break;
|
||||
const first = EXERCISES[x.ref].primary[0];
|
||||
if (!chosen.some((c) => EXERCISES[c.ref].primary[0] === first)) chosen.push(x);
|
||||
}
|
||||
for (const x of rest) if (chosen.length < count && !chosen.includes(x)) chosen.push(x);
|
||||
|
||||
const amount = (/** @type {(typeof pool)[number]} */ x, /** @type {number} */ factor) => {
|
||||
const n = x.unit === "m" ? Math.max(100, Math.round((x.reps * factor) / 50) * 50) : Math.max(1, Math.round(x.reps * factor));
|
||||
return x.unit ? `${n} ${x.unit}` : String(n);
|
||||
};
|
||||
/** @param {(typeof pool)[number]} x @param {string} reps */
|
||||
const move = (x, reps) => ({ ref: x.ref, sets: 1, reps, rest: 0, ...(x.note ? { note: x.note } : {}) });
|
||||
|
||||
const name = `WOD du jour · ${frenchDay(today)}${draw > 1 ? ` (${draw})` : ""}`;
|
||||
if (kind === "amrap") {
|
||||
const minutes = pick(rnd, [10, 12, 15, 20]);
|
||||
return { name, oneOff: true, format: { type: "amrap", minutes }, exercises: chosen.map((x) => move(x, amount(x, 1))) };
|
||||
}
|
||||
if (kind === "emom") {
|
||||
const minutes = chosen.length * pick(rnd, [4, 5]);
|
||||
return { name, oneOff: true, format: { type: "emom", minutes }, exercises: chosen.map((x) => move(x, amount(x, x.m === "M" ? 0.6 : 0.8))) };
|
||||
}
|
||||
if (kind === "rounds") {
|
||||
const rounds = pick(rnd, [3, 4, 5]);
|
||||
const factor = rounds === 3 ? 1.5 : rounds === 4 ? 1.2 : 1;
|
||||
return { name, oneOff: true, format: { type: "fortime", rounds, capMinutes: rounds * 4 }, exercises: chosen.map((x) => move(x, amount(x, factor))) };
|
||||
}
|
||||
// 21-15-9 : un couplet court et intense ; 12-9-6 pour un mouvement lourd (peu de
|
||||
// répétitions par tour d'AMRAP) ; un mouvement de cardio garde une distance.
|
||||
return {
|
||||
name, oneOff: true, format: { type: "fortime", capMinutes: 10 },
|
||||
exercises: chosen.map((x) => move(x, x.unit ? `${amount(x, 1)} par tour` : x.reps >= 9 ? "21-15-9" : "12-9-6")),
|
||||
};
|
||||
}
|
||||
|
||||
/** @template T @param {() => number} rnd @param {readonly T[]} list @returns {T[]} */
|
||||
function shuffle(rnd, list) {
|
||||
const out = [...list];
|
||||
for (let i = out.length - 1; i > 0; i--) {
|
||||
const j = Math.floor(rnd() * (i + 1));
|
||||
[out[i], out[j]] = [out[j], out[i]];
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
const MONTHS = ["janv.", "févr.", "mars", "avr.", "mai", "juin", "juil.", "août", "sept.", "oct.", "nov.", "déc."];
|
||||
/** « 23 nov. » @param {string} day */
|
||||
const frenchDay = (day) => `${Number(day.slice(8, 10))} ${MONTHS[Number(day.slice(5, 7)) - 1]}`;
|
||||
+1
-1
@@ -149,7 +149,7 @@ startRouter(root, (route, nav) => {
|
||||
case "sync": return syncScreen({ service: sync, store, nav });
|
||||
case "pair": return pairScreen({ service: sync, store, nav, key: pairKey });
|
||||
case "library": return libraryScreen({ store, nav, query: route.query });
|
||||
case "wods": return wodCatalogScreen({ store, nav });
|
||||
case "wods": return wodCatalogScreen({ store, nav, today, query: route.query });
|
||||
case "wod": return wodItemScreen({ store, nav, today, id: route.id });
|
||||
case "library-item": return libraryItemScreen({ store, nav, today, id: route.id });
|
||||
case "connect-ai": return connectAiScreen({ service: sync, nav, hash: "?" + route.query });
|
||||
|
||||
@@ -123,3 +123,6 @@
|
||||
.lib-more > summary::-webkit-details-marker { display: none; }
|
||||
.lib-more > summary::before { content: "+"; font-family: var(--font-mark); }
|
||||
.lib-more[open] > summary::before { content: "−"; }
|
||||
|
||||
/* WOD du jour (lot 5c), en tête du catalogue. */
|
||||
.wod-daily { margin-bottom: var(--space-5); display: grid; gap: var(--space-2); }
|
||||
|
||||
+4
-3
@@ -32,7 +32,7 @@
|
||||
* | {name: "connect-ai", query: string}
|
||||
* | {name: "library", query: string}
|
||||
* | {name: "library-item", id: string, query: string}
|
||||
* | {name: "wods"}
|
||||
* | {name: "wods", query: string}
|
||||
* | {name: "wod", id: string}
|
||||
* | {name: "reserved"}
|
||||
* | {name: "not-found"}} Route
|
||||
@@ -65,7 +65,7 @@ export function parseRoute(hash) {
|
||||
if (head === "connecter-ia" && parts.length === 1) return { name: "connect-ai", query };
|
||||
if (head === "bibliotheque" && parts.length === 1) return { name: "library", query };
|
||||
if (head === "bibliotheque" && parts.length === 2 && arg) return { name: "library-item", id: arg, query };
|
||||
if (head === "wod" && parts.length === 1) return { name: "wods" };
|
||||
if (head === "wod" && parts.length === 1) return { name: "wods", query };
|
||||
if (head === "wod" && parts.length === 2 && arg) return { name: "wod", id: arg };
|
||||
if (parts.length === 1 && WITH_QUERY[head]) return /** @type {Route} */ ({ name: WITH_QUERY[head], query });
|
||||
if (parts.length === 1 && SIMPLE[head]) return /** @type {Route} */ ({ name: SIMPLE[head] });
|
||||
@@ -120,7 +120,8 @@ export const href = {
|
||||
sync: () => "#/synchro",
|
||||
pair: () => "#/relier",
|
||||
library: (/** @type {string} */ query = "") => "#/bibliotheque" + (query ? "?" + query : ""),
|
||||
wods: () => "#/wod",
|
||||
/** Le catalogue, et le tirage du WOD du jour (1 omis). */
|
||||
wods: (/** @type {number} */ draw = 1) => withParams("#/wod", { tirage: draw > 1 ? draw : null }),
|
||||
wod: (/** @type {string} */ id) => "#/wod/" + enc(id),
|
||||
libraryItem: (/** @type {string} */ id, /** @type {string} */ query = "") => "#/bibliotheque/" + enc(id) + (query ? "?" + query : ""),
|
||||
};
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
// Le catalogue des WOD de référence (lot 4d) : la liste, et la fiche d'un WOD avec
|
||||
// Le catalogue des WOD de référence (lot 4d), précédé du WOD du jour généré hors
|
||||
// ligne (lot 5c, domain/wod-generator.js) : la liste, et la fiche d'un WOD avec
|
||||
// son record, « Faire aujourd'hui » (ajouté au programme comme WOD ponctuel) et
|
||||
// « Demander à mon IA de l'adapter ». Données : domain/benchmarks.js.
|
||||
|
||||
import { h } from "../dom.js";
|
||||
import { h, replace } from "../dom.js";
|
||||
import { generateWod } from "../../domain/wod-generator.js";
|
||||
import { BENCHMARKS, BENCHMARK_FAMILIES, benchmark } from "../../domain/benchmarks.js";
|
||||
import { formatHint, formatLabel, scoreLabel, wodKey } from "../../domain/wod.js";
|
||||
import { wodRecords } from "../../domain/analysis.js";
|
||||
@@ -23,14 +25,67 @@ import { toast } from "../feedback.js";
|
||||
const recordOf = (state, b) => wodRecords(state).find((r) => r.key === wodKey(b.session.name, /** @type {any} */ (b.session.format))) ?? null;
|
||||
|
||||
/**
|
||||
* @param {{store: import("../store.js").Store, nav: import("../router.js").Navigation}} ctx
|
||||
* Le tirage du WOD du jour, lu dans l'adresse (#/wod?tirage=2) ; 1 par défaut.
|
||||
* @param {string} query
|
||||
*/
|
||||
export function readDraw(query) {
|
||||
const n = Number(new URLSearchParams(query).get("tirage"));
|
||||
return Number.isInteger(n) && n >= 1 && n <= 99 ? n : 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Le WOD du jour : généré par les règles de l'app, avec le matériel du profil.
|
||||
* @param {{store: import("../store.js").Store, nav: import("../router.js").Navigation, today: () => string, query: string}} ctx
|
||||
*/
|
||||
function dailyWod({ store, nav, today, query }) {
|
||||
let draw = readDraw(query);
|
||||
const box = h("section", { class: "block wod-daily", "aria-labelledby": "wod-daily" });
|
||||
const paint = () => {
|
||||
const state = store.getState();
|
||||
const session = generateWod({ today: today(), draw, kit: state.profile.kit, sessions: state.sessions });
|
||||
const format = /** @type {import("../../domain/wod.js").WodFormat} */ (session.format);
|
||||
const pending = pendingOneOffs(state.program, state.sessions).find((s) => s.format && wodKey(s.name, s.format) === wodKey(session.name, format));
|
||||
const doToday = () => {
|
||||
if (pending) return nav.go(href.session(pending.key));
|
||||
const program = store.getState().program;
|
||||
if (!program) return;
|
||||
const { program: next, key } = withOneOff(program, session, store.getState().sessions);
|
||||
store.dispatch("ProgramAdopted", { program: next, source: "app", reason: `WOD du jour ajouté : ${formatLabel(format)}.` });
|
||||
nav.go(href.session(key));
|
||||
};
|
||||
replace(box,
|
||||
h("p", { class: "kicker" }, "Composé par l'app, hors ligne"),
|
||||
h("h2", { class: "block__title", id: "wod-daily" }, "WOD du jour"),
|
||||
h("p", { class: "wod-format__label" }, formatLabel(format)),
|
||||
h("p", { class: "muted" }, formatHint(format)),
|
||||
h("ol", { class: "wod-moves" }, session.exercises.map((x) => {
|
||||
const r = resolveExercise(x);
|
||||
return h("li", { class: "wod-move" },
|
||||
h("div", { class: "wod-move__main" }, h("span", { class: "wod-move__reps num" }, x.reps), h("a", { class: "wod-move__name", href: href.libraryItem(/** @type {string} */ (x.ref)) }, r.name)),
|
||||
x.note && h("p", { class: "wod-move__note" }, x.note));
|
||||
})),
|
||||
!state.profile.kit && h("p", { class: "coach-note coach-note--plain" }, "Sans matériel coché dans ton profil, le WOD reste au poids du corps et à la course. ",
|
||||
h("a", { href: href.profile() }, "Cocher mon matériel")),
|
||||
h("div", { class: "btn-stack" },
|
||||
state.program
|
||||
? h("button", { type: "button", class: "btn btn--primary btn--block", on: { click: doToday } }, pending ? "Reprendre ce WOD" : "Faire aujourd'hui")
|
||||
: h("p", { class: "muted" }, "Crée d'abord ton programme : le WOD s'y ajoutera, hors rotation."),
|
||||
!pending && h("button", { type: "button", class: "btn btn--ghost btn--block", on: { click: () => { draw = draw >= 99 ? 1 : draw + 1; nav.set(href.wods(draw)); paint(); } } }, "Un autre")));
|
||||
};
|
||||
paint();
|
||||
return box;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {{store: import("../store.js").Store, nav: import("../router.js").Navigation, today: () => string, query: string}} ctx
|
||||
* @returns {import("../router.js").Screen}
|
||||
*/
|
||||
export function wodCatalogScreen({ store, nav }) {
|
||||
export function wodCatalogScreen({ store, nav, today, query }) {
|
||||
const state = store.getState();
|
||||
const node = h("div", { class: "screen" },
|
||||
screenHeader({ back: { label: "Accueil", onClick: () => nav.back(href.home()) }, kicker: "WOD", title: "Références",
|
||||
sub: "Les WOD que tout le monde connaît : fais-les, note ton score, et bats ton record la fois suivante." }),
|
||||
screenHeader({ back: { label: "Accueil", onClick: () => nav.back(href.home()) }, kicker: "Cross-training", title: "WOD",
|
||||
sub: "Le WOD du jour, composé par l'app, et les WOD que tout le monde connaît : fais-les, note ton score, bats ton record." }),
|
||||
dailyWod({ store, nav, today, query }),
|
||||
Object.entries(BENCHMARK_FAMILIES).map(([family, label]) => {
|
||||
const list = BENCHMARKS.filter((b) => b.family === family);
|
||||
return [
|
||||
@@ -44,7 +99,7 @@ export function wodCatalogScreen({ store, nav }) {
|
||||
h("span", { class: "chevron", "aria-hidden": "true" })));
|
||||
}))];
|
||||
}));
|
||||
return { node, title: "WOD de référence" };
|
||||
return { node, title: "WOD" };
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -53,7 +108,7 @@ export function wodCatalogScreen({ store, nav }) {
|
||||
*/
|
||||
export function wodItemScreen({ store, nav, today, id }) {
|
||||
const b = benchmark(id);
|
||||
const back = { label: "Références", onClick: () => nav.back(href.wods()) };
|
||||
const back = { label: "WOD", onClick: () => nav.back(href.wods()) };
|
||||
if (!b) return { title: "WOD introuvable", node: h("div", { class: "screen" }, screenHeader({ back, title: "Introuvable", sub: "Ce WOD n'est pas dans le catalogue." })) };
|
||||
const state = store.getState();
|
||||
const format = /** @type {import("../../domain/wod.js").WodFormat} */ (b.session.format);
|
||||
|
||||
Reference in New Issue
Block a user