Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updating Message Samples + MultiPoint #56

Merged
merged 20 commits into from
Dec 9, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import pathlib
from setuptools import setup, find_packages

VERSION = "1.3.0"
VERSION = "1.3.1"
DESCRIPTION = "CDOT Work Zone WZDx Translators"
HERE = pathlib.Path(__file__).parent
README = (HERE / "README.md").read_text()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -330,14 +330,14 @@
"MMax": 449.589,
"MMin": 0.0,
"Measure": 60.0,
"Route": "070A",
"Route": "070A_DEC",
},
"route_details_start": {
"Distance": 0.91,
"MMax": 449.589,
"MMin": 0.0,
"Measure": 50.0,
"Route": "070A",
"Route": "070A_DEC",
},
"condition_1": False,
"beginning_milepost": 50.0,
Expand Down
12 changes: 11 additions & 1 deletion tests/tools/cdot_geospatial_api_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,20 @@ def test_get_route_between_measures():


def test_get_route_between_measures():
routeId = "070A"
startMeasure = 50
endMeasure = 60
actual = cdot_geospatial_api.GeospatialApi().get_route_between_measures(
routeId, startMeasure, endMeasure, compressed=True, adjustRoute=False
)
assert len(actual) == 108


def test_get_route_between_measures_allow_reversal():
routeId = "070A"
startMeasure = 50
endMeasure = 60
actual = cdot_geospatial_api.GeospatialApi().get_route_between_measures(
routeId, startMeasure, endMeasure, compressed=True
)
assert len(actual) == 109
assert len(actual) == 81
20 changes: 14 additions & 6 deletions wzdx/experimental_combination/attenuator.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@ def main():
geotab_avl = [json.loads(open(geotabFile, "r").read())]
outputPath = output_dir + "/wzdx_attenuator_combined.geojson"
if updateDates == "true":
geotab_avl[0]["avl_location"]["source"]["collection_timestamp"] = (
date_tools.get_current_ts_millis() / 1000
)
geotab_avl[0]["avl_location"]["source"]["collection_timestamp"] = datetime.now()
wzdx[0]["features"][0]["properties"]["start_date"] = (
date_tools.get_iso_string_from_datetime(datetime.now() - timedelta(days=2))
)
Expand Down Expand Up @@ -107,9 +105,19 @@ def validate_dates(geotab: dict, wzdx: dict) -> bool:
Returns:
bool: Whether the Geotab date falls within the WZDx date range
"""
geotab_date = date_tools.get_unix_from_iso_string(
geotab["avl_location"]["source"]["collection_timestamp"]
)
if type(geotab["avl_location"]["source"]["collection_timestamp"]) == datetime:
geotab_date = date_tools.date_to_unix(
geotab["avl_location"]["source"]["collection_timestamp"]
)
elif type(geotab["avl_location"]["source"]["collection_timestamp"]) == str:
geotab_date = date_tools.get_unix_from_iso_string(
geotab["avl_location"]["source"]["collection_timestamp"]
)
else:
logging.error(
f"Invalid Geotab date format: avl_location.source.collection_timestamp is type {type(geotab['avl_location']['source']['collection_timestamp'])}"
)
return False
logging.debug(f"Geotab: {json.dumps(geotab)}")
if not geotab_date:
geotab_date = (
Expand Down
67 changes: 61 additions & 6 deletions 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 Expand Up @@ -754,6 +797,10 @@ def create_rtdh_standard_msg(
pd.get("properties/clearTime"),
)

beginning_milepost, ending_milepost = get_mileposts_from_description(
description
)

begin_cross_street, end_cross_street = get_cross_streets_from_description(
description
)
Expand All @@ -767,16 +814,22 @@ def create_rtdh_standard_msg(

direction = pd.get("properties/direction", default="unknown")

beginning_milepost = pd.get("properties/startMarker", default="")
ending_milepost = pd.get("properties/endMarker", default="")
beginning_milepost = pd.get(
"properties/startMarker", default=beginning_milepost
)
ending_milepost = pd.get("properties/endMarker", default=ending_milepost)
recorded_direction = pd.get("properties/recorded_direction")
reversed = False
if (
direction == REVERSED_DIRECTION_MAP.get(recorded_direction)
and direction != "unknown"
):
reversed = True
coordinates.reverse()
beginning_milepost = pd.get("properties/endMarker", default="")
ending_milepost = pd.get("properties/startMarker", default="")
beginning_milepost = pd.get("properties/endMarker", default=ending_milepost)
ending_milepost = pd.get(
"properties/startMarker", default=beginning_milepost
)

roadName = wzdx_translator.remove_direction_from_street_name(
pd.get("properties/routeName")
Expand Down Expand Up @@ -836,7 +889,9 @@ def create_rtdh_standard_msg(
return {}

route_details_start, route_details_end = (
get_route_details_for_coordinates_lngLat(cdotGeospatialApi, coordinates)
get_route_details_for_coordinates_lngLat(
cdotGeospatialApi, coordinates, reversed
)
)

return {
Expand Down
Loading
Loading