move ysf metadata parsing to server; improve map pin behavior

This commit is contained in:
Jakob Ketterl 2021-01-17 19:21:13 +01:00
parent c59c5b76d8
commit 3246e5ab3a
2 changed files with 21 additions and 16 deletions

View File

@ -137,14 +137,13 @@
marker.band = update.band; marker.band = update.band;
marker.comment = update.location.comment; marker.comment = update.location.comment;
// TODO the trim should happen on the server side if (expectedCallsign && expectedCallsign == update.callsign) {
if (expectedCallsign && expectedCallsign == update.callsign.trim()) {
map.panTo(pos); map.panTo(pos);
showMarkerInfoWindow(update.callsign, pos); showMarkerInfoWindow(update.callsign, pos);
expectedCallsign = false; expectedCallsign = false;
} }
if (infowindow && infowindow.callsign && infowindow.callsign == update.callsign.trim()) { if (infowindow && infowindow.callsign && infowindow.callsign == update.callsign) {
showMarkerInfoWindow(infowindow.callsign, pos); showMarkerInfoWindow(infowindow.callsign, pos);
} }
break; break;
@ -319,6 +318,8 @@
delete infowindow.callsign; delete infowindow.callsign;
}); });
} }
delete infowindow.locator;
delete infowindow.callsign;
return infowindow; return infowindow;
} }

View File

@ -24,7 +24,7 @@ class DmrCache(object):
self.cacheTimeout = timedelta(seconds=86400) self.cacheTimeout = timedelta(seconds=86400)
def isValid(self, key): def isValid(self, key):
if not key in self.cache: if key not in self.cache:
return False return False
entry = self.cache[key] entry = self.cache[key]
return entry["timestamp"] + self.cacheTimeout > datetime.now() return entry["timestamp"] + self.cacheTimeout > datetime.now()
@ -55,20 +55,20 @@ class DmrMetaEnricher(object):
def enrich(self, meta): def enrich(self, meta):
if not Config.get()["digital_voice_dmr_id_lookup"]: if not Config.get()["digital_voice_dmr_id_lookup"]:
return None return meta
if not "source" in meta: if "source" not in meta:
return None return meta
id = meta["source"] id = meta["source"]
cache = DmrCache.getSharedInstance() cache = DmrCache.getSharedInstance()
if not cache.isValid(id): if not cache.isValid(id):
if not id in self.threads: if id not in self.threads:
self.threads[id] = threading.Thread(target=self.downloadRadioIdData, args=[id], daemon=True) self.threads[id] = threading.Thread(target=self.downloadRadioIdData, args=[id], daemon=True)
self.threads[id].start() self.threads[id].start()
return None return meta
data = cache.get(id) data = cache.get(id)
if "count" in data and data["count"] > 0 and "results" in data: if "count" in data and data["count"] > 0 and "results" in data:
return data["results"][0] meta["additional"] = data["results"][0]
return None return meta
class YsfMetaEnricher(object): class YsfMetaEnricher(object):
@ -76,11 +76,17 @@ class YsfMetaEnricher(object):
self.parser = parser self.parser = parser
def enrich(self, meta): def enrich(self, meta):
for key in ["source", "up", "down", "target"]:
if key in meta:
meta[key] = meta[key].strip()
for key in ["lat", "lon"]:
if key in meta:
meta[key] = float(meta[key])
if "source" in meta and "lat" in meta and "lon" in meta: if "source" in meta and "lat" in meta and "lon" in meta:
# TODO parsing the float values should probably happen earlier # TODO parsing the float values should probably happen earlier
loc = LatLngLocation(float(meta["lat"]), float(meta["lon"])) loc = LatLngLocation(meta["lat"], meta["lon"])
Map.getSharedInstance().updateLocation(meta["source"], loc, "YSF", self.parser.getBand()) Map.getSharedInstance().updateLocation(meta["source"], loc, "YSF", self.parser.getBand())
return None return meta
class MetaParser(Parser): class MetaParser(Parser):
@ -95,7 +101,5 @@ class MetaParser(Parser):
if "protocol" in meta: if "protocol" in meta:
protocol = meta["protocol"] protocol = meta["protocol"]
if protocol in self.enrichers: if protocol in self.enrichers:
additional_data = self.enrichers[protocol].enrich(meta) meta = self.enrichers[protocol].enrich(meta)
if additional_data is not None:
meta["additional"] = additional_data
self.handler.write_metadata(meta) self.handler.write_metadata(meta)