From ade52dedb91e177567f0729f099ca70ef7999bb1 Mon Sep 17 00:00:00 2001 From: Mark Jessop Date: Sun, 11 Aug 2019 20:02:50 +0930 Subject: [PATCH] Allow bearing store to be cleared from the web UI --- chasemapper/bearings.py | 15 +++++++++++++++ horusmapper.py | 10 ++++++++++ static/js/bearings.js | 23 ++++++++++++++++++++--- static/js/tables.js | 14 ++++++++++++++ templates/index.html | 24 ++++++++++++++++++++++-- 5 files changed, 81 insertions(+), 5 deletions(-) diff --git a/chasemapper/bearings.py b/chasemapper/bearings.py index 32476a1..d0b55a4 100644 --- a/chasemapper/bearings.py +++ b/chasemapper/bearings.py @@ -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() diff --git a/horusmapper.py b/horusmapper.py index 85adb6c..130d196 100644 --- a/horusmapper.py +++ b/horusmapper.py @@ -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 """ diff --git a/static/js/bearings.js b/static/js/bearings.js index a14b5bd..e762d02 100644 --- a/static/js/bearings.js +++ b/static/js/bearings.js @@ -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){ } } + diff --git a/static/js/tables.js b/static/js/tables.js index c01be79..ec58aa7 100644 --- a/static/js/tables.js +++ b/static/js/tables.js @@ -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(); } diff --git a/templates/index.html b/templates/index.html index d9235a0..ee82520 100644 --- a/templates/index.html +++ b/templates/index.html @@ -323,6 +323,22 @@ }) .addTo(map); + + L.control.custom({ + position: 'bottomright', + content : "
", + 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 @@
-
+
-
+

Bearing Style

@@ -756,6 +772,10 @@ Custom Color
+
+
+
+