コード例 #1
0
def here_basic_routing_test(valid_here_routing_response):
    origin = make_pt_object(type_pb2.POI, 2.439938, 48.572841)
    destination = make_pt_object(type_pb2.STOP_AREA, 2.440548, 48.57307)
    fallback_extremity = PeriodExtremity(str_to_time_stamp('20161010T152000'),
                                         True)
    response = Here._read_response(
        response=valid_here_routing_response,
        mode='walking',
        origin=origin,
        destination=destination,
        fallback_extremity=fallback_extremity,
        request={'datetime': str_to_time_stamp('20170621T174600')},
    )
    assert response.status_code == 200
    assert response.response_type == response_pb2.ITINERARY_FOUND
    assert len(response.journeys) == 1
    assert response.journeys[0].duration == 588
    assert len(response.journeys[0].sections) == 1
    section = response.journeys[0].sections[0]
    assert section.type == response_pb2.STREET_NETWORK
    assert section.length == 4012
    assert section.duration == 588
    assert section.destination == destination
    assert section.origin == origin
    assert section.begin_date_time == str_to_time_stamp('20161010T152000')
    assert section.end_date_time == section.begin_date_time + section.duration
コード例 #2
0
def create_journey_with_pt_and_crowfly():
    journey = response_pb2.Journey()
    journey.departure_date_time = str_to_time_stamp("20180618T060500")
    journey.duration = 0
    journey.nb_transfers = 1

    add_whole_pt_section(journey, journey.departure_date_time)

    # Car crow_fly
    origin = make_pt_object(type_pb2.ADDRESS, 0.0, 0.0, "Chez tonton")
    destination = make_pt_object(type_pb2.ADDRESS, 1.0, 1.0, "Chez tata")
    add_section(
        journey,
        origin,
        destination,
        5 * 60,
        journey.sections[-1].end_date_time,
        response_pb2.CROW_FLY,
        response_pb2.Car,
        None,
    )

    journey.arrival_date_time = journey.sections[-1].end_date_time

    assert len(journey.sections) == 5
    assert journey.duration == 6600
    assert journey.arrival_date_time == journey.departure_date_time + journey.duration

    return journey
コード例 #3
0
def test_matrix(valid_here_matrix):
    instance = MagicMock()
    instance.walking_speed = 1.12
    here = Here(instance=instance,
                service_base_url='bob.com',
                app_id='toto',
                app_code='tata')
    origin = make_pt_object(type_pb2.ADDRESS, 2.439938, 48.572841)
    destination = make_pt_object(type_pb2.ADDRESS, 2.440548, 48.57307)
    with requests_mock.Mocker() as req:
        req.get(requests_mock.ANY, json=valid_here_matrix, status_code=200)
        response = here.get_street_network_routing_matrix(
            [origin],
            [destination, destination, destination],
            mode='walking',
            max_duration=42,
            request={'datetime': str_to_time_stamp('20170621T174600')},
        )
        assert response.rows[0].routing_response[0].duration == 440
        assert response.rows[0].routing_response[
            0].routing_status == response_pb2.reached
        assert response.rows[0].routing_response[1].duration == -1
        assert response.rows[0].routing_response[
            1].routing_status == response_pb2.unreached
        assert response.rows[0].routing_response[2].duration == 701
        assert response.rows[0].routing_response[
            2].routing_status == response_pb2.reached
コード例 #4
0
ファイル: helper_classes_test.py プロジェクト: Xzya/navitia
def extend_journey_for_build_to_test():
    # create a journey with 4 sections having PUBLIC_TRANSPORT at the begining and at the end
    pt_journey = create_journeys_with_pt()

    fallback_extremity = PeriodExtremity(pt_journey.arrival_date_time, True)

    # create a response having on single section CROW_FLY journey
    cf_origin = make_pt_object(type_pb2.STOP_POINT, 4.0, 4.0,
                               "stop_point_4_bis")
    cf_destination = make_pt_object(type_pb2.ADDRESS, 5.0, 5.0, "address_1")
    response = create_response_with_crow_fly(start_date="20180618T075000",
                                             end_date="20180618T075500",
                                             origin=cf_origin,
                                             destination=cf_destination)
    _extend_journey(pt_journey, response, fallback_extremity)

    pt_journey.sections.sort(SectionSorter())
    assert len(pt_journey.sections) == 5

    # We should have CROW_FLY section at the end of last section PUBLIC_TRANSPORT
    crowfly_section = pt_journey.sections[-1]
    pt_section = pt_journey.sections[-2]
    assert crowfly_section.type == response_pb2.CROW_FLY
    assert pt_section.type == response_pb2.PUBLIC_TRANSPORT

    # We should have the same object used for the last pt_section.destination and crowfly_section.origin
    assert crowfly_section.origin == pt_section.destination
    assert crowfly_section.origin.uri == "stop_point_4"
コード例 #5
0
ファイル: helper_classes_test.py プロジェクト: Xzya/navitia
def extend_journey_for_build_from_test():
    # create a journey with 4 sections having PUBLIC_TRANSPORT at the begining and at the end
    pt_journey = create_journeys_with_pt()

    fallback_extremity = PeriodExtremity(pt_journey.departure_date_time, False)

    # create a response having on single section CROW_FLY journey
    cf_origin = make_pt_object(type_pb2.ADDRESS, 1.0, 1.0, "address_1")
    cf_destination = make_pt_object(type_pb2.STOP_POINT, 2.0, 2.0,
                                    "stop_point_1_bis")
    response = create_response_with_crow_fly(start_date="20180618T060000",
                                             end_date="20180618T060500",
                                             origin=cf_origin,
                                             destination=cf_destination)

    _extend_journey(pt_journey, response, fallback_extremity)

    pt_journey.sections.sort(SectionSorter())
    assert len(pt_journey.sections) == 5

    # We should have CROW_FLY section at the begining of the journey following by a section PUBLIC_TRANSPORT
    crowfly_section = pt_journey.sections[0]
    pt_section = pt_journey.sections[1]
    assert crowfly_section.type == response_pb2.CROW_FLY
    assert pt_section.type == response_pb2.PUBLIC_TRANSPORT

    # We should have the same object used for crowfly_section.destination and pt_section.origin
    assert crowfly_section.destination == pt_section.origin
    assert crowfly_section.destination.uri == "stop_point_1"
コード例 #6
0
def test_update_fallback_sections_ending_fallback():
    journey = create_journey_with_pt_and_crowfly()
    origin = make_pt_object(type_pb2.ADDRESS, 9.0, 9.0, "Not Home")
    destination = make_pt_object(type_pb2.ADDRESS, 12.0, 12.0, "Home")
    fallback_dp = create_car_journey_with_leave_parking("20180618T080500", origin, destination)
    fallback_period_extremity = PeriodExtremity(str_to_time_stamp('20180618T080500'), True)
    fallback_type = StreetNetworkPathType.ENDING_FALLBACK
    access_point = make_pt_object(type_pb2.ACCESS_POINT, 9.0, 9.0, "access_point_toto")

    _update_fallback_sections(journey, fallback_dp, fallback_period_extremity, fallback_type, access_point)

    assert len(journey.sections) == 6
    assert journey.sections[4].origin.uri == "stop_point_4"
    assert journey.sections[4].origin == journey.sections[3].destination
    assert journey.sections[4].vias[0].uri == "access_point_toto"
コード例 #7
0
def test_update_fallback_sections_beginning_fallback():
    journey = create_journey_with_crowfly_and_pt()
    origin = make_pt_object(type_pb2.ADDRESS, 9.0, 9.0, "Home")
    destination = make_pt_object(type_pb2.ADDRESS, 12.0, 12.0, "Not Home")
    fallback_dp = create_car_journey_with_parking("20180618T050500", origin, destination)
    fallback_period_extremity = PeriodExtremity(str_to_time_stamp('20180618T050500'), False)
    fallback_type = StreetNetworkPathType.BEGINNING_FALLBACK
    access_point = make_pt_object(type_pb2.ACCESS_POINT, 9.0, 9.0, "access_point_toto")

    _update_fallback_sections(journey, fallback_dp, fallback_period_extremity, fallback_type, access_point)

    # Car + Park + 4 PT
    assert len(journey.sections) == 6
    assert journey.sections[1].destination.uri == "stop_point_1"
    assert journey.sections[1].destination == journey.sections[2].origin
    assert journey.sections[1].vias[0].uri == "access_point_toto"
コード例 #8
0
ファイル: here_test.py プロジェクト: xlqian/navitia
def test_post_matrix(valid_matrix_post_resp):
    instance = MagicMock()
    instance.walking_speed = 1.12
    here = Here(instance=instance, service_base_url='bob.com', apiKey='toto')
    origin = make_pt_object(type_pb2.ADDRESS, 2.439938, 48.572841)
    destination = make_pt_object(type_pb2.ADDRESS, 2.440548, 48.57307)
    with requests_mock.Mocker() as req:
        req.post(requests_mock.ANY,
                 json=valid_matrix_post_resp,
                 status_code=202)
        post_resp = here.post_matrix_request(
            [origin],
            [destination, destination, destination],
            request={'datetime': str_to_time_stamp('20170621T174600')},
        )
        assert post_resp['status'] == 'accepted'
        assert post_resp['matrixId'] == 'ca6631e0-6e2a-48cd-a359-f3a4f21d0e54'
コード例 #9
0
def test_matrix_timeout():
    instance = MagicMock()
    instance.walking_speed = 1.12
    here = Here(instance=instance,
                service_base_url='bob.com',
                app_id='toto',
                app_code='tata')
    origin = make_pt_object(type_pb2.ADDRESS, 2.439938, 48.572841)
    destination = make_pt_object(type_pb2.ADDRESS, 2.440548, 48.57307)
    with requests_mock.Mocker() as req:
        # a HERE timeout should raise a TechnicalError
        req.get(requests_mock.ANY, exc=requests.exceptions.Timeout)
        with pytest.raises(TechnicalError):
            here.get_street_network_routing_matrix(
                [origin], [destination, destination, destination],
                mode='walking',
                max_duration=42,
                request={'datetime': str_to_time_stamp('20170621T174600')})
コード例 #10
0
def create_journeys_with_pt():
    journey = response_pb2.Journey()
    journey.departure_date_time = str_to_time_stamp("20180618T060500")
    journey.arrival_date_time = str_to_time_stamp("20180618T075000")
    journey.duration = 105 * 60
    journey.nb_transfers = 1

    s = journey.sections.add()
    s.begin_date_time = journey.departure_date_time
    s.type = response_pb2.PUBLIC_TRANSPORT
    origin = make_pt_object(type_pb2.STOP_POINT, 2.0, 2.0, "stop_point_1")
    s.origin.CopyFrom(origin)
    destination = make_pt_object(type_pb2.STOP_POINT, 3.0, 3.0, "stop_point_2")
    s.destination.CopyFrom(destination)
    s.vehicle_journey.uri = "vj_toto"
    s.duration = 50 * 60
    s.end_date_time = s.begin_date_time + s.duration

    s = journey.sections.add()
    s.type = response_pb2.TRANSFER
    s.duration = 3 * 60
    s.begin_date_time = journey.sections[-2].end_date_time
    s.end_date_time = s.begin_date_time + s.duration

    s = journey.sections.add()
    s.type = response_pb2.WAITING
    s.duration = 2 * 60
    s.begin_date_time = journey.sections[-2].end_date_time
    s.end_date_time = s.begin_date_time + s.duration

    s = journey.sections.add()
    s.type = response_pb2.PUBLIC_TRANSPORT
    s.origin.uri = "stop_point_3"
    s.destination.uri = "stop_point_4"
    s.duration = 50 * 60
    s.begin_date_time = journey.sections[-2].end_date_time
    s.end_date_time = s.begin_date_time + s.duration
    return journey
コード例 #11
0
ファイル: here_test.py プロジェクト: xlqian/navitia
def test_get_matrix(valid_matrix_get_resp, valid_matrix_post_resp):
    instance = MagicMock()
    instance.walking_speed = 1.12
    here = Here(instance=instance, service_base_url='bob.com', apiKey='toto')
    origin = make_pt_object(type_pb2.ADDRESS, 2.439938, 48.572841)
    destination = make_pt_object(type_pb2.ADDRESS, 2.440548, 48.57307)
    with requests_mock.Mocker() as req:
        req.get(requests_mock.ANY, json=valid_matrix_get_resp, status_code=200)
        response = here.get_matrix_response(
            [origin], [destination, destination, destination, destination],
            post_resp=valid_matrix_post_resp)
        assert response.rows[0].routing_response[0].duration == 7146
        assert response.rows[0].routing_response[
            0].routing_status == response_pb2.reached
        assert response.rows[0].routing_response[1].duration == 7434
        assert response.rows[0].routing_response[
            1].routing_status == response_pb2.reached
        assert response.rows[0].routing_response[2].duration == 12927
        assert response.rows[0].routing_response[
            2].routing_status == response_pb2.reached
        assert response.rows[0].routing_response[3].duration == 14838
        assert response.rows[0].routing_response[
            3].routing_status == response_pb2.reached
コード例 #12
0
def add_whole_pt_section(journey, whole_section_begin_date_time):
    origin = make_pt_object(type_pb2.STOP_POINT, 2.0, 2.0, "stop_point_1")
    destination = make_pt_object(type_pb2.STOP_POINT, 3.0, 3.0, "stop_point_2")
    add_section(
        journey,
        origin,
        destination,
        50 * 60,
        whole_section_begin_date_time,
        response_pb2.PUBLIC_TRANSPORT,
        None,
        "vj_toto",
    )

    # Transfert
    add_section(journey, None, None, 3 * 60,
                journey.sections[-1].end_date_time, response_pb2.TRANSFER,
                None, None)

    # Waiting
    add_section(journey, None, None, 2 * 60,
                journey.sections[-1].end_date_time, response_pb2.WAITING, None,
                None)

    origin = make_pt_object(type_pb2.STOP_POINT, 6.0, 6.0, "stop_point_3")
    destination = make_pt_object(type_pb2.STOP_POINT, 7.0, 7.0, "stop_point_4")
    add_section(
        journey,
        origin,
        destination,
        50 * 60,
        journey.sections[-1].end_date_time,
        response_pb2.PUBLIC_TRANSPORT,
        None,
        "vj_tata",
    )
コード例 #13
0
ファイル: here_test.py プロジェクト: xlqian/navitia
def here_basic_routing_test(valid_here_routing_response):
    origin = make_pt_object(type_pb2.POI, 2.439938, 48.572841)
    destination = make_pt_object(type_pb2.STOP_AREA, 2.440548, 48.57307)

    # for a beginning fallback
    fallback_extremity = PeriodExtremity(str_to_time_stamp('20161010T152000'),
                                         True)
    response = Here._read_response(
        response=valid_here_routing_response,
        mode='walking',
        origin=origin,
        destination=destination,
        fallback_extremity=fallback_extremity,
        request={'datetime': str_to_time_stamp('20161010T152000')},
        direct_path_type=StreetNetworkPathType.BEGINNING_FALLBACK,
    )
    assert response.status_code == 200
    assert response.response_type == response_pb2.ITINERARY_FOUND
    assert len(response.journeys) == 1
    assert response.journeys[0].duration == 1468
    assert len(response.journeys[0].sections) == 1
    section = response.journeys[0].sections[0]
    assert section.type == response_pb2.STREET_NETWORK
    assert section.length == 21919
    assert section.duration == 1468
    assert section.destination == destination
    assert section.origin == origin
    assert section.begin_date_time == str_to_time_stamp('20161010T152000')
    assert section.end_date_time == section.begin_date_time + section.duration
    assert section.base_begin_date_time == str_to_time_stamp(
        '20161010T152000') + (1468 - 1344)
    assert section.base_end_date_time == section.begin_date_time + section.duration
    # dynamic_speed
    dynamic_speeds = section.street_network.dynamic_speeds
    assert len(dynamic_speeds) == 6
    first_ds = dynamic_speeds[0]
    assert round(first_ds.base_speed, 2) == 13.89
    assert round(first_ds.traffic_speed, 2) == 11.94
    assert first_ds.geojson_offset == 0
    last_ds = dynamic_speeds[5]
    assert round(last_ds.base_speed, 2) == 13.89
    assert round(last_ds.traffic_speed, 2) == 13.89
    assert last_ds.geojson_offset == 769

    # for a direct path and clockiwe == True
    response = Here._read_response(
        response=valid_here_routing_response,
        mode='walking',
        origin=origin,
        destination=destination,
        fallback_extremity=fallback_extremity,
        request={'datetime': str_to_time_stamp('20161010T152000')},
        direct_path_type=StreetNetworkPathType.DIRECT,
    )
    assert response.status_code == 200
    assert response.response_type == response_pb2.ITINERARY_FOUND
    assert len(response.journeys) == 1
    assert len(response.journeys[0].sections) == 1
    section = response.journeys[0].sections[0]
    assert section.begin_date_time == str_to_time_stamp('20161010T152000')
    assert section.end_date_time == section.begin_date_time + section.duration
    assert section.base_begin_date_time == str_to_time_stamp(
        '20161010T152000') + (1468 - 1344)
    assert section.base_end_date_time == section.begin_date_time + section.duration

    # for a ending fallback
    fallback_extremity = PeriodExtremity(str_to_time_stamp('20161010T152000'),
                                         True)
    response = Here._read_response(
        response=valid_here_routing_response,
        mode='walking',
        origin=origin,
        destination=destination,
        fallback_extremity=fallback_extremity,
        request={'datetime': str_to_time_stamp('20161010T152000')},
        direct_path_type=StreetNetworkPathType.ENDING_FALLBACK,
    )
    assert response.status_code == 200
    assert response.response_type == response_pb2.ITINERARY_FOUND
    assert len(response.journeys) == 1
    section = response.journeys[0].sections[0]
    assert section.begin_date_time == str_to_time_stamp(
        '20161010T152000') - section.duration
    assert section.end_date_time == str_to_time_stamp('20161010T152000')
    assert section.base_begin_date_time == str_to_time_stamp(
        '20161010T152000') - section.duration
    assert section.base_end_date_time == section.end_date_time - (1468 - 1344)

    # for a direct path and clockiwe == False
    fallback_extremity = PeriodExtremity(str_to_time_stamp('20161010T152000'),
                                         False)
    response = Here._read_response(
        response=valid_here_routing_response,
        mode='walking',
        origin=origin,
        destination=destination,
        fallback_extremity=fallback_extremity,
        request={'datetime': str_to_time_stamp('20161010T152000')},
        direct_path_type=StreetNetworkPathType.DIRECT,
    )
    assert response.status_code == 200
    assert response.response_type == response_pb2.ITINERARY_FOUND
    assert len(response.journeys) == 1
    assert len(response.journeys[0].sections) == 1
    section = response.journeys[0].sections[0]
    assert section.end_date_time == str_to_time_stamp('20161010T152000')
    assert section.begin_date_time == section.end_date_time - section.duration
    assert section.base_end_date_time == section.end_date_time
    assert section.base_begin_date_time == section.base_end_date_time - section.duration + (
        1468 - 1344)

    # for a beginning fallback and clockiwe == False
    fallback_extremity = PeriodExtremity(str_to_time_stamp('20161010T152000'),
                                         False)
    response = Here._read_response(
        response=valid_here_routing_response,
        mode='walking',
        origin=origin,
        destination=destination,
        fallback_extremity=fallback_extremity,
        request={'datetime': str_to_time_stamp('20161010T152000')},
        direct_path_type=StreetNetworkPathType.BEGINNING_FALLBACK,
    )
    assert response.status_code == 200
    assert response.response_type == response_pb2.ITINERARY_FOUND
    assert len(response.journeys) == 1
    assert len(response.journeys[0].sections) == 1
    section = response.journeys[0].sections[0]
    assert section.end_date_time == str_to_time_stamp('20161010T152000')
    assert section.begin_date_time == section.end_date_time - section.duration
    assert section.base_end_date_time == section.end_date_time
    assert section.base_begin_date_time == section.base_end_date_time - section.duration + (
        1468 - 1344)