26 lines
810 B
Python
26 lines
810 B
Python
import json
|
|
|
|
from edge.detectors.zone import Zone
|
|
|
|
|
|
def zones_from_config(config: dict) -> list[Zone]:
|
|
out: list[Zone] = []
|
|
rows = config.get("zones", []) or []
|
|
if not isinstance(rows, list):
|
|
return []
|
|
for row in rows:
|
|
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, IndexError, json.JSONDecodeError):
|
|
continue
|
|
return out
|
|
|
|
|
|
def thresholds_from_config(config: dict) -> dict:
|
|
t = config.get("thresholds")
|
|
return t if isinstance(t, dict) else {}
|