Status page: status ranges passed to plotly at once

add_vrect revalidated every previous shape on each call: on NIEDERHORN over two weeks, 132 ranges
took most of the run. The ranges are now built as plain shapes and set in one update_layout; the
generated page is byte-identical, and the run (so the data loader's Analyse) drops from ~10 s to ~2 s.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
maximeandClaude Opus 5.5 committed 2026-10-29 13:18:35 +01:00
1 parent aa2578873d
commit 7924997b73
1 file changed
+7 -5
+7 -5
View File
@@ -199,15 +199,17 @@ def page(dossier, du=None, au=None):
row=4, col=1)
rang = {k: i for i, k in enumerate(detecteurs.score.categories.CATEGORIES)}
vus, ev = set(), []
vus, ev, plages = set(), [], []
for k, d0, d1 in morceaux:
s = affiches[k][0]
for r in range(2, len(titres) + 1):
fig.add_vrect(x0=d0, x1=d1, row=r, col=1, fillcolor=TEINTES.get(s["category"], detecteurs.GRIS), opacity=0.2,
line_width=0, layer="below", legend="legend2", legendgroup=s["label"], name=s["label"],
legendrank=rang.get(s["category"], 99), showlegend=s["label"] not in vus)
for r in range(2, len(titres) + 1): # les plages d'un coup : add_vrect revalide toutes les précédentes à chaque appel (~7 s sur 2 semaines)
plages.append({"type": "rect", "xref": f"x{r}", "yref": f"y{r} domain", "x0": d0, "x1": d1, "y0": 0, "y1": 1,
"fillcolor": TEINTES.get(s["category"], detecteurs.GRIS), "opacity": 0.2, "line": {"width": 0},
"layer": "below", "legend": "legend2", "legendgroup": s["label"], "name": s["label"],
"legendrank": rang.get(s["category"], 99), "showlegend": s["label"] not in vus})
vus.add(s["label"])
ev.append(k)
fig.update_layout(shapes=plages)
fig.update_layout(height=sum(hauteurs) + 260, hovermode="closest", plot_bgcolor="white",
margin={"l": 60, "r": 20, "t": 100, "b": 40}, bargap=0.15,
uniformtext={"minsize": 9, "mode": "hide"}, # une étiquette trop courte pour son nom : au survol seul