Add the sensor detail to the Diagnosis tab (D-053)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
maximeandClaude Opus 5.5 committed 2026-10-16 14:54:22 +02:00
1 parent 13697e094a
commit d00eacdfdd
3 files changed
+63 -3

No files matched your search

+2 -1
View File
@@ -20,7 +20,7 @@ OUT = ROOT / "out"
DEFAULT = ROOT / "vues-deplacements" / "cas" / "2026-10_NORDEND" / "NORDEND"
sys.path.insert(0, str(ROOT / "src"))
sys.path.insert(0, str(ROOT / "agents" / "diagnostic" / "outils"))
from common.page import open_html # noqa: E402 (bascule seule sur .venv si plotly manque)
from common.page import AUTOSCALE_Y_JS, open_html # noqa: E402 (bascule seule sur .venv si plotly manque)
import donnees # noqa: E402 (lecture des exports, bibliothèque standard)
COLUMNS = ("corr_x", "corr_y", "error_value") # grandeurs de la grille (spec §2)
@@ -92,6 +92,7 @@ def page(folder):
text = (HERE / "explore_template.html").read_text()
text = text.replace("<!--PLATFORM-->", html.escape(data["platform"]))
text = text.replace("/*DATA*/null", json.dumps(data).replace("</", "<\\/"))
text = text.replace("/*AUTOSCALE*/", AUTOSCALE_Y_JS.replace("'{plot_id}'", "plotId")) # ordonnée recalée (D-013)
OUT.mkdir(exist_ok=True)
out = OUT / f"vues_deplacements_{Path(folder).resolve().name}.html"
out.write_text(text)
@@ -61,6 +61,12 @@
font: inherit; cursor: pointer; }
.toolbar button.active { background: var(--blue); border-color: var(--blue); color: #fff; }
.toolbar .meta { margin-left: auto; color: var(--muted); }
/* Détail d'un capteur (spec §4). */
.detail { border: 1px solid var(--line); border-radius: 4px; margin-top: 10px; }
.detail header { display: flex; justify-content: space-between; align-items: center; padding: 6px 12px;
border-bottom: 1px solid var(--line); color: var(--text); font-size: 15px; }
.detail header button { border: 0; background: none; color: var(--muted); font-size: 20px; cursor: pointer; }
</style>
</head>
<body>
@@ -202,6 +208,7 @@ function setT(j) {
document.getElementById("instant").textContent = `T = ${utc(D.times[T])}`;
Plotly.relayout("grid", { shapes: [tLine()] });
drawImage();
opened.forEach(i => Plotly.relayout(`detail-plot-${i}`, { shapes: [tLine()] }));
}
const columns = document.getElementById("columns");
@@ -213,12 +220,64 @@ columns.addEventListener("click", ev => {
markColumn();
drawGrid();
drawImage();
opened.forEach(i => drawDetail(i));
});
// Détail d'un capteur (spec §4, version 0) : la grandeur de la grille, puis error_value et son seuil ; T marqué.
const opened = []; // index des capteurs dépliés, dans l'ordre d'ouverture
function autoscale(plotId) {
/*AUTOSCALE*/
}
function detailFigure(i) {
const s = S[i], ends = [D.times[0], D.times[D.times.length - 1]];
return [[
{ type: "scatter", mode: "lines", x: D.times, y: s.values[col], name: col, line: { color: "#2a78d6", width: 1.5 } },
{ type: "scatter", mode: "lines", x: D.times, y: s.values.error_value, name: "error_value", yaxis: "y2",
line: { color: "#d03b3b", width: 1.5 } },
{ type: "scatter", mode: "lines", x: ends, y: [s.threshold, s.threshold], name: "error_threshold", yaxis: "y2",
line: { color: "#d03b3b", width: 1, dash: "dash" }, hoverinfo: "skip" },
], {
height: 380, margin: { l: 60, r: 10, t: 30, b: 40 }, legend: { orientation: "h", x: 0, y: 1.12 },
xaxis: { type: "date", anchor: "y2" },
yaxis: { domain: [0.55, 1], fixedrange: true, title: { text: col } },
yaxis2: { domain: [0, 0.45], fixedrange: true, title: { text: "error_value" } },
shapes: [tLine()],
}];
}
function drawDetail(i) {
const id = `detail-plot-${i}`;
Plotly.purge(id);
Plotly.newPlot(id, ...detailFigure(i), CONFIG).then(() => autoscale(id));
}
function openDetail(i) {
if (opened.includes(i)) return;
opened.push(i);
const box = document.createElement("div");
box.className = "detail";
box.innerHTML = `<header><b></b><button type="button" title="Close">×</button></header><div id="detail-plot-${i}"></div>`;
box.querySelector("b").textContent = `${NAMES[i]} · ${S[i].kind}`;
box.querySelector("button").addEventListener("click", () => {
Plotly.purge(`detail-plot-${i}`);
box.remove();
opened.splice(opened.indexOf(i), 1);
});
document.getElementById("details").append(box);
drawDetail(i);
}
markColumn();
document.getElementById("instant").textContent = `T = ${utc(D.times[T])}`;
Promise.all([drawGrid(), drawImage()]).then(() => {
document.getElementById("grid").on("plotly_click", ev => setT(ev.points[0].pointNumber[1]));
document.getElementById("grid").on("plotly_click", ev => { // une case : T devient son instant, son capteur se déplie
const [i, j] = ev.points[0].pointNumber;
setT(j);
openDetail(i);
});
document.getElementById("image").on("plotly_click", ev => openDetail(ev.points[0].customdata)); // un marqueur
for (const name of (ASKED.get("open") || "").split(",")) if (NAMES.includes(name)) openDetail(NAMES.indexOf(name));
});
if (D.images.length) { // la taille de l'image, lue sur la première, place la photo sous les marqueurs
const probe = new Image();