add pskreporter dupe check and stats

This commit is contained in:
Jakob Ketterl 2019-11-22 17:16:40 +01:00
parent 7dde793f9e
commit 98901ac668

View File

@ -3,9 +3,12 @@ import threading
import time import time
import random import random
import socket import socket
from functools import reduce
from operator import and_
from owrx.config import PropertyManager from owrx.config import PropertyManager
from owrx.version import openwebrx_version from owrx.version import openwebrx_version
from owrx.locator import Locator from owrx.locator import Locator
from owrx.metrics import Metrics, CounterMetric
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@ -49,6 +52,11 @@ class PskReporter(object):
self.spotLock = threading.Lock() self.spotLock = threading.Lock()
self.uploader = Uploader() self.uploader = Uploader()
self.timer = None self.timer = None
metrics = Metrics.getSharedInstance()
self.dupeCounter = CounterMetric()
metrics.addMetric("pskreporter.duplicates", self.dupeCounter)
self.spotCounter = CounterMetric()
metrics.addMetric("pskreporter.spots", self.spotCounter)
def scheduleNextUpload(self): def scheduleNextUpload(self):
if self.timer: if self.timer:
@ -58,10 +66,26 @@ class PskReporter(object):
self.timer = threading.Timer(delay, self.upload) self.timer = threading.Timer(delay, self.upload)
self.timer.start() self.timer.start()
def spotEquals(self, s1, s2):
keys = ["callsign", "timestamp", "locator", "mode", "msg"]
return reduce(
and_,
map(
lambda key: s1[key] == s2[key],
keys
)
)
def spot(self, spot): def spot(self, spot):
if not spot["mode"] in PskReporter.supportedModes: if not spot["mode"] in PskReporter.supportedModes:
return return
with self.spotLock: with self.spotLock:
if any(x for x in self.spots if self.spotEquals(spot, x)):
# dupe
self.dupeCounter.inc()
else:
self.spotCounter.inc()
self.spots.append(spot) self.spots.append(spot)
self.scheduleNextUpload() self.scheduleNextUpload()