Files
Support-Agent/maquettes/user/energy.py
T
maximeandClaude Opus 5.5 8452973912 Add the client Energy mockup and switch site texts to English
D-022: page mockups are HTML built from real data, in maquettes/user/
(client) and maquettes/support/; Figma only on request.
maquettes/user/energy.py renders the System Summary page with a
Diagnostic section: an Energy box with the day's color, a one-line
headline, a battery scale (zones from the collector's LiFePO4 OCV
table, no percentage shown), the trend against the day before, an
"Activate energy save mode" button on orange and red days (mockup
only, sends nothing), and two collapsibles: the full history (D-021
figure) and the guide (part 1 of the manual, rendered from Markdown).

D-023: everything meant for the monitoring site is in English,
including the titles, legends, axes and hovers of the 03/04 panels.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-12 16:23:37 +02:00

65 lines
3.2 KiB
Python

"""Maquette côté client « Energy » : page System Summary du site de monitoring, avec une section Diagnostic (D-020 à D-023).
Données réelles VERMONT. Bloc Energy : couleur du dernier jour de la fenêtre, échelle de batterie et tendance face à la veille
(src/day_color.py), puis historique complet (energy_plot.daily_figure, D-021) et guide (partie 1 du manuel), repliés.
Écrit out/maquette_user_energy.html et l'ouvre dans le navigateur.
Usage : python3 maquettes/user/energy.py [AAAA-MM-JJ début] [AAAA-MM-JJ fin] (défaut : 2026-09-18 à 2026-09-28)
"""
import json
import re
import sys
from datetime import date, datetime, time, timedelta, timezone
from pathlib import Path
HERE = Path(__file__).resolve().parent
ROOT = HERE.parent.parent
sys.path.insert(0, str(ROOT / "src"))
from analyse_01 import open_html # noqa: E402 (bascule seule sur .venv si plotly manque)
import battery_state as bs # noqa: E402
import battery_trend as bt # noqa: E402
import day_color as dc # noqa: E402
import energy_check as ec # noqa: E402
import energy_plot as ep # noqa: E402
START = date.fromisoformat(sys.argv[1]) if len(sys.argv) > 1 else date(2026, 9, 18)
END = date.fromisoformat(sys.argv[2]) if len(sys.argv) > 2 else date(2026, 9, 28)
series = ec.load_stations([str(ROOT / "data")])["VERMONT"]
v = series["BusVoltage"]
in_window = lambda t: START <= t.date() <= END # noqa: E731
hours = [[t.isoformat(), v[t]] for t in sorted(v) if in_window(t)]
daily = {}
for t, x in hours:
if x is not None:
d = daily.setdefault(t[:10], {"lo": [t, x], "hi": [t, x]})
d["lo"] = min(d["lo"], [t, x], key=lambda p: p[1])
d["hi"] = max(d["hi"], [t, x], key=lambda p: p[1])
end = datetime.combine(END, time(23), timezone.utc)
table = []
for metric in sorted(series):
last = [x for t, x in series[metric].items() if t <= end and x is not None]
table.append([metric, f"{last[-1]:.2f} [unknown]" if last else "—"])
facts = {p["t"].date(): p["facts"] for p in dc.run(series)["points"]}
# Guide : partie 1 du manuel (lecture rapide, pour le client), relue à chaque génération ; titres décalés de deux niveaux.
manual = (ROOT / "docs" / "guide" / "diagnostic-energetique.md").read_text()
part1 = manual[manual.index("# Partie 1"):manual.index("# Partie 2")].split("\n", 1)[1] # sans son titre
guide = re.sub(r"^#", "###", part1.rstrip().removesuffix("---"), flags=re.M)
data = {"hours": hours, "daily": list(daily.values()), "table": table, "guide": guide,
"range": [START.isoformat(), (END + timedelta(days=1)).isoformat()],
"energy": {"cur": facts.get(END), "label": END.strftime("%a %d %b %Y")},
"rule": {"full_charge_v": bs.FULL_CHARGE_V, "plateau_floor_v": bs.PLATEAU_FLOOR_V, "min_rise_v": bs.MIN_RISE_V,
"deadband_v": bt.NIGHT_END_DEADBAND_V}}
html = (HERE / "energy_template.html").read_text()
for key, value in (("/*DATA*/null", json.dumps(data)),
("/*DAILY*/null", ep.daily_figure("VERMONT", series).to_json()),
("/*AUTOSCALE*/", ep.AUTOSCALE_Y_JS.replace("{plot_id}", "daily"))):
html = html.replace(key, value)
out = ROOT / "out" / "maquette_user_energy.html"
out.parent.mkdir(exist_ok=True)
out.write_text(html)
print(out)
open_html(out)