diff options
| author | Copilot <198982749+Copilot@users.noreply.github.com> | 2025-11-06 20:34:36 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-11-06 20:34:36 +0100 |
| commit | a24639e17b63c5ebb9b2bb26af18e17302e9360b (patch) | |
| tree | 3301a4f8f278cab61696b2cd0212cb71e0676363 /data/vigo | |
| parent | 9a2e46b6e8f0decbd1995c14d34b0b8c0d663b49 (diff) | |
Add manual stop creation and override alerts with alternate stop codes (#74)
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: arielcostas <94913521+arielcostas@users.noreply.github.com>
Co-authored-by: Ariel Costas Guerrero <ariel@costas.dev>
Diffstat (limited to 'data/vigo')
| -rw-r--r-- | data/vigo/download-stops.py | 66 | ||||
| -rw-r--r-- | data/vigo/overrides/example-new-stops.yaml | 31 |
2 files changed, 96 insertions, 1 deletions
diff --git a/data/vigo/download-stops.py b/data/vigo/download-stops.py index a57d30f..f332f5b 100644 --- a/data/vigo/download-stops.py +++ b/data/vigo/download-stops.py @@ -29,12 +29,20 @@ def load_stop_overrides(file_path): return {} def apply_overrides(stops, overrides): - """Apply overrides to the stop data""" + """Apply overrides to the stop data and add new stops""" + # Track existing stop IDs + existing_stop_ids = {stop.get("stopId") for stop in stops} + + # Apply overrides to existing stops for stop in stops: stop_id = stop.get("stopId") if stop_id in overrides: override = overrides[stop_id] + # Override name if provided + if "name" in override: + stop["name"]["original"] = override["name"] + # Apply or add alternate names if "alternateNames" in override: for key, value in override["alternateNames"].items(): @@ -55,6 +63,62 @@ def apply_overrides(stops, overrides): if "hide" in override: stop["hide"] = override["hide"] + # Mark stop as cancelled + if "cancelled" in override: + stop["cancelled"] = override["cancelled"] + + # Add alert title + if "title" in override: + stop["title"] = override["title"] + + # Add alert message + if "message" in override: + stop["message"] = override["message"] + + # Add alternate codes + if "alternateCodes" in override: + stop["alternateCodes"] = override["alternateCodes"] + + # Add new stops (those with "new: true" parameter) + new_stops_added = 0 + for stop_id, override in overrides.items(): + # Check if this is a new stop + if override.get("new") and stop_id not in existing_stop_ids: + # Ensure stop_id is an integer for consistency + stop_id_int = int(stop_id) if isinstance(stop_id, str) else stop_id + + # Create the new stop + new_stop = { + "stopId": stop_id_int, + "name": { + "original": override.get("name", f"Stop {stop_id_int}") + }, + "latitude": override.get("location", {}).get("latitude"), + "longitude": override.get("location", {}).get("longitude"), + "lines": override.get("lines", []) + } + + # Add optional fields (excluding the 'new' parameter) + if "alternateNames" in override: + for key, value in override["alternateNames"].items(): + new_stop["name"][key] = value + if "amenities" in override: + new_stop["amenities"] = override["amenities"] + if "cancelled" in override: + new_stop["cancelled"] = override["cancelled"] + if "title" in override: + new_stop["title"] = override["title"] + if "message" in override: + new_stop["message"] = override["message"] + if "alternateCodes" in override: + new_stop["alternateCodes"] = override["alternateCodes"] + + stops.append(new_stop) + new_stops_added += 1 + + if new_stops_added > 0: + print(f"Added {new_stops_added} new stops from overrides") + return stops def main(): diff --git a/data/vigo/overrides/example-new-stops.yaml b/data/vigo/overrides/example-new-stops.yaml new file mode 100644 index 0000000..6937471 --- /dev/null +++ b/data/vigo/overrides/example-new-stops.yaml @@ -0,0 +1,31 @@ +# Example: Adding a new stop using the 'new' parameter +# New stops are added directly in override files with new: true + +# Example 1: New stop with basic information (commented out to avoid affecting production) +# 99001: +# new: true +# name: "New Development Stop" +# location: +# latitude: 42.229188 +# longitude: -8.722469 +# lines: +# - "5" +# - "12" +# amenities: +# - shelter + +# Example 2: New stop with alert information +# 99002: +# new: true +# name: "Temporary Event Stop" +# location: +# latitude: 42.230000 +# longitude: -8.723000 +# lines: +# - "EVENT" +# title: "Special Event Stop" +# message: "This stop is active during special events only." + +# Note: The 'new: true' parameter tells the system to create a new stop. +# This parameter is automatically removed after the stop is added to the dataset. +# Choose stop IDs in the 90000+ range to avoid conflicts with existing stops. |
