From 03e198b80c89233dac48ccf13f31fda4800d9b29 Mon Sep 17 00:00:00 2001 From: Pablo Revilla Date: Mon, 22 Sep 2025 10:18:06 -0700 Subject: [PATCH] Updates stats with pie chart and report for channel --- meshview/store.py | 28 +++++ meshview/templates/stats.html | 191 +++++++++++++++++++++------------- meshview/web.py | 11 ++ 3 files changed, 158 insertions(+), 72 deletions(-) diff --git a/meshview/store.py b/meshview/store.py index 2768dd1..7c7454d 100644 --- a/meshview/store.py +++ b/meshview/store.py @@ -340,3 +340,31 @@ async def get_packet_stats( "from_node": from_node, "data": data } + + +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. + period_type: "hour" or "day" + length: number of hours or days to look back + """ + now = datetime.now() + + if period_type == "hour": + start_time = now - timedelta(hours=length) + elif period_type == "day": + start_time = now - timedelta(days=length) + else: + raise ValueError("period_type must be 'hour' or 'day'") + + async with database.async_session() as session: + q = ( + select(Packet.channel) + .where(Packet.import_time >= start_time) + .distinct() + .order_by(Packet.channel) + ) + + result = await session.execute(q) + channels = [row[0] for row in result if row[0] is not None] + return channels diff --git a/meshview/templates/stats.html b/meshview/templates/stats.html index 29263c8..0fbec38 100644 --- a/meshview/templates/stats.html +++ b/meshview/templates/stats.html @@ -76,6 +76,15 @@ color: #66bb6a; font-weight: bold; } + +#channelSelect { + margin-bottom: 8px; + padding: 4px 6px; + background:#444; + color:#fff; + border:none; + border-radius:4px; +} {% endblock %} {% block head %} @@ -84,26 +93,24 @@ {% block body %}
-

Mesh Statistics - Summary (all available in Database)

+

Mesh Statistics - Summary (all available in Database)

-
-
-

Total Nodes

-
{{ "{:,}".format(total_nodes) }}
+
+
+

Total Nodes

+
{{ "{:,}".format(total_nodes) }}
+
+
+

Total Packets

+
{{ "{:,}".format(total_packets) }}
+
+
+

Total Packets Seen

+
{{ "{:,}".format(total_packets_seen) }}
+
-
-

Total Packets

-
{{ "{:,}".format(total_packets) }}
-
-
-

Total Packets Seen

-
{{ "{:,}".format(total_packets_seen) }}
-
-
- - - {# Daily Charts #} +

Packets per Day - All Ports (Last 14 Days)

Total: 0
@@ -120,7 +127,18 @@
- {# Hourly Charts #} + +
+

Packet Types - Last 24 Hours

+ + + +
+
+ +

Packets per Hour - All Ports

Total: 0
@@ -137,47 +155,7 @@
-
-

Packets per Hour - Position (Port 3)

-
Total: 0
- - -
-
- -
-

Packets per Hour - Node Info (Port 4)

-
Total: 0
- - -
-
- -
-

Packets per Hour - Telemetry (Port 67)

-
Total: 0
- - -
-
- -
-

Packets per Hour - Traceroute (Port 70)

-
Total: 0
- - -
-
- -
-

Packets per Hour - Neighbor Info (Port 71)

-
Total: 0
- - -
-
- - {# Node breakdown charts #} +

Hardware Breakdown

@@ -200,7 +178,7 @@
-{# Modal for expanded charts #} +