mirror of
https://github.com/pablorevilla-meshtastic/meshview.git
synced 2026-03-04 23:27:46 +01:00
Multiple changes to the code. Important to mentioned:
- Added ways to show the node data on the page with links to the nodes themselves. - more work on the graphs.
This commit is contained in:
@@ -26,3 +26,5 @@ Other Options:
|
||||
--topic
|
||||
MQTT Topic, default is 'msh/US/bayarea/#'
|
||||
|
||||
Screenshots
|
||||

|
||||
+42
-9
@@ -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
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -34,7 +34,7 @@
|
||||
</head>
|
||||
<body hx-indicator="#spinner">
|
||||
<br><div style="text-align:center"><strong>Bay Area Mesh - http://bayme.sh</strong></div>
|
||||
<div style="text-align:center">Quick Links: <a href="/">Search for a node </a> - <a href="/chat">Conversations</a> - <a href="/firehose">See <strong>everything</strong> </a> - Mesh Graph <a href="/graph/longfast">LG</a> - <a href="/graph/mediumslow">MS </a> - <a href="/nodelist">Nodes</a> - <a href="/stats">Stats </a></div><br>
|
||||
<div style="text-align:center">Quick Links: <a href="/">Search for a node </a> - <a href="/chat">Conversations</a> - <a href="/firehose">See <strong>everything</strong> </a> - Mesh Graph <a href="/graph/longfast">LF</a> - <a href="/graph/mediumslow">MS </a> - <a href="/nodelist">Nodes</a> - <a href="/stats">Stats </a></div><br>
|
||||
<div id="spinner" class="spinner-border secondary-primary htmx-indicator position-absolute top-50 start-50" role="status">
|
||||
<span class="visually-hidden">Loading...</span>
|
||||
</div>
|
||||
|
||||
@@ -33,7 +33,6 @@ tr:nth-child(odd) {
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Node ID</th>
|
||||
<th>Long Name</th>
|
||||
<th>Short Name</th>
|
||||
<th>HW Model</th>
|
||||
@@ -48,16 +47,15 @@ tr:nth-child(odd) {
|
||||
<tbody>
|
||||
{% for node in nodes %}
|
||||
<tr>
|
||||
<td> <a href="/packet_list/{{node.node_id }}">{{node.node_id }}</a></td>
|
||||
<td>{{ node.long_name }}</td>
|
||||
<td> <a href="/packet_list/{{node.node_id }}">{{node.long_name}}</a></td>
|
||||
<td>{{ node.short_name }}</td>
|
||||
<td>{{ node.hw_model }}</td>
|
||||
<td><a href="/nodelist?hw_model={{node.hw_model}}">{{node.hw_model if node.hw_model else "N/A"}}</a></td>
|
||||
<td>{{ node.firmware }}</td>
|
||||
<td>{{ node.role if node.role else "N/A" }}</td>
|
||||
<td>{{ node.last_lat if node.last_lat else "N/A" }}</td>
|
||||
<td>{{ node.last_long if node.last_long else "N/A" }}</td>
|
||||
<td>{{ node.channel }}</td>
|
||||
<td>{{ node.last_update.strftime('%-I:%M:%S %p - %d-%m-%Y') if node.last_update else "N/A" }}</td>
|
||||
<td><a href="/nodelist?role={{node.role}}">{{node.role if node.role else "N/A"}}</a></td>
|
||||
<td>{{ "{:.7f}".format(node.last_lat / 10**7) if node.last_lat else "N/A" }}</td>
|
||||
<td>{{ "{:.7f}".format(node.last_long / 10**7) if node.last_long else "N/A" }}</td>
|
||||
<td><a href="/nodelist?channel={{node.channel}}">{{node.channel if node.channel else "N/A"}}</a></td>
|
||||
<td>{{ node.last_update.strftime('%-I:%M:%S %p - %m-%d-%Y') if node.last_update else "N/A" }}</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
|
||||
+13
-5
@@ -1261,7 +1261,7 @@ async def graph_network_longfast(request):
|
||||
if edge_type[(src, dest)] in ('ni'):
|
||||
color = '#FF0000'
|
||||
elif edge_type[(src, dest)] in ('sni'):
|
||||
color = '#00FF00'
|
||||
color = '#040fb3'
|
||||
else:
|
||||
color = '#000000'
|
||||
edge_dir = "forward"
|
||||
@@ -1296,7 +1296,7 @@ async def graph_network_longfast(request):
|
||||
async def graph_network_mediumslow(request):
|
||||
try:
|
||||
root = request.query.get("root")
|
||||
depth = int(request.query.get("depth", 5))
|
||||
depth = int(request.query.get("depth", 3))
|
||||
hours = int(request.query.get("hours", 24))
|
||||
minutes = int(request.query.get("minutes", 0))
|
||||
|
||||
@@ -1423,6 +1423,7 @@ async def graph_network_mediumslow(request):
|
||||
label=node_name,
|
||||
shape='box',
|
||||
color=color,
|
||||
fontsize="10", width="0", height="0",
|
||||
href=f"/graph/mediumslow?root={node_id}&depth={depth-1}",
|
||||
))
|
||||
|
||||
@@ -1441,7 +1442,7 @@ async def graph_network_mediumslow(request):
|
||||
if edge_type[(src, dest)] in ('ni'):
|
||||
color = '#FF0000'
|
||||
elif edge_type[(src, dest)] in ('sni'):
|
||||
color = '#00FF00'
|
||||
color = '#040fb3'
|
||||
else:
|
||||
color = '#000000'
|
||||
edge_dir = "forward"
|
||||
@@ -1456,8 +1457,9 @@ async def graph_network_mediumslow(request):
|
||||
str(dest),
|
||||
color=color,
|
||||
tooltip=f'{await get_node_name(src)} -> {await get_node_name(dest)}',
|
||||
penwidth=1.85,
|
||||
penwidth=.5,
|
||||
dir=edge_dir,
|
||||
arrowsize=".5",
|
||||
))
|
||||
|
||||
return web.Response(
|
||||
@@ -1472,7 +1474,13 @@ async def graph_network_mediumslow(request):
|
||||
@routes.get("/nodelist")
|
||||
async def nodelist(request):
|
||||
try:
|
||||
nodes= await store.get_nodes()
|
||||
role = request.query.get("role")
|
||||
#print(role)
|
||||
channel = request.query.get("channel")
|
||||
print(channel)
|
||||
hw_model = request.query.get("hw_model")
|
||||
print(hw_model)
|
||||
nodes= await store.get_nodes(role,channel, hw_model)
|
||||
template = env.get_template("nodelist.html")
|
||||
return web.Response(
|
||||
text=template.render(nodes=nodes),
|
||||
|
||||
Reference in New Issue
Block a user