Files
Support-Agent/maquettes/support/home.py
T
maximeandClaude Opus 5.5 9177982de1 Add DAILY_MAINS_POWER: on mains, a mains loss turns the day red at once
A station is on mains when its BusVoltage mean over the 3 days before
the day is >= 14.0 V (solar never exceeds 13.50 V on VERMONT; mains
stays >= 14.08 V). On mains, the mains loss decides the day color
instead of the state x trend matrix: red as soon as an hour falls under
13.4 V (top of the OCV plateau; mains-on hours stay >= 13.65 V, mains-off
hours are 13.1-13.3 V). On MISSISSIPPI the day turns red 1-2 h after the
loss instead of 29-40 h with the matrix; WEISSHORN and NORDEND (mains)
raise no false alert, VERMONT (solar) is unchanged (D-043).

The matrix drawio gets the mains case, the site figure a third panel,
and the support notification and the client Energy block header show
"On mains" / "Not on mains" / "Mains unknown".

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-13 17:22:16 +02:00

98 lines
5.5 KiB
Python

"""Maquette côté support « Home » : page d'accueil du site de monitoring (toutes les stations), avec en haut une section
Status. Elle porte une notification par station et par domaine dont le dernier jour de la fenêtre est Orange ou Red
(src/<domaine>/day_color.py : Energy, Storage, Cellular, Temperature ; D-025, D-030). Energy y ajoute son statut
d'alimentation, sur secteur ou non (DAILY_MAINS_POWER, D-043).
La notification, comme la vignette de la station, mène à la vue client de la station (son menu principal) :
out/maquette_user_<STATION>.html, écrite par maquettes/user/summary.py (à lancer avec les mêmes dates).
Données réelles : les stations de data/ (VERMONT, WEISSHORN, NORDEND). Les autres, noms repris du site, n'ont pas de données.
Écrit out/maquette_support_home.html et l'ouvre dans le navigateur.
Usage : python3 maquettes/support/home.py [AAAA-MM-JJ début] [AAAA-MM-JJ fin] (défaut : 2026-09-18 à 2026-09-28)
"""
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 common.page import open_html # noqa: E402
from common.stations import load_stations # noqa: E402
from cellular import day_color as cellular # noqa: E402
from energy import day_color as energy # noqa: E402
from storage import day_color as storage # noqa: E402
from temperature import day_color as temperature # 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)
# Stations de la page d'accueil du site, dans son ordre (capture du 2026-10-12).
STATIONS = ["ALLALINHORN", "BREITHORN", "CASTOR", "CLARIDEN", "DOM", "FINSTERAARHORN", "FLORIDA", "GRAMMONT", "JUNGFRAU",
"LENZSPITZE", "LINDENBERG", "LISKAMM", "MICHIGAN", "MISSISSIPPI", "NEBRASKA", "NIEDERHORN", "NORDEND",
"PIZBERNINA", "PIZBUIN", "POLLUX", "RINGELSPITZ", "VERMONT", "WEISSHORN", "ADULA", "ALASKA", "DAMMASTOCK",
"FAULHORN", "GRANDCOMBIN", "MARYLAND", "MONTANA", "NADELHORN", "PONT_TREMBLEX-01", "SNCF01", "WILDSTRUBEL",
"WYOMING"]
DOMAINS = {"Energy": energy, "Storage": storage, "Cellular": cellular, "Temperature": temperature} # contrat de notification (D-030)
NAME = {"RED": "Red", "ORANGE": "Orange"} # couleurs notifiées, la plus grave d'abord ; Green ne notifie rien
series = load_stations([str(d) for d in sorted((ROOT / "data").iterdir()) if d.is_dir()])
user_view = lambda name: f"maquette_user_{name}.html" if name in series else "#" # noqa: E731 (maquettes/user/)
def spark(v):
"""Vignette : BusVoltage horaire de la fenêtre en SVG (coupé aux heures sans mesure), et sa dernière valeur."""
pts = [(t, x) for t, x in sorted(v.items()) if START <= t.date() <= END and x is not None]
lo, hi = min(x for _, x in pts), max(x for _, x in pts)
t0, span = datetime.combine(START, time(), timezone.utc), ((END - START).days + 1) * 86400
d, prev = "", None
for t, x in pts:
pen = "L" if prev and t - prev <= timedelta(hours=1) else "M"
d += f"{pen}{(t - t0).total_seconds() / span * 200:.1f},{38 - (x - lo) / (hi - lo or 1) * 36:.1f}"
prev = t
return f'<svg viewBox="0 0 200 40" preserveAspectRatio="none"><path d="{d}"/></svg>', pts[-1][1]
tiles = []
for name in STATIONS:
if "BusVoltage" not in series.get(name, {}):
tiles.append(f'<div class="tile none" title="No data in this mockup"><div class="tile-head">{name}<span>—</span>'
f'</div><svg></svg></div>')
continue
svg, last = spark(series[name]["BusVoltage"])
tiles.append(f'<a class="tile" href="{user_view(name)}"><div class="tile-head">{name}<span>{last:.2f}[V]</span>'
f'</div>{svg}</a>')
def facts_of(dc, station):
"""Faits du dernier jour de la fenêtre pour un domaine, couleur comprise ; {} si la station n'a pas ses mesures."""
try:
points = dc.run(series[station])["points"]
except KeyError: # série du domaine absente (VERMONT n'a ni disque ni modem)
return {}
return {p["t"].date(): p["facts"] for p in points}.get(END, {})
notes = []
for name in series:
for domain, dc in DOMAINS.items():
facts = facts_of(dc, name)
color = facts.get("color")
power = f'<span class="power">{dc.POWER_LABEL[facts["power"]]}</span>' if "power" in facts else ""
if color in NAME:
notes.append((list(NAME).index(color), name, domain,
f'<li><span class="status {color}">{NAME[color]}</span><b>{name}</b><span>{domain}</span>{power}'
f'<span class="meta">{END.strftime("%a %d %b %Y")}</span><span>{dc.HEADLINE[color]}</span>'
f'<a href="{user_view(name)}">Open {name} →</a></li>'))
status = "".join(n[-1] for n in sorted(notes)) or '<li class="empty">No problem or point of attention.</li>'
html = (HERE / "home_template.html").read_text()
for key, value in (("<!--COUNT-->", f"{len(notes)} notification{'s' * (len(notes) != 1)}"),
("<!--STATUS-->", status), ("<!--TILES-->", "\n".join(tiles))):
html = html.replace(key, value)
out = ROOT / "out" / "maquette_support_home.html"
out.parent.mkdir(exist_ok=True)
out.write_text(html)
print(out)
if not all((out.parent / user_view(name)).exists() for name in series):
print("Vue client absente : lancer python3 maquettes/user/summary.py avec les mêmes dates.")
open_html(out)