Allow bearing store to be cleared from the web UI

bearings
Mark Jessop 2019-08-11 20:02:50 +09:30
rodzic 2e8b716f59
commit ade52dedb9
5 zmienionych plików z 81 dodań i 5 usunięć

Wyświetl plik

@ -13,6 +13,8 @@
import logging
import time
from threading import Lock
class Bearings(object):
@ -48,6 +50,8 @@ class Bearings(object):
# }
self.bearings = {}
self.bearing_lock = Lock()
# Internal record of the chase car position, which is updated with incoming GPS data.
# If incoming bearings do not contain lat/lon information, we fuse them with this position,
@ -130,6 +134,8 @@ class Bearings(object):
if bearing['type'] != 'BEARING':
return
_arrival_time = time.time()
# Get a copy of the current car position, in case it is updated
@ -195,11 +201,14 @@ class Bearings(object):
return
# We now have our bearing - now we need to store it
self.bearing_lock.acquire()
self.bearings["%.4f" % _arrival_time] = _new_bearing
# Now we need to do a clean-up of our bearing list.
# At this point, we should always have at least 2 bearings in our store
if len(self.bearings) == 1:
self.bearing_lock.release()
return
# Keep a list of what we remove, so we can pass it on to the web clients.
@ -229,6 +238,7 @@ class Bearings(object):
# Advance to the next entry in the list.
_curr_time = float(_bearing_list[0])
self.bearing_lock.release()
# Now we need to update the web clients on what has changed.
_client_update = {
@ -240,6 +250,11 @@ class Bearings(object):
self.sio.emit('bearing_change', _client_update, namespace='/chasemapper')
def flush(self):
""" Clear the bearing store """
self.bearing_lock.acquire()
self.bearings = {}
self.bearing_lock.release()

Wyświetl plik

@ -527,6 +527,16 @@ def clear_car_data(data):
logging.warning("Client requested all chase car data be cleared.")
car_track = GenericTrack()
@socketio.on('bearing_store_clear', namespace='/chasemapper')
def clear_bearing_data(data):
""" Clear all bearing data """
global bearing_store
logging.warning("Client requested bearing data be cleared.")
bearing_store.flush()
@socketio.on('mark_recovered', namespace='/chasemapper')
def mark_payload_recovered(data):
""" Mark a payload as recovered, by uploading a station position """

Wyświetl plik

@ -85,7 +85,7 @@ function bearingValid(bearing){
return _show_bearing;
}
function addBearing(timestamp, bearing){
function addBearing(timestamp, bearing, live){
bearing_store[timestamp] = bearing;
@ -106,6 +106,12 @@ function addBearing(timestamp, bearing){
if (bearingValid(bearing_store[timestamp]) == true){
bearing_store[timestamp].line.addTo(map);
}
if (live == true){
$("#bearing_table").tabulator("setData", [{id:1, bearing: bearing_store[timestamp].true_bearing.toFixed(0), confidence: bearing_store[timestamp].confidence.toFixed(0)}]);
$("#bearing_table").show();
}
}
@ -187,7 +193,7 @@ function initialiseBearings(){
success: function(data) {
$.each(data, function(key, value) {
addBearing(key, value);
addBearing(key, value, false);
});
}
});
@ -198,7 +204,7 @@ function initialiseBearings(){
function bearingUpdate(data){
// Remove any bearings that have been requested.
removeBearings(data.remove);
addBearing(data.add.timestamp, data.add);
addBearing(data.add.timestamp, data.add, true);
}
@ -232,6 +238,16 @@ function toggleBearingsOnlyMode(){
}
function flushBearings(){
// Send a message to the server to flush the bearing store, then clear our local bearing store.
var _confirm = confirm("Really clear all Bearing data?");
if (_confirm == true){
socket.emit('bearing_store_clear', {data: 'plzkthx'});
destroyAllBearings();
}
}
/**
Returns the point that is a distance and heading away from
the given origin point.
@ -282,3 +298,4 @@ function calculateBearingOpacity(bearing_timestamp){
}
}

Wyświetl plik

@ -151,6 +151,20 @@ function initTables(){
toggleSummarySize();
}
});
$("#bearing_table").tabulator({
layout:"fitData",
layoutColumnsOnNewData:true,
//selectable:1, // TODO...
columns:[ //Define Table Columns
{title:"Bearing", field:"bearing", headerSort:false},
{title:"Score", field:'confidence', headerSort:false}
],
data:[{id: 1, bearing:0.0, confidence:0.0}]
});
$("#bearing_table").hide();
}

Wyświetl plik

@ -323,6 +323,22 @@
})
.addTo(map);
L.control.custom({
position: 'bottomright',
content : "<div id='bearing_table'></div>",
classes : 'btn-group-vertical btn-group-sm',
id: 'bearing_data',
style :
{
margin: '5px',
padding: '0px 0 0 0',
cursor: 'pointer',
}
})
.addTo(map);
// Follow buttons - these just set the radio buttons on the settings pane.
// TODO: Figure out how to centre the icons under iOS's Safari browser.
// Also TODO: Find a decent balloon icon!
@ -722,10 +738,10 @@
<div class="paramRow">
<button type="button" class="paramSelector" id="clearBearingsBtn" onclick='destroyAllBearings();'>Clear Bearings</button></br>
<button type="button" class="paramSelector" id="clearBearingsBtn" onclick='destroyAllBearings();'>Clear Map</button></br>
</div>
<div class="paramRow">
<button type="button" class="paramSelector" id="redrawBearingsBtn" onclick='redrawBearings();'>Redraw Bearings</button></br>
<button type="button" class="paramSelector" id="flushBearingsBtn" onclick='flushBearings();'>Flush Bearing Store</button></br>
</div>
<h3>Bearing Style</h3>
@ -756,6 +772,10 @@
<b>Custom Color</b><input type="text" class="paramEntry" id="bearingCustomColor" value="#FF0000"><br/>
</div>
<div class="paramRow">
<button type="button" class="paramSelector" id="redrawBearingsBtn" onclick='redrawBearings();'>Redraw Bearings</button></br>
</div>
</div>
</div>
</div>