Heinrich's-law play: the signals we already compute but used to throw away
become a spatial risk map of the workplace, drawn over the camera's own frame.
Edge:
- near_fall (INFO): a track that reached FALLING (sustained prone) but recovered
before the FALLEN confirm. Treated as a full event per product decision -
same ingest, snapshots, dedup, ack flow as incidents. Fix en route: prone_s
used a truthiness check that turned prone_since=0.0 into "no timer".
- Every per-track event (fall/no_motion/near_fall/immobility/zone hits) now
carries the foot point in the zones' normalized 0..1 space (reusing the zone
detector's own coordinate math); ghost's pixel-space loss point is normalized
at emit. to_payload omits the key when absent, so an old server ignores it.
Server:
- move_events.spatial_x/spatial_y (nullable DOUBLE) + validator: optional
[x, y] finite-number pair; range deliberately NOT enforced (an off-by-a-hair
foot must never reject a FALL alert - renderers clamp).
- MIGRATION FIX: chk_events_type would have REJECTED the previous commit's
lone_worker/overcapacity/overstay inserts on MySQL 8.0.16+ - the constraint
is rebuilt with all 13 types (incl. near_fall).
- GET /api/heatmap/{camera}?days=N (1..90, default 30, 5000-point cap):
spatial points with the same fail-closed site scoping as the event list.
UI (zone editor): "위험 히트맵" toggle + day window. Additive radial blots in
an offscreen layer under the zone polygons; severity weighs the alpha so a
cluster of near-misses reads lighter than one confirmed fall at the same spot.
Events console/detail label near_fall in Korean.
Verified: pytest 222 pass / PHPUnit 130 pass + Chrome real-render (blue
near-miss cluster + red incident hotspot inside the restricted zone, amber
cluster in the warning zone, zones drawn on top; no console errors).
31 lines
1.4 KiB
Python
31 lines
1.4 KiB
Python
from edge.events import EventType, Severity, Event, severity_for
|
|
|
|
|
|
def test_severity_mapping():
|
|
assert severity_for(EventType.NO_MOTION) == Severity.CRITICAL
|
|
assert severity_for(EventType.ZONE_RESTRICTED) == Severity.HIGH
|
|
assert severity_for(EventType.FALL) == Severity.HIGH
|
|
assert severity_for(EventType.IMMOBILITY) == Severity.WARNING
|
|
assert severity_for(EventType.ZONE_WARNING) == Severity.WARNING
|
|
|
|
|
|
def test_event_to_payload_shape():
|
|
e = Event(EventType.FALL, Severity.HIGH, camera_id="cam-01", track_id=7,
|
|
zone_id=None, occurred_at=1000.0, duration_s=3.2,
|
|
metrics={"torso_angle": 78.0}, spatial=None)
|
|
p = e.to_payload(device_id="pi-01")
|
|
assert p["device_id"] == "pi-01"
|
|
assert p["event_type"] == "fall"
|
|
assert p["severity"] == "high"
|
|
assert p["track_id"] == 7
|
|
assert p["metrics"]["torso_angle"] == 78.0
|
|
assert "snapshots" not in p # snapshots는 Alerter가 붙임
|
|
assert "spatial" not in p # None이면 키 생략 (구서버 하위호환)
|
|
|
|
|
|
def test_event_to_payload_includes_spatial_when_present():
|
|
e = Event(EventType.FALL, Severity.HIGH, camera_id="cam-01", track_id=7,
|
|
zone_id=None, occurred_at=1000.0, duration_s=3.2,
|
|
metrics={}, spatial=(0.51234, 0.87))
|
|
p = e.to_payload(device_id="pi-01")
|
|
assert p["spatial"] == [0.5123, 0.87] # 0..1 정규화 좌표, 4자리 반올림
|