Finish code to segment trajectories and store them in database.