server-side removal of map positions
This commit is contained in:
parent
d0cecbdfd7
commit
d1f46c8f55
@ -230,3 +230,10 @@ csdr_print_bufsizes = False # This prints the buffer sizes used for csdr proces
|
|||||||
csdr_through = False # Setting this True will print out how much data is going into the DSP chains.
|
csdr_through = False # Setting this True will print out how much data is going into the DSP chains.
|
||||||
|
|
||||||
nmux_memory = 50 #in megabytes. This sets the approximate size of the circular buffer used by nmux.
|
nmux_memory = 50 #in megabytes. This sets the approximate size of the circular buffer used by nmux.
|
||||||
|
|
||||||
|
google_maps_api_key = ""
|
||||||
|
|
||||||
|
# how long should positions be visible on the map?
|
||||||
|
# they will start fading out after half of that
|
||||||
|
# in seconds; default: 2 hours
|
||||||
|
map_position_retention_time = 2 * 60 * 60
|
49
owrx/map.py
49
owrx/map.py
@ -1,4 +1,9 @@
|
|||||||
from datetime import datetime
|
from datetime import datetime, timedelta
|
||||||
|
import threading, time
|
||||||
|
from owrx.config import PropertyManager
|
||||||
|
|
||||||
|
import logging
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class Location(object):
|
class Location(object):
|
||||||
@ -17,6 +22,16 @@ class Map(object):
|
|||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.clients = []
|
self.clients = []
|
||||||
self.positions = {}
|
self.positions = {}
|
||||||
|
|
||||||
|
def removeLoop():
|
||||||
|
while True:
|
||||||
|
try:
|
||||||
|
self.removeOldPositions()
|
||||||
|
except Exception:
|
||||||
|
logger.exception("error while removing old map positions")
|
||||||
|
time.sleep(60)
|
||||||
|
|
||||||
|
threading.Thread(target=removeLoop, daemon=True).start()
|
||||||
super().__init__()
|
super().__init__()
|
||||||
|
|
||||||
def broadcast(self, update):
|
def broadcast(self, update):
|
||||||
@ -25,7 +40,14 @@ class Map(object):
|
|||||||
|
|
||||||
def addClient(self, client):
|
def addClient(self, client):
|
||||||
self.clients.append(client)
|
self.clients.append(client)
|
||||||
client.write_update([{"callsign": callsign, "location": record["loc"].__dict__()} for (callsign, record) in self.positions.items()])
|
client.write_update([
|
||||||
|
{
|
||||||
|
"callsign": callsign,
|
||||||
|
"location": record["location"].__dict__(),
|
||||||
|
"lastseen": record["updated"].timestamp() * 1000
|
||||||
|
}
|
||||||
|
for (callsign, record) in self.positions.items()
|
||||||
|
])
|
||||||
|
|
||||||
def removeClient(self, client):
|
def removeClient(self, client):
|
||||||
try:
|
try:
|
||||||
@ -34,9 +56,28 @@ class Map(object):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
def updateLocation(self, callsign, loc: Location):
|
def updateLocation(self, callsign, loc: Location):
|
||||||
self.positions[callsign] = {"loc": loc, "updated": datetime.now()}
|
ts = datetime.now()
|
||||||
self.broadcast([{"callsign": callsign, "location": loc.__dict__()}])
|
self.positions[callsign] = {"location": loc, "updated": ts}
|
||||||
|
self.broadcast([
|
||||||
|
{
|
||||||
|
"callsign": callsign,
|
||||||
|
"location": loc.__dict__(),
|
||||||
|
"lastseen": ts.timestamp() * 1000
|
||||||
|
}
|
||||||
|
])
|
||||||
|
|
||||||
|
def removeLocation(self, callsign):
|
||||||
|
self.positions.pop(callsign, None)
|
||||||
|
# TODO broadcast removal to clients
|
||||||
|
|
||||||
|
def removeOldPositions(self):
|
||||||
|
pm = PropertyManager.getSharedInstance()
|
||||||
|
retention = timedelta(seconds=pm["map_position_retention_time"])
|
||||||
|
cutoff = datetime.now() - retention
|
||||||
|
|
||||||
|
to_be_removed = [callsign for (callsign, pos) in self.positions.items() if pos["updated"] < cutoff]
|
||||||
|
for callsign in to_be_removed:
|
||||||
|
self.removeLocation(callsign)
|
||||||
|
|
||||||
class LatLngLocation(Location):
|
class LatLngLocation(Location):
|
||||||
def __init__(self, lat: float, lon: float):
|
def __init__(self, lat: float, lon: float):
|
||||||
|
Loading…
Reference in New Issue
Block a user