Files

22 lines
1.5 KiB
Python
Raw Permalink Normal View History

"""Checks of evaluate.py: python test_evaluate.py (the check against the benchmark itself is `evaluate.py rules`)."""
import numpy as np
import evaluate
instants = ["2026-10-01T00:00Z", "2026-10-01T00:15Z", "2026-10-01T00:30Z"]
yhat = evaluate.events_to_yhat([{"start": "2026-10-01T00:15Z", "end": "2026-10-01T00:30Z", "category": "Obstruction"},
{"start": "2026-10-01T00:00Z", "end": "2026-10-01T00:00Z", "kind": "Visibility"}],
instants)
assert yhat[:, 1].tolist() == [0, 1, 1] and yhat[:, 0].tolist() == [1, 0, 0] # bounds included
y = np.zeros_like(yhat)
y[1:, 1] = 1
y[2, 0] = 1
c = evaluate.counts(y, yhat)
assert c == {"Visibility": [1, 1, 0], "Obstruction": [2, 2, 2]}, c
assert evaluate.regressions({"Obstruction": [100, 100, 50]}, {"Obstruction": [100, 30, 30]}) == [] # 20 instants: not more
assert evaluate.regressions({"Obstruction": [100, 100, 50]}, {"Obstruction": [100, 29, 29]}) == [("Obstruction", "found", 50, 29, 21)]
assert evaluate.regressions({"Obstruction": [10, 10, 5]}, {"Obstruction": [10, 4, 4]}) == [] # 10 points, 1 instant: noise
assert evaluate.regressions({"Obstruction": [10, 10, 5]}, {"Obstruction": [10, 4, 4]}, whole=True) == [("Obstruction", "found", 50, 40, 1)]
assert evaluate.regressions({"Visibility": [100, 50, 50]}, {"Visibility": [100, 100, 71]}) == [("Visibility", "correct", 100, 71, 29)]
assert evaluate.regressions({"Obstruction": [0, 15, 0]}, {}) == [] # false alarms gone: not a regression
print("ok")