From 17a1265842dac0be74d6a13ef02e874e6fbad584 Mon Sep 17 00:00:00 2001 From: Pablo Revilla Date: Tue, 25 Nov 2025 09:05:37 -0800 Subject: [PATCH] Fix the net page as it was not showing the date information --- meshview/store.py | 28 ++++++++++++++++++---------- meshview/templates/node.html | 9 +++++---- 2 files changed, 23 insertions(+), 14 deletions(-) diff --git a/meshview/store.py b/meshview/store.py index c625695..4512356 100644 --- a/meshview/store.py +++ b/meshview/store.py @@ -368,32 +368,40 @@ async def get_packet_stats( async def get_channels_in_period(period_type: str = "hour", length: int = 24): """ - Returns a list of distinct channels used in packets over a given period. + Returns a sorted list of distinct channels used in packets over a given period. period_type: "hour" or "day" length: number of hours or days to look back """ - now = datetime.now() + now_us = int(datetime.utcnow().timestamp() * 1_000_000) if period_type == "hour": - start_time = now - timedelta(hours=length) + delta_us = length * 3600 * 1_000_000 elif period_type == "day": - start_time = now - timedelta(days=length) + delta_us = length * 86400 * 1_000_000 else: raise ValueError("period_type must be 'hour' or 'day'") + start_us = now_us - delta_us + async with database.async_session() as session: - q = ( + stmt = ( select(Packet.channel) - .where(Packet.import_time >= start_time) - .distinct() - .order_by(Packet.channel) + .where(Packet.import_time_us >= start_us) + .distinct() + .order_by(Packet.channel) ) - result = await session.execute(q) - channels = [row[0] for row in result if row[0] is not None] + result = await session.execute(stmt) + + channels = [ + ch for ch in result.scalars().all() + if ch is not None + ] + return channels + async def get_total_packet_count( period_type: str | None = None, length: int | None = None, diff --git a/meshview/templates/node.html b/meshview/templates/node.html index 0d9a917..e2e481a 100644 --- a/meshview/templates/node.html +++ b/meshview/templates/node.html @@ -351,7 +351,7 @@ function formatLocalTime(us){ // --- Map --- function initMap(){ - map = L.map('map', { preferCanvas:true }).setView([37.7749, -122.4194], 12); + map = L.map('map', { preferCanvas:true }).setView([37.7749, -122.4194], 8); L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', { attribution:'© OpenStreetMap' }).addTo(map); @@ -397,9 +397,10 @@ function ensureMapVisible(){ map.invalidateSize(); const group = L.featureGroup(Object.values(markers)); if (group.getLayers().length > 0) - map.fitBounds(group.getBounds(), { padding:[20,20] }); - else - map.setView([37.7749, -122.4194], 11); + map.fitBounds(group.getBounds(), { + padding: [20, 20], + maxZoom: 11 // ← minimum zoom level after fitting + }); }); }