From df724409a563ab5c832bb03d8d35ee8555275021 Mon Sep 17 00:00:00 2001 From: Ian Renton Date: Sat, 5 Sep 2026 09:57:05 +0100 Subject: [PATCH] Fix some dodgy handling of DME references --- core/constants.py | 4 ++-- core/sig_lookup_helper.py | 8 ++++++-- providers/sigrefdata/dme.py | 6 +++++- templates/add_spot.html | 2 +- templates/alerts.html | 2 +- templates/bands.html | 4 ++-- templates/base.html | 10 +++++----- templates/conditions.html | 2 +- templates/map.html | 4 ++-- templates/spots.html | 4 ++-- templates/status.html | 2 +- 11 files changed, 28 insertions(+), 20 deletions(-) diff --git a/core/constants.py b/core/constants.py index 6c57950..acadaad 100644 --- a/core/constants.py +++ b/core/constants.py @@ -253,10 +253,10 @@ SIGS = [ description="Diploma Municipios de España", sig_type=SIGType.REGIONAL, ref_type=SIGRefType.TOWN, - ref_regex=r"\d{4,5}", + ref_regex=r"DME[\- ]\d{3,5}", icon="fa-building", region_flag="🇪🇸", - refs_globally_unique=False, + refs_globally_unique=True, ), SIG( name="FEA", diff --git a/core/sig_lookup_helper.py b/core/sig_lookup_helper.py index e5fc5be..92ca542 100644 --- a/core/sig_lookup_helper.py +++ b/core/sig_lookup_helper.py @@ -1,4 +1,5 @@ import logging +import re from pyhamtools.locator import latlong_to_locator, locator_to_latlong @@ -41,9 +42,12 @@ def get_sig_ref_info(sig_name, ref_id): ### FUDGES ### # # DME fudge. Our database has leading zeros padding to 5 digits which is the expected format, but not all - # activators add leading zeros. + # activators add leading zeros. We also need to normalise "DME 01234" to "DME-01234" to match what's in our + # database. if sig_name.upper() == "DME": - ref_id = ref_id.zfill(5) + match = re.match(r"DME[\- ]\d{3,5}", ref_id, re.IGNORECASE) + number = match.group(1) + return f"DME-{number.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 diff --git a/providers/sigrefdata/dme.py b/providers/sigrefdata/dme.py index c46b1bc..315061b 100644 --- a/providers/sigrefdata/dme.py +++ b/providers/sigrefdata/dme.py @@ -23,7 +23,11 @@ class DME(LocalFileSIGRefDataProvider): new_data = [] with open(path, encoding="latin-1") as _f: for row in csv.DictReader(_f, delimiter=";"): - ref_id = row["COD_INE"][:5] + # Store reference IDs with the "DME-" prefix rather than just the number. This will prevent Spothole + # from agressively thinking every number in a spot comment is DME after it's seen "DME" once. The only + # numbers that count are straight after "DME " or "DME-". The dash versus space is normalised in + # sig_lookup_helper.py. + ref_id = "DME-" + row["COD_INE"][:5] latitude = ( float(row["LATITUD_ETRS89_REGCAN95"].replace(",", ".")) if row.get("LATITUD_ETRS89_REGCAN95") diff --git a/templates/add_spot.html b/templates/add_spot.html index d3ca997..c9a69b6 100644 --- a/templates/add_spot.html +++ b/templates/add_spot.html @@ -77,7 +77,7 @@ - + diff --git a/templates/alerts.html b/templates/alerts.html index 704537b..78f0126 100644 --- a/templates/alerts.html +++ b/templates/alerts.html @@ -81,7 +81,7 @@ - + diff --git a/templates/bands.html b/templates/bands.html index 6610b7b..86e9496 100644 --- a/templates/bands.html +++ b/templates/bands.html @@ -76,8 +76,8 @@ - - + + diff --git a/templates/base.html b/templates/base.html index c60fa1c..b213f7d 100644 --- a/templates/base.html +++ b/templates/base.html @@ -1,6 +1,6 @@ {% extends "skeleton.html" %} {% block head_extra %} - + @@ -16,10 +16,10 @@ window.fetchEventSource = fetchEventSource; - - - - + + + + {% end %} {% block body %}
diff --git a/templates/conditions.html b/templates/conditions.html index 9b8e6e5..6f698ed 100644 --- a/templates/conditions.html +++ b/templates/conditions.html @@ -284,7 +284,7 @@
- + diff --git a/templates/map.html b/templates/map.html index 359b0a5..c57d5b7 100644 --- a/templates/map.html +++ b/templates/map.html @@ -113,8 +113,8 @@ const CARTODB_API_KEY = "{{ web_ui_options.get('cartodb_api_key', '') }}"; - - + + diff --git a/templates/spots.html b/templates/spots.html index 306cf69..25da752 100644 --- a/templates/spots.html +++ b/templates/spots.html @@ -113,8 +113,8 @@ - - + + diff --git a/templates/status.html b/templates/status.html index f595bd4..a80e593 100644 --- a/templates/status.html +++ b/templates/status.html @@ -86,7 +86,7 @@ - +