Skip to content

Commit 232a974

Browse files
committed
Fixing bugs for alternating traffic and incorrect geometry directions
1 parent ac214fc commit 232a974

File tree

8 files changed

+28636
-20
lines changed

8 files changed

+28636
-20
lines changed

wzdx/raw_to_standard/planned_events.py

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -563,15 +563,17 @@ def get_lane_impacts(
563563
)
564564

565565

566-
def all_lanes_open(lanes: list[dict]) -> bool:
567-
"""Check if all lanes are open
566+
def all_lanes_open(lanes: list[dict], description: str) -> bool:
567+
"""Check if all lanes are open, or if the description indicates alternating traffic
568568
569569
Args:
570570
lanes (list[dict]): WZDx lanes list
571571
572572
Returns:
573573
bool: whether all lanes are open
574574
"""
575+
if "alternating traffic" in description.lower():
576+
return False
575577
for i in lanes:
576578
if i["status"] != "open":
577579
return False
@@ -748,6 +750,8 @@ def get_route_details_for_coordinates_lngLat(
748750
route_details_end = get_route_details(
749751
cdotGeospatialApi, coordinates[-1][1], coordinates[-1][0]
750752
)
753+
print("Route details start:", route_details_start)
754+
print("Route details end:", route_details_end)
751755

752756
# Update route IDs based on directionality
753757
if route_details_start and route_details_end:
@@ -759,7 +763,7 @@ def get_route_details_for_coordinates_lngLat(
759763
)
760764
return route_details_start, route_details_end
761765
else:
762-
if route_details_start["Measure"] > route_details_end["Measure"]:
766+
if route_details_start["Measure"] < route_details_end["Measure"]:
763767
route_details_start["Route"] = route_details_start["Route"].replace(
764768
"_DEC", ""
765769
)
@@ -836,14 +840,31 @@ def create_rtdh_standard_msg(
836840
beginning_milepost = pd.get("properties/startMarker")
837841
ending_milepost = pd.get("properties/endMarker")
838842
recorded_direction = pd.get("properties/recorded_direction")
843+
geometry_direction = geospatial_tools.get_road_direction_from_coordinates(
844+
coordinates
845+
)
846+
847+
lane_impacts = get_lane_impacts(
848+
pd.get("properties/laneImpacts"), pd.get("properties/direction")
849+
)
850+
if direction != recorded_direction and all_lanes_open(
851+
lane_impacts, description
852+
):
853+
logging.info(
854+
f'Unable to retrieve geometry coordinates for event: {pd.get("properties/id", default="")}'
855+
)
856+
return {}
857+
858+
print(f"{direction}, {recorded_direction}, {geometry_direction}")
839859
if (
840-
direction == REVERSED_DIRECTION_MAP.get(recorded_direction)
860+
direction == REVERSED_DIRECTION_MAP.get(geometry_direction)
841861
and direction != "unknown"
842862
):
863+
print("reversing coordinates")
843864
coordinates.reverse()
844865
beginning_milepost = pd.get("properties/endMarker")
845866
ending_milepost = pd.get("properties/startMarker")
846-
867+
print(f"{beginning_milepost}, {ending_milepost}")
847868
roadName = wzdx_translator.remove_direction_from_street_name(
848869
pd.get("properties/routeName")
849870
)
@@ -892,15 +913,6 @@ def create_rtdh_standard_msg(
892913

893914
condition_1 = event_status in ["active", "pending", "planned"]
894915

895-
lane_impacts = get_lane_impacts(
896-
pd.get("properties/laneImpacts"), pd.get("properties/direction")
897-
)
898-
if direction != recorded_direction and all_lanes_open(lane_impacts):
899-
logging.info(
900-
f'Unable to retrieve geometry coordinates for event: {pd.get("properties/id", default="")}'
901-
)
902-
return {}
903-
904916
route_details_start, route_details_end = (
905917
get_route_details_for_coordinates_lngLat(cdotGeospatialApi, coordinates)
906918
)
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
{
2+
"feed_info": {
3+
"publisher": "CDOT",
4+
"version": "1.0",
5+
"license": "https://creativecommons.org/publicdomain/zero/1.0/",
6+
"data_sources": [
7+
{
8+
"data_source_id": "409ce0f7-e260-4cbb-bc51-a9d2e86e71e3",
9+
"organization_name": "CDOT",
10+
"update_date": "2025-08-07T21:20:04Z",
11+
"update_frequency": 300,
12+
"contact_name": "Heather Pickering-Hilgers",
13+
"contact_email": "heather.pickeringhilgers@state.co.us"
14+
}
15+
],
16+
"update_date": "2025-08-07T21:20:04Z",
17+
"update_frequency": 300,
18+
"contact_name": "Heather Pickering-Hilgers",
19+
"contact_email": "heather.pickeringhilgers@state.co.us"
20+
},
21+
"type": "FeatureCollection",
22+
"features": [
23+
{
24+
"id": "33661cfa-5362-5527-a4f8-74bf7c38e5a1",
25+
"type": "Feature",
26+
"properties": {
27+
"core_details": {
28+
"event_type": "work-zone",
29+
"data_source_id": "409ce0f7-e260-4cbb-bc51-a9d2e86e71e3",
30+
"road_names": ["I-70"],
31+
"direction": "westbound",
32+
"name": "OpenTMS-Event26569868512_westbound",
33+
"description": "Between Exit 273: Pecos Street and Exit 271B: Lowell Boulevard (Denver) from Mile Point 272.1 to Mile Point 272. Wall maintenance. Starting today at 6:00PM MDT until tomorrow at about 5:30AM MDT. Full schedule below: • August 7, 6:00PM - August 8, 5:30AM Comment: WB I-70 off-ramp closure with detour route in place",
34+
"update_date": "2025-08-07T21:13:29Z"
35+
},
36+
"start_date": "2025-08-08T00:00:00Z",
37+
"end_date": "2025-08-08T11:30:00Z",
38+
"is_start_date_verified": false,
39+
"is_end_date_verified": false,
40+
"is_start_position_verified": false,
41+
"is_end_position_verified": false,
42+
"location_method": "channel-device-method",
43+
"work_zone_type": "static",
44+
"vehicle_impact": "all-lanes-open",
45+
"lanes": [
46+
{ "order": 1, "type": "exit-ramp", "status": "open" },
47+
{ "order": 2, "type": "general", "status": "open" },
48+
{ "order": 3, "type": "general", "status": "open" }
49+
],
50+
"beginning_cross_street": "Pecos Street",
51+
"ending_cross_street": "Lowell Boulevard",
52+
"types_of_work": [{ "type_name": "barrier-work", "is_architectural_change": false }],
53+
"beginning_milepost": 272.0,
54+
"ending_milepost": 272.131,
55+
"route_details_start": {
56+
"Route": "070A_DEC",
57+
"Measure": 272.0,
58+
"MMin": 0.0,
59+
"MMax": 449.589,
60+
"Distance": 0.73
61+
},
62+
"route_details_end": {
63+
"Route": "070A_DEC",
64+
"Measure": 272.131,
65+
"MMin": 0.0,
66+
"MMax": 449.589,
67+
"Distance": 0.44
68+
},
69+
"condition_1": true
70+
},
71+
"geometry": {
72+
"type": "LineString",
73+
"coordinates": [
74+
[-105.02552069299998, 39.784365911000066],
75+
[-105.02420656199996, 39.78435750400007],
76+
[-105.02337293199997, 39.784291523000036],
77+
[-105.02278930299997, 39.78418364700008]
78+
]
79+
}
80+
}
81+
],
82+
"condition_1": true
83+
}

0 commit comments

Comments
 (0)