Add the storage analyses and their day color
DAILY_STORAGE_STATE classifies the end-of-day free space of /data and DAYS_UNTIL_STORAGE_FULL divides it by the median daily fill over 7 days. The day color reads a state x horizon matrix drawn in docs/storage/matrice-etat-horizon.drawio. Thresholds are arbitrary for now (D-034, D-035); expert questions stay open. On WEISSHORN the disk fills at 28.2 MiB/day and would be full around 06/02/2027. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
75b681d2db
commit
d43db2a66a
14 files changed
+668
-22
No files matched your search
@@ -0,0 +1,78 @@
|
||||
"""Les analyses Storage ensemble, pour les comparer (D-016) : les panneaux des analyses, puis un graphique par série.
|
||||
|
||||
Usage : python3 src/storage/all_analyses.py [CSV ou dossiers...] (défaut : data/WEISSHORN/)
|
||||
Écrit out/<STATION>_storage.html et l'ouvre. Documentation : docs/storage/analyses/ (une fiche par analyse)
|
||||
"""
|
||||
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 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
|
||||
|
||||
# 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)
|
||||
|
||||
mesures = dict(legendgroup="mesures", legendgrouptitle_text="Mesures")
|
||||
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)
|
||||
for a, b in gaps(s):
|
||||
fig.add_vrect(x0=a, x1=b, fillcolor="gray", opacity=0.3, line_width=0, row=row, col=1)
|
||||
fig.update_yaxes(title_text="GiB", row=row, col=1)
|
||||
fig.update_xaxes(showticklabels=True) # dates sous chaque graphique, pas seulement le dernier
|
||||
fig.update_yaxes(fixedrange=True) # zoom horizontal seulement : l'ordonnée est recalée par AUTOSCALE_Y_JS
|
||||
fig.update_layout(title=f"{station} : analyses {ss.RULE['id']}, {du.RULE['id']}", height=300 * row,
|
||||
legend=dict(groupclick="toggleitem"))
|
||||
return fig
|
||||
|
||||
|
||||
def main(paths):
|
||||
"""Pour chaque station qui a les mesures du disque : out/<STATION>_storage.html. -> chemins écrits."""
|
||||
(ROOT / "out").mkdir(exist_ok=True)
|
||||
written = []
|
||||
for station, series in sorted(load_stations(paths).items()):
|
||||
if not set(METRICS) <= series.keys():
|
||||
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(
|
||||
path, include_plotlyjs="cdn", post_script=AUTOSCALE_Y_JS, config={"scrollZoom": True})
|
||||
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)
|
||||
@@ -0,0 +1,49 @@
|
||||
"""Couleur du jour Storage : matrice état (DAILY_STORAGE_STATE) × horizon (DAYS_UNTIL_STORAGE_FULL) -> vert / orange / rouge (D-035).
|
||||
|
||||
Documentation : docs/storage/matrice-etat-horizon.drawio, docs/decisions.md (D-035)
|
||||
Bibliothèque standard uniquement (cible : système embarqué de la station).
|
||||
"""
|
||||
from storage import days_until_full as du, storage_state as ss
|
||||
|
||||
# Jours avant saturation : choix arbitraire de l'utilisateur (2026-10-13), à revoir avec l'expert (délai d'intervention).
|
||||
ORANGE_DAYS = 60
|
||||
RED_DAYS = 14
|
||||
|
||||
# Matrice tenue par l'utilisateur dans docs/storage/matrice-etat-horizon.drawio : MATRIX[état][horizon].
|
||||
# Horizon None : estimation impossible (moins de 4 rythmes dans la fenêtre). État None : gris, l'horizon l'est aussi.
|
||||
MATRIX = {
|
||||
"OK": {"BEYOND_60_DAYS": "GREEN", "WITHIN_60_DAYS": "ORANGE", "WITHIN_14_DAYS": "RED", None: None},
|
||||
"LOW": {"BEYOND_60_DAYS": "ORANGE", "WITHIN_60_DAYS": "ORANGE", "WITHIN_14_DAYS": "RED", None: "ORANGE"},
|
||||
"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."}
|
||||
|
||||
RULE = {
|
||||
"id": "DAY_COLOR",
|
||||
"verdict": "aucun : anomaly = None ; la couleur est dans facts.color (None = inconnu)",
|
||||
"orange_days": ORANGE_DAYS,
|
||||
"red_days": RED_DAYS,
|
||||
"matrix": MATRIX,
|
||||
"doc": "docs/storage/matrice-etat-horizon.drawio",
|
||||
}
|
||||
|
||||
|
||||
def horizon(facts):
|
||||
"""Classe de DAYS_UNTIL_STORAGE_FULL ; un disque qui ne se remplit pas est au-delà de 60 jours."""
|
||||
if facts["filling"] is None:
|
||||
return None
|
||||
days = facts.get("days_until_full", float("inf"))
|
||||
return "WITHIN_14_DAYS" if days < RED_DAYS else "WITHIN_60_DAYS" if days < ORANGE_DAYS else "BEYOND_60_DAYS"
|
||||
|
||||
|
||||
def run(series):
|
||||
"""Couleur du jour, causale comme les deux analyses. Un point par jour UTC."""
|
||||
points = []
|
||||
for s, d in zip(ss.run(series)["points"], du.run(series)["points"]): # mêmes jours, même ordre (du part de ss)
|
||||
facts = {**s["facts"], **d["facts"], "horizon": horizon(d["facts"])}
|
||||
facts["color"] = MATRIX.get(facts["state"], {}).get(facts["horizon"])
|
||||
points.append({"t": s["t"], "value": facts["color"], "anomaly": None, "facts": facts})
|
||||
return {"analysis": RULE["id"], "rule": RULE, "points": points}
|
||||
@@ -0,0 +1,48 @@
|
||||
"""DAYS_UNTIL_STORAGE_FULL : jours avant que l'espace libre de /data n'atteigne 0, au rythme des 7 derniers jours.
|
||||
|
||||
Documentation : docs/storage/analyses/days_until_storage_full.md
|
||||
Bibliothèque standard uniquement (cible : système embarqué de la station).
|
||||
"""
|
||||
import statistics
|
||||
from datetime import datetime, timedelta
|
||||
|
||||
from storage import storage_state as ss
|
||||
|
||||
# Constantes (fiche days_until_storage_full, « Constantes et sources »).
|
||||
WINDOW_DAYS = 7 # fenêtre de plusieurs jours, multiple de 24 h (principe du projet, CLAUDE.md)
|
||||
MIN_RATES = 4 # plus de la moitié de la fenêtre : la médiane ne dépend pas d'un seul jour (une purge)
|
||||
|
||||
RULE = {
|
||||
"id": "DAYS_UNTIL_STORAGE_FULL",
|
||||
"phase": "estimation seule, sans verdict (anomaly = None)",
|
||||
"window_days": WINDOW_DAYS,
|
||||
"min_rates": MIN_RATES,
|
||||
"doc": "docs/storage/analyses/days_until_storage_full.md",
|
||||
}
|
||||
|
||||
|
||||
def run(series):
|
||||
"""Analyse DAYS_UNTIL_STORAGE_FULL, causale : le jour d n'utilise que les fins de jour jusqu'à d. Un point par jour UTC."""
|
||||
free = series["data_storage_free_gb"]
|
||||
points, rates, prev = [], {}, None # rates : {jour: GiB consommés par jour depuis la fin de jour mesurée précédente}
|
||||
for p in ss.run(series)["points"]:
|
||||
d, f = p["t"].date(), p["facts"]
|
||||
if f["state"] is not None:
|
||||
t = datetime.fromisoformat(f["measured_at"]) # dernière mesure du jour, valeur non arrondie lue dans la série
|
||||
if prev:
|
||||
rates[d] = (free[prev] - free[t]) / ((t - prev) / timedelta(days=1))
|
||||
prev = t
|
||||
window = [r for day, r in rates.items() if d - day < timedelta(days=WINDOW_DAYS)]
|
||||
facts = {"rates": len(window), "free_gb": f.get("free_gb")}
|
||||
if f["state"] is None or len(window) < MIN_RATES:
|
||||
facts["filling"] = None # UNKNOWN : pas de mesure ce jour-là, ou trop peu de jours dans la fenêtre
|
||||
else:
|
||||
rate = statistics.median(window)
|
||||
facts["fill_rate_mib_per_day"] = round(rate * 1024, 2)
|
||||
facts["filling"] = rate > 0
|
||||
if rate > 0:
|
||||
days = free[t] / rate
|
||||
facts["days_until_full"] = round(days, 1)
|
||||
facts["full_date"] = (t + timedelta(days=days)).date().isoformat()
|
||||
points.append({"t": p["t"], "value": facts.get("days_until_full"), "anomaly": None, "facts": facts})
|
||||
return {"analysis": RULE["id"], "rule": RULE, "points": points}
|
||||
@@ -0,0 +1,44 @@
|
||||
"""DAILY_STORAGE_STATE : espace libre de la partition /data en fin de jour (état seul, sans verdict).
|
||||
|
||||
Documentation : docs/storage/analyses/daily_storage_state.md
|
||||
Bibliothèque standard uniquement (cible : système embarqué de la station).
|
||||
"""
|
||||
import math
|
||||
|
||||
# Constantes (fiche daily_storage_state, « Constantes et sources »).
|
||||
# Planchers d'espace libre, en % de l'espace utilisable : choix arbitraire de l'utilisateur (2026-10-13), à revoir avec l'expert.
|
||||
STATES = ["OK", "LOW", "CRITICAL"] # du meilleur au pire
|
||||
FREE_PERCENT_FLOORS = [20, 10] # plancher de OK, de LOW
|
||||
|
||||
RULE = {
|
||||
"id": "DAILY_STORAGE_STATE",
|
||||
"phase": "état seul, sans verdict (anomaly = None)",
|
||||
"free_percent_floors": FREE_PERCENT_FLOORS,
|
||||
"doc": "docs/storage/analyses/daily_storage_state.md",
|
||||
}
|
||||
|
||||
|
||||
def day_facts(free_gb, used_gb):
|
||||
"""Dernière mesure du jour (GiB) -> faits et état. Espace utilisable = utilisé + libre, comme le `percent` de psutil :
|
||||
la réserve de root n'en fait pas partie (docs/storage/domaine/point-de-depart.md)."""
|
||||
free_percent = 100 * free_gb / (free_gb + used_gb)
|
||||
state = next((s for s, f in zip(STATES, FREE_PERCENT_FLOORS) if free_percent >= f), STATES[-1])
|
||||
return {"state": state, "free_gb": round(free_gb, 4), "free_percent": round(free_percent, 2),
|
||||
"usable_gb": round(free_gb + used_gb, 4)}
|
||||
|
||||
|
||||
def run(series):
|
||||
"""Analyse DAILY_STORAGE_STATE, causale : le jour d n'utilise que ses propres heures. Un point par jour UTC."""
|
||||
free, used = series["data_storage_free_gb"], series["data_storage_used_gb"]
|
||||
last, measured = {}, {}
|
||||
for t in sorted(free):
|
||||
last[t.date()] = t
|
||||
if all(x is not None and math.isfinite(x) for x in (free[t], used.get(t))): # NaN/inf = pas de mesure
|
||||
measured[t.date()] = t
|
||||
points = []
|
||||
for d in sorted(last):
|
||||
t = measured.get(d)
|
||||
facts = day_facts(free[t], used[t]) if t else {"state": None} # UNKNOWN : aucune mesure ce jour-là
|
||||
facts["measured_at"] = t.isoformat() if t else None
|
||||
points.append({"t": last[d], "value": facts.get("free_percent"), "anomaly": None, "facts": facts})
|
||||
return {"analysis": RULE["id"], "rule": RULE, "points": points}
|
||||
Reference in new issue
Block a user