Last active
January 7, 2024 21:08
-
-
Save joaofig/1219521593cca798d6445963d43edfb1 to your computer and use it in GitHub Desktop.
Main loop for speed inference data preparation.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def main(): | |
config = get_config(tile_extract='./valhalla/custom_files/valhalla_tiles.tar', | |
verbose=True) | |
trips = get_all_trips() | |
for traj_id, vehicle_id, trip_id in trips: | |
print(f"Vehicle {vehicle_id}, trip {trip_id}, trajectory: {traj_id}") | |
trip_df = get_trip_signals(vehicle_id, trip_id) | |
lat_array = trip_df["match_latitude"].values | |
lon_array = trip_df["match_longitude"].values | |
time_stamps = trip_df["time_stamp"].values | |
day_num = float(trip_df["day_num"].values[0]) | |
trajectory = Trajectory(lat=lat_array, lon=lon_array, time=time_stamps) | |
try: | |
actor = Actor(config) | |
encoded_line = map_match(actor, list(zip(lon_array, lat_array))) | |
except RuntimeError as e: | |
print(e) | |
continue | |
polyline = np.array(decode_polyline(encoded_line, order="latlng")) | |
compound = CompoundTrajectory(trajectory, polyline[:,0], polyline[:,1]) | |
converted = compound.to_trajectory() | |
segments = generate_segments(converted, day_num, traj_id) | |
if len(segments): | |
insert_segments(segments) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment