fix(server): use max instead of sum for multi-node person aggregation

With nodes in the same room, each node sees the same people. Summing
per-node counts double-counted (2 nodes × 1 person = 2 persons).
Now uses max() so 2 nodes × 1 person = 1 person.

Verified on real hardware: COM6 (node 1) + COM9 (node 2) on ruv.net,
estimated_persons=1 with 1 person in room.

Co-Authored-By: claude-flow <ruv@ruv.net>
This commit is contained in:
ruv 2026-03-30 14:50:38 -04:00
parent 8fa4e1cbb9
commit e4c0f66922
1 changed files with 8 additions and 2 deletions

View File

@ -3210,11 +3210,14 @@ async fn udp_receiver_task(state: SharedState, udp_port: u16) {
else { 0.05 };
// Aggregate person count across all active nodes.
// Use max (not sum) because nodes in the same room see the
// same people — summing would double-count.
let now = std::time::Instant::now();
let total_persons: usize = s.node_states.values()
.filter(|n| n.last_frame_time.map_or(false, |t| now.duration_since(t).as_secs() < 10))
.map(|n| n.prev_person_count)
.sum();
.max()
.unwrap_or(0);
// Build nodes array with all active nodes.
let active_nodes: Vec<NodeInfo> = s.node_states.iter()
@ -3413,11 +3416,14 @@ async fn udp_receiver_task(state: SharedState, udp_port: u16) {
else { 0.05 };
// Aggregate person count across all active nodes.
// Use max (not sum) because nodes in the same room see the
// same people — summing would double-count.
let now = std::time::Instant::now();
let total_persons: usize = s.node_states.values()
.filter(|n| n.last_frame_time.map_or(false, |t| now.duration_since(t).as_secs() < 10))
.map(|n| n.prev_person_count)
.sum();
.max()
.unwrap_or(0);
// Build nodes array with all active nodes.
let active_nodes: Vec<NodeInfo> = s.node_states.iter()