move_detect/docs/PROJECT_MAP.md
유창욱 9e4225a338 feat(heatmap): near-miss events + spatial ingestion + camera risk-heatmap overlay
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).
2026-08-06 20:19:09 +09:00

3.6 KiB

PROJECT_MAP — move_detect

작업 전 이 문서로 위치를 찾고 필요한 파일만 연다 (전체 재스캔 금지). 새 파일·라우트·스키마 변경 시 해당 섹션을 갱신할 것.

개요

작업장 안전 AI CCTV. Raspberry Pi 5 + Hailo-8 엣지 추론(Python) → HMAC POST → Cafe24 웹호스팅 PHP+MySQL 대시보드. 감지: 넘어짐 · 넘어짐 후 미동 · 장시간 부동 · 위험구역 침입(경고/절대금지/협착) · 유령사고(위험 상태로 소실). 스냅샷만 전송, 라이브뷰·영상 없음.

edge/ (Python — Pi에서 구동)

파일 역할
app.py run_once 파이프라인 (프레임→추론→추적→감지→스냅샷→전송). ambiguous 리셋·stale 필터
engine.py EventEngine — 감지기 오케스트레이션, 쿨다운 dedup, 트랙 forget
tracking.py IouTracker — 전역 그리디 IoU 매칭, ambiguous() (교차 경합 트랙)
detectors/ fall.py(FALLING→FALLEN→NO_MOTION, sustained prone) · immobility.py · ghost.py · zone.py · occupancy.py(존 규칙: 2인1조/정원/체류상한 — Zone.rules 소비)
smoothing.py 트랙별 키포인트 스무딩 풀
snapshot.py RingBuffer · FaceBlurrer(PIPA) · Snapshotter
alert.py / serverclient.py HMAC+nonce POST, 커스텀 UA, no-redirect
queue.py 오프라인 전송 큐
config.py env → Config (빈 CAFE24_URL/SECRET는 기동 실패)
daemon.py / runtime.py / health.py 상주 루프 · 하트비트 텔레메트리
adapters/ hailo_pose · movenet_pose(CPU 폴백) · picamera_source(CSI) · uvc_source(USB)
probe.py / tools/ 카메라 사전 점검 · HEF/모델 fetch (빌드머신 전용)

server/ (PHP 8 + PDO — Cafe24)

  • 진입: public/index.php (라우트 전부 여기), 뷰: src/View/{layout,events,login,zones,event_detail}.php
  • 라우트: POST /api/events(ingest, HMAC) · POST /api/heartbeat · GET /api/config · GET /api/events · GET /api/devices · GET /api/heatmap/{camera}(spatial 집계) · GET/POST /api/zones* · POST /login|/logout · GET /snap/{uuid} · POST /events/{id}/ack · 페이지 /, /login, /zones, /events/{id}/view
  • src/Ingest/ HMAC+nonce+rate-limit+replay 방지 · src/Auth/ argon2id/세션/RBAC/CSRF · src/Dashboard/ 이벤트목록·디바이스상태·존편집·스냅샷프록시 · src/Repository/ 9종 (인터페이스+PDO)
  • 프런트: public/assets/app.js(이벤트 콘솔 폴링·필터) · device-tree.js(장치→카메라 트리 레일) · zone-draw.js · detail.js · app.css
  • DB: schema.sql (테이블 prefix move_), 마이그레이션 migrations/. 존 행의 rules_json(선택) = 점유 규칙 {min_workers,max_workers,max_dwell_s} — 편집기 저장 시 ZoneConfigController가 검증, /api/config로 엣지 전달
  • 배포: server/deploy/build_cafe24_package.sh → zip, server/docs/server-deploy.md

deploy/ · dist/ (납품)

  • deploy/: Pi 설치 — setup_online.sh, bundle/build_offline_bundle.sh(폐쇄망), systemd/move-detect-edge.service, device.env(사전 프로비저닝)
  • dist/: 1_cafe24_upload/ · 2_pi_install/ · PROVISION_SECRETS.md

tests/

  • Python: tests/ 31파일 (pytest) — 하드웨어 필요 테스트는 tests/hardware/ + skip 마커
  • PHP: server/tests/ 19파일 (phpunit, in-memory repo; PDO 통합은 skip 게이트)

docs/

delivery-audit.md(감사 43건, 전부 완료 — OFF-HW 실장비 검증만 잔여) · pilot-runbook.md · hardware-bringup.md · INDEX.md(작업 기록)