From f1e3a57fcfb933c45231fd115355705d81d3d93c Mon Sep 17 00:00:00 2001 From: you Date: Sat, 21 Mar 2026 23:10:10 +0000 Subject: [PATCH] fix: set header observer/path to earliest observation on DB load During _loadNormalized(), observations load in DESC order so the first observation processed is the LATEST. tx.observer_id was set from this latest observation. Added post-load pass that finds the earliest observation by timestamp and sets tx.observer_id/path_json to match. --- packet-store.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/packet-store.js b/packet-store.js index bc0cafc6..ffb300f8 100644 --- a/packet-store.js +++ b/packet-store.js @@ -156,6 +156,22 @@ class PacketStore { } } + // Post-load: set each transmission's observer/path to the EARLIEST observation + for (const tx of this.packets) { + if (tx.observations.length > 0) { + let earliest = tx.observations[0]; + for (let i = 1; i < tx.observations.length; i++) { + if (tx.observations[i].timestamp < earliest.timestamp) earliest = tx.observations[i]; + } + tx.observer_id = earliest.observer_id; + tx.observer_name = earliest.observer_name; + tx.snr = earliest.snr; + tx.rssi = earliest.rssi; + tx.path_json = earliest.path_json; + tx.direction = earliest.direction; + } + } + // Post-load: build ADVERT-by-observer index (needs all observations loaded first) for (const tx of this.packets) { if (tx.payload_type === 4 && tx.decoded_json) {