Commit graph

21 commits

Author SHA1 Message Date
jedarden
118c6b1c9d feat: add new internal packages (events, automation, ble, falldetect, mqtt, notify, prediction, sleep, tracker, zones, analytics) and dashboard modules (anomaly, automations, blepanel, fleet) 2026-04-06 09:48:31 -04:00
jedarden
c75428d488 ci: set VERSION to 0.1.0 for image build 2026-04-06 08:53:25 -04:00
jedarden
14c49cb919 feat(breathing): implement stationary person detection via breathing analysis
Add FFT-based breathing detection with long-dwell presence tracking:

- FFTBreathingDetector: Rolling 30-second buffer, Hann window, FFT analysis
  to detect periodic breathing signals in 0.2-1.0 Hz band
- DwellTracker: State machine with CLEAR → MOTION_DETECTED →
  POSSIBLY_PRESENT → STATIONARY_DETECTED transitions
- Health gating: Detection disabled when link health < 0.7
- Dashboard: Slow-pulsing blue dot for stationary detection with BPM tooltip
- Timeline: Event logging on transition to STATIONARY_DETECTED

Physics: CSI phase oscillates at 2x breathing rate due to round-trip
path length change. 15 BPM breathing → 0.5 Hz CSI phase oscillation.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-29 20:25:17 -04:00
jedarden
f7b9719d1b feat(localization): implement self-improving localization with BLE ground truth
Implement a complete self-improving localization system that uses BLE
RSSI triangulation as ground truth to learn per-link, per-zone weights
for the Fresnel zone fusion engine.

Key components:
- Ground truth sample collection with confidence > 0.7 and distance < 0.5m gates
- Spatial weight learner using online SGD with L2 regularization
- Validation gate that rejects updates without 5% improvement on holdout set
- Bilinear interpolation for smooth weight transitions between zones
- SQLite persistence for weights with 10,000 sample cap per person
- Position accuracy trend visualization in dashboard Accuracy panel

Backend (mothership/internal/localization/):
- groundtruth.go: BLE trilateration provider with Gauss-Newton optimization
- groundtruth_store.go: SQLite storage with weekly accuracy rollups
- spatial_weights.go: SpatialWeightLearner with SGD, validation, interpolation
- weightlearner.go: WeightLearner with error history tracking
- weightstore.go: Weight persistence to SQLite

Frontend (dashboard/js/accuracy.js):
- fetchPositionAccuracy/fetchPositionHistory functions
- drawPositionSparkline for weekly median error trend
- Position accuracy section with median error, trend indicator, sample count

Tests cover:
- Sample collection gates (confidence/distance thresholds)
- SGD weight updates after 100 samples
- Validation gate rejection of adversarial samples
- Bilinear interpolation smoothness
- SQLite sample cap enforcement
- Weight persistence across restarts

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-29 20:11:22 -04:00
jedarden
fb218f5410 feat(learning): complete feedback loop with time-range queries and zone breakdown
- Add GetFeedbackInTimeRange() to query feedback by timestamp for accuracy computation
- Add GetUniqueScopeIDs() to extract unique link/zone/person IDs from feedback
- Update accuracy.go to use the new store methods for proper scope filtering
- Add zone breakdown visualization in accuracy panel with clickable zone items
- Add blob hover tooltips with thumbs up/down feedback buttons in 3D view
- Wire up feedback processor and accuracy computer in main startup

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-29 18:03:45 -04:00
jedarden
20aadb54f0 feat(learning): expose showToast for feedback module integration
Add showToast to SpaxelApp public API so the Feedback module can
display toast notifications when users submit feedback on detections.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-29 16:47:38 -04:00
jedarden
037ac09d9e feat(analytics): implement crowd flow visualization
Add trajectory accumulation, directional flow maps, and dwell time
hotspot visualization for occupancy pattern analysis.

Backend:
- FlowAccumulator records trajectory segments and dwell time in SQLite
- REST endpoints for flow map, dwell heatmap, and detected corridors
- Bresenham rasterization for flow vector aggregation
- Connected component analysis for corridor detection

Frontend:
- Pattern controls in dashboard sidebar (flow, dwell, corridors toggles)
- Time filter dropdown (7d, 30d, all time)
- 3D visualization with ArrowHelper for flow, PlaneGeometry for heatmaps
- Pulsating animation on flow arrows

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-29 15:38:40 -04:00
jedarden
4af8046acd feat(learning): implement detection feedback loop and accuracy tracking
- Add feedback_store.go with SQLite storage for detection feedback and accuracy metrics
- Add feedback_processor.go for background processing of user feedback
- Add accuracy.go for weekly precision/recall/F1 metric computation
- Add handler.go with REST API routes for feedback submission and accuracy retrieval
- Wire learning package into main_phase6.go with background processing
- Add dashboard/js/feedback.js with thumbs-up/down UI components
- Add dashboard/js/accuracy.js with accuracy panel rendering and sparkline trends
- Add comprehensive tests for feedback storage and accuracy computation

Feedback UI provides:
- Thumbs-up/down buttons for detection events
- Feedback form with false positive/negative options
- Missed detection reporting with position/zone selection
- Motivational counter showing improvement from user corrections

Accuracy panel shows:
- Circular gauge with F1 score
- Week-over-week trend sparkline
- Per-zone breakdown of precision/recall
- Total corrections count and improvement percentage

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-29 14:50:36 -04:00
jedarden
bc2c377e0c feat(signal): implement Phase 5 Reliability & Intelligence
Phase 5 deliverables:
- Diurnal adaptive baseline (24-slot hourly vectors, 7-day learning, crossfade, confidence indicator)
- Stationary person detection (breathing band 0.1-0.5 Hz, long-dwell logic with health gating)
- Ambient confidence score (per-link health: SNR, phase stability, packet rate, drift; composite gauge)
- Link weather diagnostics (root-cause suggestions, weekly trends, repositioning advice)
- Baseline persistence (SQLite storage for EMA and diurnal baselines)

Key components:
- signal/diurnal.go: 24-hour baseline slots with cosine crossfade
- signal/breathing.go: 4th-order Butterworth bandpass filter for breathing detection
- signal/ambient.go: Per-link health scoring with weighted composite
- signal/persist.go: SQLite persistence for baselines
- signal/healthpersist.go: Health log aggregation for weekly trends
- diagnostics/linkweather.go: 5 diagnostic rules with actionable advice
- diagnostics/reposition.go: GDOP-based repositioning target computation
- fleet/healer.go: Self-healing fleet with role re-optimization
- dashboard/js/app.js: Quality gauge UI with health polling

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-29 12:16:56 -04:00
jedarden
6294f44411 feat(diagnostics): add health persistence tests and frontend enhancements
- Add comprehensive tests for HealthStore (healthpersist_test.go)
- Add link health panel CSS styles and sparkline visualization
- Add ghost node rendering for repositioning advice in viz3d.js
- Wire up all diagnostic API routes in main.go
- Minor test cleanup in linkweather_test.go

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-29 12:07:58 -04:00
jedarden
66e640522d feat(signal): add ambient confidence score and link health monitoring
Implements per-link health metrics that gate and weight detection algorithms:

Per-Link Health Metrics (LinkHealthScorer in ambient.go):
- SNR Estimate (40% weight): motion/quiet deltaRMS ratio via log10 mapping
- Phase Stability (30% weight): phase variance with 0.5 rad threshold
- Packet Rate Health (20% weight): actual vs configured rate
- Baseline Drift (10% weight): hourly normalized L2 change

Gating Effects:
- BreathingDetector: disabled when health_score < 0.7
- FusionEngine: link contributions weighted by health_score

Dashboard Visualization:
- 3D link line color: green (1.0) → yellow (0.5) → red (0.0)
- 3D link line thickness: 2px (>0.7), 1px (0.4-0.7), 0.5px (<0.4)
- System-wide Detection Quality gauge in header
- Link Health panel with per-metric breakdown and sparklines

API: GET /api/links returns health_score and health_details for each link

Tests:
- Health score computation with weighted sub-metrics
- SNR mapping: SNR=100 → 1.0, SNR=10 → 0.5
- Phase stability: variance=0 → 1.0, variance=0.5 → 0.0
- Breathing health gating at 0.7 threshold
- Fusion engine link weight verification

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-29 01:41:43 -04:00
jedarden
90e230f9d9 feat(dashboard): complete Phase 4 onboarding & OTA system
Interactive onboarding wizard:
- 8-step Web Serial-based provisioning flow
- Firmware flashing via esp-web-install-button (CDN)
- Live CSI waveform feedback during guided calibration
- Server-side provisioning with client-side fallback
- Serial JSON response handling with error mapping
- Post-calibration reinforcement card with link count

OTA firmware management:
- Firmware list with SHA-256 hashes and size display
- Per-node progress tracking (idle/pending/downloading/rebooting/verified/failed/rollback)
- Rolling update orchestration via REST API
- Status bar button with state indicators (normal/in-progress/has-update)
- Node list badges for OTA status and rollback warnings

Guided troubleshooting:
- First-time feature tooltips with 8s auto-dismiss
- Sequential tooltip tour triggered on first node connection
- Node offline cards with step-by-step recovery instructions
- Factory reset instructions modal
- Client-side link health check (60s no-frame threshold)
- Captive portal recovery documentation

Exit criteria: New ESP32-S3 from unboxed to streaming CSI in under 5 minutes.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-28 21:21:55 -04:00
jedarden
7b325703bd feat(dashboard): interactive 3D node placement with real-time GDOP coverage overlay
Adds TransformControls for dragging nodes in the 3D scene, a room dimension
editor (width/depth/height), a GDOP (Geometric Dilution of Precision) coverage
overlay on the ground plane that updates in real-time during node drag, virtual
node support for planning optimal placement before hardware purchase, and REST
API integration to persist positions and room config to the mothership.

Backend adds PUT /api/nodes/{mac}/position, POST /api/nodes/virtual,
DELETE /api/nodes/{mac}, PUT /api/room endpoints. Also wires OTA status
handler and improves firmware manifest to use actual latest binary filename.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-28 09:25:44 -04:00
jedarden
570e5eec41 feat(dashboard): guided troubleshooting and first-time UX
Add troubleshooting infrastructure for non-technical users:

- TroubleshootManager: node offline cards with stepped recovery
  guidance, factory reset modal, and detection quality banners
- TooltipManager: first-time feature tooltips with localStorage
  persistence, auto-dismiss, and sequential tour
- Onboarding failure guidance: human-readable error messages for
  browser compatibility, USB connection, WiFi provisioning, and
  node detection failures
- Post-calibration reinforcement card with summary and next steps
- Client-side link health check with auto-recovery
- CSS for offline cards, tooltips, quality banners, and modals
- Script tags wired in index.html for troubleshoot.js and tooltips.js
- 30 tests covering all troubleshooting and tooltip functionality

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-28 04:19:06 -04:00
jedarden
1b0e7ea2b4 fix(dashboard): fix onboarding wizard test failures
- Fix WebSocket mock to use factory function so resetAllMocks doesn't
  break it (state.ws.close is not a function errors)
- Fix TextEncoderStream mock to provide functional readable/writable
  for pipeTo (needed by provisioning serial send tests)
- Fix flash_firmware test to check wizard-nav for "Skip Flashing"
  button instead of wizard-content
- Fix provisionAndSend "no port" test to use mockResolvedValue
  instead of mockResolvedValueOnce so both primary and fallback
  paths fail consistently

All 60 tests now pass.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-28 04:01:20 -04:00
jedarden
5ddb8973e2 feat(dashboard): interactive onboarding wizard for ESP32-S3 node provisioning
Web Serial-based wizard that takes a non-technical user from unboxed
ESP32-S3 to streaming CSI in under 5 minutes. 8-step state machine:
browser check → connect → flash firmware (esp-web-tools) → provision
WiFi → detect node → guided calibration → placement guidance → complete.

Includes sessionStorage persistence for resumability across page refreshes,
live CSI waveform during calibration, human-friendly error messages for
all failure modes, and comprehensive Jest test coverage (34 tests).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-28 02:36:58 -04:00
jedarden
75edd8339a feat(dashboard): presence panel with per-link motion indicators and deltaRMS time series
Add 500ms periodic presence_update broadcast from the dashboard hub with
per-link motion state (is_motion, delta_rms, confidence). Surface this in
a new Presence panel on the dashboard with coloured dot indicators
(green=clear, amber=motion, red=high-confidence) and deltaRMS values.
Includes a rolling 10s Canvas 2D line chart of deltaRMS with a threshold
line at 0.02 for the selected link.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-27 23:49:08 -04:00
jedarden
bcd19ad756 feat(dashboard): 3D spatial visualization with humanoid SkinnedMesh figures
Implements plan item 17 — full Three.js Phase 3 visualization layer:

- Room bounds: floor, ceiling, semi-transparent walls and wireframe edges
  built from registry_state room config (width/depth/height/origin)
- Floor plan texture: upload any image via status-bar button; mapped to
  ground plane via THREE.TextureLoader
- Humanoid figures: SkinnedMesh + AnimationMixer with 13-bone skeleton;
  four AnimationClip postures (standing, walking, seated, lying); smooth
  0.35 s crossfade transitions; walking speed scales animation timeScale;
  figures orient in direction of travel
- Vertical pillar anchors: line from floor to ceiling at each blob position
- Footprint trails: floor-level Line geometry following blob.trail history
- Node meshes: OctahedronGeometry at registry node 3-D positions; link
  lines redrawn whenever link_active/inactive events arrive
- View presets: 3D perspective, top-down orthographic, first-person follow
  (lerps camera to track first active blob)
- WebSocket: handles registry_state, loc_update, link_inactive message types
  newly routed through handleJSONMessage; existing CSI/motion pipeline intact

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-27 00:26:25 -04:00
jedarden
fb691904c6 feat(dashboard): per-link motion presence indicator with amplitude time series
- Dashboard hub broadcasts motion state changes immediately on transition
  (idle↔motion) via BroadcastMotionState; periodic state snapshots include
  motion_states for new client init
- Per-link presence badge (green CLEAR / red MOTION) rendered in link list
  alongside global presence indicator in status bar
- Amplitude mean time-series chart (60 s rolling window) for selected link,
  line segments colored by motion state at each sample
- Fix: links created from JSON link_active/state events now initialize
  ampHistory and lastAmpSample so time-series accumulates from first frame

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-26 22:55:33 -04:00
jedarden
de424a1f63 feat(mothership): complete Phase 2 signal processing & detection
- Dashboard presence indicator: per-link MOTION/CLEAR badges with global
  status bar indicator, motion_state WebSocket messages, amplitude chart
- CSI recording buffer: disk-backed circular buffer (replay/store.go) with
  magic-tagged binary format, wrap/eviction, 360 MB default (~48 h at 20 Hz)
- Adaptive sensing rate: RateController ramps nodes to 20 Hz on motion,
  drops to 2 Hz after 10 s idle; wires to SendConfigToMAC over WebSocket
- Fix: alias internal/signal as sigproc to avoid conflict with os/signal
- Fix: add GetAllMotionStates() to MockIngestionState in dashboard tests

All tests pass (signal, ingestion, replay, dashboard).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-26 22:27:24 -04:00
jedarden
8230ef4222 feat(dashboard): web dashboard skeleton with Three.js 3D scene and CSI visualization
- Static HTML/JS dashboard served by mothership at /
- Three.js 3D scene with ground grid, OrbitControls (pan/zoom/rotate)
- WebSocket connection at /ws/dashboard for real-time CSI streaming
- Binary CSI frame parsing (24-byte header + I/Q payload)
- Amplitude bar chart (64 subcarriers) as 2D Canvas overlay
- Node/link panels with live status and click-to-select
- Dashboard Go package with Hub for client broadcasting
- Ingestion server broadcasts CSI frames and node events to dashboard
- 5 new tests for dashboard hub operations

Complete: 3D scene, WebSocket, amplitude chart, node/link panels
Remaining: Docker packaging (Phase 1 final item)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-26 07:40:53 -04:00