Skip to content

Commit

Permalink
Updating dec route processing
Browse files Browse the repository at this point in the history
  • Loading branch information
jacob6838 committed Nov 14, 2024
1 parent 411c48d commit ae0006b
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 2 deletions.
45 changes: 44 additions & 1 deletion wzdx/raw_to_standard/planned_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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


Expand Down
15 changes: 14 additions & 1 deletion wzdx/tools/cdot_geospatial_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}")
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit ae0006b

Please sign in to comment.