def setUp(self): odx = ODX(0, 1) odx.load_gtfs() day = dt.datetime.strptime("01/30/18 00:00", "%m/%d/%y %H:%M") megas = odx.preprocess_gtfs(day) builder = NetworkBuilder(700) self.net = builder.build(megas, 1)
def test_schedule_maker(self): """ :return: """ odx = ODX(0, 1) odx.load_gtfs() scheduler = ScheduleMaker(odx.gtfs['trips'], odx.gtfs['calendar'], odx.gtfs['stop_times'], odx.gtfs['stops'], odx.gtfs['routes']) day = dt.datetime.strptime("01/30/18 00:00", "%m/%d/%y %H:%M") train, bus = scheduler.build_daily_table(day)
def test_get_megas_stops(self): odx = ODX(0, 1) odx.load_gtfs() day = dt.datetime.strptime("01/30/18 00:00", "%m/%d/%y %H:%M") megas = odx.preprocess_gtfs(day) plotter = PlotStops() for stop in megas['51']: plotter.add_mega( stop) # for s in stop.stops: # plotter.add_stop(s) for stop in megas['RAIL']: plotter.add_mega(stop) plotter.export('test.html')
def test_with_apc(self): odx = ODX(0, 1) odx.load_gtfs() day = dt.datetime.strptime("01/30/18 00:00", "%m/%d/%y %H:%M") self.megas = odx.preprocess_gtfs(day) builder = NetworkBuilder(700) net = builder.build(self.megas, 1) fileDir = os.path.realpath(__file__).split('/version_1_0')[0] path = os.path.join(fileDir, 'Data/breeze_test.pick') breeze_load = Breeze_Loader() df = breeze_load.load_breeze(path) self.assertTrue(isinstance(df, pd.DataFrame), msg="Loader works well") df = breeze_load.get_marta_only(df) self.assertTrue(df.shape[0] - df.Dev_Operator.str.contains('MARTA').sum() == 0, msg=' contains non Marta Data') bus, rail = breeze_load.split_frame(df) rail[~(rail.Dev_Operator.str.contains("Rail"))].to_csv('bad_data.csv') self.assertEqual(rail.shape[0] - rail.Dev_Operator.str.contains("Rail").sum(), 0, msg='Contains non rail data') self.assertEqual(bus.shape[0] - bus.Dev_Operator.str.contains("Bus").sum(), 0, msg='Contains non bus data') path = os.path.join(fileDir, 'Data/RailStopsMap.csv') loader = RailMappingLoader() map_df = loader.load_rail_mappings(path) map_df = loader.clean_rail_mappings(map_df) map_df = loader.fit_2_network(map_df, net) path = os.path.join(fileDir, 'Data/apc_test.pick') apc_load = APC_Loader(net) apc_df = apc_load.load_apc(path) apc_df = apc_load.join_megas(apc_df) #load.match_2_apc(bus, apc_df).to_csv('apc_match_test.csv') bus_dict = apc_load.build_search_dict(apc_df) bus_df = breeze_load.apc_match(bus, bus_dict) bus_df.head(n=2000).to_csv('apc_breeze_test.csv') rail_df = breeze_load.match_rail_stops(rail, map_df) rail_df.head(n=100).to_csv('rail_breeze_test.csv') data = pd.concat([bus_df, rail_df]) data.to_csv('Data_set_11_13.csv') print(data.columns)
class TestODX(unittest.TestCase): def setUp(self): self.odx = ODX(0,1) self.odx.load_gtfs() self.day = dt.datetime.strptime("01/30/18 00:00", "%m/%d/%y %H:%M") def test_odx_preprocess_gtfs(self): self.assertEqual(type(self.odx.preprocess_gtfs(self.day)),dict,"gtfs MegaStops incorrect type") i , j = list(self.odx.megas.items())[1] self.assertEqual(type(i),str,"Route is incorrect Type") self.assertEqual(type(j), list, 'Mega Stop collection mapped to incorrect type') self.assertEqual(type(j[0]),MegaStop, "Megas does not have mega stops in it") i, j = list(self.odx.megas.items())[0] self.assertEqual(type(j), list, 'Mega Stop collection mapped to incorrect type') self.assertEqual(type(j[0]), MegaStop, "Megas does not have mega stops in it") def test_odx_build_network(self): pass
def test_single(self): odx = ODX(0, 1) odx.load_gtfs() day = dt.datetime.strptime("01/30/18 00:00", "%m/%d/%y %H:%M") self.megas = odx.preprocess_gtfs(day) builder = NetworkBuilder(700) net = builder.build(self.megas, 1) fileDir = os.path.realpath(__file__).split('/version_1_0')[0] path = os.path.join(fileDir, 'Data/apc_test.pick') load = apc_loader.APC_Loader(net) df = load.load_apc(path) self.assertTrue(isinstance(load.load_apc(path), pd.DataFrame), msg="Loader works well") self.assertTrue(type(load.get_route_tree('19')) != int, msg='Network stored as int works incorrectly') self.assertTrue(type(load.get_route_tree(19)) == int, msg='Test works incorrectly') self.assertTrue(load.join_megas(df, True) == 0, msg='Test for bad matches') _ = load.join_megas(df) print(_) _.to_csv('apc_test_w_ms.csv') print(load.build_bus_tree(df))
def test_build_ball_tree(self): odx = ODX(0, 1) odx.load_gtfs() day = dt.datetime.strptime("01/30/18 00:00", "%m/%d/%y %H:%M") odx.preprocess_gtfs(day) fac = MegaStopFac(700)
def setUp(self): odx = ODX(0, 1) odx.load_gtfs() day = dt.datetime.strptime("01/30/18 00:00", "%m/%d/%y %H:%M") self.megas = odx.preprocess_gtfs(day)
def test_import_files(self): odx = ODX(0, 1) odx.load_gtfs() scheduler = ScheduleMaker(odx.gtfs['trips'], odx.gtfs['calendar'], odx.gtfs['stop_times'], odx.gtfs['stops'], odx.gtfs['routes'])