create reporting engine to distribute spots

This commit is contained in:
Jakob Ketterl 2021-01-14 20:52:56 +01:00
parent 2334ad1d5b
commit 132bd2b445
5 changed files with 63 additions and 38 deletions

View File

@ -11,7 +11,7 @@ from owrx.sdr import SdrService
from socketserver import ThreadingMixIn from socketserver import ThreadingMixIn
from owrx.service import Services from owrx.service import Services
from owrx.websocket import WebSocketConnection from owrx.websocket import WebSocketConnection
from owrx.pskreporter import PskReporter from owrx.reporting import ReportingEngine
from owrx.version import openwebrx_version from owrx.version import openwebrx_version
@ -67,4 +67,4 @@ Support and info: https://groups.io/g/openwebrx
except KeyboardInterrupt: except KeyboardInterrupt:
WebSocketConnection.closeAll() WebSocketConnection.closeAll()
Services.stop() Services.stop()
PskReporter.stop() ReportingEngine.stop()

View File

@ -4,10 +4,10 @@ import re
from js8py import Js8 from js8py import Js8
from js8py.frames import Js8FrameHeartbeat, Js8FrameCompound from js8py.frames import Js8FrameHeartbeat, Js8FrameCompound
from .map import Map, LocatorLocation from .map import Map, LocatorLocation
from .pskreporter import PskReporter
from .metrics import Metrics, CounterMetric from .metrics import Metrics, CounterMetric
from .config import Config from .config import Config
from abc import ABCMeta, abstractmethod from abc import ABCMeta, abstractmethod
from owrx.reporting import ReportingEngine
import logging import logging
@ -102,7 +102,7 @@ class Js8Parser(Parser):
Map.getSharedInstance().updateLocation( Map.getSharedInstance().updateLocation(
frame.callsign, LocatorLocation(frame.grid), "JS8", self.band frame.callsign, LocatorLocation(frame.grid), "JS8", self.band
) )
PskReporter.getSharedInstance().spot({ ReportingEngine.getSharedInstance().spot({
"callsign": frame.callsign, "callsign": frame.callsign,
"mode": "JS8", "mode": "JS8",
"locator": frame.grid, "locator": frame.grid,

View File

@ -9,43 +9,19 @@ from owrx.config import Config
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 from owrx.metrics import Metrics, CounterMetric
from owrx.reporting import Reporter
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
class PskReporterDummy(object): class PskReporter(Reporter):
"""
used in place of the PskReporter when reporting is disabled.
does nothing.
"""
def spot(self, spot):
pass
def cancelTimer(self):
pass
class PskReporter(object):
sharedInstance = None
creationLock = threading.Lock()
interval = 300 interval = 300
supportedModes = ["FT8", "FT4", "JT9", "JT65", "FST4", "FST4W", "JS8"]
@staticmethod def getSupportedModes(self):
def getSharedInstance(): return ["FT8", "FT4", "JT9", "JT65", "FST4", "FST4W", "JS8"]
with PskReporter.creationLock:
if PskReporter.sharedInstance is None:
if Config.get()["pskreporter_enabled"]:
PskReporter.sharedInstance = PskReporter()
else:
PskReporter.sharedInstance = PskReporterDummy()
return PskReporter.sharedInstance
@staticmethod def stop(self):
def stop(): self.cancelTimer()
if PskReporter.sharedInstance:
PskReporter.sharedInstance.cancelTimer()
def __init__(self): def __init__(self):
self.spots = [] self.spots = []
@ -72,8 +48,6 @@ class PskReporter(object):
return reduce(and_, map(lambda key: s1[key] == s2[key], keys)) 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:
return
with self.spotLock: with self.spotLock:
if any(x for x in self.spots if self.spotEquals(spot, x)): if any(x for x in self.spots if self.spotEquals(spot, x)):
# dupe # dupe

51
owrx/reporting.py Normal file
View File

@ -0,0 +1,51 @@
import threading
from abc import ABC, abstractmethod
from owrx.config import Config
class Reporter(ABC):
@abstractmethod
def stop(self):
pass
@abstractmethod
def spot(self, spot):
pass
@abstractmethod
def getSupportedModes(self):
return []
class ReportingEngine(object):
creationLock = threading.Lock()
sharedInstance = None
@staticmethod
def getSharedInstance():
with ReportingEngine.creationLock:
if ReportingEngine.sharedInstance is None:
ReportingEngine.sharedInstance = ReportingEngine()
return ReportingEngine.sharedInstance
@staticmethod
def stopAll():
with ReportingEngine.creationLock:
if ReportingEngine.sharedInstance is not None:
ReportingEngine.sharedInstance.stop()
def __init__(self):
self.reporters = []
if Config.get()["pskreporter_enabled"]:
# inline import due to circular dependencies
from owrx.pskreporter import PskReporter
self.reporters += [PskReporter()]
def stop(self):
for r in self.reporters:
r.stop()
def spot(self, spot):
for r in self.reporters:
if spot["mode"] in r.getSupportedModes():
r.spot(spot)

View File

@ -2,7 +2,7 @@ from datetime import datetime, timezone
from owrx.map import Map, LocatorLocation from owrx.map import Map, LocatorLocation
import re import re
from owrx.metrics import Metrics, CounterMetric from owrx.metrics import Metrics, CounterMetric
from owrx.pskreporter import PskReporter from owrx.reporting import ReportingEngine
from owrx.parser import Parser from owrx.parser import Parser
from owrx.audio import AudioChopperProfile from owrx.audio import AudioChopperProfile
from abc import ABC, ABCMeta, abstractmethod from abc import ABC, ABCMeta, abstractmethod
@ -168,7 +168,7 @@ class WsjtParser(Parser):
Map.getSharedInstance().updateLocation( Map.getSharedInstance().updateLocation(
out["callsign"], LocatorLocation(out["locator"]), mode, self.band out["callsign"], LocatorLocation(out["locator"]), mode, self.band
) )
PskReporter.getSharedInstance().spot(out) ReportingEngine.getSharedInstance().spot(out)
self.handler.write_wsjt_message(out) self.handler.write_wsjt_message(out)
except (ValueError, IndexError): except (ValueError, IndexError):