Skip to content

Commit

Permalink
Map: neighbors cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinelliott committed Jul 1, 2024
1 parent 8b0c319 commit fd52c3a
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions templates/static/map.html.j2
Original file line number Diff line number Diff line change
Expand Up @@ -223,17 +223,20 @@
if (node.neighbors.length == 0) {
panel += 'None';
} else {
panel += "<table border=1 cellpadding=2 cellspacing=0 width=100% class='border border-gray-300'>";
panel += "<tr><th width=33% align=left>Node</th><th width=33% align=center>SNR</th><th width=33% align=right>Distance</th></tr>";
panel += node.neighbors.map(function(neighbor) {
var nnode = nodes[neighbor.id];
if (!nnode) {
return '<span class="text-gray-600">UNK </span> / SNR: ' + neighbor.snr;
return '<tr><td class="text-gray-600">UNK</td><td align=center>' + neighbor.snr + '</td><td></td></tr>';
}
const distance = Math.sqrt(
Math.pow(node.position[0] - nnode.position[0], 2) +
Math.pow(node.position[1] - nnode.position[1], 2)
) * 111.32;
return nnode.shortname + ' / SNR: ' + neighbor.snr + ' / Distance: ' + distance.toFixed(2) + ' km';
}).join('<br/>');
return '<tr><td align=left>' + nnode.shortname + '</td><td align=center>' + neighbor.snr + '</td><td align=right>' + distance.toFixed(2) + ' km</td></tr>';
}).join('');
panel += "</table>";
node.neighbors.map(function(neighbor) {
var nnode = nodes[neighbor.id];
Expand Down Expand Up @@ -266,7 +269,7 @@
}
panel += '<br/><br/>';
panel += '<b>Heard By Nodes</b><br/>';
panel += '<b>Heard By Neighbors</b><br/>';
var heard_by = Object.keys(nodes).filter(function(id) {
return nodes[id].neighbors.some(function(neighbor) {
return neighbor.id == node.id;
Expand All @@ -275,21 +278,24 @@
if (heard_by.length == 0) {
panel += 'None';
} else {
panel += "<table border=1 cellpadding=2 cellspacing=0 width=100% class='border border-gray-300'>";
panel += "<tr><th width=33% align=left>Node</th><th width=33% align=center>SNR</th><th width=33% align=right>Distance</th></tr>";
panel += heard_by.map(function(id) {
var nnode = nodes[id];
var neighbor = nnode.neighbors.find(function(neighbor) {
return neighbor.id == node.id;
});
if (!nnode) {
return '<span class="text-gray-600">UNK </span> / SNR: ' + neighbor.snr;
return '<tr><td class="text-gray-600">UNK</td><td align=center>' + neighbor.snr + '</td><td></td></tr>';
}
// calculate distance between two nodes without using ol.sphere
const distance = Math.sqrt(
Math.pow(node.position[0] - nnode.position[0], 2) +
Math.pow(node.position[1] - nnode.position[1], 2)
) * 111.32;
return nnode.shortname + ' / SNR: ' + neighbor.snr + ' / Distance: ' + distance.toFixed(2) + ' km';
}).join('<br/>');
return '<tr><td align=left>' + nnode.shortname + '</td><td align=center>' + neighbor.snr + '</td><td align=right>' + distance.toFixed(2) + ' km</td></tr>';
}).join('');
panel += "</table>";
// add the heard_by lines
heard_by.map(function(id) {
Expand Down Expand Up @@ -331,7 +337,7 @@
});
}
panel += '<br/><br/>';
panel += '<br/>';
panel += '<b>Elsewhere</b><br/>';
var node_id = parseInt(node.id.replace('!', ''), 16);
Expand Down

0 comments on commit fd52c3a

Please sign in to comment.