Five components that ship as one product:
- behavision/ the recognition engine. RTSP ingest, YuNet detection, IoU
tracking, ArcFace embeddings, a FAISS/SQLite gallery, and a
FastAPI dashboard. Identity is decided once per TRACK from an
average of at least three embeddings, never per frame.
- agent/ the Go edge agent: supervises the engine, holds a durable
spool, and drains it to MQTT. Nothing is acked before the
broker confirms.
- desktop/ the shop PC application (Wails + React + tray).
- server/ the cloud API, MQTT consumer, reports and assistant.
- web/ platform.loyaly.ai, the head-office app, embedded in the
server binary.
The gallery stores 512-float embeddings and timestamps - no images unless
`app.store_faces` is switched on. Those embeddings are biometric personal
data under GDPR and India's DPDP: template inversion reconstructs a
recognisable face from an ArcFace vector, so data/behavision.db is treated
as a biometric database and DELETE /api/visitors/{id} is a real erasure.
CLAUDE.md carries the reasoning behind every non-obvious decision here,
including the ones that were measured and the ones that were wrong first.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HViLj9gYNRtSr7YVZmW5sn
43 lines
1.3 KiB
JavaScript
43 lines
1.3 KiB
JavaScript
import { useCallback, useEffect, useRef, useState } from 'react'
|
|
|
|
// usePolled runs `fn` now and every `everyMs`, and is careful about the two
|
|
// things every screen would otherwise get wrong on its own: overlapping
|
|
// requests when the server is slower than the interval, and setting state
|
|
// after the component has gone.
|
|
export function usePolled(fn, everyMs, deps = []) {
|
|
const [data, setData] = useState(null)
|
|
const [error, setError] = useState(null)
|
|
const [loading, setLoading] = useState(true)
|
|
const inFlight = useRef(false)
|
|
const alive = useRef(true)
|
|
|
|
const run = useCallback(async () => {
|
|
if (inFlight.current) return
|
|
inFlight.current = true
|
|
try {
|
|
const out = await fn()
|
|
if (!alive.current) return
|
|
setData(out)
|
|
setError(null)
|
|
} catch (err) {
|
|
if (!alive.current) return
|
|
setError(err)
|
|
} finally {
|
|
inFlight.current = false
|
|
if (alive.current) setLoading(false)
|
|
}
|
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
}, deps)
|
|
|
|
useEffect(() => {
|
|
alive.current = true
|
|
run()
|
|
if (!everyMs) return () => { alive.current = false }
|
|
const t = setInterval(run, everyMs)
|
|
return () => { alive.current = false; clearInterval(t) }
|
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
}, [run, everyMs])
|
|
|
|
return { data, error, loading, reload: run }
|
|
}
|