def test_different_services(self, query_1, query_2):
        connection_query = ConnectionQuery.from_dict(query_1)
        connection_results_1 = self.connection_solver.find_connections(
            connection_query)
        connection_results_1 = [[
            (action.start_stop_name, action.end_stop_name)
            for action in connection.actions
        ] for connection in connection_results_1.connections]

        connection_query = ConnectionQuery.from_dict(query_2)
        connection_results_2 = self.connection_solver.find_connections(
            connection_query)
        connection_results_2 = [[
            (action.start_stop_name, action.end_stop_name)
            for action in connection.actions
        ] for connection in connection_results_2.connections]
        self.assertNotEqual(connection_results_1, connection_results_2)
    def test_exception_days(self, query_1, query_2):
        connection_query = ConnectionQuery.from_dict(query_1)
        connection_results_1 = self.connection_solver.find_connections(
            connection_query)
        connection_results_1 = [[
            (transfer.start_stop_name, transfer.end_stop_name,
             transfer.route_name, transfer.headsign)
            for transfer in connection.transfers
        ] for connection in connection_results_1.connections]

        connection_query = ConnectionQuery.from_dict(query_2)
        connection_results_2 = self.connection_solver.find_connections(
            connection_query)
        connection_results_2 = [[
            (transfer.start_stop_name, transfer.end_stop_name,
             transfer.route_name, transfer.headsign)
            for transfer in connection.transfers
        ] for connection in connection_results_2.connections]
        self.assertEqual(connection_results_1, connection_results_2)
 def test_connection_duration(self, query, duration):
     connection_query = ConnectionQuery.from_dict(query)
     connection_results: ConnectionResults = self.connection_solver.find_connections(
         connection_query)
     connections = connection_results.connections
     for connection in connections:
         if connection.end_datetime - connection.start_datetime < timedelta(
                 minutes=duration):
             return
     self.fail()
 def test_connection_has_walking_edge(self, query):
     connection_query = ConnectionQuery.from_dict(query)
     connection_results: ConnectionResults = self.connection_solver.find_connections(
         connection_query)
     connections = connection_results.connections
     for connection in connections:
         for action in connection.actions:
             if isinstance(action, Walk):
                 return
     self.fail()
def random_connection_query(stops_df):
    sample = stops_df.sample(2)
    start_stop_name, end_stop_name = list(sample['stop_name'])
    start_stop_lat, end_stop_lat = list(sample['stop_lat'])
    start_stop_lon, end_stop_lon = list(sample['stop_lon'])
    distance = get_walking_distance(start_stop_lon, start_stop_lat,
                                    end_stop_lon, end_stop_lat)
    query = ConnectionQuery(
        0, datetime.strptime("2020-05-24 12:00:00", DATETIME_FORMAT),
        start_stop_name, end_stop_name)
    return distance / 1000, query
 def test_particular_connection_exists_by_times(self, query, start_datetime,
                                                end_datetime):
     start_datetime = datetime.strptime(start_datetime, DATETIME_FORMAT)
     end_datetime = datetime.strptime(end_datetime, DATETIME_FORMAT)
     connection_query = ConnectionQuery.from_dict(query)
     connection_results: ConnectionResults = self.connection_solver.find_connections(
         connection_query)
     connections = connection_results.connections
     for connection in connections:
         if connection.start_datetime == start_datetime and connection.end_datetime == end_datetime:
             return
     self.fail()
 def test_particular_connection_exists_by_routes(self, query,
                                                 expected_route_names):
     connection_query = ConnectionQuery.from_dict(query)
     connection_results: ConnectionResults = self.connection_solver.find_connections(
         connection_query)
     connections = connection_results.connections
     for connection in connections:
         route_names = [
             transfer.route_name for transfer in connection.transfers
         ]
         if route_names == expected_route_names:
             return
     self.fail()
 def test_connection_result_not_empty(self, query):
     connection_query = ConnectionQuery.from_dict(query)
     connection_results: ConnectionResults = self.connection_solver.find_connections(
         connection_query)
     self.assertNotEqual(len(connection_results.connections), 0)
Exemple #9
0
    # merged_data.save('merged_data.pickle')
    # bfs_solver_data.save('bfs_solver_data.pickle')

    # merged_data = ParsedData.load('merged_data.pickle')
    # bfs_solver_data = BfsSolverData.load('bfs_solver_data.pickle')

    solver = BfsConnectionSolver(bfs_solver_data,
                                 earliest_arrival_time=True,
                                 latest_departure_time=True,
                                 minimal_transfers_count=True)

    start_stop_id = 1362
    end_stop_id = 333
    start_dt = datetime(2020, 10, 14, 12, 34)

    query = ConnectionQuery(42, start_dt, start_stop_id, end_stop_id)

    t1 = time.time()
    connections = solver.find_connections(query)
    t2 = time.time()
    print(f'{t2 - t1:.3f} s')

    connection = connections[0]
    for transfer in connection.transfers:
        start_datetime = transfer.start_datetime
        end_datetime = transfer.end_datetime
        route_name = merged_data.routes_df.loc[transfer.route_id,
                                               'route_short_name']
        start_stop_name = merged_data.stops_df.loc[transfer.start_stop_id,
                                                   'stop_name']
        end_stop_name = merged_data.stops_df.loc[transfer.end_stop_id,