The PHP app runs on Cafe24 shared web hosting -- calling it 'cloud' was misleading. Renames the directory, the edge client module, and every doc/script/identifier that used the term. - cloud/ -> server/ (incl. server/deploy/build_cafe24_package.sh paths) - edge/cloudclient.py -> edge/serverclient.py, CloudClient -> ServerClient - cloud/docs/cloud-deploy.md -> server/docs/server-deploy.md - CLOUD_* env/config keys -> SERVER_* - tests renamed to match Tests: PHP 109 pass (4 skipped), pytest 167 pass. dist/ regenerated.
51 lines
2.2 KiB
Python
51 lines
2.2 KiB
Python
import json
|
|
import logging
|
|
|
|
from edge.detectors.zone import Zone
|
|
|
|
log = logging.getLogger(__name__)
|
|
|
|
# Zones are stored NORMALIZED (0..1 of the image) by the current dashboard. Polygons drawn by the
|
|
# pre-normalization dashboard were saved in canvas PIXELS (values in the hundreds); after the edge
|
|
# normalizes the foot point, a pixel polygon can never match — silently killing that zone's
|
|
# intrusion detection with no error. Flag such rows loudly so the operator redraws them, instead
|
|
# of failing dark. A normalized coordinate may round slightly past 1.0, so allow a small margin.
|
|
_NORMALIZED_MAX = 1.5
|
|
|
|
|
|
def _looks_like_pixels(polygon: list[tuple[float, float]]) -> bool:
|
|
return any(abs(x) > _NORMALIZED_MAX or abs(y) > _NORMALIZED_MAX for x, y in polygon)
|
|
|
|
|
|
def zones_from_config(config: dict, camera_id: str | None = None) -> list[Zone]:
|
|
"""Parse server config zone rows into Zone objects. When camera_id is given, only
|
|
rows for that camera are kept (multi-camera routing); None keeps all rows."""
|
|
out: list[Zone] = []
|
|
rows = config.get("zones", []) or []
|
|
if not isinstance(rows, list):
|
|
return []
|
|
for row in rows:
|
|
try:
|
|
if camera_id is not None and str(row["camera_id"]) != str(camera_id):
|
|
continue
|
|
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
|
|
if _looks_like_pixels(polygon):
|
|
log.warning(
|
|
"zone %s on camera %s has un-normalized (pixel-space) coordinates %r — it "
|
|
"would match nothing after foot normalization. Skipping; redraw this zone in "
|
|
"the dashboard so it is stored normalized (0..1).",
|
|
row.get("zone_id"), row.get("camera_id"), polygon[:2])
|
|
continue
|
|
out.append(Zone(str(row["zone_id"]), str(row["level"]), polygon))
|
|
except (KeyError, ValueError, TypeError, IndexError, AttributeError, json.JSONDecodeError):
|
|
continue
|
|
return out
|
|
|
|
|
|
def thresholds_from_config(config: dict) -> dict:
|
|
t = config.get("thresholds")
|
|
return t if isinstance(t, dict) else {}
|