27 lines
1.2 KiB
Python
27 lines
1.2 KiB
Python
# Daily share of "own" rejections per sensor: rejected while at most K other sensors are rejected at the same instant. Args: station_folder FROM TO sensor[,sensor...] K
|
|||
|
|
import sys
|
||
|
|
from datetime import datetime, timezone
|
||
|
|
sys.path[:0] = ["/home/maxime/aimsight-tools/scripts", "/home/maxime/aimsight-detectors/scripts"]
|
||
|
|
from data import load
|
||
|
|
from target_issue import rejected
|
||
|
|
|
||
|
|
folder, a, b, sensors, k = sys.argv[1], sys.argv[2], sys.argv[3], sys.argv[4].split(","), int(sys.argv[5])
|
||
|
|
ms = load(folder)
|
||
|
|
a = datetime.fromisoformat(a).replace(tzinfo=timezone.utc)
|
||
|
|
b = datetime.fromisoformat(b).replace(tzinfo=timezone.utc)
|
||
|
|
at = {}
|
||
|
|
for s, l in ms.items():
|
||
|
|
for m in l:
|
||
|
|
if rejected(m):
|
||
|
|
at[m["t"]] = at.get(m["t"], 0) + 1
|
||
|
|
days = {}
|
||
|
|
for s in sensors:
|
||
|
|
for m in ms.get(s, []):
|
||
|
|
t = m["t"]
|
||
|
|
if a <= t < b:
|
||
|
|
c = days.setdefault(t.date(), {}).setdefault(s, [0, 0])
|
||
|
|
c[0] += rejected(m) and at[t] - 1 <= k
|
||
|
|
c[1] += 1
|
||
|
|
print("day " + " ".join(f"{s:>8}" for s in sensors))
|
||
|
|
for d in sorted(days):
|
||
|
|
print(d, " ".join(f"{100 * days[d][s][0] / days[d][s][1]:7.0f}%" if s in days[d] else " -" for s in sensors))
|