From ae0006bd6c1d283d23feec8ae0a4c07f1cba10f8 Mon Sep 17 00:00:00 2001 From: jacob6838 Date: Wed, 13 Nov 2024 18:15:06 -0700 Subject: [PATCH] Updating dec route processing --- wzdx/raw_to_standard/planned_events.py | 45 +++++++++++++++++++++++++- wzdx/tools/cdot_geospatial_api.py | 15 ++++++++- 2 files changed, 58 insertions(+), 2 deletions(-) diff --git a/wzdx/raw_to_standard/planned_events.py b/wzdx/raw_to_standard/planned_events.py index de70c15..a2d19ad 100644 --- a/wzdx/raw_to_standard/planned_events.py +++ b/wzdx/raw_to_standard/planned_events.py @@ -683,14 +683,32 @@ def get_cross_streets_from_description(description: str) -> tuple[str, str]: return ("", "") +def get_mileposts_from_description(message: str) -> tuple[str, str]: + """Get mileposts from a description string using regular expression "^Between Exit ([0-9.]{0-4}): .*? and Exit ([0-9.]{0-4}):" + Args: + description (str): description string + Returns: + tuple[str, str]: beginning milepost, ending milepost + """ + desc_regex = "^Between Exit (.*?): .*? and Exit (.*?):" + m = regex.search(desc_regex, message) + try: + return m.group(1, 2) + except: + return ("", "") + + def get_route_details_for_coordinates_lngLat( - cdotGeospatialApi: cdot_geospatial_api.GeospatialApi, coordinates: list[list[float]] + cdotGeospatialApi: cdot_geospatial_api.GeospatialApi, + coordinates: list[list[float]], + reversed: bool, ) -> tuple[dict, dict]: """Get GIS route details for start and end coordinates Args: cdotGeospatialApi (cdot_geospatial_api.GeospatialApi): customized GeospatialApi object, for retrieving route details coordinates (list[list[float]]): planned event coordinates + reversed (bool): whether the coordinates are reversed Returns: tuple[dict, dict]: GIS route details for start and end coordinates @@ -708,6 +726,31 @@ def get_route_details_for_coordinates_lngLat( cdotGeospatialApi, coordinates[-1][1], coordinates[-1][0] ) + # Update route IDs based on directionality + if route_details_start and route_details_end: + if route_details_start["Route"].replace("_DEC", "") != route_details_end[ + "Route" + ].replace("_DEC", ""): + logging.warning( + f"Routes did not match! route details: {route_details_start['Route']}, {route_details_end['Route']}" + ) + return route_details_start, route_details_end + else: + if route_details_start["Measure"] > route_details_end["Measure"]: + route_details_start["Route"] = route_details_start["Route"].replace( + "_DEC", "" + ) + route_details_end["Route"] = route_details_end["Route"].replace( + "_DEC", "" + ) + else: + route_details_start["Route"] = ( + route_details_start["Route"].replace("_DEC", "") + "_DEC" + ) + route_details_end["Route"] = ( + route_details_end["Route"].replace("_DEC", "") + "_DEC" + ) + return route_details_start, route_details_end diff --git a/wzdx/tools/cdot_geospatial_api.py b/wzdx/tools/cdot_geospatial_api.py index c7fdd7d..42040e8 100644 --- a/wzdx/tools/cdot_geospatial_api.py +++ b/wzdx/tools/cdot_geospatial_api.py @@ -300,7 +300,11 @@ def get_route_between_measures( """ # Get lat/long points between two mile markers on route if dualCarriageway and self.is_route_dec(startMeasure, endMeasure): - routeId = f"{routeId}_DEC" + routeId = f"{routeId.replace('_DEC', '')}_DEC" + + if self.is_route_id_dec(routeId): + if startMeasure < endMeasure: + startMeasure, endMeasure = endMeasure, startMeasure parameters = [] parameters.append(f"routeId={routeId}") @@ -341,6 +345,15 @@ def is_route_dec(self, startMeasure: float, endMeasure: float) -> bool: """ return endMeasure > startMeasure + def is_route_id_dec(self, route_id: str) -> bool: + """Check if the route is a reversed dual carriageway + Args: + route_id (str): Route ID + Returns: + bool: True if route is a reversed dual carriageway + """ + return route_id.lower().endswith("_dec") + def _make_cached_web_request( self, url: str,