Files
Support-Agent/src/cellular/final.py
T
maximeandClaude Opus 5.5 f0990c16e6 Deliver Storage and Cellular in the mockups, with site figures and guides
The mockups now walk a list of domains (D-039): the support Home loads
every station in data/ and notifies each station x domain that is Orange
or Red; the client view becomes maquettes/user/summary.py, one System
Summary page per station with one block per measured domain. Storage
shows a free-space scale and the estimated full date; Cellular shows the
day's sends in words and a four-class signal scale.

HEADLINE moves into each day_color.py, with a Green sentence for the
client view. src/storage/final.py and src/cellular/final.py write the
site figures in English; the comparison pages reuse their panels. Each
domain gets a short two-layer guide in docs/<domaine>/guide/.

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

104 lines
5.8 KiB
Python

"""Analyses de la couleur du jour Cellular (D-037) : DAILY_LINK_STATE et DAILY_SIGNAL_STATE, en une figure pour le site (D-021).
Usage : python3 src/cellular/final.py [CSV ou dossiers...] (défaut : data/WEISSHORN/ et data/NORDEND/)
Écrit out/<STATION>_cellular_daily.html (page de démo) et .json (figure Plotly pour le site, Plotly.newPlot), puis les ouvre.
Documentation : docs/cellular/analyses/daily_link_state.md et daily_signal_state.md ; guide docs/cellular/guide/
"""
import sys
from pathlib import Path
sys.path.insert(0, str(Path(__file__).resolve().parents[1])) # src/ : paquets common, energy et cellular
from common.page import AUTOSCALE_Y_JS, ROOT, open_html # noqa: E402 (bascule seule sur .venv si plotly manque)
from common.stations import load_stations # noqa: E402
from plotly.subplots import make_subplots # noqa: E402
from cellular import link_state as ls, signal_state as ss # noqa: E402
from energy.final import noon # noqa: E402 (points journaliers à midi UTC, D-019)
# Couleurs validées par le skill dataviz (toutes paires, fond blanc ; vert/rouge refusé : deutéranopie).
# Le jaune contraste peu avec le fond : chaque état a aussi son symbole, sa légende et son survol.
GRAY = ("#8c8c8c", "circle-open")
LINK_STYLE = {"UP": ("#008300", "circle"), "MISSING": ("#eda100", "diamond"), "DOWN": ("#4a3aa7", "x"), None: GRAY}
CLASS_STYLE = {"EXCELLENT": ("#008300", "circle"), "GOOD": ("#2a78d6", "square"),
"MID_CELL": ("#eda100", "diamond"), "CELL_EDGE": ("#4a3aa7", "x"), None: GRAY}
def hover(p):
return f"{p['t']:%Y-%m-%d}<br>" + "<br>".join(f"{k}={v}" for k, v in p["facts"].items())
def state_markers(fig, pts, y_key, state_key, styles, row, group):
"""Un marqueur par jour à midi, une trace par état (légende et symbole propres)."""
for state, (color, symbol) in styles.items():
sel = [p for p in pts if p["facts"].get(state_key) == state and p["facts"].get(y_key) is not None]
if sel:
fig.add_scatter(x=[noon(p["t"].date()) for p in sel], y=[p["facts"][y_key] for p in sel],
name=f"{state or 'unknown'}", mode="markers", text=[hover(p) for p in sel],
hovertemplate="%{text}<extra></extra>",
marker=dict(color=color, symbol=symbol, size=9, line=dict(color="white", width=1)),
row=row, col=1, **group)
def link_panel(fig, result, row):
"""Panneau DAILY_LINK_STATE : part des envois reçus par jour, état en marqueurs (fiche daily_link_state)."""
group = dict(legendgroup=result["analysis"], legendgrouptitle_text=f"Analysis {result['analysis']}")
state_markers(fig, result["points"], "received_percent", "state", LINK_STYLE, row, group)
fig.update_yaxes(title_text="sends received [%]", row=row, col=1)
def floors_panel(fig, result, row, y_key, class_key, floors, unit):
"""Panneau DAILY_SIGNAL_STATE pour une mesure : médiane du jour, planchers de la grille, classe en marqueurs."""
group = dict(legendgroup=f"{result['analysis']} {unit}", legendgrouptitle_text=f"{result['analysis']} ({unit})")
pts = result["points"]
x = [noon(p["t"].date()) for p in pts]
fig.add_scatter(x=x, y=[p["facts"].get(y_key) for p in pts], name="daily median", mode="lines",
line=dict(color="#52514e", width=1.5), hoverinfo="skip", row=row, col=1, **group)
# Planchers tracés comme des courbes (un point par jour) : AUTOSCALE_Y_JS les garde visibles au zoom (D-013).
for f, c in zip(floors, ss.CLASSES):
fig.add_scatter(x=x, y=[f] * len(x), name=f"{c} floor {f} {unit}", mode="lines", hoverinfo="skip",
line=dict(color=CLASS_STYLE[c][0], dash="dash", width=1), row=row, col=1, **group)
state_markers(fig, pts, y_key, class_key, CLASS_STYLE, row, group)
fig.update_yaxes(title_text=f"daily median [{unit}]", row=row, col=1)
TITLES = [f"Analysis {ls.RULE['id']}", f"Analysis {ss.RULE['id']}: RSRP", f"Analysis {ss.RULE['id']}: RSRQ"]
def analysis_panels(fig, series):
"""Les trois panneaux des analyses, rangées 1 à 3 : partagés par la figure du site et la page de comparaison."""
link_panel(fig, ls.run(series), 1)
signal = ss.run(series)
floors_panel(fig, signal, 2, "rsrp_median_dbm", "rsrp_class", ss.RSRP_FLOORS_DBM, "dBm")
floors_panel(fig, signal, 3, "rsrq_median_db", "rsrq_class", ss.RSRQ_FLOORS_DB, "dB")
def daily_figure(station, series):
"""Graphique pour le site de monitoring : DAILY_LINK_STATE en haut, DAILY_SIGNAL_STATE (RSRP, RSRQ) dessous."""
fig = make_subplots(rows=3, cols=1, shared_xaxes=True, vertical_spacing=0.08, subplot_titles=TITLES)
analysis_panels(fig, series)
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}: data sent and 4G signal", height=900, legend=dict(groupclick="toggleitem"))
return fig
def main(paths):
"""Pour chaque station qui a les mesures du modem : out/<STATION>_cellular_daily.html et .json. -> chemins écrits."""
(ROOT / "out").mkdir(exist_ok=True)
written = []
for station, series in sorted(load_stations(paths).items()):
if "rsrp_dBm" not in series or not {"link", "last_sync"} & series.keys():
print(f"{station} : ignorée, pas de mesures du modem (rsrp_dBm, et link ou last_sync)")
continue
path = ROOT / "out" / f"{station}_cellular_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.with_suffix(".json"))
print(path)
written.append(path)
return written
if __name__ == "__main__":
for p in main(sys.argv[1:] or [str(ROOT / "data" / s) for s in ("WEISSHORN", "NORDEND")]):
open_html(p)