Add anomaly periods, text summary and CLI for MA7D_DROP

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
maximeandClaude Opus 5.5 committed 2026-10-09 19:26:44 +02:00
1 parent 041770ec47
commit d91ab866e2
3 files changed
+123 -1

No files matched your search

+41 -1
View File
@@ -1,11 +1,12 @@
"""Tests de régression de l'analyse MA7D_DROP, sur données réelles uniquement (spec §9)."""
import functools
import io
import json
import shutil
import sys
import tempfile
import unittest
from contextlib import redirect_stderr
from contextlib import redirect_stderr, redirect_stdout
from datetime import datetime, timedelta, timezone
from pathlib import Path
@@ -127,5 +128,44 @@ class Ma7dDrop(unittest.TestCase):
ec.run({"BusVoltage": v})
class Reporting(unittest.TestCase):
def test_vermont_period_is_ongoing(self):
per = ec.periods(result("VERMONT")["points"])
self.assertEqual(per[-1]["start"], at(2026, 9, 24, 7))
self.assertIsNone(per[-1]["end"])
def test_mississippi_first_period_is_closed(self):
per = ec.periods(result("MISSISSIPPI")["points"])
self.assertEqual((per[0]["start"], per[0]["end"]), (at(2025, 12, 9, 12), at(2025, 12, 18, 6)))
def test_florida_has_no_period(self):
self.assertEqual(ec.periods(result("FLORIDA")["points"]), [])
def test_summary_vocabulary(self):
for name, word in [("FLORIDA", "not observed"), ("VERMONT", "consistent with")]:
res = result(name)
self.assertIn(word, ec.summary(name, res, ec.periods(res["points"])))
def test_summary_short_history_is_insufficient_evidence(self):
v = stations()["JUNGFRAU"]["BusVoltage"]
res = ec.run({"BusVoltage": {t: x for t, x in v.items() if t < min(v) + timedelta(days=5)}})
self.assertIn("insufficient evidence", ec.summary("JUNGFRAU", res, ec.periods(res["points"])))
def test_cli_writes_json_and_summary(self):
out = io.StringIO()
with tempfile.TemporaryDirectory() as d, redirect_stdout(out):
ec.main([str(VERMONT), "--out", d])
doc = json.loads((Path(d) / "VERMONT_energy.json").read_text())
self.assertEqual((doc["station"], doc["analysis"]), ("VERMONT", "MA7D_DROP"))
self.assertIsNone(doc["periods"][-1]["end"])
self.assertIn("VERMONT : anomalie énergétique", out.getvalue())
def test_cli_skips_station_without_busvoltage(self):
out = io.StringIO()
with tempfile.TemporaryDirectory() as d, redirect_stdout(out):
ec.main([str(VERMONT_THERMAL), "--out", d])
self.assertIn("ignorée, pas de BusVoltage", out.getvalue())
if __name__ == "__main__":
unittest.main()