diff --git a/meshview/store.py b/meshview/store.py index 711f532..b5deba3 100644 --- a/meshview/store.py +++ b/meshview/store.py @@ -171,29 +171,41 @@ async def get_total_node_count(channel: str = None) -> int: async def get_top_traffic_nodes(): - async with database.async_session() as session: - result = await session.execute(text(""" - SELECT - n.node_id, - n.long_name, - n.role, - COUNT(p.id) AS packet_count - FROM - packet p - JOIN - node n - ON - p.from_node_id = n.node_id - WHERE - p.import_time >= DATETIME('now', 'localtime', '-1 day') - GROUP BY - n.long_name, n.role - ORDER BY - packet_count DESC - LIMIT 100; - """)) + try: + async with database.async_session() as session: # Assuming this is your DB session + result = await session.execute(text(""" + SELECT + n.node_id, + n.long_name, + n.short_name, + n.channel, + COUNT(DISTINCT p.id) AS total_packets_sent, + COUNT(ps.packet_id) AS total_times_seen + FROM node n + LEFT JOIN packet p ON n.node_id = p.from_node_id + AND p.import_time >= DATETIME('now', '-24 hours') + LEFT JOIN packet_seen ps ON p.id = ps.packet_id + GROUP BY n.node_id, n.long_name, n.short_name + ORDER BY total_times_seen DESC; + """)) + + rows = result.fetchall() + + nodes = [{ + 'node_id': row[0], + 'long_name': row[1], + 'short_name': row[2], + 'channel': row[3], + 'total_packets_sent': row[4], + 'total_times_seen': row[5] + } for row in rows] + return nodes + + except Exception as e: + print(f"Error retrieving top traffic nodes: {str(e)}") + return [] + - return result.fetchall() # Returns a list of tuples async def get_node_traffic(node_id: int): try: diff --git a/meshview/templates/base.html b/meshview/templates/base.html index 9b422e4..b45b3ac 100644 --- a/meshview/templates/base.html +++ b/meshview/templates/base.html @@ -10,8 +10,6 @@ - - {% block head %} {% endblock %} @@ -34,7 +32,7 @@ {% endblock %} -
+| Node Name | -Role | -Packet Count | -||
|---|---|---|---|---|
| Long Name | +Short Name | +Channel | +Packets Sent | +Times Seen | +
| {{ node[1] }} | -{{ node[2] }} | -{{ node[3] }} | -||
| {{ node.long_name }} | +{{ node.short_name }} | +{{ node.channel }} | +{{ node.total_packets_sent }} | +{{ node.total_times_seen }} | +
No top traffic nodes available.
+ {% endif %} + + {% endblock %} diff --git a/meshview/web.py b/meshview/web.py index 220b371..f7b3a06 100644 --- a/meshview/web.py +++ b/meshview/web.py @@ -1163,7 +1163,7 @@ async def net(request): # Filter packets: exclude "seq \d+$" but include those containing Tag filtered_packets = [ p for p in ui_packets - if not seq_pattern.match(p.payload) and CONFIG["site"]["net_tag"] in p.payload.lower() + if not seq_pattern.match(p.payload) and (CONFIG["site"]["net_tag"]).lower() in p.payload.lower() ] # Render template