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>
This commit is contained in:
1 parent
28d441889f
commit
f0990c16e6
22 files changed
+682
-246
No files matched your search
@@ -11,60 +11,18 @@ from common.page import AUTOSCALE_Y_JS, ROOT, open_html # noqa: E402 (bascule
|
||||
from common.stations import gaps, 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)
|
||||
from cellular.final import TITLES, analysis_panels # noqa: E402 (panneaux partagés avec la figure du site)
|
||||
|
||||
# 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}
|
||||
METRICS = ["rsrp_dBm", "rsrq_dB", "rssi_dbm", "ber_percent"] # liste explicite : jamais SIM_CCID ni ip
|
||||
|
||||
|
||||
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 'inconnu'}", 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 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="médiane du jour", 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"plancher {c} {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"médiane du jour [{unit}]", row=row, col=1)
|
||||
|
||||
|
||||
def figure(station, series, link, signal):
|
||||
titles = [f"Analyse {ls.RULE['id']}", f"Analyse {ss.RULE['id']} : RSRP", f"Analyse {ss.RULE['id']} : RSRQ"]
|
||||
fig = make_subplots(rows=len(titles) + len(METRICS) + 1, cols=1, shared_xaxes=True, vertical_spacing=0.03,
|
||||
subplot_titles=titles + METRICS + ["envois reçus par heure (last_sync, sinon link)"])
|
||||
group = dict(legendgroup=ls.RULE["id"], legendgrouptitle_text=f"Analyse {ls.RULE['id']}")
|
||||
state_markers(fig, link["points"], "received_percent", "state", LINK_STYLE, 1, group)
|
||||
fig.update_yaxes(title_text="envois reçus [%]", row=1, col=1)
|
||||
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 figure(station, series):
|
||||
fig = make_subplots(rows=len(TITLES) + len(METRICS) + 1, cols=1, shared_xaxes=True, vertical_spacing=0.03,
|
||||
subplot_titles=TITLES + METRICS + ["envois reçus par heure (last_sync, sinon link)"])
|
||||
analysis_panels(fig, series)
|
||||
|
||||
mesures = dict(legendgroup="mesures", legendgrouptitle_text="Mesures")
|
||||
row = len(titles)
|
||||
row = len(TITLES)
|
||||
for row, m in enumerate(METRICS, start=row + 1):
|
||||
s = series.get(m, {})
|
||||
fig.add_scatter(x=sorted(s), y=[s[t] for t in sorted(s)], name=m, line=dict(width=1), row=row, col=1,
|
||||
@@ -90,7 +48,7 @@ def main(paths):
|
||||
print(f"{station} : ignorée, pas de mesures du modem (rsrp_dBm, et link ou last_sync)")
|
||||
continue
|
||||
path = ROOT / "out" / f"{station}_cellular.html"
|
||||
figure(station, series, ls.run(series), ss.run(series)).write_html(
|
||||
figure(station, series).write_html(
|
||||
path, include_plotlyjs="cdn", post_script=AUTOSCALE_Y_JS, config={"scrollZoom": True})
|
||||
print(path)
|
||||
written.append(path)
|
||||
|
||||
@@ -15,9 +15,10 @@ MATRIX = {
|
||||
"DOWN": {**dict.fromkeys(KNOWN, "ORANGE"), None: "RED"},
|
||||
}
|
||||
|
||||
# Une phrase par couleur notifiée, en anglais (D-023) ; Green ne notifie rien (D-025).
|
||||
HEADLINE = {"RED": "The station stopped sending data for a large part of the day.",
|
||||
"ORANGE": "The station's 4G connection showed interruptions."}
|
||||
# Une phrase par couleur, en anglais (D-023) ; Green ne notifie rien (D-025), sa phrase ne sert qu'à la vue client.
|
||||
HEADLINE = {"GREEN": "The station sent all its data over 4G.",
|
||||
"ORANGE": "The station's 4G connection showed interruptions.",
|
||||
"RED": "The station stopped sending data for a large part of the day."}
|
||||
|
||||
RULE = {
|
||||
"id": "DAY_COLOR",
|
||||
|
||||
@@ -0,0 +1,103 @@
|
||||
"""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)
|
||||
@@ -15,6 +15,12 @@ MATRIX = {
|
||||
"BELOW_PLATEAU": {"BETTER": "RED", "STABLE": "RED", "WORSE": "RED"},
|
||||
}
|
||||
|
||||
# Une phrase par couleur, en anglais (D-023), reprise par la vue client et par les notifications du support.
|
||||
# Green ne notifie rien (D-025) : sa phrase ne sert qu'à la vue client.
|
||||
HEADLINE = {"GREEN": "The station is receiving enough energy.",
|
||||
"ORANGE": "The station's energy supply is uncertain.",
|
||||
"RED": "The station is not receiving enough energy."}
|
||||
|
||||
RULE = {
|
||||
"id": "DAY_COLOR",
|
||||
"verdict": "aucun : anomaly = None ; la couleur est dans facts.color (None = inconnu, état ou tendance absent)",
|
||||
|
||||
@@ -15,7 +15,7 @@ import plotly.graph_objects as go # noqa: E402
|
||||
from energy import battery_state as bs, battery_trend as bt, day_color as dc # noqa: E402
|
||||
from energy.final import STATE_STYLE, TREND_STYLE, noon # noqa: E402
|
||||
|
||||
# Statuts : noms et couleurs de la maquette System Summary (maquettes/user/energy_template.html).
|
||||
# Statuts : noms et couleurs de la maquette System Summary (maquettes/user/summary_template.html).
|
||||
COLOR = {"GREEN": ("Green", "#008300"), "ORANGE": ("Orange", "#eda100"), "RED": ("Red", "#d03b3b"),
|
||||
None: ("Unknown", "#8c8c8c")}
|
||||
# Condition qui a donné l'état (fiche daily_battery_state, « Principe », dans l'ordre d'évaluation).
|
||||
|
||||
@@ -10,40 +10,19 @@ sys.path.insert(0, str(Path(__file__).resolve().parents[1])) # src/ : paquets c
|
||||
from common.page import AUTOSCALE_Y_JS, ROOT, open_html # noqa: E402 (bascule seule sur .venv si plotly manque)
|
||||
from common.stations import gaps, load_stations # noqa: E402
|
||||
from plotly.subplots import make_subplots # noqa: E402
|
||||
from cellular.all_analyses import GRAY, hover, state_markers # noqa: E402 (mêmes marqueurs que Cellular)
|
||||
from energy.final import noon # noqa: E402 (points journaliers à midi UTC, D-019)
|
||||
from storage import days_until_full as du, storage_state as ss # noqa: E402
|
||||
from storage.final import TITLES, analysis_panels # noqa: E402 (panneaux partagés avec la figure du site)
|
||||
|
||||
# Couleurs de la page Cellular, validées par le skill dataviz.
|
||||
STATE_STYLE = {"OK": ("#008300", "circle"), "LOW": ("#eda100", "diamond"), "CRITICAL": ("#4a3aa7", "x"), None: GRAY}
|
||||
METRICS = ["data_storage_free_gb", "data_storage_used_gb", "data_storage_total_gb"]
|
||||
|
||||
|
||||
def figure(station, series, state, days):
|
||||
titles = [f"Analyse {ss.RULE['id']}", f"Analyse {du.RULE['id']}"]
|
||||
fig = make_subplots(rows=len(titles) + len(METRICS), cols=1, shared_xaxes=True, vertical_spacing=0.04,
|
||||
subplot_titles=titles + METRICS)
|
||||
group = dict(legendgroup=ss.RULE["id"], legendgrouptitle_text=f"Analyse {ss.RULE['id']}")
|
||||
pts = state["points"]
|
||||
x = [noon(p["t"].date()) for p in pts]
|
||||
fig.add_scatter(x=x, y=[p["value"] for p in pts], name="espace libre du jour", mode="lines",
|
||||
line=dict(color="#52514e", width=1.5), hoverinfo="skip", row=1, 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, s in zip(ss.FREE_PERCENT_FLOORS, ss.STATES):
|
||||
fig.add_scatter(x=x, y=[f] * len(x), name=f"plancher {s} {f} %", mode="lines", hoverinfo="skip",
|
||||
line=dict(color=STATE_STYLE[s][0], dash="dash", width=1), row=1, col=1, **group)
|
||||
state_markers(fig, pts, "free_percent", "state", STATE_STYLE, 1, group)
|
||||
fig.update_yaxes(title_text="libre / utilisable [%]", row=1, col=1)
|
||||
|
||||
pts = [p for p in days["points"] if p["value"] is not None]
|
||||
fig.add_scatter(x=[noon(p["t"].date()) for p in pts], y=[p["value"] for p in pts], name="jours avant saturation",
|
||||
mode="lines+markers", text=[hover(p) for p in pts], hovertemplate="%{text}<extra></extra>",
|
||||
line=dict(color="#2a78d6", width=1.5), legendgroup=du.RULE["id"],
|
||||
legendgrouptitle_text=f"Analyse {du.RULE['id']}", row=2, col=1)
|
||||
fig.update_yaxes(title_text="jours restants", row=2, col=1)
|
||||
def figure(station, series):
|
||||
fig = make_subplots(rows=len(TITLES) + len(METRICS), cols=1, shared_xaxes=True, vertical_spacing=0.04,
|
||||
subplot_titles=TITLES + METRICS)
|
||||
analysis_panels(fig, series)
|
||||
|
||||
mesures = dict(legendgroup="mesures", legendgrouptitle_text="Mesures")
|
||||
for row, m in enumerate(METRICS, start=len(titles) + 1):
|
||||
for row, m in enumerate(METRICS, start=len(TITLES) + 1):
|
||||
s = series[m]
|
||||
fig.add_scatter(x=sorted(s), y=[s[t] for t in sorted(s)], name=m, line=dict(width=1), row=row, col=1,
|
||||
**mesures)
|
||||
@@ -66,7 +45,7 @@ def main(paths):
|
||||
print(f"{station} : ignorée, pas de mesures du disque ({', '.join(METRICS)})")
|
||||
continue
|
||||
path = ROOT / "out" / f"{station}_storage.html"
|
||||
figure(station, series, ss.run(series), du.run(series)).write_html(
|
||||
figure(station, series).write_html(
|
||||
path, include_plotlyjs="cdn", post_script=AUTOSCALE_Y_JS, config={"scrollZoom": True})
|
||||
print(path)
|
||||
written.append(path)
|
||||
|
||||
@@ -17,9 +17,10 @@ MATRIX = {
|
||||
"CRITICAL": {"BEYOND_60_DAYS": "RED", "WITHIN_60_DAYS": "RED", "WITHIN_14_DAYS": "RED", None: "RED"},
|
||||
}
|
||||
|
||||
# Une phrase par couleur notifiée, en anglais (D-023) ; Green ne notifie rien (D-025).
|
||||
HEADLINE = {"RED": "The station is about to run out of storage space.",
|
||||
"ORANGE": "The station's storage space is running low."}
|
||||
# Une phrase par couleur, en anglais (D-023) ; Green ne notifie rien (D-025), sa phrase ne sert qu'à la vue client.
|
||||
HEADLINE = {"GREEN": "The station has enough storage space.",
|
||||
"ORANGE": "The station's storage space is running low.",
|
||||
"RED": "The station is about to run out of storage space."}
|
||||
|
||||
RULE = {
|
||||
"id": "DAY_COLOR",
|
||||
|
||||
@@ -0,0 +1,83 @@
|
||||
"""Analyses de la couleur du jour Storage (D-035) : DAILY_STORAGE_STATE et DAYS_UNTIL_STORAGE_FULL, en une figure pour le site (D-021).
|
||||
|
||||
Usage : python3 src/storage/final.py [CSV ou dossiers...] (défaut : data/WEISSHORN/)
|
||||
Écrit out/<STATION>_storage_daily.html (page de démo) et .json (figure Plotly pour le site, Plotly.newPlot), puis les ouvre.
|
||||
Documentation : docs/storage/analyses/daily_storage_state.md et days_until_storage_full.md ; guide docs/storage/guide/
|
||||
"""
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
sys.path.insert(0, str(Path(__file__).resolve().parents[1])) # src/ : paquets common, energy, cellular et storage
|
||||
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.final import GRAY, hover, state_markers # noqa: E402 (mêmes marqueurs que Cellular)
|
||||
from energy.final import noon # noqa: E402 (points journaliers à midi UTC, D-019)
|
||||
from storage import days_until_full as du, storage_state as ss # noqa: E402
|
||||
|
||||
# Couleurs de la page Cellular, validées par le skill dataviz.
|
||||
STATE_STYLE = {"OK": ("#008300", "circle"), "LOW": ("#eda100", "diamond"), "CRITICAL": ("#4a3aa7", "x"), None: GRAY}
|
||||
TITLES = [f"Analysis {ss.RULE['id']}", f"Analysis {du.RULE['id']}"]
|
||||
|
||||
|
||||
def state_panel(fig, result, row):
|
||||
"""Panneau DAILY_STORAGE_STATE : espace libre en fin de jour, planchers, état en marqueurs (fiche daily_storage_state)."""
|
||||
group = dict(legendgroup=result["analysis"], legendgrouptitle_text=f"Analysis {result['analysis']}")
|
||||
pts = result["points"]
|
||||
x = [noon(p["t"].date()) for p in pts]
|
||||
fig.add_scatter(x=x, y=[p["value"] for p in pts], name="free space (end of day)", 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, s in zip(ss.FREE_PERCENT_FLOORS, ss.STATES):
|
||||
fig.add_scatter(x=x, y=[f] * len(x), name=f"{s} floor {f} %", mode="lines", hoverinfo="skip",
|
||||
line=dict(color=STATE_STYLE[s][0], dash="dash", width=1), row=row, col=1, **group)
|
||||
state_markers(fig, pts, "free_percent", "state", STATE_STYLE, row, group)
|
||||
fig.update_yaxes(title_text="free / usable [%]", row=row, col=1)
|
||||
|
||||
|
||||
def days_panel(fig, result, row):
|
||||
"""Panneau DAYS_UNTIL_STORAGE_FULL : jours avant saturation, au rythme médian sur 7 jours (fiche days_until_storage_full)."""
|
||||
pts = [p for p in result["points"] if p["value"] is not None]
|
||||
fig.add_scatter(x=[noon(p["t"].date()) for p in pts], y=[p["value"] for p in pts], name="days until full",
|
||||
mode="lines+markers", text=[hover(p) for p in pts], hovertemplate="%{text}<extra></extra>",
|
||||
line=dict(color="#2a78d6", width=1.5), legendgroup=result["analysis"],
|
||||
legendgrouptitle_text=f"Analysis {result['analysis']}", row=row, col=1)
|
||||
fig.update_yaxes(title_text="days left", row=row, col=1)
|
||||
|
||||
|
||||
def analysis_panels(fig, series):
|
||||
"""Les deux panneaux des analyses, rangées 1 et 2 : partagés par la figure du site et la page de comparaison."""
|
||||
state_panel(fig, ss.run(series), 1)
|
||||
days_panel(fig, du.run(series), 2)
|
||||
|
||||
|
||||
def daily_figure(station, series):
|
||||
"""Graphique pour le site de monitoring : DAILY_STORAGE_STATE en haut, DAYS_UNTIL_STORAGE_FULL dessous."""
|
||||
fig = make_subplots(rows=2, 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}: storage space", height=700, legend=dict(groupclick="toggleitem"))
|
||||
return fig
|
||||
|
||||
|
||||
def main(paths):
|
||||
"""Pour chaque station qui a les mesures de /data : out/<STATION>_storage_daily.html et .json. -> chemins écrits."""
|
||||
(ROOT / "out").mkdir(exist_ok=True)
|
||||
written = []
|
||||
for station, series in sorted(load_stations(paths).items()):
|
||||
if "data_storage_free_gb" not in series:
|
||||
print(f"{station} : ignorée, pas de mesures de /data (data_storage_*)")
|
||||
continue
|
||||
path = ROOT / "out" / f"{station}_storage_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" / "WEISSHORN")]):
|
||||
open_html(p)
|
||||
Reference in new issue
Block a user