Events: read-event skill to consult the base (D-085), cases renamed events E-xxx (D-086)
- read-event: map and index first, then the card of close events only, then their data with the reading tools; never all cards at once. Diagnostic agent, critiquer-lot and builder point to it; the index header too. Signature length: about 250 characters, a guideline. - "Cas" becomes "event": events/E-xxx/event.md, skills new-event, review-event, anonymize-event. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
4d99585474
commit
446fde3192
1206 files changed
+2172
-2129
No files matched your search
@@ -0,0 +1,108 @@
|
||||
"""La page de revue d'un event 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/review-event/E-xxx.md, si elle existe), puis la page des détecteurs sur la
|
||||
plage (detecteurs.py, sur data/<STATION>/, sinon sur le dossier de l'event) ; dessous, la fiche, l'étiquetage, le rendu du
|
||||
builder et la critique du lot d'origine, puis toutes les figures : celles de l'event 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/review-event/page.py E-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
|
||||
|
||||
EVENTS = os.path.join(ROOT, "events")
|
||||
|
||||
|
||||
def lire(chemin):
|
||||
return open(chemin, encoding="utf-8").read() if os.path.exists(chemin) else None
|
||||
|
||||
|
||||
def station_de_l_event(event):
|
||||
with open(os.path.join(ICI, "..", "anonymize-event", "registre.csv"), encoding="utf-8") as f:
|
||||
for ligne in csv.DictReader(f):
|
||||
if ligne["code"] == event:
|
||||
return ligne["station"]
|
||||
raise SystemExit(f"{event} n'est pas dans le registre.")
|
||||
|
||||
|
||||
def lot_d_origine(event, fiche, station):
|
||||
m = re.search(r"séance `?(?: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, "boucle", f"{m[1]}_{station}", "lot-*", "builder.md"))):
|
||||
# avant D-086, les builders écrivaient « Cas créés » et C-xxx
|
||||
if re.search(rf"\*\*(?:Cas|Events) créés\*\*.*\b[CE]-{event[2:]}\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("</", "<\\/")
|
||||
return (f"<details{' open' if ouvert else ''}><summary><h2 style='display:inline'>{html.escape(titre)}</h2></summary>"
|
||||
f"<div class='md' data-md='{html.escape(source, quote=True)}'></div></details>")
|
||||
|
||||
|
||||
def figure(chemin):
|
||||
donnees = base64.b64encode(open(chemin, "rb").read()).decode()
|
||||
nom = os.path.relpath(chemin, ROOT)
|
||||
return f"<figure><img src='data:image/png;base64,{donnees}' alt='{html.escape(nom)}'><figcaption>{html.escape(nom)}</figcaption></figure>"
|
||||
|
||||
|
||||
def page(event, du, au):
|
||||
dossier_event = os.path.join(EVENTS, event)
|
||||
fiche = lire(os.path.join(dossier_event, "event.md"))
|
||||
if fiche is None:
|
||||
raise SystemExit(f"Pas de fiche {dossier_event}/event.md.")
|
||||
station = station_de_l_event(event)
|
||||
lot = lot_d_origine(event, fiche, station)
|
||||
donnees = os.path.join(ROOT, "data", station)
|
||||
if not os.path.isdir(donnees):
|
||||
donnees = dossier_event
|
||||
|
||||
presentation = lire(os.path.join(ROOT, "out", "review-event", f"{event}.md"))
|
||||
entete = (f"<h1>Revue de {event} : {html.escape(station)}</h1>"
|
||||
f"<p>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))}</p>")
|
||||
entete += bloc("Présentation de l'agent revue", presentation) if presentation else "<p>Pas encore de présentation de l'agent revue.</p>"
|
||||
|
||||
annexe = bloc("Fiche de l'event (event.md, noms codés)", fiche)
|
||||
for titre, chemin in [("Étiquetage de l'event", os.path.join(dossier_event, "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_event, "*.png"))) + (sorted(glob.glob(os.path.join(lot, "*.png"))) if lot else [])
|
||||
annexe += f"<h2>Figures ({len(pngs)})</h2>" + "".join(figure(p) for p in pngs)
|
||||
annexe += """<style>details{margin:12px 0} summary{cursor:pointer} .md{max-width:70em} .md table{margin:8px 0}
|
||||
figure{margin:16px 0} figure img{max-width:100%;border:1px solid #e6e6e2} figcaption{color:#5f5e5a;font-size:13px}</style>
|
||||
<script src="https://cdn.jsdelivr.net/npm/marked@12.0.2/marked.min.js"></script>
|
||||
<script>document.querySelectorAll('.md').forEach(d => d.innerHTML = marked.parse(JSON.parse(d.dataset.md)));</script>"""
|
||||
|
||||
chemin = os.path.join(ROOT, "out", "review-event", f"{event}.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("event")
|
||||
p.add_argument("--du", required=True)
|
||||
p.add_argument("--au", required=True)
|
||||
o = p.parse_args()
|
||||
chemin = page(o.event, o.du, o.au)
|
||||
print(chemin)
|
||||
open_served(chemin)
|
||||
Reference in new issue
Block a user