Plot DAILY_BATTERY_STATE as the third analysis panel

Daily maximum and night-end voltage, 14.0 V and 12.8 V thresholds,
one marker colour and symbol per day state.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
maximeandClaude Opus 5.5 committed 2026-10-12 10:52:40 +02:00
1 parent 1ae176cc5a
commit a3590fab62
1 file changed
+43 -2
+43 -2
View File
@@ -1,6 +1,6 @@
"""Graphique HTML des analyses énergétiques, un panneau par analyse (poste de dev, plotly dans .venv).
Documentation : docs/analyses/analyse_01.md, docs/analyses/analyse_02.md
Documentation : docs/analyses/analyse_01.md, docs/analyses/analyse_02.md, docs/analyses/analyse_03.md
"""
import argparse
import os
@@ -8,6 +8,7 @@ import os
from plotly.subplots import make_subplots
import energy_check as ec
import battery_state as bs
# Plotly ne recale pas l'ordonnée sur la plage visible : après chaque zoom ou déplacement horizontal,
# ce script recalcule l'axe vertical de chaque graphique sur les points visibles (5 % de marge),
@@ -55,6 +56,43 @@ ZONES = [
("pleine charge", 14.0, 14.4, "green", "top left"), # absorption 14,0-14,3 [V] ; secteur 14,2-14,4 [E]
]
# États de DAILY_BATTERY_STATE : couleurs validées par le skill dataviz (toutes paires, fond blanc).
# Le jaune contraste peu avec le fond : chaque état a aussi son symbole, sa légende et son survol.
STATE_STYLE = {
"FULL_CHARGE": ("pleine charge", "#008300", "circle"),
"PARTIAL_CHARGE": ("charge partielle (incertain)", "#eda100", "diamond"),
"BELOW_PLATEAU": ("sous le plateau", "#2a78d6", "triangle-down"),
"NO_CHARGE": ("aucune charge", "#4a3aa7", "x"),
None: ("état inconnu", "#8c8c8c", "circle-open"),
}
def daily_state_panel(fig, result, row):
"""Panneau DAILY_BATTERY_STATE : maximum et fin de nuit par jour, seuils, état en marqueurs (fiche analyse_03)."""
group = dict(legendgroup=result["analysis"], legendgrouptitle_text=f"Analyse {result['analysis']}")
rule, pts = result["rule"], result["points"]
x = [p["t"] for p in pts]
fig.add_scatter(x=x, y=[p["facts"].get("max_v") for p in pts], name="maximum du jour", mode="lines",
line=dict(color="#52514e", width=1.5), hoverinfo="skip", row=row, col=1, **group)
fig.add_scatter(x=x, y=[p["facts"].get("night_end_v") for p in pts], name="fin de nuit", mode="lines",
line=dict(color="#9a9893", width=1.5), hovertemplate="fin de nuit %{y:.2f} V<extra></extra>",
row=row, col=1, **group)
# Seuils tracés comme des courbes (un point par jour) : AUTOSCALE_Y_JS les garde visibles au zoom (D-013).
for v, name, state in ((rule["full_charge_v"], "pleine charge", "FULL_CHARGE"),
(rule["plateau_floor_v"], "bas du plateau", "BELOW_PLATEAU")):
fig.add_scatter(x=x, y=[v] * len(x), name=f"{name} {v} V", mode="lines", hoverinfo="skip",
line=dict(color=STATE_STYLE[state][1], dash="dash", width=1), row=row, col=1, **group)
for state, (label, color, symbol) in STATE_STYLE.items():
sel = [p for p in pts if p["facts"]["state"] == state and p["facts"].get("max_v") is not None]
if not sel:
continue
hover = [f"{p['t']:%Y-%m-%d} : {label}<br>" + "<br>".join(f"{k}={val}" for k, val in p["facts"].items())
for p in sel]
fig.add_scatter(x=[p["t"] for p in sel], y=[p["facts"]["max_v"] for p in sel], name=label, mode="markers",
marker=dict(color=color, symbol=symbol, size=8, line=dict(color="white", width=1)),
text=hover, hovertemplate="%{text}<extra></extra>", row=row, col=1, **group)
fig.update_yaxes(title_text="BusVoltage [V]", row=row, col=1)
def gaps(v):
"""Plages de créneaux sans BusVoltage : [(premier créneau vide, première valeur suivante)]."""
@@ -79,6 +117,9 @@ def figure(station, series, results):
subplot_titles=[f"Analyse {r['analysis']}" for r in results] + metrics)
for row, result in enumerate(results, start=1):
if result["analysis"] == bs.RULE["id"]:
daily_state_panel(fig, result, row)
continue
analyse = dict(legendgroup=result["analysis"], legendgrouptitle_text=f"Analyse {result['analysis']}")
thr = result["rule"]["threshold_v"]
pts = result["points"]
@@ -126,7 +167,7 @@ def main(argv=None):
print(f"{station} : ignorée, pas de BusVoltage")
continue
path = os.path.join(a.out, f"{station}_energy.html")
figure(station, series, [ec.run(series), ec.run_midnight(series)]).write_html(
figure(station, series, [ec.run(series), ec.run_midnight(series), bs.run(series)]).write_html(
path, include_plotlyjs="cdn", post_script=AUTOSCALE_Y_JS, config={"scrollZoom": True})
print(path)
paths.append(path)