Beispiel #1
0
def find_max_duration__counterclockwise_test():
    resp_builder = ResponseBuilder()\
        .journey(sections=[
            {'mode': 'Walking', 'duration': 240},
            {'type': 'PT', 'duration': 300},
            {'mode': 'Walking', 'duration': 120},
        ], type='best', arrival='T1231')\
        .journey(uri='rapid', sections=[
            {'mode': 'Walking', 'duration': 120},
            {'type': 'PT', 'duration': 300},
            {'mode': 'Walking', 'duration': 120},
        ], type='rapid', arrival='T1501')\
        .journey(uri='non pt', sections=[
            {'mode': 'Walking', 'duration': 130},
        ], type='non_pt_walk', arrival='T1534')

    response = resp_builder.response

    scenario = default.Scenario()
    assert scenario._find_max_duration(response.journeys, Instance(),
                                       False) == 580
    scenario._delete_too_long_journey(response, Instance(), False)
    assert len(response.journeys) == 2
    assert response.journeys[0] == resp_builder.get_journey('rapid')
    assert response.journeys[1] == resp_builder.get_journey('non pt')
Beispiel #2
0
def previous_journey_test():
    """ In the default scenario, the previous journey is one minute before the first 'rapid' if we get one"""
    builder = ResponseBuilder(default_date=datetime.date(2016, 10, 10))\
        .journey(type='rapid', departure='T1200', arrival='T1500')\
        .journey(type='fastest', departure='T1100', arrival='T1700')\
        .journey(type='non_pt_walk', departure='T1000', arrival='T1534')\
        .journey(type='car', departure='T1300', arrival='T1534')

    scenario = default.Scenario()
    eq_(scenario.previous_journey_datetime(builder.get_journeys()), str_to_time_stamp('20161010T145900'))
Beispiel #3
0
def previous_journey_test_no_rapid():
    """ In the default scenario, if we don't get a rapid,
    the previous journey is one minute before the tardiest journey
    """
    builder = ResponseBuilder(default_date=datetime.date(2016, 10, 10))\
        .journey(type='fastest', departure='T1100', arrival='T1700')\
        .journey(type='non_pt_walk', departure='T1000', arrival='T1534')\
        .journey(type='car', departure='T2000', arrival='T1534')

    scenario = default.Scenario()
    eq_(scenario.previous_journey_datetime(builder.get_journeys()), str_to_time_stamp('20161010T165900'))
Beispiel #4
0
def next_journey_test():
    """ In the default scenario, the next journey is one minute after the first 'rapid' if we get one"""
    builder = ResponseBuilder(default_date=datetime.date(2016, 10, 10))\
        .journey(type='rapid', departure='T1200', arrival='T1500')\
        .journey(type='fastest', departure='T1100', arrival='T1700')\
        .journey(type='non_pt_walk', departure='T1000', arrival='T1534')\
        .journey(type='car', departure='T1300', arrival='T1534')

    scenario = default.Scenario()
    assert scenario.next_journey_datetime(
        builder.get_journeys(),
        clockwise=True) == str_to_time_stamp('20161010T120100')
Beispiel #5
0
def has_bike_and_tc_crowfly_test():
    resp_builder = ResponseBuilder().journey(sections=[
        {'mode': 'Bike', 'type': 'CROW_FLY'},
        {'type': 'PT'},
        {'mode': 'Walking'},
    ])
    assert destineo.has_bike_and_tc(resp_builder.response.journeys[0])
Beispiel #6
0
def has_bike_and_tc_bss_test():
    resp_builder = ResponseBuilder().journey(sections=[
        {'mode': 'Walking'}, {'type': 'BSS_RENT'}, {'mode': 'Bike'}, {'type': 'BSS_PUT_BACK'},
        {'type': 'PT'},
        {'mode': 'Walking'},
    ])
    assert not destineo.has_bike_and_tc(resp_builder.response.journeys[0])
Beispiel #7
0
def sort_destineo_test():
    resp_builder = ResponseBuilder()\
        .journey(uri='journey_tc3', sections=[
            {'mode': 'Walking'}, {'type': 'PT'}, {'mode': 'Walking'},
        ], departure='T1230')\
        .journey(uri='journey_tc1', sections=[
            {'mode': 'Walking'}, {'type': 'PT'}, {'mode': 'Walking'},
        ], departure='T1100')\
        .journey(uri='journey_bike', sections=[
            #{'mode': 'Bike'}
        ], type='non_pt_bike', departure='T1100')\
        .journey(uri='journey_bss', sections=[
            {'mode': 'Walking'},
            {'type': 'BSS_RENT'}, {'mode': 'Bike'}, {'type': 'BSS_PUT_BACK'},
            {'mode': 'Walking'}
        ], type='non_pt_bss', departure='T1100')\
        .journey(uri='journey_walk', sections=[
            #{'mode': 'Walking'},
        ], type='non_pt_walk', departure='T1100')\
        .journey(uri='journey_tc2', sections=[
            {'mode': 'Walking'}, {'type': 'PT'}, {'mode': 'Walking'},
        ], departure='T1200')\
        .journey(uri='journey_bss_and_tc', sections=[
            {'mode': 'Walking'}, {'type': 'BSS_RENT'}, {'mode': 'Bike'}, {'type': 'BSS_PUT_BACK'},
            {'type': 'PT'},
            {'mode': 'Walking'},
        ], departure='T1200')\
        .journey(uri='journey_bike_and_tc', sections=[
            {'mode': 'Bike'},
            {'type': 'PT'},
            {'mode': 'Walking'},
        ], departure='T1200')\
        .journey(uri='journey_car_and_tc', sections=[
            {'mode': 'Car'},
            {'type': 'PT'},
            {'mode': 'Walking'},
        ], departure='T1200')\

    response = resp_builder.response
    scenario = destineo.Scenario()
    scenario._custom_sort_journeys(response,
                                   clockwise=True,
                                   timezone='Africa/Abidjan')
    assert response.journeys[0] == resp_builder.get_journey('journey_tc1')
    assert response.journeys[1] == resp_builder.get_journey('journey_tc2')
    assert response.journeys[2] == resp_builder.get_journey('journey_tc3')
    assert response.journeys[3] == resp_builder.get_journey('journey_bss')
    assert response.journeys[4] == resp_builder.get_journey(
        'journey_bss_and_tc')
    assert response.journeys[5] == resp_builder.get_journey(
        'journey_bike_and_tc')
    assert response.journeys[6] == resp_builder.get_journey(
        'journey_car_and_tc')
    assert response.journeys[7] == resp_builder.get_journey('journey_walk')
    assert response.journeys[8] == resp_builder.get_journey('journey_bike')
Beispiel #8
0
def has_bike_and_tc_simple_test():
    resp_builder = ResponseBuilder().journey(sections=[{
        'mode': 'Walking'
    }, {
        'type': 'PT'
    }, {
        'mode': 'Walking'
    }])
    assert not destineo.has_bike_and_tc(resp_builder.response.journeys[0])
Beispiel #9
0
def is_pure_tc_simple_test():
    resp_builder = ResponseBuilder().journey(sections=[{
        'mode': 'Walking'
    }, {
        'type': 'PT'
    }, {
        'mode': 'Walking'
    }])
    assert destineo.is_pure_tc(resp_builder.response.journeys[0])
Beispiel #10
0
def is_pure_tc_crowfly_test():
    resp_builder = ResponseBuilder().journey(sections=[
        {
            'type': 'CROW_FLY',
            'mode': 'Walking'
        },
        {
            'type': 'PT'
        },
        {
            'mode': 'Walking'
        },
    ])
    assert destineo.is_pure_tc(resp_builder.response.journeys[0])
Beispiel #11
0
def find_max_duration_clockwise_no_walk_test():
    """
    we don't have a journey with walking so max_duration is None, and we keep all journeys
    """
    resp_builder = (ResponseBuilder().journey(
        uri='best',
        sections=[
            {
                'mode': 'Bike',
                'duration': 240
            },
            {
                'type': 'PT',
                'duration': 300
            },
            {
                'mode': 'Walking',
                'duration': 120
            },
        ],
        type='best',
        arrival='T1534',
    ).journey(
        uri='rapid',
        sections=[
            {
                'mode': 'Walking',
                'duration': 120
            },
            {
                'type': 'PT',
                'duration': 300
            },
            {
                'mode': 'Bike',
                'duration': 120
            },
        ],
        type='rapid',
        arrival='T1534',
    ))
    response = resp_builder.response

    scenario = default.Scenario()
    assert scenario._find_max_duration(response.journeys, Instance(),
                                       True) == None
    scenario._delete_too_long_journey(response, Instance(), True)
    assert len(response.journeys) == 2
    assert response.journeys[0] == resp_builder.get_journey('best')
    assert response.journeys[1] == resp_builder.get_journey('rapid')
Beispiel #12
0
def find_max_duration_clockwise_test_no_walk():
    """
    we don't have a journey with walking so max_duration is None, and we keep all journeys
    """
    resp_builder = ResponseBuilder()\
        .journey(uri='best', sections=[
            {'mode': 'Bike', 'duration': 240},
            {'type': 'PT', 'duration': 300},
            {'mode': 'Walking', 'duration': 120},
        ], type='best', arrival='T1534')\
        .journey(uri='rapid', sections=[
            {'mode': 'Walking', 'duration': 120},
            {'type': 'PT', 'duration': 300},
            {'mode': 'Bike', 'duration': 120},
        ], type='rapid', arrival='T1534')
    response = resp_builder.response

    scenario = default.Scenario()
    eq_(scenario._find_max_duration(response.journeys, Instance(), True), None)
    scenario._delete_too_long_journey(response, Instance(), True)
    eq_(len(response.journeys), 2)
    eq_(response.journeys[0], resp_builder.get_journey('best'))
    eq_(response.journeys[1], resp_builder.get_journey('rapid'))
Beispiel #13
0
def find_max_duration_clockwise_test():
    resp_builder = ResponseBuilder()\
        .journey(sections=[
            {'mode': 'Walking', 'duration': 240},
            {'type': 'PT', 'duration': 300},
            {'mode': 'Walking', 'duration': 120},
        ], type='best', arrival='T1501')\
        .journey(uri='rapid', sections=[
            {'mode': 'Walking', 'duration': 120},
            {'type': 'PT', 'duration': 300},
            {'mode': 'Walking', 'duration': 120},
        ], type='rapid', arrival='T1501')\
        .journey(uri='non pt', sections=[
            {'mode': 'Walking', 'duration': 130},
        ], type='non_pt_walk', arrival='T1231')

    response = resp_builder.response

    scenario = default.Scenario()
    eq_(scenario._find_max_duration(response.journeys, Instance(), True), 580)
    scenario._delete_too_long_journey(response, Instance(), True)
    eq_(len(response.journeys), 2)
    eq_(response.journeys[0], resp_builder.get_journey('rapid'))
    eq_(response.journeys[1], resp_builder.get_journey('non pt'))
Beispiel #14
0
def next_journey_test_no_rapid_test():
    """ In the default scenario, if we don't get a rapid,
    the next journey is one minute after the earliest journey
    """
    builder = (ResponseBuilder(
        default_date=datetime.date(2016, 10, 10)).journey(
            type='fastest', departure='T1100',
            arrival='T1700').journey(type='non_pt_walk',
                                     departure='T1000',
                                     arrival='T1534').journey(
                                         type='car',
                                         departure='T2000',
                                         arrival='T1534'))

    scenario = default.Scenario()
    assert scenario.next_journey_datetime(
        builder.get_journeys(),
        clockwise=True) == str_to_time_stamp('20161010T100100')