Extract propagation mode from grid<mode>grid type comments #113

This commit is contained in:
Ian Renton
2026-06-21 09:30:30 +01:00
parent 0c256447a8
commit 5f24f1f9fb
10 changed files with 50 additions and 23 deletions

View File

@@ -10,7 +10,7 @@ import pytz
from pyhamtools.locator import locator_to_latlong, latlong_to_locator
from core.config import MAX_SPOT_AGE
from core.constants import MODE_ALIASES
from core.constants import MODE_ALIASES, PROPAGATION_MODES
from core.geo_utils import lat_lon_to_cq_zone, lat_lon_to_itu_zone
from core.lookup_helper import lookup_helper, infer_band_from_freq, infer_mode_from_comment, \
infer_mode_from_frequency, infer_mode_type_from_mode
@@ -99,6 +99,8 @@ class Spot:
freq: float | None = None
# Band, defined by the frequency, e.g. "40m" or "70cm"
band: str | None = None
# Propagation mode, if known
propagation_mode: str | None = None
# Comment left by the spotter, if any
comment: str | None = None
# QRT state. Some APIs return spots marked as QRT. Otherwise we can check the comments.
@@ -288,19 +290,30 @@ class Spot:
if self.sig_refs and len(self.sig_refs) > 0 and not self.sig:
self.sig = self.sig_refs[0].sig
# Parse "de_grid<mode>dx_grid" structures from the comment, e.g. "JN61ES<ES>JM56XT" or "JO02GQ<>KN17LG". These
# are common on cluster spots and can provide grid references in preference to e.g. QRZ lookup.
# Parse "de_grid<prop_mode>dx_grid" structures from the comment, e.g. "JN61ES<ES>JM56XT" or "JO02GQ<>KN17LG".
# These are common on cluster spots and can provide grid references in preference to e.g. QRZ lookup, as well as
# being the only source we have for propagation mode.
if self.comment:
grid_pair_match = re.search(
r'\b([A-Ra-r]{2}\d{2}(?:[A-Xa-x]{2}(?:\d{2})?)?)<[^>]*>([A-Ra-r]{2}\d{2}(?:[A-Xa-x]{2}(?:\d{2})?)?)\b',
grid_mode_grid_match = re.search(
r'\b([A-Ra-r]{2}\d{2}(?:[A-Xa-x]{2}(?:\d{2})?)?)<([^>]*)>([A-Ra-r]{2}\d{2}(?:[A-Xa-x]{2}(?:\d{2})?)?)\b',
self.comment)
if grid_pair_match:
if grid_mode_grid_match:
# regex matches, so extract grids:
if not self.de_grid:
self.de_grid = grid_pair_match.group(1).upper()
self.de_grid = grid_mode_grid_match.group(1).upper()
if not self.dx_grid:
self.dx_grid = grid_pair_match.group(2).upper()
self.dx_grid = grid_mode_grid_match.group(3).upper()
self.dx_location_source = "SPOT"
# And extract propagation mode:
mode_tag = grid_mode_grid_match.group(2).upper()
if mode_tag and not self.propagation_mode:
if mode_tag in PROPAGATION_MODES:
self.propagation_mode = PROPAGATION_MODES[mode_tag]
else:
self.propagation_mode = mode_tag
logging.info("Seen a new propagation mode tag not yet in the system: {}", mode_tag)
# DX Grid to lat/lon and vice versa in case one is missing
if self.dx_grid and not self.dx_latitude:
try: