Refactor activity names to use an enum instead of a string to avoid typos #147

This commit is contained in:
Ian Renton
2026-09-18 18:09:41 +01:00
parent ab79e7e01c
commit e5caf7353d
61 changed files with 735 additions and 638 deletions
+11 -10
View File
@@ -18,9 +18,9 @@ from core.activity_utils import (
)
from core.call_lookup_helper import get_call_info
from core.config import MAX_SPOT_AGE
from core.constants import ACTIVITIES, PROPAGATION_MODES
from core.constants import PROPAGATION_MODES
from core.data_store import DATA_STORE
from core.enums import Continent, LocationSourceForSpot, Mode, ModeSource, ModeType
from core.enums import ActivityName, Continent, LocationSourceForSpot, Mode, ModeSource, ModeType
from core.geo_utils import lat_lon_to_cq_zone, lat_lon_to_itu_zone
from core.utils import (
get_flag_for_dxcc,
@@ -29,6 +29,7 @@ from core.utils import (
infer_mode_from_frequency,
infer_mode_type_from_mode,
)
from data.activities import ACTIVITIES
from data.activity_ref import ActivityRef
logger = logging.getLogger(__name__)
@@ -311,7 +312,7 @@ class Spot:
# name, but where the activity reference is unique-looking enough that we can't confuse it with any other
# activity.
if self.comment:
for activity in ACTIVITIES:
for activity in ACTIVITIES.values():
if activity.refs_globally_unique and activity.ref_regex:
ref_matches = re.finditer(
r"(^|\W)(" + activity.ref_regex + r")($|\W)", self.comment, re.IGNORECASE
@@ -343,7 +344,7 @@ class Spot:
):
self.dx_latitude = activity_ref.latitude
self.dx_longitude = activity_ref.longitude
if self.sig == "WAB" or self.sig == "WAI" or self.sig == "Tiles":
if self.sig in (ActivityName.WAB, ActivityName.WAI, ActivityName.TILES):
self.dx_location_source = LocationSourceForSpot.GRID
else:
self.dx_location_source = LocationSourceForSpot.SIG_REF_LOOKUP
@@ -380,16 +381,16 @@ class Spot:
# Set activities based on propagation mode
if self.propagation_mode == "Satellite" and not self.sig:
self.sig = "Satellite"
self.sig = ActivityName.SATELLITE
if self.propagation_mode == "Earth-Moon-Earth" and not self.sig:
self.sig = "EME"
self.sig = ActivityName.EME
# Set activities based on the DX callsign suffix
if self.dx_call and not self.sig:
if self.dx_call.upper().endswith("/AM"):
self.sig = "/AM"
elif self.dx_call.upper().endswith("/MM"):
self.sig = "/MM"
if self.dx_call.upper().endswith(ActivityName.AERONAUTICAL_MOBILE):
self.sig = ActivityName.AERONAUTICAL_MOBILE
elif self.dx_call.upper().endswith(ActivityName.MARITIME_MOBILE):
self.sig = ActivityName.MARITIME_MOBILE
# Parse "de_grid -> dx_grid" structures from the comment
if self.comment: