Add the Error rate line and its colorbar to the loop's end-of-session page, shared with detecteurs.py

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
maximeandClaude Opus 5.5 committed 2026-10-27 10:05:04 +01:00
1 parent a55280056d
commit fb2160a12d
4 files changed
+38 -29

No files matched your search

+6 -20
View File
@@ -12,14 +12,12 @@ import html
import os
import statistics
# du vert au rouge (demande de l'utilisateur, 2026-10-27) : couleurs d'état de la palette de référence (skill dataviz)
VERT_ROUGE = ["#0ca30c", "#fab219", "#ec835a", "#d03b3b"]
import comparaison # noqa: E402 (met src/, detectors/ et les outils sur le chemin ; barres, survol, couleurs)
from comparaison import AUTOSCALE_Y_JS, ROOT, est_reference, go, make_subplots, open_html, score
def page(dossier, du=None, au=None):
def page(dossier, du=None, au=None, entete="", annexe="", chemin=None):
"""entete, annexe : HTML ajouté avant et après la figure (page de /revue-cas) ; chemin : la page, sinon out/detecteurs_…."""
mesures = score.charger(dossier)
if not mesures:
raise SystemExit(f"Aucun export « advanced » dans {dossier}.")
@@ -37,14 +35,6 @@ def page(dossier, du=None, au=None):
presentes = {v["category"] for v in evts}
ordre = [c for c in [*score.categories.CATEGORIES, *sorted(presentes - set(score.categories.CATEGORIES))] if c in presentes]
par_t = {}
for ms in mesures.values():
for m in ms:
if a <= m["t"] < b and m["error_value"] is not None:
par_t.setdefault(m["t"], []).append((m["error_value"], m["error_threshold"]))
erreurs = sorted(par_t.items())
# Error rate dans sa propre rangée : une heatmap sur les axes des barres fait planter plotly.js 4.1.1
fig = make_subplots(rows=4, cols=1, shared_xaxes=True, vertical_spacing=0.025,
row_heights=[260, 260, 30 * len(ordre) + 20, 30],
subplot_titles=("corr_x (px)", "corr_y (px)", "Événements des détecteurs, par catégorie", ""))
@@ -56,13 +46,7 @@ def page(dossier, du=None, au=None):
hovertemplate=f"{s} : %{{y:.3f}} px<extra></extra>"), row=row, col=1)
if spans:
fig.add_trace(comparaison.barres("Détecteurs", comparaison.SCRIPTS, spans, pas, 1, "d"), row=3, col=1)
fig.add_trace(go.Heatmap(
x=[t for t, _ in erreurs], y=["Error rate"], z=[[statistics.mean(e for e, _ in v) for _, v in erreurs]],
text=[[f"{len(v)} capteurs, {sum(1 for e, th in v if th is not None and e > th)} rejetés" for _, v in erreurs]],
zmin=0, zmax=1, colorscale=[[i / (len(VERT_ROUGE) - 1), c] for i, c in enumerate(VERT_ROUGE)],
colorbar={"title": {"text": "Error rate", "side": "right"}, "thickness": 12, "len": 0.3, "y": 0, "yanchor": "bottom"},
hovertemplate="%{x|%Y-%m-%d %H:%M} UTC<br>error_value moyenne : %{z:.3f}<br>"
"%{text}<extra></extra>"), row=4, col=1)
fig.add_trace(comparaison.taux_erreur(mesures, a, b), row=4, col=1)
fig.update_layout(bargap=0.3, height=680 + 30 * len(ordre), showlegend=False, hovermode="closest", plot_bgcolor="white",
margin={"l": 170, "r": 90, "t": 40, "b": 40})
fig.update_xaxes(type="date", range=[a, b], showgrid=True, gridcolor="#e6e6e2")
@@ -75,18 +59,20 @@ def page(dossier, du=None, au=None):
station = os.path.basename(os.path.normpath(dossier))
nom = f"{station}_{score.iso(a)[:10]}_{score.iso(b)[:10]}"
corps = fig.to_html(include_plotlyjs="cdn", full_html=False, post_script=AUTOSCALE_Y_JS, config={"scrollZoom": False})
chemin = os.path.join(ROOT, "out", f"detecteurs_{nom}.html")
chemin = chemin or os.path.join(ROOT, "out", f"detecteurs_{nom}.html")
os.makedirs(os.path.dirname(chemin), exist_ok=True)
with open(chemin, "w", encoding="utf-8") as f:
f.write(f"""<!doctype html><html lang="fr"><head><meta charset="utf-8"><title>Détecteurs {html.escape(nom)}</title>
<style>body{{font-family:system-ui,sans-serif;margin:16px;background:#fff;color:#1a1a19}} p{{color:#5f5e5a;max-width:70em}}
table{{border-collapse:collapse;font-size:14px}} th,td{{padding:4px 10px;border-bottom:1px solid #e6e6e2;text-align:left;vertical-align:top}}
th{{font-weight:600;color:#3d3d3a}}</style></head><body>
{entete}
<h2>Détecteurs, {html.escape(station)} : {score.iso(a)} → {score.iso(b)} (UTC)</h2>
<p>Les détecteurs du journal tels qu'ils sont (version {comparaison.benchmark.version()}), la plage classée avec ses 3 jours d'historique.
Survol d'une barre : capteurs et phrase ; ligne Error rate : error_value moyenne de tous les capteurs à chaque instant. Zoom par sélection ; la liste complète est sous la figure.</p>
{corps}<h3>{len(evts)} événement(s)</h3>
<table><tr><th>Début</th><th>Fin</th><th>Catégorie</th><th>Capteurs</th><th>Phrase</th></tr>{lignes}</table>
{annexe}
</body></html>""")
return chemin