mirror of
https://git.ianrenton.com/ian/spothole.git
synced 2026-09-20 14:27:42 +00:00
Add icons back to spots & alerts
This commit is contained in:
+29
-23
@@ -2,20 +2,22 @@ import logging
|
||||
|
||||
from pyhamtools.locator import latlong_to_locator, locator_to_latlong
|
||||
|
||||
from core.constants import SIGS
|
||||
from core.data_store import DATA_STORE
|
||||
from core.enums import SIGRefType
|
||||
from core.geo_utils import wab_wai_square_to_lat_lon
|
||||
from data.sig_ref import SIGRef
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def get_sig_ref_info(sig, ref_id):
|
||||
def get_sig_ref_info(sig_name, 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."""
|
||||
|
||||
if sig is None or sig == "" or ref_id is None or ref_id == "":
|
||||
if sig_name is None or sig_name == "" or ref_id is None or ref_id == "":
|
||||
logger.debug("Failed to look up sig_ref info, sig or ref were not set.")
|
||||
return None
|
||||
|
||||
@@ -24,33 +26,43 @@ def get_sig_ref_info(sig, ref_id):
|
||||
ref_id.replace(" ", "-")
|
||||
|
||||
# Prepare the object to be returned
|
||||
sig_ref = SIGRef(sig=sig, id=ref_id)
|
||||
sig_ref = SIGRef(sig=sig_name, id=ref_id)
|
||||
|
||||
# We can always get the reference type and the icon from the SIG itself, if the reference data doesn't already
|
||||
# contain it. If the sig ref already has this data, it should be used for preference.
|
||||
for sig in SIGS:
|
||||
if sig.name.upper() == sig_name.upper():
|
||||
if not sig_ref.ref_type:
|
||||
sig_ref.ref_type = sig.ref_type
|
||||
if not sig_ref.icon:
|
||||
sig_ref.icon = sig.icon
|
||||
|
||||
try:
|
||||
### FUDGES ###
|
||||
#
|
||||
# DME fudge. Our database has leading zeros padding to 5 digits which is the expected format, but not all
|
||||
# activators add leading zeros.
|
||||
if sig.upper() == "DME":
|
||||
if sig_name.upper() == "DME":
|
||||
ref_id = ref_id.zfill(5)
|
||||
|
||||
# DTMBA spotters sometimes include spaces and dashes, our regex allows them but they must be removed here so we
|
||||
# can look up against the official list which doesn't have them
|
||||
if sig.upper() == "DTMBA":
|
||||
if sig_name.upper() == "DTMBA":
|
||||
ref_id = ref_id.replace("-", "").replace(" ", "")
|
||||
|
||||
# If the SIG is HEMA, we have no current lookup for this so just skip the lookup here.
|
||||
if sig.upper() == "HEMA":
|
||||
sig_ref.ref_type = "Summit"
|
||||
### NO DATA SIGS ###
|
||||
#
|
||||
# If the SIG is HEMA or BIWOTA, we have no way to either generate useful data or look it up on a reference list,
|
||||
# so just skip the lookup here.
|
||||
if sig_name.upper() == "HEMA" or sig_name.upper() == "BIWOTA":
|
||||
return sig_ref
|
||||
|
||||
### PROGRAMMATIC DATA GENERATION INSTEAD OF LOOKUPS ###
|
||||
#
|
||||
# If the SIG is Tiles, WAB, WAI or BOTA (Beaches), we don't have anything to look up from the data store, we can
|
||||
# calculate all the information we are going to get directly.
|
||||
if sig.upper() == "TILES":
|
||||
if sig_name.upper() == "TILES":
|
||||
# Tiles on the Air just uses Maidenhead 6-digit squares, so ID, Name and Grid are all the same
|
||||
sig_ref.ref_type = "Grid"
|
||||
if not sig_ref.name:
|
||||
sig_ref.name = sig_ref.id
|
||||
if not sig_ref.grid:
|
||||
@@ -61,8 +73,7 @@ def get_sig_ref_info(sig, ref_id):
|
||||
sig_ref.longitude = ll[1]
|
||||
return sig_ref
|
||||
|
||||
elif sig.upper() == "WAB" or sig.upper() == "WAI":
|
||||
sig_ref.ref_type = "Grid"
|
||||
elif sig_name.upper() == "WAB" or sig_name.upper() == "WAI":
|
||||
ll = wab_wai_square_to_lat_lon(ref_id)
|
||||
if ll:
|
||||
sig_ref.name = ref_id
|
||||
@@ -74,20 +85,15 @@ def get_sig_ref_info(sig, ref_id):
|
||||
logger.warning("Invalid lat/lon received for WAB/WAI reference")
|
||||
return sig_ref
|
||||
|
||||
elif sig.upper() == "BOTA":
|
||||
elif sig_name.upper() == "BOTA":
|
||||
# For BOTA all we can ever generate is the URL, there is no data file or lookup for lat/longs
|
||||
sig_ref.ref_type = "Beach"
|
||||
if not sig_ref.name:
|
||||
sig_ref.name = sig_ref.id
|
||||
if sig_ref.name:
|
||||
sig_ref.url = f"https://www.beachesontheair.com/beaches/{sig_ref.name.lower().replace(' ', '-')}"
|
||||
return sig_ref
|
||||
|
||||
elif sig.upper() == "BIWOTA":
|
||||
# For BIWOTA there are no references, all we can set is a type
|
||||
sig_ref.ref_type = "Waterway"
|
||||
|
||||
elif sig.upper() == "GMA Islands":
|
||||
elif sig_name.upper() == "GMA Islands":
|
||||
# GMA Islands is a bit of a mess of GMA and IOTA references. Try looking them both up and see what returns
|
||||
# the best result.
|
||||
iota_lookup = get_sig_ref_info("IOTA", ref_id)
|
||||
@@ -98,14 +104,14 @@ def get_sig_ref_info(sig, ref_id):
|
||||
for key, value in gma_lookup.__dict__.items():
|
||||
if value is not None and sig_ref.__dict__.get(key) is None:
|
||||
sig_ref.__dict__[key] = value
|
||||
sig_ref.ref_type = "Island"
|
||||
sig_ref.ref_type = SIGRefType.ISLAND
|
||||
return sig_ref
|
||||
|
||||
### ACTUAL LOOKUP ###
|
||||
#
|
||||
# OK, this is something we have to look up. Now check to see if our data store contains reference data and use
|
||||
# that.
|
||||
key = f"{sig}:{ref_id}"
|
||||
key = f"{sig_name}:{ref_id}"
|
||||
lookup_data = DATA_STORE.sigrefs.get(key) if key in DATA_STORE.sigrefs else None
|
||||
if lookup_data:
|
||||
return lookup_data
|
||||
@@ -113,10 +119,10 @@ def get_sig_ref_info(sig, ref_id):
|
||||
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.
|
||||
logger.debug(f"{sig} database did not contain data for ref {ref_id}")
|
||||
logger.debug(f"{sig_name} database did not contain data for ref {ref_id}")
|
||||
|
||||
except Exception:
|
||||
logger.exception(f"Exception when looking up sig_ref info for {sig} ref {ref_id}")
|
||||
logger.exception(f"Exception when looking up sig_ref info for {sig_name} ref {ref_id}")
|
||||
return sig_ref
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user