Fix bug with time in map.html and web.py

This commit is contained in:
Pablo Revilla
2025-04-21 13:41:50 -07:00
parent 9f40458597
commit c3c59bda53
3 changed files with 40 additions and 27 deletions

View File

@@ -57,23 +57,23 @@
var bounds = L.latLngBounds();
var channels = new Set(); // Stores unique channels
var nodes = [
{% for node in nodes %}
{
lat: {{ node.last_lat / 10**7 if node.last_lat else "null" }},
long: {{ node.last_long / 10**7 if node.last_long else "null" }},
long_name: "{{ node.long_name | escape }}",
short_name: "{{ node.short_name | escape }}",
channel: "{{ node.channel | escape }}",
hw_model: "{{ node.hw_model | escape }}",
role: "{{ node.role | escape }}",
last_update: "{{ node.last_update | escape }}",
firmware: "{{ node.firmware | escape }}",
id: "{{ node.node_id }}",
isRouter: "{{ 'router' in node.role.lower() }}"
},
{% endfor %}
];
var nodes = [
{% for node in nodes %}
{
lat: {{ (node.last_lat / 10**7)|round(7) }},
long: {{ (node.last_long / 10**7)|round(7) if node.last_long is not none else "null" }},
long_name: {{ (node.long_name or "") | tojson }},
short_name: {{ (node.short_name or "") | tojson }},
channel: {{ (node.channel or "") | tojson }},
hw_model: {{ (node.hw_model or "") | tojson }},
role: {{ (node.role or "") | tojson }},
last_update: {{ node.last_update | default("", true) | tojson }},
firmware: {{ (node.firmware or "") | tojson }},
id: {{ (node.node_id or "") | tojson }},
isRouter: "{{ 'router' in node.role.lower() }}"
}{{ "," if not loop.last else "" }}
{% endfor %}
];
function timeAgo(date) {
var now = new Date();
@@ -197,4 +197,4 @@
</script>
{% endblock %}
{% endblock %}

View File

@@ -81,7 +81,12 @@ select {
{% endblock %}
{% block body %}
<h1>Top Traffic Nodes</h1>
<h1>Top Traffic Nodes (last 24 hours)</h1>
<!-- Channel Filter Dropdown -->
<select id="channelFilter">
<option value="all">All Channels</option>
</select>
<div id="stats">
<p>This chart shows a bell curve (normal distribution) based on the total <strong>"Times Seen"</strong> values for all nodes. It helps visualize how frequently nodes are heard, relative to the average.</p>
@@ -89,10 +94,6 @@ select {
<p><strong>Mean:</strong> <span id="mean"></span> - <strong>Standard Deviation:</strong> <span id="stdDev"></span></p>
</div>
<!-- Channel Filter Dropdown -->
<select id="channelFilter">
<option value="all">All Channels</option>
</select>
<!-- Chart -->
<div id="bellCurveChart"></div>

View File

@@ -28,6 +28,7 @@ from meshview import decode_payload
from meshview import models
from meshview import store
from meshview.store import get_total_node_count
import traceback
CONFIG = config.CONFIG
@@ -1188,15 +1189,25 @@ async def net(request):
@routes.get("/map")
async def map(request):
try:
nodes= await store.get_nodes()
nodes = await store.get_nodes()
# Filter out nodes with no latitude
nodes = [node for node in nodes if node.last_lat is not None]
# Optional datetime formatting
for node in nodes:
if hasattr(node, "last_update") and isinstance(node.last_update, datetime.datetime):
node.last_update = node.last_update.isoformat()
print (node.last_update)
template = env.get_template("map.html")
print_memory_usage()
return web.Response(
text=template.render(nodes=nodes, site_config = CONFIG),
text=template.render(nodes=nodes, site_config=CONFIG),
content_type="text/html",
)
except Exception as e:
import traceback
traceback.print_exc()
return web.Response(
text="An error occurred while processing your request.",
status=500,
@@ -1204,6 +1215,7 @@ async def map(request):
)
# Print memory usage
def print_memory_usage():
process = psutil.Process(os.getpid())