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>
This commit is contained in:
1 parent
28ed86baba
commit
9177982de1
18 files changed
+359
-43
No files matched your search
@@ -0,0 +1,53 @@
|
||||
"""DAILY_MAINS_POWER : la station est-elle sur secteur ? Sur secteur, a-t-elle perdu le secteur ce jour-là ?
|
||||
|
||||
Documentation : docs/energy/analyses/daily_mains_power.md
|
||||
Bibliothèque standard uniquement (cible : système embarqué de la station).
|
||||
"""
|
||||
import math
|
||||
from collections import defaultdict
|
||||
from datetime import timedelta
|
||||
|
||||
from energy import battery_state as bs
|
||||
|
||||
# Constantes (fiche daily_mains_power, « Constantes et sources »).
|
||||
WINDOW_DAYS = 3 # demande de l'utilisateur : moyenne glissante sur les 3 jours qui précèdent J
|
||||
MAINS_MEAN_V = bs.FULL_CHARGE_V # 14,0 V : moyenne sur 3 jours, solaire <= 13,50 V (VERMONT), secteur >= 14,08 V (4 stations)
|
||||
MAINS_LOST_V = 13.4 # haut du plateau (table OCV) : secteur présent >= 13,65 V à l'heure, heure pleine sans secteur 13,11-13,30 V (MISSISSIPPI)
|
||||
MIN_COVERAGE = bs.MIN_COVERAGE # 0,8 : 58 h mesurées sur 72
|
||||
|
||||
RULE = {
|
||||
"id": "DAILY_MAINS_POWER",
|
||||
"verdict": "aucun : anomaly = None ; le statut est dans facts.power, la perte du secteur dans facts.hours_lost",
|
||||
"window_days": WINDOW_DAYS,
|
||||
"mains_mean_v": MAINS_MEAN_V,
|
||||
"mains_lost_v": MAINS_LOST_V,
|
||||
"min_coverage": MIN_COVERAGE,
|
||||
"doc": "docs/energy/analyses/daily_mains_power.md",
|
||||
}
|
||||
|
||||
|
||||
def run(series):
|
||||
"""Analyse DAILY_MAINS_POWER, causale : le statut de J vient des 3 jours avant J, la perte des heures de J.
|
||||
Un point par jour UTC, les mêmes jours que DAILY_BATTERY_STATE."""
|
||||
v = series["BusVoltage"]
|
||||
days, last = defaultdict(list), {}
|
||||
for t in sorted(v):
|
||||
last[t.date()] = t
|
||||
if v[t] is not None and math.isfinite(v[t]): # NaN/inf = pas de mesure, comme DAILY_BATTERY_STATE
|
||||
days[t.date()].append(v[t])
|
||||
points = []
|
||||
for d in sorted(last):
|
||||
window = [x for k in range(1, WINDOW_DAYS + 1) for x in days.get(d - timedelta(days=k), [])]
|
||||
coverage = len(window) / (24 * WINDOW_DAYS)
|
||||
mean_v = round(sum(window) / len(window), 3) if window else None
|
||||
if coverage < MIN_COVERAGE:
|
||||
power = None # UNKNOWN : trop de trous pour conclure
|
||||
else:
|
||||
power = "MAINS" if mean_v >= MAINS_MEAN_V else "NOT_MAINS"
|
||||
today = days.get(d, [])
|
||||
# Sur secteur seulement : heures de J sous le plateau haut, donc sans chargeur (None : pas sur secteur, ou J sans mesure).
|
||||
hours_lost = sum(x < MAINS_LOST_V for x in today) if power == "MAINS" and today else None
|
||||
facts = {"power": power, "mean_3_days_v": mean_v, "coverage_3_days": round(coverage, 3),
|
||||
"min_v": round(min(today), 3) if today else None, "hours_lost": hours_lost}
|
||||
points.append({"t": last[d], "value": mean_v, "anomaly": None, "facts": facts})
|
||||
return {"analysis": RULE["id"], "rule": RULE, "points": points}
|
||||
Reference in new issue
Block a user