mirror of
https://git.ianrenton.com/ian/spothole.git
synced 2026-09-25 08:44:33 +00:00
Strict adherence to canonical ActivityNames, to avoid the problem where Spothole was giving out activities like ["Towers", "TOWERS"]. All uses of ActivityName should now be canonical not arbitrary strings, and attempts to convert unknown strings to activitynames will be logged for me to check out.
This commit is contained in:
+28
-42
@@ -68,15 +68,6 @@ class GMA(HTTPSpotProvider):
|
||||
# Filter out some weird mode strings
|
||||
mode=Mode.from_name(source_spot["MODE"].upper()) if "<>" not in source_spot["MODE"] else None,
|
||||
comment=source_spot["TEXT"],
|
||||
activity_refs=[
|
||||
ActivityRef(
|
||||
id=source_spot["REF"],
|
||||
activity="",
|
||||
name=source_spot["NAME"],
|
||||
latitude=lat,
|
||||
longitude=lon,
|
||||
)
|
||||
],
|
||||
time=time,
|
||||
dx_latitude=lat,
|
||||
dx_longitude=lon,
|
||||
@@ -98,57 +89,52 @@ class GMA(HTTPSpotProvider):
|
||||
and ref_response.text != "\n"
|
||||
):
|
||||
ref_info = ref_response.json()
|
||||
if spot.activity_refs and ref_info and "reftype" in ref_info:
|
||||
if ref_info and "reftype" in ref_info:
|
||||
activity: ActivityName | None = None
|
||||
ref_type: ActivityRefType | None = None
|
||||
match ref_info["reftype"]:
|
||||
case "Summit":
|
||||
# Summits are a bit complicated, they can be SOTA or GMA depending on the
|
||||
# separate "sota" field:
|
||||
if "sota" in ref_info and ref_info["sota"] != "":
|
||||
spot.activity_refs[0].activity = ActivityName.SOTA
|
||||
spot.activity_refs[0].ref_type = ActivityRefType.SUMMIT
|
||||
spot.add_activity(ActivityName.SOTA)
|
||||
activity, ref_type = ActivityName.SOTA, ActivityRefType.SUMMIT
|
||||
else:
|
||||
spot.activity_refs[0].activity = ActivityName.GMA
|
||||
spot.activity_refs[0].ref_type = ActivityRefType.SUMMIT
|
||||
spot.add_activity(ActivityName.GMA)
|
||||
activity, ref_type = ActivityName.GMA, ActivityRefType.SUMMIT
|
||||
case "POTA":
|
||||
spot.activity_refs[0].activity = ActivityName.POTA
|
||||
spot.activity_refs[0].ref_type = ActivityRefType.PARK
|
||||
spot.add_activity(ActivityName.POTA)
|
||||
activity, ref_type = ActivityName.POTA, ActivityRefType.PARK
|
||||
case "WWFF":
|
||||
spot.activity_refs[0].activity = ActivityName.WWFF
|
||||
spot.activity_refs[0].ref_type = ActivityRefType.PARK
|
||||
spot.add_activity(ActivityName.WWFF)
|
||||
activity, ref_type = ActivityName.WWFF, ActivityRefType.PARK
|
||||
case "IOTA Island":
|
||||
spot.activity_refs[0].activity = ActivityName.IOTA
|
||||
spot.activity_refs[0].ref_type = ActivityRefType.ISLAND
|
||||
spot.add_activity(ActivityName.IOTA)
|
||||
activity, ref_type = ActivityName.IOTA, ActivityRefType.ISLAND
|
||||
case "GMA Island":
|
||||
spot.activity_refs[0].activity = ActivityName.GMA_ISLANDS
|
||||
spot.activity_refs[0].ref_type = ActivityRefType.ISLAND
|
||||
spot.add_activity(ActivityName.GMA_ISLANDS)
|
||||
activity, ref_type = ActivityName.GMA_ISLANDS, ActivityRefType.ISLAND
|
||||
case "Lighthouse (ILLW)":
|
||||
spot.activity_refs[0].activity = ActivityName.ILLW
|
||||
spot.activity_refs[0].ref_type = ActivityRefType.LIGHTHOUSE
|
||||
spot.add_activity(ActivityName.ILLW)
|
||||
activity, ref_type = ActivityName.ILLW, ActivityRefType.LIGHTHOUSE
|
||||
case "Lighthouse (ARLHS)":
|
||||
spot.activity_refs[0].activity = ActivityName.ARLHS
|
||||
spot.activity_refs[0].ref_type = ActivityRefType.LIGHTHOUSE
|
||||
spot.add_activity(ActivityName.ARLHS)
|
||||
activity, ref_type = ActivityName.ARLHS, ActivityRefType.LIGHTHOUSE
|
||||
case "Castle":
|
||||
spot.activity_refs[0].activity = ActivityName.WCA
|
||||
spot.activity_refs[0].ref_type = ActivityRefType.CASTLE
|
||||
spot.add_activity(ActivityName.WCA)
|
||||
activity, ref_type = ActivityName.WCA, ActivityRefType.CASTLE
|
||||
case "Mill":
|
||||
spot.activity_refs[0].activity = ActivityName.MOTA
|
||||
spot.activity_refs[0].ref_type = ActivityRefType.MILL
|
||||
spot.add_activity(ActivityName.MOTA)
|
||||
activity, ref_type = ActivityName.MOTA, ActivityRefType.MILL
|
||||
case _:
|
||||
logger.warning(
|
||||
f"GMA spot found with ref type {ref_info['reftype']}, developer needs to add support for this!"
|
||||
)
|
||||
spot.activity_refs[0].activity = ref_info["reftype"]
|
||||
spot.add_activity(ref_info["reftype"])
|
||||
|
||||
# Now we know the activity, add the reference to the spot. If it's an activity we
|
||||
# don't know, there's no ActivityName for it, so we can't add a reference.
|
||||
if activity is not None:
|
||||
spot.activity_refs = [
|
||||
ActivityRef(
|
||||
id=source_spot["REF"],
|
||||
activity=activity,
|
||||
ref_type=ref_type,
|
||||
name=source_spot["NAME"],
|
||||
latitude=lat,
|
||||
longitude=lon,
|
||||
)
|
||||
]
|
||||
spot.add_activity(activity)
|
||||
|
||||
elif not ref_response.from_cache:
|
||||
if not ref_response.ok:
|
||||
|
||||
Reference in New Issue
Block a user