From 91ff7edbf9db0655d0fe93495c90af30df9177fd Mon Sep 17 00:00:00 2001 From: Pablo Revilla Date: Fri, 28 Mar 2025 14:05:48 -0700 Subject: [PATCH] Changes: - Added the link to another sample instance --- meshview/store.py | 62 ++++++-------------------------- meshview/templates/base.html | 20 +++++++---- meshview/templates/map.html | 69 ++++++++++++++++++++++-------------- meshview/web.py | 8 +++-- 4 files changed, 72 insertions(+), 87 deletions(-) diff --git a/meshview/store.py b/meshview/store.py index 5d35edd..711f532 100644 --- a/meshview/store.py +++ b/meshview/store.py @@ -144,14 +144,6 @@ async def get_total_packet_count(): result = await session.execute(q) return result.scalar() # Return the total count of packets -# We count the total amount of nodes -async def get_total_node_count(): - async with database.async_session() as session: - q = select(func.count(Node.id)) # Use SQLAlchemy's func to count nodes - q = q.where(Node.last_update > datetime.datetime.now() - datetime.timedelta(days=1)) # Look for nodes with nodeinfo updates in the last 24 hours - result = await session.execute(q) - return result.scalar() # Return the total count of nodes - # We count the total amount of seen packets async def get_total_packet_seen_count(): async with database.async_session() as session: @@ -160,59 +152,24 @@ async def get_total_packet_seen_count(): return result.scalar() # Return the total count of seen packets -async def get_total_node_count_longfast() -> int: + +async def get_total_node_count(channel: str = None) -> int: try: - # Open an asynchronous session with the database async with database.async_session() as session: - # Build the query to count nodes where channel == 'LongFast' - q = select(func.count(Node.id)) - q = q.where(Node.last_update > datetime.datetime.now() - datetime.timedelta( days=1)) # Look for nodes with nodeinfo updates in the last 24 hours - q = q.where(Node.channel == 'LongFast') # + q = select(func.count(Node.id)).where( + Node.last_update > datetime.datetime.now() - datetime.timedelta(days=1) + ) + + if channel: + q = q.where(Node.channel == channel) - # Execute the query asynchronously and fetch the result result = await session.execute(q) - - # Return the scalar value (the count of nodes) return result.scalar() except Exception as e: - # Log or handle the exception if needed (optional, replace with logging if necessary) print(f"An error occurred: {e}") - return 0 # Return 0 or an appropriate fallback value in case of an error + return 0 -async def get_total_node_count_mediumslow() -> int: - try: - # Open an asynchronous session with the database - async with database.async_session() as session: - # Build the query to count nodes where channel == 'LongFast' - q = select(func.count(Node.id)) - q = q.where(Node.last_update > datetime.datetime.now() - datetime.timedelta( - days=1)) # Look for nodes with nodeinfo updates in the last 24 hours - q = q.where(Node.channel == 'MediumSlow') # - # Execute the query asynchronously and fetch the result - result = await session.execute(q) - - # Return the scalar value (the count of nodes) - return result.scalar() - except Exception as e: - # Log or handle the exception if needed (optional, replace with logging if necessary) - print(f"An error occurred: {e}") - return 0 # Return 0 or an appropriate fallback value in case of an error - - -# Get Nodes for mediumslow only -# p.r. -async def get_nodes_mediumslow(): - async with database.async_session() as session: - result = await session.execute( - select(Node) - .where( - (Node.channel == "MediumSlow") - ) - ) - - return result.scalars() - async def get_top_traffic_nodes(): async with database.async_session() as session: result = await session.execute(text(""" @@ -312,3 +269,4 @@ async def get_nodes(role=None, channel=None, hw_model=None): except Exception as e: print("error reading DB") # Consider using logging instead of print return [] # Return an empty list in case of failure + diff --git a/meshview/templates/base.html b/meshview/templates/base.html index b6d438b..af3a8c4 100644 --- a/meshview/templates/base.html +++ b/meshview/templates/base.html @@ -37,12 +37,20 @@
{{ site_config["site"]["title"] }} {{ site_config["site"]["domain"] }}
{{ site_config["site"]["message"] }}
-
Quick Links:  Nodes - Conversations - See everything -  - Mesh Graph LF - MS  - Stats -  - Weekly Net - Map - Top Traffic

-
- Loading... -
+
Quick Links:   + {% if site_config["site"]["nodes"] == "True" %}Nodes - {% endif %} + {% if site_config["site"]["conversations"] == "True" %}Conversations - {% endif %} + {% if site_config["site"]["everything"] == "True" %}See everything - {% endif %} + {% if site_config["site"]["graph_lf"] == "True" %} Mesh Graph: LF - {% endif %} + {% if site_config["site"]["graph_ms"] == "True" %}MS - {% endif %} + {% if site_config["site"]["graph_mf"] == "True" %}MF - {% endif %} + {% if site_config["site"]["net"] == "True" %}Weekly Net - {% endif %} + {% if site_config["site"]["map"] == "True" %}Map - {% endif %} + {% if site_config["site"]["stats"] == "True" %}Stats - {% endif %} + {% if site_config["site"]["top"] == "True" %}Top Traffic{% endif %} +

+ + {% block body %} {% endblock %}
Visit Meshview on Github. Also visit the original Meshview by Armooo.

diff --git a/meshview/templates/map.html b/meshview/templates/map.html index c214036..f3984c3 100644 --- a/meshview/templates/map.html +++ b/meshview/templates/map.html @@ -34,10 +34,7 @@
- LongFast - MediumSlow - LongFast Routers - MediumSlow Routers +
+ {% endblock %} diff --git a/meshview/web.py b/meshview/web.py index 773147b..5608a28 100644 --- a/meshview/web.py +++ b/meshview/web.py @@ -26,6 +26,8 @@ import gc from meshview import config import json +from meshview.store import get_total_node_count + CONFIG = config.CONFIG env = Environment(loader=PackageLoader("meshview"), autoescape=select_autoescape()) @@ -1191,8 +1193,8 @@ async def stats(request): total_packets = await store.get_total_packet_count() total_nodes = await store.get_total_node_count() total_packets_seen = await store.get_total_packet_seen_count() - total_nodes_longfast = await store.get_total_node_count_longfast() - total_nodes_mediumslow = await store.get_total_node_count_mediumslow() + total_nodes_longfast = await get_total_node_count("LongFast") + total_nodes_mediumslow = await get_total_node_count("MediumSlow") print_memory_usage() template = env.get_template("stats.html") return web.Response( @@ -1208,7 +1210,7 @@ async def stats(request): ) except Exception as e: return web.Response( - text="An error occurred while processing your request.", + text=f"An error occurred: {str(e)}", status=500, content_type="text/plain", )