Harden MA7D_DROP inputs and report UNKNOWN stretches

- NaN/inf values are treated as missing instead of poisoning the
  running sum (which produced a false "not observed").
- Unreadable CSV files are skipped with a message naming the file;
  a station whose analysis fails is skipped with its name and the
  scan continues.
- The summary now states hours without verdict and the longest
  UNKNOWN stretch (5 months on MISSISSIPPI were silent).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
maximeandClaude Opus 5.5 committed 2026-10-09 19:37:56 +02:00
1 parent 79bd98c9cb
commit 53b4f7e47c
2 files changed
+91 -22

No files matched your search

+35
View File
@@ -73,6 +73,17 @@ class Loading(unittest.TestCase):
self.assertEqual(list(st), ["JUNGFRAU"])
self.assertIn("export.csv", err.getvalue())
def test_empty_csv_file_is_skipped_with_message(self):
with tempfile.TemporaryDirectory() as d:
shutil.copy(JUNGFRAU_V, d)
empty = Path(d) / "FLORIDA_BusVoltage_2026_04_13_14_00 to 2026_10_09_14_00.csv"
empty.touch()
err = io.StringIO()
with redirect_stderr(err):
st = ec.load_stations([d])
self.assertEqual(list(st), ["JUNGFRAU"])
self.assertIn(empty.name, err.getvalue())
class Ma7dDrop(unittest.TestCase):
def test_florida_never_anomalous(self):
@@ -127,6 +138,11 @@ class Ma7dDrop(unittest.TestCase):
with self.assertRaises(ValueError):
ec.run({"BusVoltage": v})
def test_nan_value_is_treated_as_missing(self):
v = dict(stations()["VERMONT"]["BusVoltage"])
v[at(2026, 6, 1)] = float("nan")
self.assertEqual(first_anomaly(ec.run({"BusVoltage": v})), at(2026, 9, 24, 7))
class Reporting(unittest.TestCase):
def test_vermont_period_is_ongoing(self):
@@ -166,6 +182,25 @@ class Reporting(unittest.TestCase):
ec.main([str(VERMONT_THERMAL), "--out", d])
self.assertIn("ignorée, pas de BusVoltage", out.getvalue())
def test_cli_continues_after_station_error(self):
out, err = io.StringIO(), io.StringIO()
with tempfile.TemporaryDirectory() as d:
shutil.copy(JUNGFRAU_V, d)
florida = Path(d) / "FLORIDA_BusVoltage_2026_04_13_14_00 to 2026_10_09_14_00.csv"
shutil.copy(DATA / florida.name, florida)
with open(florida, "a") as f:
f.write(",2026-10-09 14:30:00+00:00,\n") # horodatage hors grille, sans mesure
with redirect_stdout(out), redirect_stderr(err):
ec.main([d, "--out", d])
self.assertIn("FLORIDA : ignorée", err.getvalue())
self.assertIn("JUNGFRAU : aucune anomalie", out.getvalue())
def test_summary_reports_longest_unknown_stretch(self):
res = result("MISSISSIPPI")
text = ec.summary("MISSISSIPPI", res, ec.periods(res["points"]))
self.assertIn("sans verdict (UNKNOWN)", text)
self.assertIn("du 2025-12-26 23:00 au 2026-06-07 16:00", text)
if __name__ == "__main__":
unittest.main()