27 lines
1.2 KiB
Python
27 lines
1.2 KiB
Python
"""Max |deviation| in noises per label, from ranges.py --k 2 outputs (range extremes)."""
|
|||
|
|
import json, re, sys
|
||
|
|
labels = [json.loads(l) for l in open(sys.argv[1])]
|
||
|
|
for f in sys.argv[2:]:
|
||
|
|
print("==", f)
|
||
|
|
col = None
|
||
|
|
rows = []
|
||
|
|
for line in open(f):
|
||
|
|
m = re.match(r"(corr_[xy]): ranges", line)
|
||
|
|
if m: col = m.group(1); continue
|
||
|
|
p = line.split()
|
||
|
|
if col and len(p) >= 7 and re.match(r"\d{4}-", p[1] if len(p) > 1 else ""):
|
||
|
|
# sensor may be glued to the start date
|
||
|
|
m2 = re.match(r"(.+?)(\d{4}-\d\d-\d\dT\d\d:\d\dZ)$", p[0])
|
||
|
|
if m2: sensor, start = m2.groups(); rest = p[1:]
|
||
|
|
else: sensor, start = p[0], p[1]; rest = p[2:]
|
||
|
|
end, n, val, nz, at = rest[0], rest[1], rest[2], rest[3], rest[4]
|
||
|
|
rows.append((col, sensor, at, float(nz)))
|
||
|
|
for L in labels:
|
||
|
|
inside = [r for r in rows if L["start"] <= r[2] <= L["end"]]
|
||
|
|
best = {}
|
||
|
|
for c in ("corr_x", "corr_y"):
|
||
|
|
cand = [r for r in inside if r[0] == c]
|
||
|
|
if cand:
|
||
|
|
b = max(cand, key=lambda r: abs(r[3])); best[c] = f"{b[1]} {b[3]:+.1f} at {b[2]}"
|
||
|
|
else: best[c] = "<2"
|
||
|
|
print(L["id"], L["start"], L["end"], "|", best["corr_x"], "|", best["corr_y"])
|