Split out event type SIGs, and do other enum conversions. Closes #138

This commit is contained in:
Ian Renton
2026-09-02 09:38:05 +01:00
parent 606cf1be68
commit 9d117a6069
54 changed files with 363 additions and 155 deletions
+26 -25
View File
@@ -5,17 +5,9 @@ import simplejson
from pyhamtools.frequency import freq_to_band
from pyhamtools.locator import latlong_to_locator
from core.constants import (
ALL_MODES,
BANDS,
CW_MODES,
DATA_MODES,
MODE_ALIASES,
PHONE_MODES,
UNKNOWN_BAND,
)
from core.constants import BANDS, UNKNOWN_BAND
from core.data_store import DATA_STORE
from core.enums import Continent, ModeType
from core.enums import MODE_ALIASES, Continent, Mode, ModeType
from data.callsign import Callsign, LocationSourceForCallsign
logger = logging.getLogger(__name__)
@@ -28,31 +20,40 @@ def safe_json_dumps(obj):
return simplejson.dumps(obj, ensure_ascii=False, ignore_nan=True, default=lambda o: o.__dict__)
def infer_mode_from_comment(comment):
def infer_mode_from_comment(comment: str) -> Mode:
"""Infer a mode from the comment"""
for mode in ALL_MODES:
if not comment:
return Mode.UNKNOWN
for mode in Mode:
if re.search(r"(^|\W)" + mode + r"($|\W)", comment, re.IGNORECASE):
return mode
for mode in MODE_ALIASES:
if re.search(r"(^|\W)" + mode + r"($|\W)", comment, re.IGNORECASE):
return MODE_ALIASES[mode]
return None
for alias in MODE_ALIASES:
if re.search(r"(^|\W)" + alias + r"($|\W)", comment, re.IGNORECASE):
return Mode(MODE_ALIASES[alias])
return Mode.UNKNOWN
def infer_mode_type_from_mode(mode):
"""Infer a "mode family" from a mode."""
def infer_mode_type_from_mode(mode: str) -> ModeType:
"""Infer a "mode family" from a mode ."""
if mode.upper() in CW_MODES:
return ModeType.CW
elif mode.upper() in PHONE_MODES:
return ModeType.PHONE
elif mode.upper() in DATA_MODES:
if not mode:
return ModeType.UNKNOWN
try:
mode = Mode(mode.upper())
if mode.is_cw:
return ModeType.CW
if mode.is_phone:
return ModeType.PHONE
return ModeType.DATA
else:
except ValueError:
if mode.upper() != "OTHER" and mode != "?":
logger.warning(f"Found an unrecognised mode: {mode}. Developer should categorise this.")
return None
return ModeType.UNKNOWN
def infer_band_from_freq(freq):