1144 lines
71 KiB
HTML
1144 lines
71 KiB
HTML
<!doctype html>
|
||
<html lang="en">
|
||
<head>
|
||
<meta charset="utf-8">
|
||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||
<title><!--PLATFORM--> · Explore</title>
|
||
<script src="https://cdn.plot.ly/plotly-4.1.1.min.js"></script>
|
||
<style>
|
||
/* Maquette de la page Explore, onglets View, Diagnosis (D-053, D-054) et Displacements (D-055) (vues-deplacements/maquette/spec.md). Données injectées
|
||
par explore.py. Habillage repris de maquettes/user/summary_template.html. */
|
||
:root {
|
||
--sidebar: #2a3f54; --topbar: #ededed; --page: #f7f7f7; --panel-border: #e6e9ed;
|
||
--muted: #73879c; --text: #333; --line: #dee2e6; --blue: #2a78d6;
|
||
}
|
||
* { box-sizing: border-box; }
|
||
body { margin: 0; background: var(--page); color: var(--muted);
|
||
font: 13px/1.47 "Helvetica Neue", Roboto, Arial, "Droid Sans", sans-serif; }
|
||
svg.i { width: 15px; height: 15px; fill: currentColor; vertical-align: -2px; }
|
||
|
||
.sidebar { position: fixed; inset: 0 auto 0 0; width: 230px; background: var(--sidebar); color: #fff; }
|
||
.brand { height: 57px; padding: 0 10px; display: flex; align-items: center; font-size: 22px; }
|
||
.profile { display: flex; align-items: center; gap: 22px; padding: 18px 12px 24px; }
|
||
.avatar { width: 56px; height: 56px; border-radius: 50%; background: #9b59b6; border: 3px solid #fff;
|
||
display: grid; place-items: center; font-size: 19px; box-shadow: 0 0 0 1px rgba(0,0,0,.15); }
|
||
.profile small { display: block; color: #bab8b8; font-size: 13px; }
|
||
.profile span { font-size: 14px; }
|
||
.section { padding: 0 23px 18px; font-size: 11px; font-weight: bold; letter-spacing: .3px; }
|
||
.nav a { display: flex; align-items: center; gap: 4px; padding: 13px 15px; color: #e7e7e7;
|
||
text-decoration: none; font-weight: bold; }
|
||
.nav a .chev { margin-left: auto; }
|
||
|
||
.topbar { margin-left: 230px; height: 52px; background: var(--topbar); border-bottom: 1px solid #d9dee4;
|
||
display: flex; align-items: center; justify-content: space-between; padding: 0 15px; }
|
||
.topbar .burger { color: #5a738e; width: 26px; height: 26px; }
|
||
.user { display: flex; align-items: center; gap: 10px; color: #515356; }
|
||
.user .avatar { width: 29px; height: 29px; border-width: 0; font-size: 11px; box-shadow: none; }
|
||
|
||
main { margin-left: 230px; padding: 10px 28px; }
|
||
.panel { background: #fff; border: 1px solid var(--panel-border); padding: 10px 17px 20px; }
|
||
.panel-title { display: flex; align-items: center; border-bottom: 2px solid var(--panel-border); padding: 4px 6px 12px; }
|
||
.panel-title h2 { margin: 0; font-size: 18px; font-weight: 400; }
|
||
.panel-title h2 small { font-size: 14px; margin-left: 10px; }
|
||
.panel-title .tools { margin-left: auto; color: #c5c7cb; }
|
||
|
||
/* Période (inerte) et onglets, comme la page Explore de la plateforme. */
|
||
.period { display: flex; margin: 22px 22px 0; }
|
||
.period span { border: 1px solid #ced4da; border-radius: 4px 0 0 4px; padding: 7px 12px; color: var(--text); font-size: 15px; }
|
||
.period b { background: #6c757d; color: #fff; padding: 7px 12px; font-weight: normal; font-size: 15px; border-radius: 0 4px 4px 0; }
|
||
.tabs { display: flex; margin: 18px 22px 0; border-bottom: 1px solid var(--line); }
|
||
.tabs button { border: 1px solid transparent; border-bottom: 0; background: none; padding: 7px 16px; margin-bottom: -1px;
|
||
font: inherit; font-size: 15px; color: var(--blue); cursor: pointer; border-radius: 4px 4px 0 0; }
|
||
.tabs button.active { color: var(--text); background: #fff; border-color: var(--line); }
|
||
.pane { display: none; margin: 0 22px; padding-top: 14px; }
|
||
.pane.active { display: block; }
|
||
.pane > img { display: block; width: 100%; margin-bottom: 8px; border: 1px solid var(--line); }
|
||
.empty { padding: 30px 0; color: var(--muted); }
|
||
|
||
/* Onglet Diagnosis (spec §1 à §3). */
|
||
.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-bottom: 8px; color: var(--text); font-size: 14px;
|
||
white-space: nowrap; }
|
||
.toolbar button { border: 1px solid var(--line); background: #fff; border-radius: 4px; padding: 4px 10px;
|
||
font: inherit; cursor: pointer; }
|
||
.toolbar button.active { background: var(--blue); border-color: var(--blue); color: #fff; }
|
||
.toolbar .meta { margin-left: auto; color: var(--muted); }
|
||
|
||
/* Onglet View (spec « L'onglet View ») : images au glisseur, film, comparaison à ±24 h, zoom commun. */
|
||
.viewer { margin: 0 auto; width: min(100%, calc((100vh - 370px) * 1.5 * var(--n, 1))); }
|
||
.frames { display: flex; gap: 8px; }
|
||
.frame { flex: 1; position: relative; margin: 0; aspect-ratio: 3 / 2; overflow: hidden; background: #000;
|
||
cursor: grab; touch-action: none; user-select: none; }
|
||
.layer { position: absolute; inset: 0; transform-origin: 0 0; } /* l'image et ses repères, zoomés ensemble */
|
||
.layer > * { position: absolute; inset: 0; width: 100%; height: 100%; }
|
||
/* Cercle et nom de chaque capteur ; le nom garde sa taille à l'écran quel que soit le zoom (font-size, voir zoom()). */
|
||
.marks { overflow: visible; pointer-events: none; font-family: sans-serif; }
|
||
.marks circle { fill: none; stroke: currentColor; stroke-width: 1.5; vector-effect: non-scaling-stroke; }
|
||
.marks text { fill: currentColor; text-anchor: middle; paint-order: stroke; stroke: rgba(0,0,0,.85); stroke-width: .25em;
|
||
stroke-linejoin: round; }
|
||
.marks .target { color: #ffd400; }
|
||
.marks .global_ref { color: #3cc8ff; }
|
||
.marks .ref { color: #ff9f1c; }
|
||
.marks .sel text { font-weight: bold; text-decoration: underline; }
|
||
.marks .sel circle { stroke-width: 3; }
|
||
.marks .over circle { stroke-width: 3; stroke-dasharray: 5 3; } /* error_value au-dessus du seuil : mesure rejetée */
|
||
.strip figcaption.over { color: #d0021b; }
|
||
.legend b { font-weight: normal; padding: 0 4px; border-radius: 3px; background: #333; }
|
||
.frame figcaption { position: absolute; left: 8px; top: 6px; padding: 2px 8px; border-radius: 3px;
|
||
background: rgba(0,0,0,.6); color: #fff; font-size: 13px; pointer-events: none; }
|
||
#v-slider { width: 100%; margin: 10px 0 0; }
|
||
/* Bandes d'error_value (système, puis cible du gros plan) : une colonne par image, alignées sur le glisseur (8 px :
|
||
demi-curseur). */
|
||
#v-band { display: block; width: calc(100% - 16px); height: 19px; margin: 2px 8px 0; image-rendering: pixelated; cursor: pointer; }
|
||
.days { position: relative; height: 18px; font-size: 11px; }
|
||
.days span { position: absolute; transform: translateX(-50%); }
|
||
|
||
/* Gros plan d'une cible, avec les images d'avant et d'après (spec « L'onglet View »). */
|
||
.sub { margin: 22px 0 8px; padding-top: 12px; border-top: 1px solid var(--line); font-size: 15px; color: var(--text); }
|
||
.toolbar input, .toolbar select { font: inherit; }
|
||
.note { margin: 0 0 10px; color: var(--text); }
|
||
.strip { display: flex; justify-content: safe center; align-items: flex-end; gap: 6px; overflow-x: auto; margin-bottom: 14px; }
|
||
.strip figure { flex: none; margin: 0; color: var(--text); font-size: 12px; white-space: pre-line; line-height: 1.3; }
|
||
.strip canvas { display: block; cursor: pointer; }
|
||
.strip .now canvas { outline: 2px solid var(--blue); cursor: default; }
|
||
#t-also { flex: 1; white-space: normal; }
|
||
|
||
/* Demande à l'agent (Diagnosis). */
|
||
#d-targets, #d-question { flex: 1; white-space: normal; }
|
||
#d-question { min-width: 300px; padding: 4px 8px; border: 1px solid var(--line); border-radius: 4px; }
|
||
#d-request textarea { width: 100%; font: 13px/1.4 monospace; padding: 6px 8px; border: 1px solid var(--line); }
|
||
#d-request p { margin: 4px 0; color: var(--text); }
|
||
|
||
/* Onglet Displacements (D-055) : à gauche les sauts groupés en événements et les tendances, à droite les courbes en mm,
|
||
qui restent à l'écran quand la liste défile ; le survol d'une ligne montre où elle a lieu sur les courbes. */
|
||
.rgrid { display: grid; grid-template-columns: minmax(460px, 40%) minmax(0, 1fr); gap: 20px; align-items: start; }
|
||
#r-curves { position: sticky; top: 6px; }
|
||
#displacements .how { margin: 0 0 8px; color: var(--muted); }
|
||
#displacements .how summary { cursor: pointer; font-size: 12px; }
|
||
#displacements .hint { color: var(--muted); font-size: 12px; }
|
||
#displacements .note { margin: 4px 0 0; }
|
||
#displacements .sub { margin: 18px 0 6px; }
|
||
#displacements .sub:first-child { margin-top: 0; padding-top: 0; border-top: 0; }
|
||
#r-trends { margin: 0 0 12px; }
|
||
#r-events details { margin: 0 0 12px; color: var(--text); }
|
||
#r-events summary { font-size: 15px; cursor: pointer; padding: 4px 0; }
|
||
|
||
/* Onglet Journal (spec « L'onglet Journal ») : courbes, frise des épisodes, journal en texte de la plage visible. */
|
||
#journal .hint { color: var(--muted); font-size: 12px; margin: 2px 0 10px; }
|
||
.jentry { margin: 0 0 8px; padding: 8px 10px; border: 1px solid var(--line); border-left: 5px solid; border-radius: 4px;
|
||
background: #fff; color: var(--text); cursor: pointer; }
|
||
.jentry:hover { background: #e8f0fb; }
|
||
.jentry .when { color: var(--muted); font-size: 12px; }
|
||
.jentry b { font-size: 14px; }
|
||
.jentry details { margin-top: 4px; }
|
||
.jentry summary { cursor: pointer; color: var(--muted); font-size: 12px; }
|
||
.jentry button { margin-left: 6px; font-size: 12px; cursor: pointer; }
|
||
/* Timelapse d'un événement (bouton ▶ Images) : fenêtre par-dessus la page, bord rouge pendant l'événement. */
|
||
#j-video { position: fixed; inset: 0; z-index: 10; display: grid; place-items: center; background: rgba(0, 0, 0, .6); }
|
||
#j-video[hidden] { display: none; }
|
||
#j-video .box { background: #fff; padding: 12px; border-radius: 6px; }
|
||
#j-video canvas { display: block; max-width: 88vw; max-height: 78vh; border: 5px solid transparent; }
|
||
#j-video canvas.during { border-color: #d62728; }
|
||
#j-video .bar { display: flex; gap: 8px; align-items: center; margin-top: 8px; color: var(--text); }
|
||
#j-video .bar span { flex: 1; }
|
||
.rtable { border-collapse: collapse; width: 100%; margin-top: 4px; color: var(--text); }
|
||
.rtable th, .rtable td { padding: 5px 6px; border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap; }
|
||
.rtable th { color: var(--muted); font-weight: normal; white-space: normal; vertical-align: bottom; }
|
||
.rtable tbody tr { cursor: pointer; }
|
||
.rtable tbody tr:hover, .rtable tbody tr.on, #r-events summary.on { background: #e8f0fb; }
|
||
.rtable i { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 6px; }
|
||
</style>
|
||
</head>
|
||
<body>
|
||
<svg style="display:none">
|
||
<symbol id="home" viewBox="0 0 20 20"><path d="M10 2 1 10h3v8h5v-5h2v5h5v-8h3z"/></symbol>
|
||
<symbol id="list" viewBox="0 0 20 20"><path d="M1 3h3v3H1zm5 0h13v3H6zM1 8.5h3v3H1zm5 0h13v3H6zM1 14h3v3H1zm5 0h13v3H6z"/></symbol>
|
||
<symbol id="cog" viewBox="0 0 20 20"><circle cx="10" cy="10" r="6" fill="none" stroke="currentColor" stroke-width="4" stroke-dasharray="2.4 2.3"/><circle cx="10" cy="10" r="5" fill="none" stroke="currentColor" stroke-width="3"/></symbol>
|
||
<symbol id="chev" viewBox="0 0 20 20"><path d="M4 7l6 6 6-6" fill="none" stroke="currentColor" stroke-width="2.2"/></symbol>
|
||
<symbol id="burger" viewBox="0 0 20 20"><path d="M2 4h16v2.4H2zm0 4.8h16v2.4H2zm0 4.8h16V16H2z"/></symbol>
|
||
<symbol id="wrench" viewBox="0 0 20 20"><path d="M13.5 1.5a5 5 0 0 0-4.6 6.9L2 15.3 4.7 18l6.9-6.9a5 5 0 0 0 6.9-4.6l-3 3-2.8-.6-.6-2.8z"/></symbol>
|
||
</svg>
|
||
|
||
<aside class="sidebar">
|
||
<div class="brand">AIMsight monitoring</div>
|
||
<div class="profile"><div class="avatar">MP</div><div><small>Welcome,</small><span>Maxime Pasquier</span></div></div>
|
||
<div class="section">GENERAL</div>
|
||
<nav class="nav">
|
||
<a><svg class="i"><use href="#home"/></svg>Home</a>
|
||
<a><svg class="i"><use href="#list"/></svg>Explore<svg class="i chev"><use href="#chev"/></svg></a>
|
||
<a><svg class="i"><use href="#cog"/></svg>Settings<svg class="i chev"><use href="#chev"/></svg></a>
|
||
</nav>
|
||
</aside>
|
||
|
||
<header class="topbar">
|
||
<svg class="burger"><use href="#burger"/></svg>
|
||
<div class="user"><div class="avatar">MP</div>Maxime Pasquier ▾</div>
|
||
</header>
|
||
|
||
<main>
|
||
<section class="panel">
|
||
<div class="panel-title">
|
||
<h2><!--PLATFORM--><small>Explore</small></h2>
|
||
<span class="tools"><svg class="i"><use href="#wrench"/></svg> ▾</span>
|
||
</div>
|
||
<div class="period"><span id="period"></span><b>Apply</b></div>
|
||
<nav class="tabs">
|
||
<button type="button" data-pane="time_series">Time Series</button>
|
||
<button type="button" data-pane="advanced">Advanced</button>
|
||
<button type="button" data-pane="view" class="active">View</button>
|
||
<button type="button" data-pane="diagnosis">Diagnosis</button>
|
||
<button type="button" data-pane="displacements">Displacements</button>
|
||
<button type="button" data-pane="journal">Journal</button>
|
||
</nav>
|
||
<div class="pane" id="time_series"></div>
|
||
<div class="pane" id="advanced"></div>
|
||
<div class="pane active" id="view">
|
||
<div class="toolbar">
|
||
<button type="button" id="v-prev" title="Previous image (←)">◀</button>
|
||
<button type="button" id="v-play" title="Play / pause (Space)">▶ Play</button>
|
||
<button type="button" id="v-next" title="Next image (→)">▶</button>
|
||
<select id="v-speed" title="Images per second"><option>2</option><option selected>4</option><option>8</option></select> img/s
|
||
Compare <span id="v-cmp"><button type="button" data-cmp="0">Off</button><button type="button" data-cmp="-1">−24 h</button><button type="button" data-cmp="1">+24 h</button></span>
|
||
Zoom <button type="button" id="v-targets">Targets</button><button type="button" id="v-full">Full image</button>
|
||
<label><input type="checkbox" id="v-marks" checked> Sensors</label>
|
||
colored by <select id="v-color"><option value="error">error_value</option><option value="type">type</option></select>
|
||
<span class="legend" id="v-legend"></span>
|
||
<span class="meta">← → image · Shift ← → ±24 h · Space play · wheel zoom, drag to pan</span>
|
||
</div>
|
||
<div class="viewer">
|
||
<div class="frames">
|
||
<figure class="frame"><div class="layer"><img alt="" draggable="false"><svg class="marks"></svg></div><figcaption></figcaption></figure>
|
||
<figure class="frame" hidden><div class="layer"><img alt="" draggable="false"><svg class="marks"></svg></div><figcaption></figcaption></figure>
|
||
</div>
|
||
<input type="range" id="v-slider" min="0" value="0">
|
||
<canvas id="v-band" height="3"></canvas>
|
||
<div class="days" id="v-days"></div>
|
||
<div class="toolbar">
|
||
<button type="button" id="v-prev-rej">◀ Previous rejection</button><button type="button" id="v-next-rej">Next rejection ▶</button>
|
||
<span id="v-rej"></span>
|
||
<span class="meta">bands: top all sensors (mean of error_value / threshold), bottom close-up target ·
|
||
green low, orange near threshold, red above · grey no value</span>
|
||
</div>
|
||
</div>
|
||
<h3 class="sub">Target close-up</h3>
|
||
<div class="toolbar">
|
||
Target <select id="t-name"></select>
|
||
Crop ± <select id="t-r"><option>15</option><option selected>30</option><option>75</option><option>150</option><option>300</option></select> px
|
||
Step <select id="t-step"><option value="15">15 min</option><option value="60" selected>1 h</option><option value="180">3 h</option>
|
||
<option value="360">6 h</option><option value="1440">1 day</option></select>
|
||
Images on each side <select id="t-side"><option>2</option><option selected>3</option><option>4</option><option>6</option></select>
|
||
</div>
|
||
<div class="toolbar">Also show <span id="t-also"></span><button type="button" id="t-data">Data →</button>
|
||
<span class="meta">before and after images appear when the film is paused</span>
|
||
</div>
|
||
<p class="note">Each image is centered on the target's raw position (x, y) measured at that image's time, not on corr.
|
||
The large image is the image above; the others are the images before and after it.</p>
|
||
<div id="t-strips"></div>
|
||
</div>
|
||
<div class="pane" id="diagnosis">
|
||
<div class="toolbar">Targets <span id="d-targets"></span></div>
|
||
<div id="curves"></div>
|
||
<div class="toolbar">
|
||
<b id="d-range"></b> <span id="instant"></span>
|
||
<span class="meta">zoom the curves to choose the range · click a button to add or remove a target</span>
|
||
</div>
|
||
<div class="toolbar">
|
||
<input type="text" id="d-question" placeholder="Question for the agent (optional)">
|
||
<button type="button" id="d-ai">Analyze by AI</button><button type="button" id="d-images">Images →</button>
|
||
</div>
|
||
<div id="d-request" hidden>
|
||
<textarea rows="3" readonly></textarea>
|
||
<p>Not run from this page yet: paste this request into Claude Code. <button type="button" id="d-copy">Copy</button></p>
|
||
</div>
|
||
</div>
|
||
<div class="pane" id="displacements">
|
||
<div class="rgrid">
|
||
<div class="rlist">
|
||
<h3 class="sub">Jumps</h3>
|
||
<details class="how"><summary>How they are found</summary><p class="note" id="r-note"></p></details>
|
||
<div id="r-events"></div>
|
||
<h3 class="sub">Trends</h3>
|
||
<details class="how"><summary>How they are found</summary><p class="note" id="r-trend-note"></p></details>
|
||
<div id="r-trends"></div>
|
||
<p class="hint">Hover a row: the curves show where and how much. Click it: open it in Diagnosis.</p>
|
||
</div>
|
||
<div id="r-curves"></div>
|
||
</div>
|
||
</div>
|
||
<div class="pane" id="journal">
|
||
<div class="toolbar">Unit <button type="button" data-unit="mm">mm</button><button type="button" data-unit="px">px</button>
|
||
<button type="button" id="j-fit">Fit all</button>
|
||
<label><input type="checkbox" id="j-expand"> Expand</label>
|
||
<label><input type="checkbox" id="j-support"> Support view</label>
|
||
<span class="meta">mm: hourly averages, what the platform shows · px: every measurement, short peaks included ·
|
||
the vertical scale leaves out the greyed zones and the hidden targets</span></div>
|
||
<div id="j-curves"></div>
|
||
<p class="hint">Cleaned curves: the periods to ignore are removed, nothing else changed; the raw data stays there in thin grey,
|
||
on a grey zone. Hover a bar for details, ▶ Images to see the camera; zoom the curves
|
||
with the wheel or by dragging, double-click for the whole period.</p>
|
||
<div id="j-list"></div>
|
||
<div id="j-video" hidden><div class="box"><canvas></canvas><div class="bar"><button type="button" data-v="-1">◀</button>
|
||
<button type="button" data-v="p">❚❚ Pause</button><button type="button" data-v="1">▶</button><span></span>
|
||
<button type="button" data-v="x">✕ Close</button></div></div></div>
|
||
</div>
|
||
</section>
|
||
</main>
|
||
|
||
<script>
|
||
const D = /*DATA*/null;
|
||
const day = t => `${+t.slice(8, 10)}/${+t.slice(5, 7)}/${t.slice(0, 4)}`;
|
||
document.getElementById("period").textContent = `${day(D.times[0])} → ${day(D.times[D.times.length - 1])}`;
|
||
|
||
// Onglets : un seul volet visible ; Plotly recalcule la taille des graphiques du volet qui s'affiche. Entre View et
|
||
// Diagnosis, l'instant et les cibles passent d'un onglet à l'autre (syncTabs).
|
||
function activate(b, sync = true) {
|
||
const prev = document.querySelector(".pane.active").id;
|
||
document.querySelectorAll(".tabs button, .pane").forEach(e => e.classList.remove("active"));
|
||
b.classList.add("active");
|
||
const pane = document.getElementById(b.dataset.pane);
|
||
pane.classList.add("active");
|
||
if (sync) syncTabs(prev, b.dataset.pane);
|
||
pane.querySelectorAll(".js-plotly-plot").forEach(p => Plotly.Plots.resize(p));
|
||
}
|
||
for (const b of document.querySelectorAll(".tabs button")) b.addEventListener("click", () => activate(b));
|
||
const tabButton = pane => document.querySelector(`.tabs button[data-pane="${pane}"]`);
|
||
|
||
// Time Series et Advanced : les captures de la plateforme, telles quelles (décor, spec « La page »).
|
||
for (const [tab, srcs] of Object.entries(D.captures)) {
|
||
const pane = document.getElementById(tab);
|
||
if (!srcs.length) pane.innerHTML = '<p class="empty">No capture of this page.</p>';
|
||
for (const src of srcs) pane.insertAdjacentHTML("beforeend", `<img src="${src}" alt="">`);
|
||
}
|
||
|
||
// Onglet Diagnosis (spec « L'onglet Diagnosis ») : ce que disent les données. Courbes des cibles choisies sur une
|
||
// plage, et la demande à l'agent de diagnostic pour cette plage et ces cibles.
|
||
const S = D.sensors, NAMES = S.map(s => s.name);
|
||
const TOL = 10 * 60e3; // image ou mesure la plus proche d'un instant, à 10 min près
|
||
const CONFIG = { responsive: true, scrollZoom: true, displaylogo: false };
|
||
const ASKED = new URLSearchParams(location.hash.slice(1)); // état de départ lu dans l'adresse
|
||
let T = D.times.includes(ASKED.get("t")) ? D.times.indexOf(ASKED.get("t")) : D.times.length - 1;
|
||
let W = 0, H = 0; // taille des images de la caméra, lue sur la première
|
||
if (tabButton(ASKED.get("tab"))) activate(tabButton(ASKED.get("tab")), false); // onglet de départ (#tab=diagnosis), View sinon
|
||
const utc = t => t.replace("T", " ").replace("Z", " UTC");
|
||
const tLine = () => ({ type: "line", xref: "x", yref: "paper", x0: D.times[T], x1: D.times[T], y0: 0, y1: 1,
|
||
line: { color: "#111", width: 1.5 } });
|
||
|
||
const IMS = D.images.map(im => Date.parse(im.t)), TMS = D.times.map(t => Date.parse(t)); // instants en ms
|
||
function nearestIndex(ms, list = IMS) { // index de l'image (ou de la mesure) la plus proche de ms, à TOL près ; -1 sinon
|
||
let best = -1, gap = Infinity;
|
||
list.forEach((t, k) => {
|
||
const g = Math.abs(t - ms);
|
||
if (g < gap) { gap = g; best = k; }
|
||
});
|
||
return gap <= TOL ? best : -1;
|
||
}
|
||
|
||
function setT(j) {
|
||
T = j;
|
||
document.getElementById("instant").textContent = `· T = ${utc(D.times[T])}`;
|
||
const gd = document.getElementById("curves");
|
||
if (gd.layout) Plotly.relayout(gd, { shapes: [tLine()] }); // seulement s'il est déjà tracé
|
||
}
|
||
|
||
// Cibles choisies (SEL, dans l'ordre du choix) et plage (RANGE, la fenêtre visible des courbes et de la grille).
|
||
const PALETTE = ["#2a78d6", "#d03b3b", "#2ca02c", "#9467bd", "#ff7f0e", "#17becf", "#8c564b", "#e377c2", "#7f7f7f", "#bcbd22"];
|
||
const FULL = [D.times[0], D.times[D.times.length - 1]];
|
||
let SEL = (ASKED.get("open") || "PR17").split(",").filter(n => NAMES.includes(n)).map(n => NAMES.indexOf(n));
|
||
let RANGE = [...FULL];
|
||
const chips = document.getElementById("d-targets");
|
||
chips.innerHTML = S.map((s, i) => `<button type="button" data-i="${i}">${s.name}</button>`).join("");
|
||
function markTargets() {
|
||
chips.querySelectorAll("button").forEach(b => {
|
||
const at = SEL.indexOf(+b.dataset.i);
|
||
b.classList.toggle("active", at >= 0);
|
||
b.style.background = at >= 0 ? PALETTE[at % PALETTE.length] : ""; // la couleur de ses courbes
|
||
});
|
||
}
|
||
chips.addEventListener("click", ev => { // un clic ajoute la cible, un second la retire
|
||
const b = ev.target.closest("button");
|
||
if (!b) return;
|
||
b.blur();
|
||
const i = +b.dataset.i;
|
||
SEL = SEL.includes(i) ? SEL.filter(k => k !== i) : [...SEL, i];
|
||
markTargets();
|
||
drawCurves();
|
||
});
|
||
|
||
function autoscale(plotId) { // ordonnées recalées sur la plage visible (D-013)
|
||
/*AUTOSCALE*/
|
||
}
|
||
|
||
function drawCurves() { // une rangée par grandeur, une courbe par cible choisie ; seuils en tirets ; T marqué
|
||
Plotly.purge("curves");
|
||
const box = document.getElementById("curves");
|
||
if (!SEL.length) {
|
||
box.innerHTML = '<p class="empty">Choose targets: click a button above.</p>';
|
||
return;
|
||
}
|
||
box.innerHTML = "";
|
||
const traces = [], HR = D.hourly;
|
||
SEL.forEach((i, n) => {
|
||
const s = S[i], color = PALETTE[n % PALETTE.length], mm = HR.sensors[s.name];
|
||
if (mm) [["h", "horizontal"], ["v", "vertical"]].forEach(([k, label], r) => traces.push({ // export horaire, en mm
|
||
type: "scatter", mode: "lines", x: HR.times, y: mm[k], name: s.name, legendgroup: s.name, showlegend: false,
|
||
yaxis: `y${r ? 2 : ""}`, line: { color, width: 1.3 },
|
||
hovertemplate: `${s.name} · %{x|%d %b %H:%M} UTC (hour start)<br>${label} %{y:.2f} mm<extra></extra>` }));
|
||
traces.push({ type: "scatter", mode: "lines", x: D.times, y: s.values.error_value, yaxis: "y3", line: { color, width: 1.3 },
|
||
name: mm ? s.name : `${s.name} (no mm: not in the hourly export)`, legendgroup: s.name,
|
||
hovertemplate: `${s.name} · %{x|%d %b %H:%M} UTC<br>error_value %{y:.3f}<extra></extra>` });
|
||
traces.push({ type: "scatter", mode: "lines", x: FULL, y: [s.threshold, s.threshold], name: `${s.name} threshold`,
|
||
legendgroup: s.name, showlegend: false, yaxis: "y3", line: { color, width: 1, dash: "dash" }, hoverinfo: "skip" });
|
||
});
|
||
Plotly.newPlot("curves", traces, {
|
||
height: 620, margin: { l: 70, r: 10, t: 30, b: 40 }, legend: { orientation: "h", x: 0, y: 1.06 },
|
||
xaxis: { type: "date", anchor: "y3", range: RANGE },
|
||
yaxis: { domain: [0.70, 1], fixedrange: true, title: { text: "horizontal (mm)" } },
|
||
yaxis2: { domain: [0.36, 0.66], fixedrange: true, title: { text: "vertical (mm)" } },
|
||
yaxis3: { domain: [0, 0.32], fixedrange: true, title: { text: "error_value" } },
|
||
annotations: [{ text: "Displacement: hourly export, in mm, one point per hour (hour start, UTC) · error_value: every measurement",
|
||
xref: "paper", yref: "paper", x: 1, y: 1.06, xanchor: "right", showarrow: false, font: { size: 11, color: "#73879c" } }],
|
||
shapes: [tLine()],
|
||
}, CONFIG).then(() => {
|
||
autoscale("curves");
|
||
Plotly.relayout("curves", { "xaxis.range": RANGE }); // recale les ordonnées sur la plage dès l'ouverture
|
||
const gd = document.getElementById("curves");
|
||
gd.on("plotly_relayout", ev => onZoom(gd, ev));
|
||
gd.on("plotly_click", ev => { // un point d'une courbe : T devient son instant
|
||
const j = D.times.indexOf(minute(ev.points[0].x));
|
||
if (j >= 0) setT(j);
|
||
});
|
||
});
|
||
}
|
||
|
||
// La plage : la fenêtre visible des courbes ; un double-clic revient à toute la période.
|
||
const minute = v => String(v).replace(" ", "T").slice(0, 16) + "Z"; // borne d'axe Plotly -> instant UTC à la minute
|
||
function onZoom(gd, ev) {
|
||
if (!Object.keys(ev).some(k => k.startsWith("xaxis"))) return;
|
||
const r = ev["xaxis.autorange"] ? FULL : gd.layout.xaxis.range.map(minute);
|
||
RANGE = r;
|
||
document.getElementById("d-range").textContent = `Range: ${utc(RANGE[0])} → ${utc(RANGE[1])}`;
|
||
}
|
||
|
||
// Demande à l'agent de diagnostic : composée et affichée, pas encore lancée depuis la page.
|
||
function request() {
|
||
const q = document.getElementById("d-question").value.trim() || "Qu'est-ce qui explique le comportement de ces cibles sur cette plage ?";
|
||
return `@agent-diagnostic ${D.folder}/ Cibles : ${SEL.map(i => NAMES[i]).join(", ") || "aucune"}. ` +
|
||
`Plage : du ${RANGE[0]} au ${RANGE[1]} (UTC). Question : ${q}`;
|
||
}
|
||
document.getElementById("d-ai").addEventListener("click", ev => {
|
||
ev.currentTarget.blur();
|
||
const box = document.getElementById("d-request");
|
||
box.hidden = false;
|
||
box.querySelector("textarea").value = request();
|
||
});
|
||
document.getElementById("d-copy").addEventListener("click", ev => {
|
||
ev.currentTarget.blur();
|
||
const text = document.querySelector("#d-request textarea");
|
||
text.select();
|
||
navigator.clipboard.writeText(text.value).catch(() => document.execCommand("copy"));
|
||
});
|
||
document.getElementById("d-images").addEventListener("click", () => activate(tabButton("view")));
|
||
|
||
markTargets();
|
||
document.getElementById("instant").textContent = `· T = ${utc(D.times[T])}`;
|
||
document.getElementById("d-range").textContent = `Range: ${utc(RANGE[0])} → ${utc(RANGE[1])}`;
|
||
drawCurves();
|
||
if (D.images.length) { // la taille des images de la caméra, lue sur la première
|
||
const probe = new Image();
|
||
probe.onload = () => {
|
||
W = probe.naturalWidth; H = probe.naturalHeight;
|
||
frames.forEach(f => (f.style.aspectRatio = `${W} / ${H}`));
|
||
fit(D.view);
|
||
redrawMarks();
|
||
};
|
||
probe.src = D.images[0].src;
|
||
}
|
||
|
||
// Passage d'un onglet à l'autre : View -> Diagnosis emporte l'instant de l'image et les cibles du gros plan ;
|
||
// Diagnosis -> View emporte T et les cibles choisies (la première devient la cible du gros plan).
|
||
function syncTabs(from, to) {
|
||
if (from === "view" && to === "diagnosis") {
|
||
const j = nearestIndex(IMS[V], TMS);
|
||
SEL = [+tName.value, ...[...ALSO].filter(i => i !== +tName.value)];
|
||
markTargets();
|
||
drawCurves();
|
||
if (j >= 0) setT(j);
|
||
} else if (from === "diagnosis" && to === "view") {
|
||
if (SEL.length && S[SEL[0]].home) {
|
||
tName.value = SEL[0];
|
||
ALSO.clear();
|
||
SEL.slice(1).forEach(i => ALSO.add(i));
|
||
markAlso();
|
||
drawBand();
|
||
}
|
||
const k = nearestIndex(TMS[T]);
|
||
show(k >= 0 ? k : V);
|
||
}
|
||
}
|
||
|
||
// Onglet View : une image à la fois, au glisseur, au clavier ou en film ; à côté, si demandée, l'image la plus proche
|
||
// de la même heure la veille ou le lendemain. Les deux images partagent le zoom : échelle k, décalage x, y en fraction
|
||
// du cadre (les deux cadres ont la même taille).
|
||
const IM = D.images, DAY = 24 * 3600e3;
|
||
const frames = [...document.querySelectorAll("#view .frame")];
|
||
const slider = document.getElementById("v-slider"), playBtn = document.getElementById("v-play");
|
||
let V = IM.length - 1, cmp = { "-24": -1, "24": 1 }[ASKED.get("cmp")] || 0; // image affichée, décalage en jours
|
||
let Z = { k: 1, x: 0, y: 0 }, run = 0, playing = false;
|
||
|
||
function paint(frame, im, label) {
|
||
const img = frame.querySelector("img");
|
||
img.hidden = !im;
|
||
if (im && img.getAttribute("src") !== im.src) img.src = im.src;
|
||
img.dataset.t = im ? im.t : "";
|
||
frame.querySelector("figcaption").textContent = `${label}${im ? utc(im.t) : "No image at this time"}`;
|
||
drawMarks(frame);
|
||
}
|
||
|
||
const RING = 22; // rayon du cercle autour d'un capteur, en px de l'image (une tache de nuit fait une quinzaine de px)
|
||
const LEGENDS = { // légende des cercles, selon leur couleur (type de capteur ou error_value)
|
||
type: '<b style="color:#ffd400">target</b> <b style="color:#3cc8ff">reference</b> <b style="color:#ff9f1c">local reference</b>',
|
||
error: '<b style="color:hsl(120,90%,55%)">low</b> <b style="color:hsl(30,90%,55%)">near threshold</b> ' +
|
||
'<b style="color:#ff3b3b">- - above threshold (rejected)</b> <b style="color:#aaa">no value</b>',
|
||
};
|
||
function errorColor(e, threshold) { // vert loin du seuil, orange à son approche, rouge au-dessus
|
||
if (e === null) return "#aaa";
|
||
return e > threshold ? "#ff3b3b" : `hsl(${120 - 90 * Math.max(0, e / threshold)}, 90%, 55%)`;
|
||
}
|
||
function errorText(s, t) { // error_value du capteur s à l'heure t, face à son seuil ; null sans mesure
|
||
const j = nearestIndex(Date.parse(t), TMS), e = j < 0 ? null : s.values.error_value[j];
|
||
return e === null ? null : { text: `error ${e.toFixed(2)} ${e > s.threshold ? ">" : "≤"} ${s.threshold}`, over: e > s.threshold };
|
||
}
|
||
function drawMarks(frame) { // un cercle et le nom de chaque capteur, à x, y mesurés à l'heure de l'image ; le capteur
|
||
// du gros plan en gras souligné
|
||
const img = frame.querySelector("img"), svg = frame.querySelector("svg"), mode = document.getElementById("v-color").value;
|
||
svg.innerHTML = "";
|
||
if (img.hidden || !W || !document.getElementById("v-marks").checked) return;
|
||
svg.setAttribute("viewBox", `0 0 ${W} ${H}`);
|
||
const j = nearestIndex(Date.parse(img.dataset.t), TMS), sel = +document.getElementById("t-name").value;
|
||
if (j < 0) return;
|
||
svg.innerHTML = S.map((s, i) => {
|
||
if (s.x[j] === null) return "";
|
||
const e = s.values.error_value[j], byError = mode === "error";
|
||
const cls = [byError ? "" : s.kind, byError && e !== null && e > s.threshold ? "over" : "", i === sel ? "sel" : ""].join(" ");
|
||
const label = byError ? `${s.name} ${e === null ? "–" : e.toFixed(2)}` : s.name;
|
||
return `<g class="${cls}"${byError ? ` style="color:${errorColor(e, s.threshold)}"` : ""}>` +
|
||
`<circle cx="${s.x[j]}" cy="${s.y[j]}" r="${RING}"/><text x="${s.x[j]}" y="${s.y[j] - RING - 6}">${label}</text></g>`;
|
||
}).join("");
|
||
document.getElementById("v-legend").innerHTML = LEGENDS[mode] + " · <u><b style='color:#fff'>close-up target</b></u>";
|
||
}
|
||
const redrawMarks = () => frames.forEach(drawMarks);
|
||
|
||
function show(k) {
|
||
V = Math.max(0, Math.min(IM.length - 1, k));
|
||
slider.value = V;
|
||
const other = cmp ? nearestIndex(Date.parse(IM[V].t) + cmp * DAY) : -1;
|
||
paint(frames[0], IM[V], "");
|
||
paint(frames[1], IM[other], cmp > 0 ? "+24 h · " : "−24 h · ");
|
||
for (const n of [V + 1, other + 1]) if (n > 0 && IM[n]) new Image().src = IM[n].src; // la suivante, en cache
|
||
drawStrips();
|
||
}
|
||
|
||
function setCompare(c) {
|
||
cmp = c;
|
||
frames[1].hidden = !cmp;
|
||
document.querySelector("#view .viewer").style.setProperty("--n", cmp ? 2 : 1);
|
||
document.querySelectorAll("#v-cmp button").forEach(b => b.classList.toggle("active", +b.dataset.cmp === cmp));
|
||
show(V);
|
||
zoom(); // la largeur des cadres a changé : taille des noms à recalculer
|
||
}
|
||
|
||
function zoom() {
|
||
const px = W ? frames[0].clientWidth * Z.k / W : 0; // px d'écran par px de l'image
|
||
for (const f of frames) {
|
||
f.querySelector(".layer").style.transform = `translate(${Z.x * 100}%, ${Z.y * 100}%) scale(${Z.k})`;
|
||
if (px) f.querySelector("svg").style.fontSize = `${12 / px}px`; // les noms restent à 12 px à l'écran
|
||
}
|
||
}
|
||
|
||
function fit(box) { // cadre en pixels de l'image ({x: [x0, x1], y: [y0, y1]}), ou rien pour l'image entière
|
||
if (!box || !W) Z = { k: 1, x: 0, y: 0 };
|
||
else {
|
||
const [u0, u1] = box.x.map(x => x / W), [v0, v1] = box.y.map(y => y / H), k = Math.min(1 / (u1 - u0), 1 / (v1 - v0));
|
||
Z = { k, x: 0.5 - k * (u0 + u1) / 2, y: 0.5 - k * (v0 + v1) / 2 };
|
||
}
|
||
zoom();
|
||
}
|
||
|
||
function play(on) { // film : l'image suivante une fois les images décodées, au rythme choisi ; arrêt à la dernière
|
||
playing = on;
|
||
const me = ++run;
|
||
playBtn.textContent = on ? "❚❚ Pause" : "▶ Play";
|
||
if (!on) return drawStrips(); // à l'arrêt, les images d'avant et d'après reviennent
|
||
if (V === IM.length - 1) show(0);
|
||
const step = () => {
|
||
if (me !== run) return;
|
||
if (V === IM.length - 1) return play(false);
|
||
show(V + 1);
|
||
Promise.all(frames.map(f => f.querySelector("img").decode().catch(() => {})))
|
||
.then(() => setTimeout(step, 1000 / document.getElementById("v-speed").value));
|
||
};
|
||
setTimeout(step, 1000 / document.getElementById("v-speed").value);
|
||
}
|
||
|
||
for (const f of frames) {
|
||
f.addEventListener("wheel", ev => { // zoom autour du pointeur
|
||
ev.preventDefault();
|
||
const r = f.getBoundingClientRect(), u = (ev.clientX - r.left) / r.width, v = (ev.clientY - r.top) / r.height;
|
||
const k = Math.min(40, Math.max(1, Z.k * Math.exp(-ev.deltaY / 500)));
|
||
Z = { k, x: u - k * (u - Z.x) / Z.k, y: v - k * (v - Z.y) / Z.k };
|
||
zoom();
|
||
}, { passive: false });
|
||
f.addEventListener("pointerdown", ev => { // déplacement à la souris
|
||
f.setPointerCapture(ev.pointerId);
|
||
const r = f.getBoundingClientRect(), from = { ...Z, cx: ev.clientX, cy: ev.clientY };
|
||
f.onpointermove = e => { Z.x = from.x + (e.clientX - from.cx) / r.width; Z.y = from.y + (e.clientY - from.cy) / r.height; zoom(); };
|
||
f.onpointerup = () => (f.onpointermove = null);
|
||
});
|
||
f.addEventListener("dblclick", () => fit(D.view));
|
||
}
|
||
|
||
// Gros plan d'une cible, pour son aspect d'une heure ou d'un jour à l'autre (perte de visibilité, obstacle…), pas pour
|
||
// son déplacement : chaque vignette est centrée sur x, y mesurés à sa propre heure (la position médiane du capteur
|
||
// s'il n'y a pas de mesure), pixels non lissés. Une rangée par image du haut (T, et sa comparaison à ±24 h) : au centre,
|
||
// en grand, l'image du haut ; de part et d'autre, les images d'avant et d'après, au pas choisi.
|
||
const tName = document.getElementById("t-name"), tR = document.getElementById("t-r");
|
||
const tStep = document.getElementById("t-step"), tSide = document.getElementById("t-side");
|
||
const ALSO = new Set(), also = document.getElementById("t-also"); // capteurs montrés en plus de la cible du gros plan
|
||
const short = t => `${+t.slice(8, 10)}/${+t.slice(5, 7)} ${t.slice(11, 16)}`;
|
||
const BIG = 300, SMALL = 140; // côté des vignettes à l'écran, en px
|
||
let stripTimer = null, loading = [];
|
||
|
||
function crop(canvas, img, s, t) { // gros plan de s dans img (heure t) ; false s'il n'y a pas de x, y à cette heure
|
||
const r = +tR.value, j = t ? nearestIndex(Date.parse(t), TMS) : -1, measured = j >= 0 && s.x[j] !== null;
|
||
const [cx, cy] = measured ? [s.x[j], s.y[j]] : s.home;
|
||
const ctx = canvas.getContext("2d"), n = canvas.width;
|
||
ctx.imageSmoothingEnabled = n < 2 * r;
|
||
ctx.fillStyle = "#000";
|
||
ctx.fillRect(0, 0, n, n);
|
||
if (img) ctx.drawImage(img, Math.round(cx) - r, Math.round(cy) - r, 2 * r, 2 * r, 0, 0, n, n);
|
||
return measured;
|
||
}
|
||
|
||
function shift(min) { // décalage en texte : −2 h, +1 d, +15 min
|
||
const a = Math.abs(min);
|
||
return (min < 0 ? "−" : "+") + (a % 1440 === 0 ? `${a / 1440} d` : a % 60 === 0 ? `${a / 60} h` : `${a} min`);
|
||
}
|
||
|
||
function drawStrips() { // un peu après le dernier changement, pour ne pas charger chaque pas du glisseur
|
||
clearTimeout(stripTimer);
|
||
stripTimer = setTimeout(() => {
|
||
loading.forEach(im => (im.src = "")); // abandonne les images encore en chargement
|
||
loading = [];
|
||
const box = document.getElementById("t-strips"), primary = +tName.value;
|
||
const shown = [primary, ...[...ALSO].filter(i => i !== primary)].filter(i => S[i]); // la cible d'abord
|
||
const step = +tStep.value, side = playing ? 0 : +tSide.value, big = shown.length > 1 ? 200 : BIG; // en film : l'image du haut seule
|
||
const todo = new Map(); // image -> vignettes à y découper : chaque image n'est chargée qu'une fois
|
||
box.innerHTML = "";
|
||
for (const n of cmp ? [0, cmp] : [0]) for (const i of shown) { // groupées par heure : les capteurs l'un sous l'autre
|
||
const s = S[i], row = document.createElement("div"), base = IMS[V] + n * DAY;
|
||
row.className = "strip";
|
||
box.append(row);
|
||
for (let k = -side; k <= side; k++) {
|
||
const idx = nearestIndex(base + k * step * 60e3), size = k ? SMALL : big;
|
||
const label = k ? shift(k * step) : `${s.name} · ${n ? (n > 0 ? "+24 h" : "−24 h") : "T"}`;
|
||
const fig = document.createElement("figure");
|
||
if (!k) fig.className = "now";
|
||
fig.innerHTML = `<canvas width="${size}" height="${size}"></canvas><figcaption></figcaption>`;
|
||
row.append(fig);
|
||
const canvas = fig.querySelector("canvas"), cap = fig.querySelector("figcaption");
|
||
crop(canvas, null, s, null);
|
||
if (idx < 0) {
|
||
cap.textContent = `${label}\nno image`;
|
||
continue;
|
||
}
|
||
const err = errorText(s, IM[idx].t);
|
||
cap.textContent = `${label} · ${short(IM[idx].t)}\n${err ? err.text : "no error_value"}`;
|
||
cap.classList.toggle("over", !!err && err.over);
|
||
if (k) {
|
||
canvas.title = "Show this image above";
|
||
canvas.addEventListener("click", () => show(idx));
|
||
}
|
||
if (!todo.has(idx)) todo.set(idx, []);
|
||
todo.get(idx).push({ canvas, cap, s });
|
||
}
|
||
}
|
||
for (const [idx, tiles] of todo) {
|
||
const img = new Image();
|
||
img.onload = () => tiles.forEach(({ canvas, cap, s }) => {
|
||
if (!crop(canvas, img, s, IM[idx].t)) cap.textContent += "\nno x, y: median position";
|
||
});
|
||
img.src = IM[idx].src;
|
||
loading.push(img);
|
||
}
|
||
}, 120);
|
||
}
|
||
|
||
S.forEach((s, i) => { if (s.home) tName.add(new Option(`${s.name} · ${s.kind}`, i)); });
|
||
also.innerHTML = S.map((s, i) => (s.home ? `<button type="button" data-i="${i}">${s.name}</button>` : "")).join("");
|
||
const markAlso = () => also.querySelectorAll("button").forEach(b => b.classList.toggle("active", ALSO.has(+b.dataset.i)));
|
||
also.addEventListener("click", ev => { // un clic ajoute le capteur aux rangées, un second le retire
|
||
const b = ev.target.closest("button");
|
||
if (!b) return;
|
||
b.blur();
|
||
ALSO.has(+b.dataset.i) ? ALSO.delete(+b.dataset.i) : ALSO.add(+b.dataset.i);
|
||
markAlso();
|
||
drawStrips();
|
||
});
|
||
for (const name of (ASKED.get("also") || "").split(",")) if (NAMES.includes(name)) ALSO.add(NAMES.indexOf(name));
|
||
document.getElementById("t-data").addEventListener("click", () => activate(tabButton("diagnosis"))); // vers les données
|
||
markAlso();
|
||
const wanted = NAMES.indexOf(ASKED.get("target") || "PR17");
|
||
if (wanted >= 0 && S[wanted].home) tName.value = wanted;
|
||
for (const sel of [tName, tR, tStep, tSide]) sel.addEventListener("change", () => {
|
||
sel.blur(); // les flèches reviennent aux images
|
||
drawStrips();
|
||
if (sel === tName) { // la cible du gros plan : soulignée sur les grandes images, et ses rejets sous le glisseur
|
||
redrawMarks();
|
||
drawBand();
|
||
}
|
||
});
|
||
|
||
// Deux bandes sous le glisseur, une colonne par image, couleur des cercles (errorColor) : en haut, le système entier,
|
||
// moyenne sur les capteurs mesurés de error_value / seuil du capteur (rouge si la moyenne dépasse 1) ; en bas, la cible
|
||
// du gros plan, error_value face à son seuil. Les boutons mènent au début de l'épisode de rejet (de la cible) précédent
|
||
// ou suivant ; le survol donne le détail.
|
||
const IMJ = IMS.map(t => nearestIndex(t, TMS)); // mesure de chaque image, -1 sans mesure à 10 min près
|
||
const SYSTEM = IMJ.map(j => { // par image : moyenne des error_value / seuil, et nombre de capteurs rejetés / mesurés
|
||
const r = j < 0 ? [] : S.filter(s => s.values.error_value[j] !== null && s.threshold > 0)
|
||
.map(s => s.values.error_value[j] / s.threshold);
|
||
return r.length ? { mean: r.reduce((a, b) => a + b) / r.length, over: r.filter(v => v > 1).length, n: r.length } : null;
|
||
});
|
||
const band = document.getElementById("v-band");
|
||
let over = []; // par image : true si la cible dépasse son seuil, false en dessous, null sans valeur
|
||
|
||
function drawBand() {
|
||
const s = S[+tName.value];
|
||
if (!s) return;
|
||
const errs = IMJ.map(j => (j < 0 ? null : s.values.error_value[j]));
|
||
over = errs.map(e => (e === null ? null : e > s.threshold));
|
||
band.width = Math.max(1, IM.length);
|
||
const ctx = band.getContext("2d"); // ligne 0 : système ; ligne 1 : vide ; ligne 2 : cible
|
||
ctx.clearRect(0, 0, band.width, band.height);
|
||
errs.forEach((e, k) => {
|
||
ctx.fillStyle = errorColor(SYSTEM[k] && SYSTEM[k].mean, 1);
|
||
ctx.fillRect(k, 0, 1, 1);
|
||
ctx.fillStyle = errorColor(e, s.threshold);
|
||
ctx.fillRect(k, 2, 1, 1);
|
||
});
|
||
document.getElementById("v-rej").textContent =
|
||
`${s.name} above its threshold (${s.threshold}): ${over.filter(o => o).length} images in ${episodes().length} episodes`;
|
||
}
|
||
const episodes = () => over.map((o, k) => (o && !over[k - 1] ? k : -1)).filter(k => k >= 0); // début de chaque épisode
|
||
document.getElementById("v-prev-rej").addEventListener("click", ev => {
|
||
ev.currentTarget.blur();
|
||
const k = episodes().filter(k => k < V).pop();
|
||
if (k !== undefined) show(k);
|
||
});
|
||
document.getElementById("v-next-rej").addEventListener("click", ev => {
|
||
ev.currentTarget.blur();
|
||
const k = episodes().find(k => k > V);
|
||
if (k !== undefined) show(k);
|
||
});
|
||
const bandIndex = ev => {
|
||
const r = band.getBoundingClientRect();
|
||
return Math.max(0, Math.min(IM.length - 1, Math.round((ev.clientX - r.left) / r.width * (IM.length - 1))));
|
||
};
|
||
band.addEventListener("click", ev => show(bandIndex(ev)));
|
||
band.addEventListener("mousemove", ev => { // détail de l'image sous le pointeur
|
||
const k = bandIndex(ev), sys = SYSTEM[k], s = S[+tName.value], e = IMJ[k] < 0 ? null : s.values.error_value[IMJ[k]];
|
||
band.title = `${utc(IM[k].t)}\nAll sensors: ${sys ? `mean error_value / threshold ${sys.mean.toFixed(2)}, ` +
|
||
`${sys.over} of ${sys.n} above threshold` : "no value"}\n${s.name}: ${e === null ? "no value" :
|
||
`error_value ${e.toFixed(2)} ${e > s.threshold ? ">" : "≤"} ${s.threshold}`}`;
|
||
});
|
||
if (IM.length) drawBand();
|
||
for (const id of ["v-marks", "v-color"]) document.getElementById(id).addEventListener("change", ev => {
|
||
ev.target.blur();
|
||
redrawMarks();
|
||
});
|
||
|
||
const jumpDay = d => { const k = nearestIndex(Date.parse(IM[V].t) + d * DAY); if (k >= 0) show(k); };
|
||
document.addEventListener("keydown", ev => {
|
||
if (!document.getElementById("view").classList.contains("active")) return;
|
||
if (ev.target.matches("select, input:not([type=range])")) return; // les flèches restent au champ qui a le focus
|
||
const d = { ArrowLeft: -1, ArrowRight: 1 }[ev.key];
|
||
if (ev.key === " ") play(!playing);
|
||
else if (d) ev.shiftKey ? jumpDay(d) : show(V + d);
|
||
else return;
|
||
ev.preventDefault(); // ni défilement de la page, ni second pas du glisseur s'il a le focus
|
||
});
|
||
document.querySelector("#view .toolbar").addEventListener("click", ev => {
|
||
const b = ev.target.closest("button");
|
||
if (!b) return;
|
||
b.blur(); // la barre d'espace reste au film, sans recliquer le bouton
|
||
if (b.dataset.cmp !== undefined) setCompare(+b.dataset.cmp);
|
||
else if (b.id === "v-prev") show(V - 1);
|
||
else if (b.id === "v-next") show(V + 1);
|
||
else if (b.id === "v-play") play(!playing);
|
||
else if (b.id === "v-targets") fit(D.view);
|
||
else if (b.id === "v-full") fit(null);
|
||
});
|
||
slider.max = Math.max(0, IM.length - 1);
|
||
slider.addEventListener("input", () => show(+slider.value));
|
||
const daysBar = document.getElementById("v-days");
|
||
IM.forEach((im, k) => { // une étiquette sous le glisseur au début de chaque jour UTC
|
||
if (k && im.t.slice(0, 10) === IM[k - 1].t.slice(0, 10)) return;
|
||
daysBar.insertAdjacentHTML("beforeend",
|
||
`<span style="left:${100 * k / Math.max(1, IM.length - 1)}%">${+im.t.slice(8, 10)}/${+im.t.slice(5, 7)}</span>`);
|
||
});
|
||
if (ASKED.get("img")) { const k = nearestIndex(Date.parse(ASKED.get("img"))); if (k >= 0) V = k; }
|
||
if (IM.length) setCompare(cmp);
|
||
else document.querySelector("#view .viewer").innerHTML = '<p class="empty">No image in this folder.</p>';
|
||
|
||
// Onglet Displacements (D-055) : sauts brutaux qui durent et tendances, calculés par explore.py (regime_changes) ; les sauts
|
||
// groupés en événements, dans l'ordre du temps ; à côté, toutes les courbes en mm, en gris, celles qui ont sauté ou dérivé
|
||
// en couleur. Le survol d'une ligne la montre sur les courbes (focusOn) ; un clic ouvre l'onglet Diagnosis sur cette cible
|
||
// à cette heure. Données inchangées.
|
||
const REG = D.regime, TRENDS = D.trends, RCOL = {}, RULES = D.rules, GREY = "#d3d8de", INK = "#222";
|
||
[...REG.flatMap(e => e.targets), ...TRENDS.map(f => f.target)]
|
||
.forEach(n => { if (!(n in RCOL)) RCOL[n] = PALETTE[Object.keys(RCOL).length % PALETTE.length]; });
|
||
const signed = (v, d = 1) => `${v > 0 ? "+" : v < 0 ? "−" : ""}${Math.abs(v).toFixed(d)} mm`;
|
||
const dot = n => `<i style="background:${RCOL[n]}"></i>${n}`;
|
||
const dm = t => `${+t.slice(8, 10)}/${+t.slice(5, 7)}`;
|
||
document.getElementById("r-note").textContent = `A sudden change that stays: within 2 h, the target moves at least ` +
|
||
`${RULES.abrupt} × as much as it usually does in 2 h, and its level over the next 24 h differs from the previous 24 h ` +
|
||
`by at least ${RULES.size} × its usual daily swing (median of max − min per UTC day). Daily and weather cycles are slow ` +
|
||
`and come back; these do not. Jumps within 6 h of each other form one event. Hourly export in mm, unchanged.`;
|
||
document.getElementById("r-trend-note").textContent = `A slow, steady drift: the daily level (median of each UTC day, ` +
|
||
`jumps above set aside) keeps moving the same way, and drifts over the period by at least ${RULES.trend_size} × the ` +
|
||
`usual daily swing. Needs ${RULES.trend_days} full days or more.`;
|
||
document.getElementById("r-events").innerHTML = REG.length ? REG.map((e, n) => `
|
||
<details${e.jumps.length <= 4 ? " open" : ""}><summary data-k="e${n}"><b>${short(e.start)} → ${e.end.slice(0, 10) ===
|
||
e.start.slice(0, 10) ? e.end.slice(11, 16) : short(e.end)} UTC</b>
|
||
· ${e.targets.length === 1 ? `${e.targets[0]} alone` : `${e.targets.length} targets together`}</summary>
|
||
<table class="rtable"><thead><tr><th>Target</th><th>Axis</th><th>When (UTC)</th><th>Jump</th><th>Daily swing</th>
|
||
<th>Left at end</th></tr></thead><tbody>${e.jumps.map((f, m) => `
|
||
<tr data-k="j${n}-${m}" data-target="${f.target}" data-t="${f.t2}" title="Click: open in Diagnosis"><td>${dot(f.target)}</td>
|
||
<td>${f.axis}</td><td>${short(f.t)} → ${f.t2.slice(11, 16)}</td><td>${signed(f.jump)}</td><td>${f.swing.toFixed(1)} mm</td>
|
||
<td>${signed(f.left)}</td></tr>`).join("")}
|
||
</tbody></table></details>`).join("")
|
||
: '<p class="empty">No jump: no target changed suddenly and stayed there.</p>';
|
||
document.getElementById("r-trends").innerHTML = TRENDS.length ? `<table class="rtable"><thead><tr><th>Target</th><th>Axis</th>
|
||
<th>Drift</th><th>Per day</th><th>Daily swing</th><th>Days</th><th>Jumps set aside</th></tr></thead>
|
||
<tbody>${TRENDS.map((f, n) => `<tr data-k="t${n}" data-target="${f.target}" data-t="${f.t}" title="Click: open in Diagnosis">
|
||
<td>${dot(f.target)}</td><td>${f.axis}</td><td>${signed(f.drift)}</td><td>${signed(f.slope, 2)}</td>
|
||
<td>${f.swing.toFixed(1)} mm</td><td>${f.days + 1}</td><td>${f.jumps || ""}</td></tr>`).join("")}</tbody></table>`
|
||
: '<p class="empty">No trend: no daily level drifted steadily by more than its daily swing.</p>';
|
||
document.getElementById("displacements").addEventListener("click", ev => { // une ligne : Diagnosis, cette cible à cette heure
|
||
const tr = ev.target.closest("tr[data-target]");
|
||
if (!tr) return;
|
||
activate(tabButton("diagnosis"), false);
|
||
const i = NAMES.indexOf(tr.dataset.target), j = nearestIndex(Date.parse(tr.dataset.t), TMS);
|
||
if (i >= 0) SEL = [i];
|
||
if (j >= 0) setT(j);
|
||
markTargets();
|
||
drawCurves();
|
||
});
|
||
|
||
// Ce que montre le survol, par ligne (data-k) : la ou les cibles gardées en couleur, les autres en gris ; des formes et des
|
||
// annotations sur les courbes. Saut : ses 2 h surlignées, les niveaux des 24 h d'avant et d'après (médianes, ceux de la
|
||
// détection) en pointillés, une flèche de l'un à l'autre. Tendance : sa période, la droite de Theil-Sen en tirets, les
|
||
// niveaux journaliers en points, le début et la fin marqués, la dérive en flèche depuis le niveau de départ. Les échelles
|
||
// ne bougent pas au survol : on sait toujours ce qu'on regarde (utilisateur, 2026-10-19).
|
||
const AX = { horizontal: "y", vertical: "y2" };
|
||
const seg = (x0, x1, y0, y1, yref, line) => ({ type: "line", xref: "x", yref, x0, x1, y0, y1, line });
|
||
const zone = (x0, x1, fillcolor, opacity) => ({ type: "rect", xref: "x", yref: "paper", x0, x1, y0: 0, y1: 1, fillcolor, opacity,
|
||
line: { width: 0 }, layer: "below" });
|
||
const label = (x, y, yref, text, more) => ({ x, y, xref: "x", yref, text, showarrow: false, bgcolor: "rgba(255,255,255,.85)", borderpad: 3,
|
||
font: { size: 12, color: INK }, ...more });
|
||
const arrow = (x, from, to, yref) => ({ x, y: to, ax: x, ay: from, xref: "x", yref, axref: "x", ayref: yref, text: "",
|
||
showarrow: true, arrowhead: 2, arrowsize: 1.2, arrowwidth: 2, arrowcolor: INK });
|
||
const ITEMS = {};
|
||
REG.forEach((e, n) => {
|
||
ITEMS[`e${n}`] = { targets: e.targets, shapes: [zone(e.start, e.end, "#d03b3b", .15)] };
|
||
e.jumps.forEach((f, m) => {
|
||
const ya = AX[f.axis], up = f.jump > 0, small = { size: 11, color: INK };
|
||
ITEMS[`j${n}-${m}`] = { targets: [f.target],
|
||
shapes: [zone(f.t, f.t2, RCOL[f.target], .25),
|
||
seg(f.w0, f.t, f.before, f.before, ya, { color: INK, width: 2, dash: "dot" }),
|
||
seg(f.t2, f.w1, f.after, f.after, ya, { color: INK, width: 2, dash: "dot" })],
|
||
annotations: [arrow(f.t2, f.before, f.after, ya),
|
||
label(f.t2, (f.before + f.after) / 2, ya, `<b>${signed(f.jump)}</b> in 2 h<br>${f.target} ${f.axis}`,
|
||
{ xanchor: "left", xshift: 10, align: "left", bordercolor: RCOL[f.target] }),
|
||
label(f.w0, f.before, ya, "level, 24 h before", { xanchor: "left", yanchor: up ? "top" : "bottom", font: small }),
|
||
label(f.w1, f.after, ya, "level, 24 h after", { xanchor: "right", yanchor: up ? "bottom" : "top", font: small })] };
|
||
});
|
||
});
|
||
TRENDS.forEach((f, n) => {
|
||
const ya = AX[f.axis], L = f.line, [t0, y0] = L[0], [t1, y1] = L[L.length - 1], from = y1 - f.drift, up = f.drift > 0;
|
||
ITEMS[`t${n}`] = { targets: [f.target], yaxis: ya,
|
||
levels: f.levels, ends: [L[0], L[L.length - 1]],
|
||
shapes: [zone(t0, t1, RCOL[f.target], .07),
|
||
...L.slice(1).map((p, k) => seg(L[k][0], p[0], L[k][1], p[1], ya, { color: INK, width: 2.5, dash: "dash" })),
|
||
seg(t0, t1, from, from, ya, { color: INK, width: 1, dash: "dot" })],
|
||
annotations: [arrow(t1, from, y1, ya),
|
||
label(t1, (from + y1) / 2, ya, `<b>${signed(f.drift)}</b> from ${dm(t0)} to ${dm(t1)}<br>${signed(f.slope, 2)} per day`,
|
||
{ xanchor: "right", xshift: -10, align: "right", bordercolor: RCOL[f.target] }),
|
||
label(t0, y0, ya, `<b>start</b> ${dm(t0)} · ${y0.toFixed(1)} mm`, { xanchor: "left", yanchor: up ? "top" : "bottom",
|
||
yshift: up ? -8 : 8 }),
|
||
label(t1, y1, ya, `<b>end</b> ${dm(t1)} · ${y1.toFixed(1)} mm`, { xanchor: "right", yanchor: up ? "bottom" : "top",
|
||
yshift: up ? 8 : -8 })] };
|
||
});
|
||
|
||
const RNOTE = { text: "grey: the other targets · hourly export, in mm, hour start in UTC", xref: "paper", yref: "paper",
|
||
x: 1, y: 1.07, xanchor: "right", showarrow: false, font: { size: 11, color: "#73879c" } };
|
||
let FOCUS = null, OV = 0; // ligne survolée ; OV : index des deux traces du survol (niveaux journaliers, début et fin)
|
||
function focusOn(k) {
|
||
const gd = document.getElementById("r-curves");
|
||
if (k === FOCUS || !gd.data) return;
|
||
FOCUS = k;
|
||
document.querySelectorAll("#displacements [data-k]").forEach(e => e.classList.toggle("on", e.dataset.k === k));
|
||
const it = ITEMS[k], curves = gd.data.slice(0, OV), lit = n => it.targets.includes(n);
|
||
Plotly.restyle(gd, {
|
||
"line.color": curves.map(t => !it ? RCOL[t.name] || GREY : lit(t.name) ? RCOL[t.name] || INK : GREY),
|
||
"line.width": curves.map(t => !it ? (RCOL[t.name] ? 2 : 1) : lit(t.name) ? 2.5 : 1),
|
||
}, curves.map((_, i) => i));
|
||
const ov = it && it.levels ? [it.levels, it.ends] : [[], []];
|
||
Plotly.restyle(gd, { x: ov.map(p => p.map(q => q[0])), y: ov.map(p => p.map(q => q[1])), yaxis: it && it.yaxis || "y",
|
||
"marker.color": [it ? RCOL[it.targets[0]] : INK, INK] }, [OV, OV + 1]);
|
||
const upd = { shapes: it ? it.shapes : [], annotations: [RNOTE, ...(it && it.annotations || [])] };
|
||
Plotly.relayout(gd, upd);
|
||
}
|
||
document.querySelector("#displacements .rlist").addEventListener("mouseover", ev => { // hors d'une ligne : plus de survol
|
||
const el = ev.target.closest("[data-k]");
|
||
focusOn(el ? el.dataset.k : null);
|
||
});
|
||
|
||
function drawRegime() { // toutes les cibles en gris fin, celles qui ont sauté ou dérivé en couleur par-dessus
|
||
const grey = [], lit = [];
|
||
for (const [name, mm] of Object.entries(D.hourly.sensors)) [["h", "horizontal"], ["v", "vertical"]].forEach(([k, label], r) => {
|
||
const c = RCOL[name];
|
||
(c ? lit : grey).push({ type: "scatter", mode: "lines", x: D.hourly.times, y: mm[k], name, legendgroup: name,
|
||
showlegend: !!c && !r && Object.keys(RCOL).length <= 8, yaxis: `y${r ? 2 : ""}`, line: { color: c || GREY, width: c ? 2 : 1 }, // légende au-delà de 8 : couvre les courbes
|
||
hovertemplate: `${name} · %{x|%d %b %H:%M} UTC (hour start)<br>${label} %{y:.2f} mm<extra></extra>` });
|
||
});
|
||
if (!grey.length && !lit.length) {
|
||
document.getElementById("r-curves").innerHTML = '<p class="empty">No hourly export: no displacement in mm.</p>';
|
||
return;
|
||
}
|
||
OV = grey.length + lit.length;
|
||
const over = (name, marker) => ({ type: "scatter", mode: "markers", x: [], y: [], name, showlegend: false, marker,
|
||
hovertemplate: `${name} · %{x|%d %b} · %{y:.2f} mm<extra></extra>` });
|
||
Plotly.newPlot("r-curves", [...grey, ...lit, over("daily level (median of the UTC day)", { size: 8, line: { color: "#fff", width: 1.5 } }),
|
||
over("trend line", { size: 12 })], {
|
||
height: Math.max(420, Math.min(640, innerHeight - 30)), margin: { l: 60, r: 10, t: 40, b: 40 },
|
||
legend: { orientation: "h", x: 0, y: 1.07 }, xaxis: { type: "date", anchor: "y2" },
|
||
yaxis: { domain: [0.53, 1], fixedrange: true, title: { text: "horizontal (mm)" } },
|
||
yaxis2: { domain: [0, 0.47], fixedrange: true, title: { text: "vertical (mm)" } },
|
||
annotations: [RNOTE],
|
||
}, CONFIG).then(() => {
|
||
autoscale("r-curves");
|
||
Plotly.relayout("r-curves", { "xaxis.range": document.getElementById("r-curves").layout.xaxis.range.slice() }); // ordonnées
|
||
// fixées sur les données : les formes du survol ne les élargissent plus
|
||
if (ITEMS[ASKED.get("focus")]) focusOn(ASKED.get("focus")); // ligne survolée au départ (#focus=j0-0, t0…) : pour les captures
|
||
});
|
||
}
|
||
|
||
drawRegime();
|
||
|
||
// Onglet Journal (spec « L'onglet Journal ») : le journal du matin du client. Courbes corr_x et corr_y des cibles, zones à
|
||
// ignorer grisées, une frise d'une seule ligne « What happened » (une barre par événement, sa catégorie dedans), puis le
|
||
// journal de la plage visible, une carte par événement.
|
||
const J = D.journal, J_ROW = "What happened";
|
||
// une couleur par famille d'événement : gris-bleu ce qu'il faut ignorer (zone grisée), orange les données moyennes
|
||
// (visibilité réduite, zone en léger retrait), vert ce qui est normal (l'effet périodique), gris clair l'absence de données, rouge ce qu'il faut
|
||
// vérifier
|
||
const J_FAM = { ignore: "#6f8aa3", reduced: "#f0a030", normal: "#2ca02c", gap: "#c8c8c8", check: "#d62728" };
|
||
// ordre de dessin de la frise, de dessous à dessus, une famille de labeling/familles.md par ligne : ce qui touche une
|
||
// cible, puis toute la scène, Displacement en haut
|
||
const J_ORDER = ["Target issue", "Obstruction", "Thermal displacement", "No data", "Visibility", "Displacement"];
|
||
const J_LOCAL = ["Obstruction", "Target issue"]; // une cible, pas la scène : seule sa courbe est coupée
|
||
const jFam = e => e.category === "Displacement" ? "check" : e.category === "No data" ? "gap"
|
||
: e.category === "Visibility" && !e.ignore ? "reduced" : e.ignore ? "ignore" : "normal";
|
||
const MON = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
|
||
const jWhen = t => `${MON[+t.slice(5, 7) - 1]} ${+t.slice(8, 10)}, ${t.slice(11, 16)}`;
|
||
const plotT = ms => new Date(ms).toISOString().slice(0, 19).replace("T", " "); // instant en ms -> date Plotly (UTC)
|
||
const jEnd = e => Math.max(Date.parse(e.end), Date.parse(e.start) + 3600e3); // dessin : 1 h au moins, sinon invisible
|
||
|
||
// unité des courbes (point 20) : mm par défaut, les moyennes horaires que la plateforme montre au client (export
|
||
// horaire) ; px, chaque mesure de l'export « advanced » (corr_x, corr_y), pics d'une mesure compris ; #unit=px : captures
|
||
// vue support (point 23) : une ligne par détecteur sous « What happened » et le repli Details de chaque carte, avec les
|
||
// épisodes d'origine ; la vue client reste celle du point 8 ; #support pour les captures
|
||
let J_SUPPORT = ASKED.has("support");
|
||
// frise dépliée (point 40) : une ligne par catégorie présente, dans l'ordre de J_ORDER (Displacement en haut) ;
|
||
// repliée, la ligne unique du point 8 ; #expand pour les captures
|
||
let J_EXPAND = ASKED.has("expand");
|
||
const J_DET = { Visibility: ["Visibility", "#1f77b4"], Obstruction: ["Obstruction", "#ff7f0e"], "Target issue": ["Target issue", "#9467bd"],
|
||
Displacement: ["Displacement", "#d62728"], "Thermal displacement": ["Thermal displacement", "#2ca02c"], "No data": ["No data", "#7f7f7f"] };
|
||
let J_UNIT = ASKED.get("unit") === "px" || !Object.keys(D.hourly.sensors).length ? "px" : "mm"; // px sans export horaire
|
||
const J_PAL = PALETTE.filter(c => c !== "#7f7f7f"); // sans le gris, réservé à la brute à ignorer (point 25)
|
||
const jColor = name => J_PAL[Math.max(0, S.findIndex(s => s.name === name)) % J_PAL.length]; // même couleur en mm et en px
|
||
function jSeries() { // [{name, times, h, v}] : les courbes dans l'unité choisie
|
||
if (J_UNIT === "px") return S.filter(s => s.kind === "target" || s.kind === "ref")
|
||
.map(s => ({ name: s.name, times: D.times, h: s.values.corr_x, v: s.values.corr_y }));
|
||
return Object.entries(D.hourly.sensors).map(([name, mm]) => ({ name, times: D.hourly.times, h: mm.h, v: mm.v }));
|
||
}
|
||
|
||
function drawJournal(range) {
|
||
const series = jSeries(), AXES = [["h", "Horizontal"], ["v", "Vertical"]];
|
||
// l'échelle verticale laisse de côté les points des zones grisées et des cibles masquées (point 19) : un pic qu'on
|
||
// doit ignorer n'écrase plus les autres courbes ; ils restent dessinés, hors cadre si besoin
|
||
const step = J_UNIT === "mm" ? 3599e3 : 0; // en mm, une moyenne horaire couvre toute son heure (point 25)
|
||
const inside = (e, t) => { const T = Date.parse(t); return T <= Date.parse(e.end) && T + step >= Date.parse(e.start); };
|
||
const scene = J.filter(e => e.ignore && !J_LOCAL.includes(e.category));
|
||
const skip = s => { const h = J.filter(e => J_LOCAL.includes(e.category) && e.sensors.includes(s.name));
|
||
return s.times.map(t => scene.some(e => inside(e, t)) || h.some(e => inside(e, t))); };
|
||
// courbe nettoyée (point 25, option A) : la brute sans les points à ignorer, coupée là, rien d'interpolé ; la brute y
|
||
// reste en gris fin, reliée aux points gardés de part et d'autre (sinon un point seul, un passage, ne se verrait pas) ;
|
||
// une cible masquée n'est coupée que sur sa courbe, pas sur tout le fond (point 18)
|
||
const traces = series.flatMap(s => { const yskip = skip(s), near = yskip.map((v, k) => v || yskip[k - 1] || yskip[k + 1]);
|
||
return AXES.flatMap(([c, label], r) => [{
|
||
type: "scatter", mode: "lines", x: s.times, y: s[c].map((v, k) => yskip[k] ? null : v), yaxis: `y${r ? 2 : ""}`,
|
||
name: s.name, showlegend: false, line: { color: jColor(s.name), width: 1 }, meta: { yskip },
|
||
hovertemplate: `${s.name} · %{x|%d %b %H:%M} UTC<br>${label} %{y:.2f} ${J_UNIT}<extra></extra>` }, {
|
||
type: "scatter", mode: "lines", x: s.times, y: s[c].map((v, k) => near[k] ? v : null), yaxis: `y${r ? 2 : ""}`,
|
||
name: s.name, showlegend: false, line: { color: "#b0b0b0", width: 1 }, meta: { yskip: s.times.map(() => true) },
|
||
hovertemplate: `${s.name} (raw, to ignore) · %{x|%d %b %H:%M} UTC<br>${label} %{y:.2f} ${J_UNIT}<extra></extra>` }]); });
|
||
// frise : une barre par événement, de son début à sa fin, dans l'ordre de J_ORDER ; une barre perd son étiquette quand
|
||
// une barre dessinée par-dessus couvre son milieu (sinon les textes se mêlent ; le survol dit tout)
|
||
const bars = [...J].sort((u, v) => J_ORDER.indexOf(u.category) - J_ORDER.indexOf(v.category));
|
||
const mid = e => (Date.parse(e.start) + jEnd(e)) / 2;
|
||
const covered = e => !J_EXPAND && bars.slice(bars.indexOf(e) + 1).some(o => Date.parse(o.start) <= mid(e) && jEnd(o) >= mid(e));
|
||
traces.push({ type: "bar", orientation: "h", yaxis: "y3", name: "events", showlegend: false,
|
||
y: bars.map(e => J_EXPAND ? e.label : J_ROW), base: bars.map(e => e.start), x: bars.map(e => jEnd(e) - Date.parse(e.start)),
|
||
marker: { color: bars.map(e => J_FAM[jFam(e)]), line: { color: "#fff", width: 1 } },
|
||
width: bars.map(e => e.episodes[0].label === "Slow drift" && !J_EXPAND ? 0.2 : 0.75), // repliée, la dérive, longue, en trait fin sous les autres
|
||
text: bars.map(e => covered(e) ? "" : e.label), textposition: "inside", insidetextanchor: "middle",
|
||
insidetextfont: { color: bars.map(e => jFam(e) === "gap" ? "#333" : "#fff") }, customdata: bars.map(e => J.indexOf(e)),
|
||
hovertext: bars.map(e => `<b>${e.label}</b><br>${e.text}<br>Sensors: ${e.sensors.length ? e.sensors.join(", ") : "all"}`),
|
||
hovertemplate: "%{hovertext}<extra></extra>" });
|
||
const eps = J_SUPPORT ? J.flatMap(e => e.episodes) : []; // vue support : les épisodes bruts, une ligne par détecteur
|
||
const kinds = [...new Set([...Object.keys(J_DET), ...eps.map(p => p.kind)])].filter(k => eps.some(p => p.kind === k));
|
||
const row = k => (J_DET[k] || [k])[0];
|
||
for (const k of kinds) {
|
||
const ps = eps.filter(p => p.kind === k);
|
||
traces.push({ type: "bar", orientation: "h", yaxis: "y3", name: k, showlegend: false, y: ps.map(() => row(k)),
|
||
base: ps.map(p => p.start), x: ps.map(p => jEnd(p) - Date.parse(p.start)), marker: { color: (J_DET[k] || [, "#999"])[1] },
|
||
text: ps.map(p => p.label), textposition: "inside", insidetextanchor: "middle", insidetextfont: { color: "#fff" },
|
||
hovertext: ps.map(p => `<b>${p.label}</b> (${k})${p.text ? "<br>" + p.text : ""}<br>Sensors: ${
|
||
p.sensors.length ? p.sensors.join(", ") : "all"}`), hovertemplate: "%{hovertext}<extra></extra>" });
|
||
}
|
||
const cats = J_EXPAND ? [...new Set(bars.map(e => e.label))].reverse() : [J_ROW];
|
||
const rows = [...cats, ...kinds.map(row)];
|
||
const C = 220, G = 24, F = 10 + 30 * rows.length, A = 2 * C + 2 * G + F; // hauteurs en px, A : zone tracée
|
||
const grey = J.filter(e => (e.ignore || jFam(e) === "reduced") && !J_LOCAL.includes(e.category)).flatMap(e => ["y domain", "y2 domain"].map(yref => ({ type: "rect",
|
||
xref: "x", yref, x0: e.start, x1: plotT(jEnd(e)), y0: 0, y1: 1, fillcolor: "#888", opacity: e.ignore ? 0.25 : 0.1,
|
||
line: { width: 0 }, layer: "below" }))); // grisé ; en léger retrait pour une visibilité réduite
|
||
const end = Date.parse(D.times[D.times.length - 1]);
|
||
document.querySelectorAll("#journal [data-unit]").forEach(b => b.classList.toggle("active", b.dataset.unit === J_UNIT));
|
||
Plotly.purge("j-curves"); // redessin au changement d'unité : sans les écouteurs du dessin d'avant
|
||
Plotly.newPlot("j-curves", traces, {
|
||
height: A + 70, margin: { l: 110, r: 10, t: 20, b: 50 }, barmode: "overlay", bargap: 0.25, uniformtext: { mode: "hide", minsize: 10 },
|
||
xaxis: { type: "date", anchor: "y3", range: range || [ASKED.get("from") || plotT(end - 3 * 864e5), plotT(end)] }, // départ : les 3 derniers jours (#from=AAAA-MM-JJ : captures)
|
||
yaxis: { domain: [1 - C / A, 1], fixedrange: true, title: { text: `Horizontal (${J_UNIT})` } },
|
||
yaxis2: { domain: [1 - (2 * C + G) / A, 1 - (C + G) / A], fixedrange: true, title: { text: `Vertical (${J_UNIT})` } },
|
||
yaxis3: { domain: [0, F / A], fixedrange: true, type: "category", categoryorder: "array", categoryarray: rows.slice().reverse(),
|
||
showgrid: false }, // « What happened » (ou une ligne par catégorie) en haut, les détecteurs dessous (vue support)
|
||
shapes: grey,
|
||
}, CONFIG).then(() => {
|
||
autoscale("j-curves"); // les barres de la frise (ordonnées en texte) n'entrent pas dans le recalage
|
||
const gd = document.getElementById("j-curves");
|
||
gd.on("plotly_relayout", () => listJournal(gd.layout.xaxis.range.map(v => Date.parse(minute(v)))));
|
||
gd.on("plotly_click", d => { // clic sur une barre de la frise : son timelapse, s'il y a des images à montrer
|
||
const e = J[d.points[0].customdata];
|
||
if (e && e.process !== "aucun" && jFrames(e).length) openTimelapse(e);
|
||
});
|
||
Plotly.relayout(gd, { "xaxis.range": gd.layout.xaxis.range.slice() }); // ordonnées et journal dès l'ouverture
|
||
});
|
||
}
|
||
|
||
function listJournal([a, b]) { // les événements de la plage visible, dans l'ordre du temps ; clic : zoom sur l'événement
|
||
const eps = J.filter(e => Date.parse(e.end) >= a && Date.parse(e.start) <= b);
|
||
document.getElementById("j-list").innerHTML = eps.length ? eps.map(e => `<div class="jentry" data-n="${J.indexOf(e)}"
|
||
style="border-left-color:${J_FAM[jFam(e)]}"><div class="when">${jWhen(e.start)}${e.end === e.start ? "" : ` – ${
|
||
e.end.slice(0, 10) === e.start.slice(0, 10) ? e.end.slice(11, 16) : jWhen(e.end)}`} UTC</div><b>${e.label}</b> · ${
|
||
e.text}${J_SUPPORT && e.episodes.length ? `<details><summary>Details</summary>${e.episodes.map(p => `<div class="meta">${
|
||
p.kind} · ${p.label} · ${jWhen(p.start)}${p.end === p.start ? "" : ` – ${jWhen(p.end)}`} UTC${
|
||
p.sensors.length ? ` · ${p.sensors.join(", ")}` : ""}</div>`).join("")}</details>` : ""}${e.process === "aucun" ? ""
|
||
: jFrames(e).length ? '<button type="button">▶ Images</button>'
|
||
: '<button type="button" disabled>▶ Images</button> <span class="meta">No camera image for this period.</span>'}</div>`).join("")
|
||
: '<p class="empty">Nothing to report on this period.</p>';
|
||
}
|
||
document.querySelectorAll("#journal [data-unit]").forEach(b => b.addEventListener("click", () => { // même plage de temps
|
||
J_UNIT = b.dataset.unit;
|
||
drawJournal(document.getElementById("j-curves").layout.xaxis.range.slice());
|
||
}));
|
||
const jExpand = document.getElementById("j-expand");
|
||
jExpand.checked = J_EXPAND;
|
||
jExpand.addEventListener("change", () => { // même plage de temps
|
||
J_EXPAND = jExpand.checked;
|
||
drawJournal(document.getElementById("j-curves").layout.xaxis.range.slice());
|
||
});
|
||
const jSupport = document.getElementById("j-support");
|
||
jSupport.checked = J_SUPPORT;
|
||
jSupport.addEventListener("change", () => { // même plage de temps
|
||
J_SUPPORT = jSupport.checked;
|
||
drawJournal(document.getElementById("j-curves").layout.xaxis.range.slice());
|
||
});
|
||
document.getElementById("j-fit").addEventListener("click", () =>
|
||
Plotly.relayout("j-curves", { "yaxis.autorange": true, "yaxis2.autorange": true })); // tous les points, pics compris
|
||
document.getElementById("j-list").addEventListener("click", ev => {
|
||
const el = ev.target.closest("[data-n]");
|
||
if (!el) return;
|
||
if (ev.target.closest("button")) return openTimelapse(J[+el.dataset.n]);
|
||
if (ev.target.closest("details")) return; // le repli Details s'ouvre sans zoomer
|
||
const e = J[+el.dataset.n], a = Date.parse(e.start), b = Date.parse(e.end), m = Math.max((b - a) / 2, 2 * 3600e3); // marge
|
||
Plotly.relayout("j-curves", { "xaxis.range": [plotT(a - m), plotT(b + m)] });
|
||
});
|
||
|
||
// Bouton ▶ Images (point 7 du plan) : le timelapse des images de l'événement, encadré d'une marge avant et après où tout
|
||
// va bien, pour que le client voie tout de suite qu'on ne distinguait plus les cibles. Recadré sur les cibles (D.view,
|
||
// comme le zoom « Targets » de View), en boucle ; pas de fichier GIF, tout est joué ici.
|
||
const J_MARGIN = [3600e3, 6 * 3600e3], J_FPS = 4, J_MAX = 60; // marge : la moitié de la durée, de 1 h à 6 h ; à régler à l'œil
|
||
function jFrames(ev) { // images de la plage, une sur n au-delà de J_MAX, avec leur rôle : avant, pendant ou après
|
||
const a = Date.parse(ev.start), b = Date.parse(ev.end), m = Math.min(J_MARGIN[1], Math.max(J_MARGIN[0], (b - a) / 2));
|
||
const ims = IM.filter(im => Date.parse(im.t) >= a - m && Date.parse(im.t) <= b + m), n = Math.ceil(ims.length / J_MAX);
|
||
return ims.filter((_, k) => k % n === 0).map(im => ({ ...im,
|
||
role: Date.parse(im.t) < a ? "before" : Date.parse(im.t) > b ? "after" : "during" }));
|
||
}
|
||
const jv = document.getElementById("j-video"), jvCanvas = jv.querySelector("canvas"), jvInfo = jv.querySelector(".bar span");
|
||
const jvPause = jv.querySelector('[data-v="p"]'), ROLE = { before: "Before", during: "During", after: "After" };
|
||
let JV = { frames: [], imgs: [], k: 0, run: 0, playing: false };
|
||
function jvShow(k) { // affiche l'image k une fois décodée
|
||
JV.k = (k + JV.frames.length) % JV.frames.length;
|
||
const f = JV.frames[JV.k], img = JV.imgs[JV.k];
|
||
return img.decode().catch(() => {}).then(() => {
|
||
if (!img.naturalWidth) return;
|
||
const v = D.view || { x: [0, img.naturalWidth], y: [0, img.naturalHeight] };
|
||
const x0 = Math.max(0, v.x[0]), y0 = Math.max(0, v.y[0]);
|
||
const w = Math.min(img.naturalWidth, v.x[1]) - x0, h = Math.min(img.naturalHeight, v.y[1]) - y0;
|
||
jvCanvas.width = w; jvCanvas.height = h;
|
||
jvCanvas.getContext("2d").drawImage(img, x0, y0, w, h, 0, 0, w, h);
|
||
jvCanvas.className = f.role === "during" ? "during" : "";
|
||
jvInfo.textContent = `${utc(f.t)} · ${ROLE[f.role]} · ${JV.k + 1} / ${JV.frames.length}`;
|
||
});
|
||
}
|
||
function jvPlay(on) { // lecture en boucle, l'image suivante une fois la précédente affichée
|
||
JV.playing = on;
|
||
const me = ++JV.run;
|
||
jvPause.textContent = on ? "❚❚ Pause" : "▶ Play";
|
||
const step = () => { if (me === JV.run) jvShow(JV.k + 1).then(() => setTimeout(step, 1000 / J_FPS)); };
|
||
if (on) setTimeout(step, 1000 / J_FPS);
|
||
}
|
||
function openTimelapse(ev, k = 0, on = true) {
|
||
JV.frames = jFrames(ev);
|
||
if (!JV.frames.length) return;
|
||
JV.imgs = JV.frames.map(f => Object.assign(new Image(), { src: f.src })); // chargées d'avance
|
||
jv.hidden = false;
|
||
jvShow(k).then(() => jvPlay(on));
|
||
}
|
||
function closeTimelapse() { jvPlay(false); jv.hidden = true; }
|
||
jv.addEventListener("click", ev => {
|
||
if (ev.target === jv) return closeTimelapse(); // clic à côté de la fenêtre
|
||
const b = ev.target.closest("button");
|
||
if (!b) return;
|
||
if (b.dataset.v === "x") closeTimelapse();
|
||
else if (b.dataset.v === "p") jvPlay(!JV.playing);
|
||
else { jvPlay(false); jvShow(JV.k + +b.dataset.v); } // image par image
|
||
});
|
||
document.addEventListener("keydown", ev => { if (ev.key === "Escape" && !jv.hidden) closeTimelapse(); });
|
||
|
||
drawJournal();
|
||
if (J[ASKED.get("play")]) openTimelapse(J[ASKED.get("play")], +ASKED.get("frame") || 0, !ASKED.has("frame")); // #play=n&frame=k : captures
|
||
</script>
|
||
</body>
|
||
</html>
|