mirror of
https://github.com/pablorevilla-meshtastic/meshview.git
synced 2026-03-04 23:27:46 +01:00
Add SNR neighbors graphs.
This commit is contained in:
@@ -48,6 +48,9 @@
|
||||
{% if has_telemetry %}
|
||||
<a href="/graph/power/{{node_id}}"><img src="/graph/power/{{node_id}}" height="200em" width="200em"/></a>
|
||||
{% endif %}
|
||||
{% if neighbors %}
|
||||
<a href="/graph/neighbors/{{node_id}}"><img src="/graph/neighbors/{{node_id}}" height="200em" width="200em"/></a>
|
||||
{% endif %}
|
||||
</div>
|
||||
{% else %}
|
||||
<div class="card-body">
|
||||
|
||||
@@ -7,6 +7,7 @@ from aiohttp_sse import sse_response
|
||||
import ssl
|
||||
import re
|
||||
|
||||
from pandas import DataFrame
|
||||
import seaborn as sns
|
||||
import matplotlib.pyplot as plt
|
||||
import matplotlib.ticker as ticker
|
||||
@@ -470,6 +471,51 @@ async def graph_power(request):
|
||||
)
|
||||
|
||||
|
||||
@routes.get("/graph/neighbors/{node_id}")
|
||||
async def graph_neighbors(request):
|
||||
oldest = datetime.datetime.utcnow() - datetime.timedelta(days=4)
|
||||
|
||||
data = {}
|
||||
dates =[]
|
||||
for p in await store.get_packets_from(int(request.match_info['node_id']), PortNum.NEIGHBORINFO_APP):
|
||||
_, payload = decode_payload.decode(p)
|
||||
if p.import_time < oldest:
|
||||
break
|
||||
|
||||
dates.append(p.import_time)
|
||||
for v in data.values():
|
||||
v.append(None)
|
||||
|
||||
for n in payload.neighbors:
|
||||
data.setdefault(n.node_id, [None] * len(dates))[-1] = n.snr
|
||||
|
||||
nodes = {}
|
||||
async with asyncio.TaskGroup() as tg:
|
||||
for node_id in data:
|
||||
nodes[node_id] = tg.create_task(store.get_node(node_id))
|
||||
|
||||
data_by_short_name = {}
|
||||
for node_id, data in data.items():
|
||||
node = await nodes[node_id]
|
||||
if node:
|
||||
data_by_short_name[node.short_name] = data
|
||||
else:
|
||||
data_by_short_name[node_id_to_hex(node_id)] = data
|
||||
|
||||
fig, ax1 = plt.subplots(figsize=(10, 10))
|
||||
ax1.set_xlabel('time')
|
||||
ax1.set_ylabel('SNR')
|
||||
df = DataFrame(data_by_short_name, index=dates)
|
||||
sns.lineplot(data=df)
|
||||
|
||||
png = io.BytesIO()
|
||||
plt.savefig(png, dpi=100)
|
||||
|
||||
return web.Response(
|
||||
body=png.getvalue(),
|
||||
content_type="image/png",
|
||||
)
|
||||
|
||||
|
||||
async def run_server(bind, port, tls_cert):
|
||||
app = web.Application()
|
||||
|
||||
Reference in New Issue
Block a user