move_detect/edge/zones.py

23 lines
729 B
Python

import json
from edge.detectors.zone import Zone
def zones_from_config(config: dict) -> list[Zone]:
out: list[Zone] = []
for row in config.get("zones", []) or []:
try:
raw = row["polygon_json"]
pts = json.loads(raw) if isinstance(raw, str) else raw
polygon = [(float(p[0]), float(p[1])) for p in pts]
if len(polygon) < 3:
continue
out.append(Zone(str(row["zone_id"]), str(row["level"]), polygon))
except (KeyError, ValueError, TypeError, json.JSONDecodeError):
continue
return out
def thresholds_from_config(config: dict) -> dict:
t = config.get("thresholds")
return t if isinstance(t, dict) else {}