mirror of
https://github.com/smittix/intercept.git
synced 2026-07-17 22:08:11 -07:00
Fix heatmap: add type coercion, LAC matching, debug logging, and user feedback
The heatmap silently failed when: CID types mismatched (string vs number), LAC wasn't checked (wrong tower matched), or no data existed yet (button showed ON with no layer). Now coerces CID/LAC to Number for comparison, validates coordinates with parseFloat, logs match diagnostics to console, and only shows ON when the layer is actually rendered. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -3161,12 +3161,14 @@
|
|||||||
if (heatmapVisible) {
|
if (heatmapVisible) {
|
||||||
removeHeatmap();
|
removeHeatmap();
|
||||||
} else {
|
} else {
|
||||||
await updateHeatmap();
|
const success = await updateHeatmap();
|
||||||
heatmapVisible = true;
|
if (success) {
|
||||||
const btn = document.getElementById('heatmapToggle');
|
heatmapVisible = true;
|
||||||
btn.textContent = 'Heatmap: ON';
|
const btn = document.getElementById('heatmapToggle');
|
||||||
btn.style.borderColor = 'var(--accent-cyan)';
|
btn.textContent = 'Heatmap: ON';
|
||||||
btn.style.color = 'var(--accent-cyan)';
|
btn.style.borderColor = 'var(--accent-cyan)';
|
||||||
|
btn.style.color = 'var(--accent-cyan)';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3175,26 +3177,52 @@
|
|||||||
const response = await fetch('/gsm_spy/crowd_density?hours=1');
|
const response = await fetch('/gsm_spy/crowd_density?hours=1');
|
||||||
const data = await response.json();
|
const data = await response.json();
|
||||||
|
|
||||||
if (!data || data.length === 0) return;
|
console.log('[GSM SPY] Heatmap: crowd_density returned', Array.isArray(data) ? data.length + ' items' : data);
|
||||||
|
|
||||||
|
if (!Array.isArray(data) || data.length === 0) {
|
||||||
|
if (!heatmapVisible) {
|
||||||
|
console.warn('[GSM SPY] Heatmap: no crowd density data. Start monitoring to collect device pings.');
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
const points = [];
|
const points = [];
|
||||||
let maxIntensity = 1;
|
let maxIntensity = 1;
|
||||||
|
let matched = 0;
|
||||||
|
let unmatched = 0;
|
||||||
|
|
||||||
data.forEach(item => {
|
data.forEach(item => {
|
||||||
// Match CID to tower coordinates
|
const itemCid = Number(item.cid);
|
||||||
const cid = item.cid;
|
const itemLac = Number(item.lac);
|
||||||
|
let found = false;
|
||||||
|
|
||||||
for (const key in towers) {
|
for (const key in towers) {
|
||||||
const t = towers[key];
|
const t = towers[key];
|
||||||
if (t.cid === cid && t.lat && t.lon) {
|
if (Number(t.cid) === itemCid && Number(t.lac) === itemLac) {
|
||||||
const intensity = item.unique_devices || 1;
|
if (t.lat && t.lon && !isNaN(parseFloat(t.lat)) && !isNaN(parseFloat(t.lon))) {
|
||||||
if (intensity > maxIntensity) maxIntensity = intensity;
|
const intensity = item.unique_devices || 1;
|
||||||
points.push([t.lat, t.lon, intensity]);
|
if (intensity > maxIntensity) maxIntensity = intensity;
|
||||||
|
points.push([parseFloat(t.lat), parseFloat(t.lon), intensity]);
|
||||||
|
found = true;
|
||||||
|
} else {
|
||||||
|
console.log(`[GSM SPY] Heatmap: tower CID ${itemCid} LAC ${itemLac} has no coordinates yet`);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (found) matched++;
|
||||||
|
else unmatched++;
|
||||||
});
|
});
|
||||||
|
|
||||||
if (points.length === 0) return;
|
console.log(`[GSM SPY] Heatmap: ${matched} matched, ${unmatched} unmatched, ${points.length} points with coords`);
|
||||||
|
|
||||||
|
if (points.length === 0) {
|
||||||
|
if (!heatmapVisible) {
|
||||||
|
console.warn('[GSM SPY] Heatmap: density data exists but no towers have coordinates. Wait for geocoding.');
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
// Remove existing layer before adding new one
|
// Remove existing layer before adding new one
|
||||||
if (heatmapLayer && gsmMap.hasLayer(heatmapLayer)) {
|
if (heatmapLayer && gsmMap.hasLayer(heatmapLayer)) {
|
||||||
@@ -3210,8 +3238,10 @@
|
|||||||
}).addTo(gsmMap);
|
}).addTo(gsmMap);
|
||||||
|
|
||||||
heatmapLastRefresh = Date.now();
|
heatmapLastRefresh = Date.now();
|
||||||
|
return true;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('[GSM SPY] Heatmap update error:', error);
|
console.error('[GSM SPY] Heatmap update error:', error);
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user