def test_find_bus_stops_close_to_Politecnico(): print("Checking the find bus stops close to Politecnico, Milan") x = 9.226182 y = 45.478657 p = Point(x, y) radius = 0.0015 closest_stops = stops().find_stops_close_to(p, radius) # Check that there are some stops close to Politecnico assert len(closest_stops) > 0 print( f"The number of stops is greater than 0, they are {len(closest_stops)}" ) # Check that those buses are stopping near Politecnico bus_lines_to_check = ['19', '33'] print( f"Looking if the bus lines {bus_lines_to_check} are in the closest stops" ) bus_lines_in_the_closest_stops = set([stop[0] for stop in closest_stops]) is_the_bus_line_contained = [ bus_line in bus_lines_in_the_closest_stops for bus_line in bus_lines_to_check ] print(f"Are they contained? {is_the_bus_line_contained}") assert all(is_the_bus_line_contained) is True print("Test passed.\n")
def get_train_routes(initial_point, finishing_point): """ Retrieve the all the train routes slices of vehicles that passes near the initial point and the finishing point @param initial_point: initial user route Point @param finishing_point: finishing user route Point """ # STEP 2 # Find train stops near I. Do the same for F stops_object = stops(type_of_dataset='TRAIN') offset_square = 0.001 Ilist = stops_object.find_stops_close_to(initial_point, radius=offset_square) Flist = stops_object.find_stops_close_to(finishing_point, radius=offset_square) # STEP 3 # Do the intersection in order to find the bus lines in common Ilist, Flist = intercept(Ilist, Flist) print(f'train stops found: {Ilist}') print(f'train stops found: {Flist}') # STEP 4 # Create a list of train routes that have a starting point in Ilist and an end in Flist linestring_selector = LinestringSelector(Ilist, Flist, type_of_dataset="TRAIN") sliced_routes = linestring_selector.get_sliced_routes() print(f'train routes found: {str(len(sliced_routes))}') return sliced_routes
def test_loading_dataset(): print("Checking the type of the dataset.") print("It should be a geopandas.geodataframe.GeoDataFrame .") geo_dataframe = stops().dataset # Check that the initialized dataframe is not empty assert isinstance(geo_dataframe, geopandas.geodataframe.GeoDataFrame) print("Test passed.\n")
def test_intercept_from_Duomo_to_Politecnico(): print("Intercepting the 'from' dataset with the 'to' dataset") duomo_x = 9.18951 duomo_y = 45.46427 duomo_coordinate = Point(duomo_x, duomo_y) politecnico_x = 9.226182 politecnico_y = 45.478657 politecnico_coordinate = Point(politecnico_x, politecnico_y) radius = 0.0015 duomo_stops = stops().find_stops_close_to(duomo_coordinate, radius) polimi_stops = stops().find_stops_close_to(politecnico_coordinate, radius) relevant_duomo_stops, relevant_politecnico_stops = intercept( duomo_stops, polimi_stops) # Check the format of the output assert isinstance(relevant_duomo_stops, geopandas.geodataframe.GeoDataFrame) assert isinstance(relevant_politecnico_stops, geopandas.geodataframe.GeoDataFrame) print("The returned datasets are both GeoDataframes, Great.") expected_columns = ['bus_id', 'longitude', 'latitude', 'point'] does_result_contains_the_expected_columns = [ column in relevant_duomo_stops.columns for column in expected_columns ] assert all(does_result_contains_the_expected_columns) is True does_result_contains_the_expected_columns = [ column in relevant_politecnico_stops.columns for column in expected_columns ] assert all(does_result_contains_the_expected_columns) is True print(f"The result contains those columns {expected_columns}") # Check that only the bus line '19' is contained in both dataset duomo_lines = set(relevant_duomo_stops['bus_id']) politecnico_lines = set(relevant_politecnico_stops['bus_id']) assert len(duomo_lines) == 1 assert len(politecnico_lines) == 1 assert '19' in politecnico_lines assert '19' in duomo_lines print("Only line '19' connects Duomo to Politecnico") print("Test passed.\n")