mirror of
https://git.ianrenton.com/ian/spothole.git
synced 2026-08-06 02:21:42 +00:00
Refactor of caching & data storage part 9 #118
This commit is contained in:
@@ -326,12 +326,6 @@ class LookupHelper:
|
||||
ituz = dxcc_data["itu"]
|
||||
return ituz
|
||||
|
||||
def get_flag_for_dxcc(self, dxcc):
|
||||
"""Get an emoji flag for a given DXCC entity ID"""
|
||||
|
||||
dxcc_data = DATA_STORE.dxcc_data[dxcc] if dxcc in DATA_STORE.dxcc_data else None
|
||||
return dxcc_data["flag"] if dxcc_data else None
|
||||
|
||||
def infer_name_from_callsign_online_lookup(self, call, credentials=None):
|
||||
"""Infer an operator name from a callsign (requires QRZ.com/HamQTH)"""
|
||||
|
||||
|
||||
+5
-5
@@ -39,7 +39,7 @@ if ALLOW_SPOTTING:
|
||||
def get_spot_provider_from_config(config_providers_entry):
|
||||
"""Utility method to get a spot provider based on the class specified in its config entry."""
|
||||
|
||||
module = importlib.import_module('spotproviders.' + config_providers_entry["class"].lower())
|
||||
module = importlib.import_module('providers.spot.' + config_providers_entry["class"].lower())
|
||||
provider_class = getattr(module, config_providers_entry["class"])
|
||||
return provider_class(config_providers_entry)
|
||||
|
||||
@@ -47,7 +47,7 @@ def get_spot_provider_from_config(config_providers_entry):
|
||||
def get_alert_provider_from_config(config_providers_entry):
|
||||
"""Utility method to get an alert provider based on the class specified in its config entry."""
|
||||
|
||||
module = importlib.import_module('alertproviders.' + config_providers_entry["class"].lower())
|
||||
module = importlib.import_module('providers.alert.' + config_providers_entry["class"].lower())
|
||||
provider_class = getattr(module, config_providers_entry["class"])
|
||||
return provider_class(config_providers_entry)
|
||||
|
||||
@@ -55,7 +55,7 @@ def get_alert_provider_from_config(config_providers_entry):
|
||||
def get_solar_conditions_provider_from_config(config_providers_entry):
|
||||
"""Utility method to get a solar conditions provider based on the class specified in its config entry."""
|
||||
|
||||
module = importlib.import_module('solarconditionsproviders.' + config_providers_entry["class"].lower())
|
||||
module = importlib.import_module('providers.solarconditions.' + config_providers_entry["class"].lower())
|
||||
provider_class = getattr(module, config_providers_entry["class"])
|
||||
return provider_class(config_providers_entry)
|
||||
|
||||
@@ -63,7 +63,7 @@ def get_solar_conditions_provider_from_config(config_providers_entry):
|
||||
def get_static_data_provider_from_config(config_providers_entry):
|
||||
"""Utility method to get a static reference data provider based on the class specified in its config entry."""
|
||||
|
||||
module = importlib.import_module('staticdataproviders.' + config_providers_entry["class"].lower())
|
||||
module = importlib.import_module('providers.staticdata.' + config_providers_entry["class"].lower())
|
||||
provider_class = getattr(module, config_providers_entry["class"])
|
||||
return provider_class(config_providers_entry)
|
||||
|
||||
@@ -71,6 +71,6 @@ def get_static_data_provider_from_config(config_providers_entry):
|
||||
def get_sig_ref_data_provider_from_config(config_providers_entry):
|
||||
"""Utility method to get a SIG reference data provider based on the class specified in its config entry."""
|
||||
|
||||
module = importlib.import_module('sigrefdataproviders.' + config_providers_entry["class"].lower())
|
||||
module = importlib.import_module('providers.sigrefdata.' + config_providers_entry["class"].lower())
|
||||
provider_class = getattr(module, config_providers_entry["class"])
|
||||
return provider_class(config_providers_entry)
|
||||
|
||||
+2
-2
@@ -54,7 +54,7 @@ class DataStore:
|
||||
# Standard disk cache for static reference and SIG ref data. Separate provider threads will repopulate these on
|
||||
# a regular basis but there's no need for a TTL since old data is better than no data.
|
||||
self.dxcc_data = diskcache.Cache(CACHE_DIR + "dxcc_data")
|
||||
self.regenerateCallRegexToDXCCEntityMap()
|
||||
self.regenerate_call_regex_to_dxcc_entity_map()
|
||||
|
||||
# For SIG reference data specifically, we need to key on both SIG *and* reference, and trying to do two layers
|
||||
# of dict in diskcache absolutely destroys performance with unpickling huge dicts, so we have an ugly "SIG:ref"
|
||||
@@ -81,7 +81,7 @@ class DataStore:
|
||||
snapshot_interval_sec=self._SPOT_ALERT_SNAPSHOT_INTERVAL_SEC)
|
||||
logging.info(f"Loaded %d alerts from a previous run.", len(self.alerts.keys()))
|
||||
|
||||
def regenerateCallRegexToDXCCEntityMap(self):
|
||||
def regenerate_call_regex_to_dxcc_entity_map(self):
|
||||
"""DXCC entity data from K0SWE includes a regex which we can use to match a callsign, and determine which DXCC
|
||||
entity it belongs to. But getting every DXCC entity data object out of DiskCache, iterating, compiling its regex
|
||||
and testing the callsign every time is expensive. So instead we build a separate in-memory lookup of compiled
|
||||
|
||||
@@ -10,8 +10,8 @@ def populate_sig_ref_info(sig_ref):
|
||||
"""Look up details of a SIG reference (e.g. POTA park) such as name, lat/lon, and grid. Takes in a sig_ref object
|
||||
which must at minimum have a "sig" and an "id". The rest of the object will be populated and returned. This makes
|
||||
use of SIG ref data in the data store, live lookups from the web, or just automatic calculation depending on which
|
||||
SIG we are getting data for.
|
||||
Note there is currently no support for KRMNPA location lookup, see issue #61."""
|
||||
SIG we are getting data for. Any data currently in the object will be kept, only missing data in the object will
|
||||
be populated if it can be determined."""
|
||||
|
||||
if sig_ref.sig is None or sig_ref.sig == "" or sig_ref.id is None or sig_ref.id == "":
|
||||
logging.debug("Failed to look up sig_ref info, sig or id were not set.")
|
||||
|
||||
+9
-1
@@ -4,6 +4,7 @@ import simplejson
|
||||
from pyhamtools.frequency import freq_to_band
|
||||
|
||||
from core.constants import UNKNOWN_BAND, BANDS, CW_MODES, PHONE_MODES, DATA_MODES, MODE_ALIASES, ALL_MODES
|
||||
from core.data_store import DATA_STORE
|
||||
|
||||
|
||||
def safe_json_dumps(obj):
|
||||
@@ -68,4 +69,11 @@ def infer_mode_from_frequency(freq):
|
||||
mode = "FT4"
|
||||
return mode
|
||||
except KeyError:
|
||||
return None
|
||||
return None
|
||||
|
||||
|
||||
def get_flag_for_dxcc(dxcc):
|
||||
"""Get an emoji flag for a given DXCC entity ID"""
|
||||
|
||||
dxcc_data = DATA_STORE.dxcc_data[dxcc] if dxcc in DATA_STORE.dxcc_data else None
|
||||
return dxcc_data["flag"] if dxcc_data else None
|
||||
Reference in New Issue
Block a user