diff --git a/meshview/store.py b/meshview/store.py index 653a6c4..ad13358 100644 --- a/meshview/store.py +++ b/meshview/store.py @@ -149,7 +149,7 @@ async def get_total_packet_seen_count(): async with database.async_session() as session: q = select(func.count(PacketSeen.node_id)) # Use SQLAlchemy's func to count nodes result = await session.execute(q) - return result.scalar() # Return the total count of seen packets + return result.scalar() # Return the` total count of seen packets @@ -172,7 +172,7 @@ async def get_total_node_count(channel: str = None) -> int: async def get_top_traffic_nodes(): try: - async with database.async_session() as session: # Assuming this is your DB session + async with database.async_session() as session: result = await session.execute(text(""" SELECT n.node_id, @@ -219,7 +219,7 @@ async def get_node_traffic(node_id: int): FROM packet JOIN node ON packet.from_node_id = node.node_id WHERE node.node_id = :node_id - AND packet.import_time >= DATETIME('now', 'localtime', '-1 day') + AND packet.import_time >= DATETIME('now', 'localtime', '-24 hours') GROUP BY packet.portnum ORDER BY packet_count DESC; """), {"node_id": node_id} @@ -241,7 +241,7 @@ async def get_node_traffic(node_id: int): -async def get_nodes(role=None, channel=None, hw_model=None): +async def get_nodes(role=None, channel=None, hw_model=None, days_active=None): """ Fetches nodes from the database based on optional filtering criteria. @@ -268,6 +268,9 @@ async def get_nodes(role=None, channel=None, hw_model=None): if hw_model is not None: query = query.where(Node.hw_model == hw_model) + if days_active is not None: + query = query.where(Node.last_update > datetime.datetime.now() - datetime.timedelta(days_active)) + # Exclude nodes where last_update is an empty string query = query.where(Node.last_update != "") diff --git a/meshview/web.py b/meshview/web.py index 5a87fba..f02808b 100644 --- a/meshview/web.py +++ b/meshview/web.py @@ -800,8 +800,6 @@ async def graph_traceroute(request): ) - - @routes.get("/graph/traceroute2/{packet_id}") async def graph_traceroute2(request): packet_id = int(request.match_info['packet_id']) @@ -1180,7 +1178,7 @@ async def net(request): @routes.get("/map") async def map(request): try: - nodes = await store.get_nodes() + nodes = await store.get_nodes(days_active=3) # Filter out nodes with no latitude nodes = [node for node in nodes if node.last_lat is not None]