Show each jump and trend on the curves when hovering its row (D-055)

The Displacements tab now puts the list on the left and the curves on
the right, kept on screen while the list scrolls. Hovering a row keeps
only its target in color and draws it on the curves, with fixed scales:
a jump gets its 2 hours highlighted, the 24 h levels before and after
and an arrow with the jump in mm; a trend gets its period, the
Theil-Sen line, the daily levels, its start and end and the drift as
an arrow. #focus=j0-0, t0 or e0 opens with a row hovered, for captures.

Documented in the detection note: on NORDEND, PR17 and PR06 clear the
thresholds by a wide margin, the next curves fall short (PR03 nearest).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
maximeandClaude Opus 5.5 committed 2026-10-19 09:30:17 +02:00
1 parent 294e024e5a
commit 8d9b927600
5 files changed
+179 -41

No files matched your search

+32 -7
View File
@@ -12,7 +12,7 @@ import json
import os
import statistics
import sys
from datetime import datetime
from datetime import datetime, timezone
from pathlib import Path
from urllib.parse import quote
from zoneinfo import ZoneInfo
@@ -90,7 +90,8 @@ def find_jumps(s, swing):
def find_trend(s, jumps):
"""Tendance d'une série, sauts retirés pour le calcul seulement : pente de Theil-Sen (mm par jour) et tau de Kendall
des médianes journalières. -> (pente, tau, jours entre le premier et le dernier) ou None sous TREND_DAYS jours."""
des médianes journalières. -> (pente, tau, [(jour, médiane)…], ordonnée à l'origine de la droite) ou None sous
TREND_DAYS jours."""
kept = [(t, v - sum(j for i, j in jumps if k >= i + STEP_H)) for k, (t, v) in enumerate(s)
if not any(i < k < i + STEP_H for i, _ in jumps)]
m = sorted((datetime.fromisoformat(d).toordinal(), statistics.median(vs)) for d, vs in daily(kept).items())
@@ -99,7 +100,24 @@ def find_trend(s, jumps):
pairs = [(a, b) for k, a in enumerate(m) for b in m[k + 1:]]
slope = statistics.median((b[1] - a[1]) / (b[0] - a[0]) for a, b in pairs)
tau = sum((b[1] > a[1]) - (b[1] < a[1]) for a, b in pairs) / len(pairs)
return slope, tau, m[-1][0] - m[0][0]
return slope, tau, m, statistics.median(v - slope * x for x, v in m)
def noon(day):
"""Jour (ordinal) -> son midi UTC, où la page place le niveau du jour."""
return donnees.iso(datetime.fromordinal(day).replace(hour=12, tzinfo=timezone.utc))
def trend_line(s, jumps, m, slope, a):
"""Droite de Theil-Sen de find_trend, du midi du premier jour à celui du dernier, sauts remis : alignée sur la courbe
brute, elle marche d'un saut à chaque saut mis de côté. -> [[instant, mm]…]"""
steps = [(s[i][0], s[i + STEP_H][0], j) for i, j in jumps]
t0, t1 = noon(m[0][0]), noon(m[-1][0])
def at(t):
d = datetime.fromisoformat(t)
return a + slope * (d.toordinal() + (d.hour - 12) / 24 + d.minute / 1440) + sum(j for _, e, j in steps if e <= t)
return [[t, at(t)] for t in [t0, *(t for b, e, _ in steps if t0 < b and e < t1 for t in (b, e)), t1]]
def regime_changes(hr):
@@ -124,11 +142,18 @@ def regime_changes(hr):
for i, j in jumps:
before = statistics.median(v for _, v in s[i - WINDOW + 1:i + 1])
found.append({"target": name, "axis": axis, "t": s[i][0], "t2": s[i + STEP_H][0], "jump": j,
"swing": swing, "left": last - before})
"swing": swing, "left": last - before, "before": before, "after": before + j,
"w0": s[i - WINDOW + 1][0], "w1": s[i + STEP_H + WINDOW - 1][0]}) # fenêtres des niveaux
trend = find_trend(s, jumps)
if trend and abs(trend[0]) * trend[2] >= TREND_SIZE * swing and abs(trend[1]) >= TREND_STEADY:
trends.append({"target": name, "axis": axis, "slope": trend[0], "drift": trend[0] * trend[2],
"days": trend[2], "swing": swing, "jumps": len(jumps), "t": s[-1][0]})
if not trend:
continue
slope, tau, m, a = trend
days = m[-1][0] - m[0][0]
if abs(slope) * days >= TREND_SIZE * swing and abs(tau) >= TREND_STEADY:
trends.append({"target": name, "axis": axis, "slope": slope, "drift": slope * days, "days": days,
"swing": swing, "jumps": len(jumps), "t": s[-1][0], "line": trend_line(s, jumps, m, slope, a),
"levels": [[noon(datetime.fromisoformat(d).toordinal()), statistics.median(vs)]
for d, vs in sorted(daily(s).items())]})
at = lambda f: datetime.fromisoformat(f["t"]).timestamp() # noqa: E731
events = []
for f in sorted(found, key=lambda f: f["t"]):