Add the day color matrix, the energy diagnostic manual and the site figure
D-020: the delivered energy diagnostic keeps analyses 03 and 04 only, combined by the state x trend matrix of cas-d-usage-03-04.drawio into one color per day (green / orange / red, grey when unknown), coded in src/day_color.py (standard library). docs/guide/diagnostic-energetique.md explains it: part 1 for the client, part 2 for support. D-021: energy_plot.daily_figure builds the figure for the monitoring site (panel 03 above panel 04, shared time axis), written by analyse_01.py as out/<STATION>_daily.html and .json. battery_state no longer imports energy_check, so analyses 03 and 04 ship on their own. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
129d4ff59b
commit
fc74fec10f
9 files changed
+467
-8
No files matched your search
@@ -5,8 +5,9 @@ Bibliothèque standard uniquement (cible : système embarqué de la station).
|
||||
"""
|
||||
import math
|
||||
from collections import defaultdict
|
||||
from datetime import timedelta
|
||||
|
||||
from energy_check import HOUR
|
||||
HOUR = timedelta(hours=1) # grille des CSV : moyennes horaires (sans import d'energy_check : 03 et 04 se livrent seules)
|
||||
|
||||
# Constantes (fiche analyse_03, « Constantes et sources »).
|
||||
FULL_CHARGE_V = 14.0 # VERMONT : maxima journaliers < 13,55 V (35 j) ou 14,02-14,33 V (135 j) ; absorption ~14,2 V
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
"""Couleur du jour : matrice état (analyse 03) × tendance (analyse 04) -> vert / orange / rouge (D-020).
|
||||
|
||||
Documentation : docs/guide/diagnostic-energetique.md (§ 7, la matrice)
|
||||
Bibliothèque standard uniquement (cible : système embarqué de la station).
|
||||
"""
|
||||
import battery_state as bs
|
||||
import battery_trend as bt
|
||||
|
||||
# Matrice tenue par l'utilisateur dans cas-d-usage-03-04.drawio : MATRIX[état][tendance].
|
||||
MATRIX = {
|
||||
"FULL_CHARGE": {"BETTER": "GREEN", "STABLE": "GREEN", "WORSE": "GREEN"},
|
||||
"PARTIAL_CHARGE": {"BETTER": "GREEN", "STABLE": "ORANGE", "WORSE": "ORANGE"},
|
||||
"NO_CHARGE": {"BETTER": "ORANGE", "STABLE": "RED", "WORSE": "RED"},
|
||||
"BELOW_PLATEAU": {"BETTER": "RED", "STABLE": "RED", "WORSE": "RED"},
|
||||
}
|
||||
|
||||
RULE = {
|
||||
"id": "DAY_COLOR",
|
||||
"verdict": "aucun : anomaly = None ; la couleur est dans facts.color (None = inconnu, état ou tendance absent)",
|
||||
"matrix": MATRIX,
|
||||
"doc": "docs/guide/diagnostic-energetique.md",
|
||||
}
|
||||
|
||||
|
||||
def run(series):
|
||||
"""Couleur du jour, causale comme les analyses 03 et 04 (J et J−1). Un point par jour UTC."""
|
||||
points = []
|
||||
for s, t in zip(bs.run(series)["points"], bt.run(series)["points"]): # mêmes jours, même ordre (bt part de bs)
|
||||
facts = {**s["facts"], **t["facts"]}
|
||||
facts["color"] = MATRIX.get(facts["state"], {}).get(facts["trend"])
|
||||
points.append({"t": s["t"], "value": facts["color"], "anomaly": None, "facts": facts})
|
||||
return {"analysis": RULE["id"], "rule": RULE, "points": points}
|
||||
+21
-1
@@ -120,7 +120,7 @@ def daily_trend_panel(fig, result, row):
|
||||
sel = [p for p in pts if p["facts"]["trend"] == trend and p["value"] is not None]
|
||||
if not sel:
|
||||
continue
|
||||
hover = [f"{p['t']:%Y-%m-%d} : {label} (décidé par {p['facts']['decided_by']})<br>"
|
||||
hover = [f"{p['t']:%Y-%m-%d}: {label} (décidé par {p['facts']['decided_by']})<br>"
|
||||
f"{p['facts']['state_prev']} → {p['facts']['state']}<br>"
|
||||
+ "<br>".join(f"{k}={v}" for k, v in p["facts"].items() if k.startswith("delta")) for p in sel]
|
||||
fig.add_bar(x=[noon(p["t"].date()) for p in sel], y=[p["value"] for p in sel], name=label,
|
||||
@@ -129,6 +129,19 @@ def daily_trend_panel(fig, result, row):
|
||||
fig.update_yaxes(title_text="Δ fin de nuit [V]", row=row, col=1)
|
||||
|
||||
|
||||
def daily_figure(station, series):
|
||||
"""Graphique pour le site de monitoring (D-021) : analyse 03 en haut, analyse 04 dessous, même axe du temps."""
|
||||
fig = make_subplots(rows=2, cols=1, shared_xaxes=True, vertical_spacing=0.08,
|
||||
subplot_titles=[f"Analyse {bs.RULE['id']}", f"Analyse {bt.RULE['id']}"])
|
||||
daily_state_panel(fig, bs.run(series), 1)
|
||||
daily_trend_panel(fig, bt.run(series), 2)
|
||||
fig.update_xaxes(showticklabels=True)
|
||||
fig.update_yaxes(fixedrange=True) # zoom horizontal seulement : l'ordonnée est recalée par AUTOSCALE_Y_JS
|
||||
fig.update_layout(title=f"{station} : état et tendance de la batterie", height=700, barmode="overlay",
|
||||
legend=dict(groupclick="toggleitem"))
|
||||
return fig
|
||||
|
||||
|
||||
def gaps(v):
|
||||
"""Plages de créneaux sans BusVoltage : [(premier créneau vide, première valeur suivante)]."""
|
||||
out, start = [], None
|
||||
@@ -209,6 +222,13 @@ def main(argv=None):
|
||||
path, include_plotlyjs="cdn", post_script=AUTOSCALE_Y_JS, config={"scrollZoom": True})
|
||||
print(path)
|
||||
paths.append(path)
|
||||
# Analyses 03 et 04 : page de démo, et figure Plotly en JSON pour le site (Plotly.newPlot).
|
||||
path = os.path.join(a.out, f"{station}_daily.html")
|
||||
fig = daily_figure(station, series)
|
||||
fig.write_html(path, include_plotlyjs="cdn", post_script=AUTOSCALE_Y_JS, config={"scrollZoom": True})
|
||||
fig.write_json(path.removesuffix(".html") + ".json")
|
||||
print(path)
|
||||
paths.append(path)
|
||||
return paths
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user