Add analysis 03 DAILY_BATTERY_STATE computation (phase C)
One state per UTC day from BusVoltage: FULL_CHARGE, BELOW_PLATEAU, NO_CHARGE, PARTIAL_CHARGE or unknown, with hardware thresholds (14.0 V end of charge, 12.8 V LiFePO4 knee). No verdict yet. Includes the implementation plan. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
9be9a636f7
commit
1ae176cc5a
2 files changed
+472
No files matched your search
@@ -0,0 +1,70 @@
|
||||
"""Analyse 03 DAILY_BATTERY_STATE : état de la batterie jour par jour (phase C : état seul, sans verdict).
|
||||
|
||||
Documentation : docs/analyses/analyse_03.md
|
||||
Bibliothèque standard uniquement (cible : système embarqué de la station).
|
||||
"""
|
||||
import math
|
||||
from collections import defaultdict
|
||||
|
||||
from energy_check import HOUR
|
||||
|
||||
# Constantes (fiche analyse_03, « Constantes et sources »).
|
||||
FULL_CHARGE_V = 14.0 # VERMONT : maxima journaliers < 13,55 V (35 j) ou 14,02-14,33 V (135 j) ; absorption ~14,2 V
|
||||
PLATEAU_FLOOR_V = 12.8 # coude LiFePO4 : table OCV du collecteur (12,8 V = 30 %) ; pente nocturne doublée sous 12,8 V
|
||||
MIN_RISE_V = 0.05 # > variations horaires sur le plateau (<= 15 mV/h), < plus faible vraie montée (+0,18 V, VERMONT 04-11)
|
||||
MIN_COVERAGE = 0.8 # repris de l'analyse 01 : 20 h mesurées sur 24
|
||||
|
||||
RULE = {
|
||||
"id": "DAILY_BATTERY_STATE",
|
||||
"phase": "C : état seul, sans verdict (anomaly = None)",
|
||||
"full_charge_v": FULL_CHARGE_V,
|
||||
"plateau_floor_v": PLATEAU_FLOOR_V,
|
||||
"min_rise_v": MIN_RISE_V,
|
||||
"min_coverage": MIN_COVERAGE,
|
||||
"doc": "docs/analyses/analyse_03.md",
|
||||
}
|
||||
|
||||
|
||||
def day_facts(day):
|
||||
"""{heure UTC: tension mesurée} d'un jour -> faits et état (fiche analyse_03, « Principe »)."""
|
||||
if not day:
|
||||
return {"state": None, "coverage": 0.0}
|
||||
h_max = max(sorted(day), key=day.get) # première heure où le maximum est atteint
|
||||
max_v = day[h_max]
|
||||
night_end_v = min(v for h, v in day.items() if h <= h_max)
|
||||
rise_v = max_v - night_end_v
|
||||
hours_full = sum(v >= FULL_CHARGE_V for v in day.values())
|
||||
coverage = len(day) / 24
|
||||
# Les états 1 et 2 reposent sur une valeur mesurée : ils passent avant la couverture minimale.
|
||||
if hours_full:
|
||||
state = "FULL_CHARGE"
|
||||
elif night_end_v < PLATEAU_FLOOR_V:
|
||||
state = "BELOW_PLATEAU"
|
||||
elif coverage < MIN_COVERAGE:
|
||||
state = None # UNKNOWN : trop de trous pour conclure à une absence
|
||||
elif rise_v < MIN_RISE_V:
|
||||
state = "NO_CHARGE"
|
||||
else:
|
||||
state = "PARTIAL_CHARGE"
|
||||
return {"state": state, "max_v": round(max_v, 3), "night_end_v": round(night_end_v, 3),
|
||||
"rise_v": round(rise_v, 3), "hours_full": hours_full, "coverage": round(coverage, 3)}
|
||||
|
||||
|
||||
def run(series):
|
||||
"""Analyse DAILY_BATTERY_STATE, causale : le jour d n'utilise que les heures de d. Un point par jour UTC."""
|
||||
v = series["BusVoltage"]
|
||||
if v:
|
||||
t0 = min(v)
|
||||
if any((t - t0) % HOUR for t in v):
|
||||
raise ValueError("BusVoltage : horodatages hors de la grille horaire")
|
||||
days, last = defaultdict(dict), {}
|
||||
for t in sorted(v):
|
||||
last[t.date()] = t
|
||||
x = v[t]
|
||||
if x is not None and math.isfinite(x): # NaN/inf (ex. export pandas) = pas de mesure
|
||||
days[t.date()][t.hour] = x
|
||||
points = []
|
||||
for d in sorted(last):
|
||||
facts = day_facts(days.get(d, {}))
|
||||
points.append({"t": last[d], "value": facts.get("max_v"), "anomaly": None, "facts": facts})
|
||||
return {"analysis": RULE["id"], "rule": RULE, "points": points}
|
||||
Reference in new issue
Block a user