Migrate bandwidth-history to accumulated HourlyBandwidth data#126
Conversation
…ta (#125) Switch per-device and network hourly bandwidth endpoints from polling-based DeviceConnection rate snapshots to accumulated HourlyBandwidth byte totals. Also fixes UTC timezone bug in signal quality history timestamps. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Code ReviewThis PR migrates both bandwidth-history endpoints from polling-based 🔴 Critical — Data integrity: collector upsert silently inserts duplicates instead of updatingFile: The HourlyBandwidth.device_id == device_id # where device_id is NoneIn SQL, The fix is to use HourlyBandwidth.device_id.is_(device_id) # or .is_(None) when device_id is NoneThe same issue appears in the 🟡 High — Null guard removed from single-device chart but kept in group chartFile: The old code guarded against null fields before accumulating: if (point.download_mbps !== null && point.upload_mbps !== null) { ... }The new single-device chart drops this guard: hourlyData[hour].download_mb += point.download_bytes / 1000000; // no null check
hourlyData[hour].upload_mb += point.upload_bytes / 1000000;But the group-member chart (line 1790) retains a null check: if (timestamp >= todayMidnight && point.download_bytes !== null && point.upload_bytes !== null)
🟡 Medium — Tests never seed
|
| Severity | Finding |
|---|---|
| 🔴 Critical | Collector device_id == None lookup never matches; inserts duplicate rows on every run |
| 🟡 High | Single-device hourly chart drops null guard that group chart keeps; NaN propagates silently |
| 🟡 Medium | Bandwidth-history tests never seed HourlyBandwidth rows; new field names unverified |
| 🔵 Minor | Redundant from datetime import timedelta import inside function body |
The signal-quality timezone fix looks correct. The timezone-cutoff logic in both updated endpoints is consistent and matches the established pattern in the file.
Review by Claude Sonnet 4.6
Summary
/devices/{mac}/bandwidth-historyand/network/bandwidth-historyfrom polling-basedDeviceConnectionrate snapshots (Mbps) to accumulatedHourlyBandwidthbyte totalsdownload_mbps/upload_mbpstodownload_bytes/upload_bytessignal_analysis_service.py)Closes #125
Test plan
HourlyBandwidthtable has per-device records (device_id IS NOT NULL)/devices/{mac}/bandwidth-historyreturnsdownload_bytes/upload_bytesfields/network/bandwidth-historyreturnsdownload_bytes/upload_bytesfieldsAuthored by Merlin 🪄