diff --git a/README b/README index d4c2f7f..6e3b32e 100644 --- a/README +++ b/README @@ -26,3 +26,5 @@ Other Options: --topic MQTT Topic, default is 'msh/US/bayarea/#' +Screenshots + \ No newline at end of file diff --git a/meshview/store.py b/meshview/store.py index 3c5dec4..e0ff9df 100644 --- a/meshview/store.py +++ b/meshview/store.py @@ -506,19 +506,52 @@ async def get_nodes_mediumslow(): (Node.channel == "MediumSlow") ) ) + return result.scalars() +async def get_nodes(role=None, channel=None, hw_model=None): + """ + Fetches nodes from the database based on optional filtering criteria. -async def get_nodes(): - async with database.async_session() as session: - result = await session.execute( - select(Node) - .where(Node.last_update != "") - .order_by(Node.long_name) # Sorting by long_name - ) - return result.scalars() - + Parameters: + role (str, optional): The role of the node (converted to uppercase for consistency). + channel (str, optional): The communication channel associated with the node. + hw_model (str, optional): The hardware model of the node. + + Returns: + list: A list of Node objects that match the given criteria. + """ + try: + async with database.async_session() as session: + print(channel) # Debugging output (consider replacing with logging) + + # Start with a base query selecting all nodes + query = select(Node) + + # Apply filters based on provided parameters + if role is not None: + query = query.where(Node.role == role.upper()) # Ensure role is uppercase + if channel is not None: + query = query.where(Node.channel == channel) + if hw_model is not None: + query = query.where(Node.hw_model == hw_model) + + # Exclude nodes where last_update is an empty string + query = query.where(Node.last_update != "") + + # Order results by long_name in ascending order + query = query.order_by(Node.long_name.asc()) + + # Execute the query and retrieve results + result = await session.execute(query) + nodes = result.scalars().all() + + return nodes # Return the list of nodes + + 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 0c40b77..e99f6e3 100644 --- a/meshview/templates/base.html +++ b/meshview/templates/base.html @@ -34,7 +34,7 @@
| Node ID | Long Name | Short Name | HW Model | @@ -48,16 +47,15 @@ tr:nth-child(odd) {|||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| {{node.node_id }} | -{{ node.long_name }} | +{{node.long_name}} | {{ node.short_name }} | -{{ node.hw_model }} | +{{node.hw_model if node.hw_model else "N/A"}} | {{ node.firmware }} | -{{ node.role if node.role else "N/A" }} | -{{ node.last_lat if node.last_lat else "N/A" }} | -{{ node.last_long if node.last_long else "N/A" }} | -{{ node.channel }} | -{{ node.last_update.strftime('%-I:%M:%S %p - %d-%m-%Y') if node.last_update else "N/A" }} | +{{node.role if node.role else "N/A"}} | +{{ "{:.7f}".format(node.last_lat / 10**7) if node.last_lat else "N/A" }} | +{{ "{:.7f}".format(node.last_long / 10**7) if node.last_long else "N/A" }} | +{{node.channel if node.channel else "N/A"}} | +{{ node.last_update.strftime('%-I:%M:%S %p - %m-%d-%Y') if node.last_update else "N/A" }} |