mirror of
https://github.com/pablorevilla-meshtastic/meshview.git
synced 2026-06-27 13:31:54 +02:00
Fix the net page as it was not showing the date information
This commit is contained in:
+18
-10
@@ -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,
|
||||
|
||||
@@ -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
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user