"""La page de revue d'un cas appris : tout ce qu'il faut à l'expert pour trancher, sur une seule page (D-075). En tête, la présentation de l'agent revue (out/revue-cas/C-xxx.md, si elle existe), puis la page des détecteurs sur la plage (detecteurs.py, sur data//, sinon sur le dossier du cas) ; dessous, la fiche, l'étiquetage, le rendu du builder et la critique du lot d'origine, puis toutes les figures : celles du cas et celles du lot de la séance. Les vrais noms y figurent (registre) : la page reste dans out/, hors de git. Usage : python3 .claude/skills/revue-cas/page.py C-xxx --du AAAA-MM-JJ --au AAAA-MM-JJ (--au exclu ; page ouverte) """ import argparse import base64 import csv import glob import html import json import os import re import sys ICI = os.path.dirname(os.path.abspath(__file__)) sys.path.insert(0, os.path.join(ICI, "..", "boucle")) import detecteurs # noqa: E402 from comparaison import ROOT, open_served # noqa: E402 CAS = os.path.join(ROOT, "events") def lire(chemin): return open(chemin, encoding="utf-8").read() if os.path.exists(chemin) else None def station_du_cas(cas): with open(os.path.join(ICI, "..", "anonymiser-cas", "registre.csv"), encoding="utf-8") as f: for ligne in csv.DictReader(f): if ligne["code"] == cas: return ligne["station"] raise SystemExit(f"{cas} n'est pas dans le registre.") def lot_d_origine(cas, fiche, station): m = re.search(r"séance `?(?:vues-deplacements/boucle/)?(\d{4}-\d\d-\d\dT\d{4}Z)", fiche) if not m: return None for builder in sorted(glob.glob(os.path.join(ROOT, "vues-deplacements", "boucle", f"{m[1]}_{station}", "lot-*", "builder.md"))): if re.search(rf"\*\*Cas créés\*\*.*\b{cas}\b", lire(builder)): return os.path.dirname(builder) return None def bloc(titre, texte, ouvert=True): # les figures citées dans les .md sont dans la galerie, en bas : on retire les liens d'image, cassés depuis out/ texte = re.sub(r"!\[[^\]]*\]\([^)]*\)", "", texte) source = json.dumps(texte).replace("

{html.escape(titre)}

" f"
") def figure(chemin): donnees = base64.b64encode(open(chemin, "rb").read()).decode() nom = os.path.relpath(chemin, ROOT) return f"
{html.escape(nom)}
{html.escape(nom)}
" def page(cas, du, au): dossier_cas = os.path.join(CAS, cas) fiche = lire(os.path.join(dossier_cas, "cas.md")) if fiche is None: raise SystemExit(f"Pas de fiche {dossier_cas}/cas.md.") station = station_du_cas(cas) lot = lot_d_origine(cas, fiche, station) donnees = os.path.join(ROOT, "data", station) if not os.path.isdir(donnees): donnees = dossier_cas presentation = lire(os.path.join(ROOT, "out", "revue-cas", f"{cas}.md")) entete = (f"

Revue de {cas} : {html.escape(station)}

" f"

Lot d'origine : {html.escape(os.path.relpath(lot, ROOT)) if lot else 'introuvable'} · " f"détecteurs sur {html.escape(os.path.relpath(donnees, ROOT))}

") entete += bloc("Présentation de l'agent revue", presentation) if presentation else "

Pas encore de présentation de l'agent revue.

" annexe = bloc("Fiche du cas (cas.md, noms codés)", fiche) for titre, chemin in [("Étiquetage du cas", os.path.join(dossier_cas, "etiquetage.md")), ("Rendu du builder", lot and os.path.join(lot, "builder.md")), ("Critique de l'analyste, lot d'origine", lot and os.path.join(lot, "critique.md"))]: texte = chemin and lire(chemin) if texte: annexe += bloc(titre, texte, ouvert=False) pngs = sorted(glob.glob(os.path.join(dossier_cas, "*.png"))) + (sorted(glob.glob(os.path.join(lot, "*.png"))) if lot else []) annexe += f"

Figures ({len(pngs)})

" + "".join(figure(p) for p in pngs) annexe += """ """ chemin = os.path.join(ROOT, "out", "revue-cas", f"{cas}.html") os.makedirs(os.path.dirname(chemin), exist_ok=True) return detecteurs.page(donnees, du, au, entete=entete, annexe=annexe, chemin=chemin) if __name__ == "__main__": p = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter) p.add_argument("cas") p.add_argument("--du", required=True) p.add_argument("--au", required=True) o = p.parse_args() chemin = page(o.cas, o.du, o.au) print(chemin) open_served(chemin)