コード例 #1
0
def test_connectionscan_data_constructor_basic():
    stops_per_id = {
        "1": Stop("1", "c1", "n1", 0.0, 0.0),
        "2": Stop("2", "c2", "n2", 1.0, 1.0),
        "2a": Stop("2a", "c2a", "n2a", 1.1, 1.1),
        "3": Stop("3", "c3", "n3", 3.0, 3.0),
    }

    footpaths_per_from_to_stop_id = {
        ("1", "1"): Footpath("1", "1", 60),
        ("2", "2"): Footpath("2", "2", 70),
        ("2a", "2a"): Footpath("2a", "2a", 71),
        ("3", "3"): Footpath("3", "3", 80),
        ("2", "2a"): Footpath("2", "2a", 75),
        ("2a", "2"): Footpath("2a", "2", 75),
    }

    con_1_1 = Connection("t1", "1", "2", 60, 70)
    con_1_2 = Connection("t1", "2", "3", 72, 80)

    con_2_1 = Connection("t2", "2", "3", 50, 59)
    con_2_2 = Connection("t2", "3", "1", 60, 72)

    trips_per_id = {
        "t1": Trip("t1", [con_1_1, con_1_2]),
        "t2": Trip("t2", [con_2_1, con_2_2])
    }
    cs_data = ConnectionScanData(stops_per_id, footpaths_per_from_to_stop_id, trips_per_id)
    assert 4 == len(cs_data.stops_per_id)
    assert 4 == len(cs_data.stops_per_id)
    assert 2 == len(cs_data.trips_per_id)
    assert [con_2_1, con_1_1, con_2_2, con_1_2] == cs_data.sorted_connections
コード例 #2
0
def test_trip_get_set_of_all_stop_ids():
    trip_id = "t1"
    connections = [
        Connection(trip_id, "s1", "s2", 60, 70),
        Connection(trip_id, "s2", "s3", 70, 80),
    ]
    a_trip = Trip(trip_id, connections)
    assert {"s1", "s2", "s3"} == a_trip.get_set_of_all_stop_ids()
コード例 #3
0
def test_trip_constructor_not_stop_consistent():
    trip_id = "t1"
    connections = [
        Connection(trip_id, "s1", "s2", 60, 70),
        Connection(trip_id, "s3", "s4", 70, 80),
    ]
    with pytest.raises(ValueError):
        Trip(trip_id, connections)
コード例 #4
0
def test_trip_get_all_from_stop_ids():
    trip_id = "t1"
    connections = [
        Connection(trip_id, "s1", "s2", 60, 70),
        Connection(trip_id, "s2", "s3", 70, 80),
    ]
    a_trip = Trip(trip_id, connections)
    assert ["s1", "s2"] == a_trip.get_all_from_stop_ids()
コード例 #5
0
def test_journey_prepend_journey_leg_not_stop_consistent_2():
    journey = Journey()
    journey.prepend_journey_leg(
        JourneyLeg(Connection("t2", "s6", "s8", 50, 60),
                   Connection("t2", "s12", "s13", 80, 90), None))
    with pytest.raises(ValueError):
        journey.prepend_journey_leg(
            JourneyLeg(Connection("t1", "s1", "s2", 10, 20),
                       Connection("t1", "s5", "s7", 30, 40), None))
コード例 #6
0
def test_journey_leg_without_footpath():
    in_connection = Connection("t1", "s1", "s2", 10, 20)
    out_connection = Connection("t1", "s5", "s6", 30, 40)
    journey_leg = JourneyLeg(in_connection, out_connection, None)
    assert in_connection == journey_leg.in_connection
    assert out_connection == journey_leg.out_connection
    assert journey_leg.footpath is None
    assert "t1" == journey_leg.get_trip_id()
    assert "s1" == journey_leg.get_in_stop_id()
    assert "s6" == journey_leg.get_out_stop_id()
    assert 10 == journey_leg.get_dep_time_in_stop_id()
    assert 40 == journey_leg.get_arr_time_out_stop_id()
コード例 #7
0
def test_trip_constructor_basic():
    trip_id = "t1"
    connections = [
        Connection(trip_id, "s1", "s2", 60, 70),
        Connection(trip_id, "s2", "s3", 72, 80),
        Connection(trip_id, "s3", "s4", 82, 90),
    ]
    a_trip = Trip(trip_id, connections, trip_type=TripType(3))
    assert trip_id == a_trip.id
    assert 3 == len(a_trip.connections)
    assert "s2" == a_trip.connections[1].from_stop_id
    assert 90 == a_trip.connections[2].arr_time
    assert TripType.BUS == a_trip.trip_type
コード例 #8
0
def test_journey_leg():
    in_connection = Connection("t1", "s1", "s2", 10, 20)
    out_connection = Connection("t1", "s5", "s6", 30, 40)
    footpath = Footpath("s6", "s7", 1)
    journey_leg = JourneyLeg(in_connection, out_connection, footpath)
    assert in_connection == journey_leg.in_connection
    assert out_connection == journey_leg.out_connection
    assert footpath == journey_leg.footpath
    assert "t1" == journey_leg.get_trip_id()
    assert "s1" == journey_leg.get_in_stop_id()
    assert "s6" == journey_leg.get_out_stop_id()
    assert "s1" == journey_leg.get_first_stop_id()
    assert "s7" == journey_leg.get_last_stop_id()
    assert 10 == journey_leg.get_dep_time_in_stop_id()
    assert 40 == journey_leg.get_arr_time_out_stop_id()
コード例 #9
0
            def process_rows_of_trip(rows):
                if rows:
                    trip_id = rows[0][trip_id_index]
                    if trip_available_at_date_per_trip_id[trip_id]:
                        connections = []
                        for i in range(len(rows) - 1):
                            from_row = rows[i]
                            to_row = rows[i + 1]
                            con_dep = from_row[departure_time_index] if departure_time_index else None
                            con_arr = to_row[arrival_time_index] if arrival_time_index else None
                            if con_dep and con_arr:
                                connections += [Connection(
                                    trip_id,
                                    from_row[stop_id_index],
                                    to_row[stop_id_index],
                                    hhmmss_to_sec(con_dep),
                                    hhmmss_to_sec(con_arr))]
                            else:
                                return  # we do not want trips with missing times

                        try:
                            trip_type = TripType(route_type_per_trip_id[trip_id])
                        except ValueError:
                            trip_type = TripType.UNKNOWN
                        trips_per_id[trip_id] = Trip(trip_id, connections, trip_type)
コード例 #10
0
def test_connection_constructor_basic():
    a_connection = Connection("t1", "1", "2", 60, 120)
    assert "t1" == a_connection.trip_id
    assert "1" == a_connection.from_stop_id
    assert "2" == a_connection.to_stop_id
    assert 60 == a_connection.dep_time
    assert 120 == a_connection.arr_time
コード例 #11
0
def test_journey_leg_2():
    journey = Journey()
    journey.prepend_journey_leg(
        JourneyLeg(Connection("t2", "s6", "s8", 50, 60),
                   Connection("t2", "s12", "s13", 80, 90),
                   Footpath("s13", "s14", 1)))
    journey.prepend_journey_leg(
        JourneyLeg(Connection("t1", "s1", "s2", 10, 20),
                   Connection("t1", "s5", "s6", 30, 40), None))
    assert journey.has_legs()
    assert not journey.is_first_leg_footpath()
    assert journey.is_last_leg_footpath()
    assert "s1" == journey.get_first_stop_id()
    assert "s14" == journey.get_last_stop_id()
    assert 2 == journey.get_nb_journey_legs()
    assert 2 == journey.get_nb_pt_journey_legs()
コード例 #12
0
def create_trips(stops, running_times, stop_times, first_departure, nb_trips,
                 headway):
    trips = []
    for trip_index in range(nb_trips):
        dep_first_stop = first_departure + trip_index * headway
        trip_id = "{}_{}_{}_{}".format(stops[0].name, stops[-1].name,
                                       seconds_to_hhmmss(dep_first_stop),
                                       trip_index)
        cons = []
        arr = None
        for stop_index in range(len(stops) - 1):
            dep = dep_first_stop if stop_index == 0 else arr + stop_times[
                stop_index - 1]
            arr = dep + running_times[stop_index]
            cons += [
                Connection(trip_id, stops[stop_index].id,
                           stops[stop_index + 1].id, dep, arr)
            ]
        trips += [Trip(trip_id, cons)]
    return trips
コード例 #13
0
def test_connectionscan_data_constructor_stop_ids_in_trips_not_consistent_with_stops():
    with pytest.raises(ValueError):
        ConnectionScanData({"s1": Stop("s1", "", "", 0.0, 0.0)}, {},
                           {"t": Trip("t", [Connection("t", "s1", "s2", 30, 40)])})
    log_end(additional_message="test failed successful")
コード例 #14
0
def test_connection_constructor_not_time_consistent():
    with pytest.raises(ValueError):
        Connection("t1", "1", "2", 60, 50)
コード例 #15
0
def test_journey_leg_constructor_not_in_out_connection_consistent_2():
    in_connection = None
    out_connection = Connection("t1", "s5", "s6", 30, 40)
    footpath = Footpath("s10", "s7", 1)
    with pytest.raises(ValueError):
        JourneyLeg(in_connection, out_connection, footpath)
コード例 #16
0
def test_journey_leg_constructor_not_time_consistent():
    in_connection = Connection("t1", "s1", "s2", 10, 20)
    out_connection = Connection("t1", "s5", "s6", 5, 9)
    footpath = Footpath("s6", "s7", 1)
    with pytest.raises(ValueError):
        JourneyLeg(in_connection, out_connection, footpath)