@@ -809,8 +809,6 @@ def get_route_details_for_coordinates_lngLat(
809809 route_details_end = get_route_details (
810810 cdotGeospatialApi , coordinates [- 1 ][1 ], coordinates [- 1 ][0 ]
811811 )
812- print ("Route details start:" , route_details_start )
813- print ("Route details end:" , route_details_end )
814812
815813 # Update route IDs based on directionality
816814 if route_details_start and route_details_end :
@@ -870,187 +868,187 @@ def create_rtdh_standard_msg(
870868 Returns:
871869 dict: RTDH standard message
872870 """
873- # try:
874- description = pd .get ("properties/travelerInformationMessage" , "" )
875- if description == INVALID_EVENT_DESCRIPTION :
876- description = create_description (
877- pd .get ("properties/name" ),
878- pd .get ("properties/routeName" ),
879- pd .get ("properties/startMarker" ),
880- pd .get ("properties/endMarker" ),
881- pd .get ("properties/type" ),
882- pd .get ("properties/startTime" ),
883- pd .get ("properties/clearTime" ),
884- )
885-
886- begin_cross_street , end_cross_street = get_cross_streets_from_description (
887- description
888- )
871+ try :
872+ description = pd .get ("properties/travelerInformationMessage" , "" )
873+ if description == INVALID_EVENT_DESCRIPTION :
874+ description = create_description (
875+ pd .get ("properties/name" ),
876+ pd .get ("properties/routeName" ),
877+ pd .get ("properties/startMarker" ),
878+ pd .get ("properties/endMarker" ),
879+ pd .get ("properties/type" ),
880+ pd .get ("properties/startTime" ),
881+ pd .get ("properties/clearTime" ),
882+ )
889883
890- coordinates = get_linestring (pd .get ("geometry" ))
891- if not coordinates :
892- logging .warning (
893- f'Unable to retrieve geometry coordinates for event: { pd .get ("properties/id" , default = "" )} '
884+ begin_cross_street , end_cross_street = get_cross_streets_from_description (
885+ description
894886 )
895- return {}
896887
897- direction = pd .get ("properties/direction" , default = "unknown" )
888+ coordinates = get_linestring (pd .get ("geometry" ))
889+ if not coordinates :
890+ logging .warning (
891+ f'Unable to retrieve geometry coordinates for event: { pd .get ("properties/id" , default = "" )} '
892+ )
893+ return {}
898894
899- beginning_milepost = pd .get ("properties/startMarker" )
900- ending_milepost = pd .get ("properties/endMarker" )
901- recorded_direction = pd .get ("properties/recorded_direction" )
902- geometry_direction = geospatial_tools .get_road_direction_from_coordinates (
903- coordinates
904- )
895+ direction = pd .get ("properties/direction" , default = "unknown" )
905896
906- additional_impacts = pd .get ("properties/additionalImpacts" , [])
907- has_alternating_traffic = detect_alternating_traffic (additional_impacts )
908- lane_impacts = get_lane_impacts (
909- pd .get ("properties/laneImpacts" ),
910- pd .get ("properties/direction" ),
911- has_alternating_traffic ,
912- )
913- if direction != recorded_direction and all_lanes_open (lane_impacts ):
914- logging .info (
915- f'Unable to retrieve geometry coordinates for event: { pd .get ("properties/id" , default = "" )} '
897+ beginning_milepost = pd .get ("properties/startMarker" )
898+ ending_milepost = pd .get ("properties/endMarker" )
899+ recorded_direction = pd .get ("properties/recorded_direction" )
900+ geometry_direction = geospatial_tools .get_road_direction_from_coordinates (
901+ coordinates
916902 )
917- return {}
918-
919- print (f"{ direction } , { recorded_direction } , { geometry_direction } " )
920- if (
921- direction == REVERSED_DIRECTION_MAP .get (geometry_direction )
922- and direction != "unknown"
923- ):
924- print ("reversing coordinates" )
925- coordinates .reverse ()
926- beginning_milepost = pd .get ("properties/endMarker" )
927- ending_milepost = pd .get ("properties/startMarker" )
928- print (f"{ beginning_milepost } , { ending_milepost } " )
929- roadName = wzdx_translator .remove_direction_from_street_name (
930- pd .get ("properties/routeName" )
931- )
932903
933- now = datetime .datetime .now (datetime .timezone .utc )
934- start_date = pd .get (
935- "properties/startTime" , date_tools .parse_datetime_from_iso_string
936- )
937- end_date = pd .get ("properties/clearTime" , date_tools .parse_datetime_from_iso_string )
938-
939- if not start_date and isIncident :
940- start_date = now
904+ additional_impacts = pd .get ("properties/additionalImpacts" , [])
905+ has_alternating_traffic = detect_alternating_traffic (additional_impacts )
906+ lane_impacts = get_lane_impacts (
907+ pd .get ("properties/laneImpacts" ),
908+ pd .get ("properties/direction" ),
909+ has_alternating_traffic ,
910+ )
911+ if direction != recorded_direction and all_lanes_open (lane_impacts ):
912+ logging .info (
913+ f'Unable to retrieve geometry coordinates for event: { pd .get ("properties/id" , default = "" )} '
914+ )
915+ return {}
916+
917+ if (
918+ direction == REVERSED_DIRECTION_MAP .get (geometry_direction )
919+ and direction != "unknown"
920+ ):
921+ coordinates .reverse ()
922+ beginning_milepost = pd .get ("properties/endMarker" )
923+ ending_milepost = pd .get ("properties/startMarker" )
924+
925+ roadName = wzdx_translator .remove_direction_from_street_name (
926+ pd .get ("properties/routeName" )
927+ )
941928
942- if not start_date :
943- logging . warning (
944- f'Unable to process event, no start date for event: { pd . get ( "properties/id " , default = "" ) } '
929+ now = datetime . datetime . now ( datetime . timezone . utc )
930+ start_date = pd . get (
931+ "properties/startTime " , date_tools . parse_datetime_from_iso_string
945932 )
946- return {}
947- if not end_date :
948933 end_date = pd .get (
949- "properties/estimatedClearTime" ,
950- date_tools .parse_datetime_from_iso_string ,
934+ "properties/clearTime" , date_tools .parse_datetime_from_iso_string
951935 )
952936
953- if not end_date :
954- # Since there is no end date, assume still active, set end date in future (12 hours + n days until after current time)
955- end_date = start_date + datetime .timedelta (hours = 12 )
937+ if not start_date and isIncident :
938+ start_date = now
956939
957- delta_days = (now - end_date ).days
958- if delta_days > 0 :
959- end_date = end_date + datetime .timedelta (days = delta_days )
940+ if not start_date :
941+ logging .warning (
942+ f'Unable to process event, no start date for event: { pd .get ("properties/id" , default = "" )} '
943+ )
944+ return {}
945+ if not end_date :
946+ end_date = pd .get (
947+ "properties/estimatedClearTime" ,
948+ date_tools .parse_datetime_from_iso_string ,
949+ )
960950
961- end_date = end_date .replace (second = 0 , microsecond = 0 )
951+ if not end_date :
952+ # Since there is no end date, assume still active, set end date in future (12 hours + n days until after current time)
953+ end_date = start_date + datetime .timedelta (hours = 12 )
962954
963- event_type , types_of_work , work_zone_type = map_event_type (
964- pd . get ( "properties/type" , default = "" )
965- )
955+ delta_days = ( now - end_date ). days
956+ if delta_days > 0 :
957+ end_date = end_date + datetime . timedelta ( days = delta_days )
966958
967- restrictions = []
968- if pd .get ("properties/isOversizedLoadsProhibited" ):
969- restrictions .append ({"type" : "permitted-oversize-loads-prohibited" })
959+ end_date = end_date .replace (second = 0 , microsecond = 0 )
970960
971- event_status = date_tools .get_event_status (start_date , end_date )
961+ event_type , types_of_work , work_zone_type = map_event_type (
962+ pd .get ("properties/type" , default = "" )
963+ )
972964
973- condition_1 = event_status in ["active" , "pending" , "planned" ]
965+ restrictions = []
966+ if pd .get ("properties/isOversizedLoadsProhibited" ):
967+ restrictions .append ({"type" : "permitted-oversize-loads-prohibited" })
974968
975- route_details_start , route_details_end = get_route_details_for_coordinates_lngLat (
976- cdotGeospatialApi , coordinates
977- )
969+ event_status = date_tools .get_event_status (start_date , end_date )
978970
979- # Milepost Priority:
980- # 1. Route Details (only if start and end are on the same route)
981- # 2. properties/startMarker and properties/endMarker
982- # 3. Description parsing
983- beginning_milepost_from_description , ending_milepost_description = (
984- get_mileposts_from_description (description )
985- )
986- if (
987- route_details_start
988- and route_details_end
989- and route_details_start ["Route" ] == route_details_end ["Route" ]
990- ):
991- beginning_milepost = route_details_start ["Measure" ]
992- ending_milepost = route_details_end ["Measure" ]
993-
994- if not beginning_milepost :
995- beginning_milepost = beginning_milepost_from_description
996- if not ending_milepost :
997- ending_milepost = ending_milepost_description
998-
999- return {
1000- "rtdh_timestamp" : time .time (),
1001- "rtdh_message_id" : str (uuid .uuid4 ()),
1002- "event" : {
1003- "type" : event_type ,
1004- "types_of_work" : types_of_work ,
1005- "work_zone_type" : work_zone_type ,
1006- "source" : {
1007- "id" : pd .get ("properties/id" , default = "" ) + "_" + direction ,
1008- "last_updated_timestamp" : pd .get (
1009- "properties/lastUpdated" ,
1010- date_tools .get_unix_from_iso_string ,
1011- default = 0 ,
1012- ),
1013- },
1014- "geometry" : get_improved_geometry (
1015- cdotGeospatialApi ,
1016- coordinates ,
1017- event_status ,
1018- route_details_start ,
1019- route_details_end ,
1020- pd .get ("properties/id" , default = "" ) + "_" + direction ,
1021- ),
1022- "header" : {
1023- "description" : description ,
1024- "start_timestamp" : date_tools .date_to_unix (start_date ),
1025- "end_timestamp" : date_tools .date_to_unix (end_date ),
1026- },
1027- "detail" : {
1028- "road_name" : roadName ,
1029- "road_number" : roadName ,
1030- "direction" : direction ,
1031- },
1032- "additional_info" : {
1033- "lanes" : lane_impacts ,
1034- "restrictions" : restrictions ,
1035- "vehicle_impact" : get_vehicle_impact (
1036- lane_impacts , has_alternating_traffic
971+ condition_1 = event_status in ["active" , "pending" , "planned" ]
972+
973+ route_details_start , route_details_end = (
974+ get_route_details_for_coordinates_lngLat (cdotGeospatialApi , coordinates )
975+ )
976+
977+ # Milepost Priority:
978+ # 1. Route Details (only if start and end are on the same route)
979+ # 2. properties/startMarker and properties/endMarker
980+ # 3. Description parsing
981+ beginning_milepost_from_description , ending_milepost_description = (
982+ get_mileposts_from_description (description )
983+ )
984+ if (
985+ route_details_start
986+ and route_details_end
987+ and route_details_start ["Route" ] == route_details_end ["Route" ]
988+ ):
989+ beginning_milepost = route_details_start ["Measure" ]
990+ ending_milepost = route_details_end ["Measure" ]
991+
992+ if not beginning_milepost :
993+ beginning_milepost = beginning_milepost_from_description
994+ if not ending_milepost :
995+ ending_milepost = ending_milepost_description
996+
997+ return {
998+ "rtdh_timestamp" : time .time (),
999+ "rtdh_message_id" : str (uuid .uuid4 ()),
1000+ "event" : {
1001+ "type" : event_type ,
1002+ "types_of_work" : types_of_work ,
1003+ "work_zone_type" : work_zone_type ,
1004+ "source" : {
1005+ "id" : pd .get ("properties/id" , default = "" ) + "_" + direction ,
1006+ "last_updated_timestamp" : pd .get (
1007+ "properties/lastUpdated" ,
1008+ date_tools .get_unix_from_iso_string ,
1009+ default = 0 ,
1010+ ),
1011+ },
1012+ "geometry" : get_improved_geometry (
1013+ cdotGeospatialApi ,
1014+ coordinates ,
1015+ event_status ,
1016+ route_details_start ,
1017+ route_details_end ,
1018+ pd .get ("properties/id" , default = "" ) + "_" + direction ,
10371019 ),
1038- "beginning_milepost" : beginning_milepost ,
1039- "ending_milepost" : ending_milepost ,
1040- "beginning_cross_street" : begin_cross_street ,
1041- "ending_cross_street" : end_cross_street ,
1042- "valid" : False ,
1043- "route_details_start" : route_details_start ,
1044- "route_details_end" : route_details_end ,
1045- "condition_1" : condition_1 ,
1020+ "header" : {
1021+ "description" : description ,
1022+ "start_timestamp" : date_tools .date_to_unix (start_date ),
1023+ "end_timestamp" : date_tools .date_to_unix (end_date ),
1024+ },
1025+ "detail" : {
1026+ "road_name" : roadName ,
1027+ "road_number" : roadName ,
1028+ "direction" : direction ,
1029+ },
1030+ "additional_info" : {
1031+ "lanes" : lane_impacts ,
1032+ "restrictions" : restrictions ,
1033+ "vehicle_impact" : get_vehicle_impact (
1034+ lane_impacts , has_alternating_traffic
1035+ ),
1036+ "beginning_milepost" : beginning_milepost ,
1037+ "ending_milepost" : ending_milepost ,
1038+ "beginning_cross_street" : begin_cross_street ,
1039+ "ending_cross_street" : end_cross_street ,
1040+ "valid" : False ,
1041+ "route_details_start" : route_details_start ,
1042+ "route_details_end" : route_details_end ,
1043+ "condition_1" : condition_1 ,
1044+ },
10461045 },
1047- },
1048- }
1049- # except Exception as e:
1050- # logging.warning(
1051- # f'Error ocurred generating standard message for message {pd.get("properties/id", default="")}: {e}'
1052- # )
1053- # return {}
1046+ }
1047+ except Exception as e :
1048+ logging .error (
1049+ f'Error ocurred generating standard message for message { pd .get ("properties/id" , default = "" )} : { e } '
1050+ )
1051+ return {}
10541052
10551053
10561054def validate_closure (obj : dict | OrderedDict ) -> bool :
0 commit comments