Beispiel #1
0
def build_mocked_response():
    response = response_pb2.Response()
    for jrny in JOURNEYS:
        arrival_time, jrny_type, sections_idx = jrny
        pb_j = response.journeys.add()
        pb_j.arrival_date_time = arrival_time
        # we remove the street network section
        pb_j.nb_transfers = len(sections_idx) - 1 - (1 in sections_idx) - (
            10 in sections_idx)
        if jrny_type:
            pb_j.type = jrny_type
        for idx in sections_idx:
            section_type, network_mode, line_uri = SECTIONS_CHOICES[idx]
            section = pb_j.sections.add()
            section.type = section_type
            if network_mode:
                section.street_network.mode = network_mode
            if line_uri:
                section.uris.line = line_uri

    new_default._tag_by_mode([response])
    new_default._tag_direct_path([response])
    new_default._tag_bike_in_pt([response])

    return response
Beispiel #2
0
def build_mocked_car_response():
    response = response_pb2.Response()
    sections = (
        (response_pb2.STREET_NETWORK, response_pb2.Walking, 'walking'),
        (response_pb2.STREET_NETWORK, response_pb2.Car, 'car'),
        (response_pb2.PUBLIC_TRANSPORT, None, 'uri_1'),
        (response_pb2.PUBLIC_TRANSPORT, None, 'uri_2'),
    )
    journeys = (
        # J1
        # 10 / 15 / 2015 @ 12:30pm (UTC)
        # this journey will be tagged 'walking'
        (1444905000, 'rapid', (0, 2, 0)),
        # J2
        # 10 / 15 / 2015 @ 12:30pm (UTC)
        # this journey will be tagged 'car'
        (1444905000, 'car', (1, 3, 2)),
    )
    for jrny in journeys:
        arrival_time, jrny_type, sections_idx = jrny
        pb_j = response.journeys.add()
        pb_j.arrival_date_time = arrival_time
        # we remove the street network section
        pb_j.nb_transfers = len(sections_idx) - 1 - (1 in sections_idx) - (
            10 in sections_idx)
        if jrny_type:
            pb_j.type = jrny_type
        for idx in sections_idx:
            section_type, network_mode, line_uri = sections[idx]
            section = pb_j.sections.add()
            section.type = section_type
            if network_mode:
                section.street_network.mode = network_mode
            if line_uri:
                section.uris.line = line_uri

    new_default._tag_by_mode([response])
    new_default._tag_direct_path([response])
    new_default._tag_bike_in_pt([response])

    return response
def tag_direct_path_test():
    response = response_pb2.Response()

    # test with one walk and one pt
    journey_walk = response.journeys.add()
    section = journey_walk.sections.add()
    section.type = response_pb2.STREET_NETWORK
    section.street_network.mode = response_pb2.Walking
    journey_bike = response.journeys.add()
    section = journey_bike.sections.add()
    section.type = response_pb2.STREET_NETWORK
    section.street_network.mode = response_pb2.Bike
    journey_pt = response.journeys.add()
    section = journey_pt.sections.add()
    section.type = response_pb2.PUBLIC_TRANSPORT
    new_default._tag_direct_path([response])
    assert 'non_pt_walking' in response.journeys[0].tags
    assert 'non_pt' in response.journeys[0].tags
    assert 'non_pt_bike' in response.journeys[1].tags
    assert 'non_pt' in response.journeys[1].tags
    assert not response.journeys[2].tags