Refactor of caching & data storage part 13 #118

This commit is contained in:
Ian Renton
2026-08-03 08:56:34 +01:00
parent e31b145b8e
commit 50ab27e4a2
9 changed files with 200 additions and 638 deletions
+27 -14
View File
@@ -4,21 +4,20 @@ from pyhamtools.locator import locator_to_latlong, latlong_to_locator
from core.data_store import DATA_STORE
from core.geo_utils import wab_wai_square_to_lat_lon
from data.sig_ref import SIGRef
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
def get_sig_ref_info(sig, ref_id):
"""Look up details of a SIG reference (e.g. POTA park) such as name, lat/lon, and grid. Takes in a sig name and
a reference ID (both strings) and returns a SigRef object populated with as much data as we can find. 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. Any data currently in the object will be kept, only missing data in the object will
be populated if it can be determined."""
SIG we are getting data for."""
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.")
return sig_ref
if sig is None or sig == "" or ref_id is None or ref_id == "":
logging.debug("Failed to look up sig_ref info, sig or ref were not set.")
return None
sig = sig_ref.sig
ref_id = sig_ref.id
sig_ref = SIGRef(sig=sig, id=ref_id)
try:
### FUDGES ###
@@ -81,10 +80,8 @@ def populate_sig_ref_info(sig_ref):
key = sig + ":" + ref_id
lookup_data = DATA_STORE.sigrefs.get(key) if key in DATA_STORE.sigrefs else None
if lookup_data:
# Copy new sig ref data into existing object where data was previously missing
for key, value in lookup_data.__dict__.items():
if value is not None and sig_ref.__dict__.get(key) is None:
sig_ref.__dict__[key] = value
return lookup_data
else:
# Maybe a super new reference we don't know about yet, but more likely a typo or a test reference,
# just silently ignore it.
@@ -93,3 +90,19 @@ def populate_sig_ref_info(sig_ref):
except Exception:
logging.error("Exception when looking up sig_ref info for " + sig + " ref " + ref_id, exc_info=True)
return sig_ref
def populate_missing_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. Any data
currently in the object will be kept, only missing data in the object will be populated if it can be determined."""
lookup_data = get_sig_ref_info(sig_ref.sig, sig_ref.id)
if lookup_data:
# Copy new sig ref data into existing object where data was previously missing
for key, value in lookup_data.__dict__.items():
if value is not None and sig_ref.__dict__.get(key) is None:
sig_ref.__dict__[key] = value
return sig_ref