def qualifier_crowfly_test(): journeys = [] journey_standard = response_pb2.Journey() journey_standard.arrival_date_time = str_to_time_stamp('20140825T113224') journey_standard.duration = 2620 journey_standard.nb_transfers = 1 journey_standard.sections.add() journey_standard.sections.add() journey_standard.sections.add() journey_standard.sections[0].type = response_pb2.CROW_FLY journey_standard.sections[0].duration = 796 journey_standard.sections[-1].type = response_pb2.CROW_FLY journey_standard.sections[-1].duration = 864 journeys.append(journey_standard) journey_health = response_pb2.Journey() journey_health.arrival_date_time = str_to_time_stamp('20140825T114000') journey_health.duration = 3076 journey_health.nb_transfers = 1 journey_health.sections.add() journey_health.sections.add() journey_health.sections.add() journey_health.sections[0].type = response_pb2.CROW_FLY journey_health.sections[0].duration = 796 journey_health.sections[-1].type = response_pb2.CROW_FLY journey_health.sections[-1].duration = 0 journeys.append(journey_health) qualifier.qualifier_one(journeys, "departure") eq_(journey_standard.type, "rapid") # the standard should be the fastest eq_(journey_health.type, "less_fallback_walk")
def test_heavy_journey_walking(): """ we don't filter any journey with walking """ request = {'_min_bike': 10, '_min_car': 20} journey = response_pb2.Journey() journey.sections.add() journey.sections[-1].type = response_pb2.STREET_NETWORK journey.sections[-1].street_network.mode = response_pb2.Walking journey.sections[-1].duration = 5 journey_filter._filter_too_short_heavy_journeys([journey], request) assert 'to_delete' not in journey.tags
def remove_extra_journeys_more_with_walking_first_test(): j1 = response_pb2.Journey() j1.type = 'non_pt_walk' journeys = [j1, get_bss_bss_journey(), get_bike_car_journey(), get_bss_bike_journey()] saved_journeys = deepcopy(journeys) scenario = destineo.Scenario() scenario._remove_extra_journeys(journeys, None, clockwise=True, timezone='UTC') eq_(len(journeys), 4) scenario._remove_extra_journeys(journeys, 2, clockwise=True, timezone='UTC') eq_(len(journeys), 3) eq_(journeys[0], j1) eq_(journeys[1], saved_journeys[1]) eq_(journeys[2], saved_journeys[2])
def pt_duration_walking_test(): journey = response_pb2.Journey() section = journey.sections.add() section.type = response_pb2.STREET_NETWORK section.street_network.mode = response_pb2.Walking section.duration = 60 section = journey.sections.add() section.type = response_pb2.PUBLIC_TRANSPORT section.duration = 80 section = journey.sections.add() section.type = response_pb2.STREET_NETWORK section.street_network.mode = response_pb2.Walking section.duration = 60 assert pt_duration(journey) == 80
def test_heavy_journey_car(): """ the first time the duration of the car section is superior to the min value, so we keep the journey on the second test the duration is inferior to the min, so we delete the journey """ journey = response_pb2.Journey() journey.sections.add() journey.sections[-1].type = response_pb2.STREET_NETWORK journey.sections[-1].street_network.mode = response_pb2.Car journey.durations.car = journey.sections[-1].duration = 25 f = jf.FilterTooShortHeavyJourneys(min_bike=10, min_car=20) assert f.filter_func(journey) journey.durations.car = journey.sections[-1].duration = 15 f = jf.FilterTooShortHeavyJourneys(min_bike=10, min_car=20) assert not f.filter_func(journey)
def qualifier_one_direct_test(): journeys = [] journey_direct = response_pb2.Journey() journey_direct.arrival_date_time = str_to_time_stamp("20131107T151200") journey_direct.duration = 25 * 60 journey_direct.nb_transfers = 0 journey_direct.sections.add() journey_direct.sections.add() journey_direct.sections[0].type = response_pb2.STREET_NETWORK journey_direct.sections[0].duration = 2 * 60 journey_direct.sections[1].type = response_pb2.STREET_NETWORK journey_direct.sections[1].duration = 4 * 60 journeys.append(journey_direct) qualifier.qualifier_one(journeys, "departure") assert ("non_pt" in journey_direct.type)
def remove_extra_journeys_similar_journey_latest_dep(): j1 = response_pb2.Journey() j1.type = 'non_pt_walk' j_eq1 = generate_journey(['bob']) j_eq1.type = 'bob' # used as an id in the test j_eq1.departure_date_time = 1425989999 # leave after, it's better j_eq1.arrival_date_time = 1425990000 j_eq2 = generate_journey(['bob']) j_eq2.type = 'bobette' j_eq2.departure_date_time = 1425984855 j_eq2.arrival_date_time = 1425990000 journeys = [j1, j_eq1, j_eq2] scenario = destineo.Scenario() scenario._remove_extra_journeys(journeys, None, clockwise=True, timezone='UTC') eq_(len(journeys), 2) eq_(journeys[1].type, 'bob')
def test_heavy_journey_ridesharing(): """ the first time the duration of the ridesharing section is superior to the min value, so we keep the journey on the second test the duration is inferior to the min, so we delete the journey """ journey = response_pb2.Journey() journey.sections.add() journey.sections[-1].type = response_pb2.STREET_NETWORK journey.sections[-1].street_network.mode = response_pb2.Ridesharing journey.durations.ridesharing = journey.sections[-1].duration = 25 # Ridesharing duration is superior to min_ridesharing value so we have ridesharing section f = jf.FilterTooShortHeavyJourneys(min_ridesharing=20) assert f.filter_func(journey) # Ridesharing duration is inferior to min_ridesharing value # In this case we have reject ridesharing section journey.durations.ridesharing = journey.sections[-1].duration = 15 f = jf.FilterTooShortHeavyJourneys(min_ridesharing=20) assert not f.filter_func(journey)
def test_activate_deactivate_min_taxi(): """ A B C D *................*============================*.............* A: origin D: Destination A->B : taxi B->C : public transport C->D : taxi """ # case 1: request with duration_taxi greater than min_taxi journey = response_pb2.Journey() journey.sections.add() journey.sections[-1].type = response_pb2.STREET_NETWORK journey.sections[-1].street_network.mode = response_pb2.Taxi journey.sections[-1].duration = 5 journey.sections.add() journey.sections[-1].type = response_pb2.PUBLIC_TRANSPORT journey.sections[-1].street_network.mode = response_pb2.PUBLIC_TRANSPORT journey.sections[-1].duration = 35 journey.sections.add() journey.sections[-1].type = response_pb2.STREET_NETWORK journey.sections[-1].street_network.mode = response_pb2.Taxi journey.sections[-1].duration = 7 journey.durations.taxi = 12 f = jf.FilterTooShortHeavyJourneys(min_taxi=10) assert f.filter_func(journey) # case 2: request with duration_taxi less than min_taxi journey.sections[-1].duration = 2 journey.durations.taxi = 7 f = jf.FilterTooShortHeavyJourneys(min_taxi=10) assert not f.filter_func(journey)
def tranfers_cri_test(): journeys = [] dates = [ "20131107T100000", "20131107T150000", "20131107T050000", "20131107T100000", "20131107T150000", "20131107T050000" ] transfers = [4, 3, 8, 1, 1, 2] for i in range(6): journey = response_pb2.Journey() journey.nb_transfers = transfers[i] journey.arrival_date_time = str_to_time_stamp(dates[i]) journeys.append(journey) best = qualifier.min_from_criteria( journeys, [qualifier.transfers_crit, qualifier.arrival_crit]) #the transfert criterion is first, and then if 2 journeys have #the same nb_transfers, we compare the dates eq_(best.nb_transfers, 1) eq_(best.arrival_date_time, str_to_time_stamp("20131107T100000"))
def qualifier_two_test(): journeys = [] journey_standard = response_pb2.Journey() journey_standard.type = "none" journey_standard.arrival_date_time = str_to_time_stamp("20131107T150000") journey_standard.duration = 60 * 60 journey_standard.nb_transfers = 3 journey_standard.sections.add() journey_standard.sections.add() journey_standard.sections.add() journey_standard.sections.add() journey_standard.sections[0].type = response_pb2.STREET_NETWORK journey_standard.sections[0].duration = 10 * 60 journey_standard.sections[-1].type = response_pb2.STREET_NETWORK journey_standard.sections[-1].duration = 10 * 60 journeys.append(journey_standard) journey_rapid = response_pb2.Journey() journey_rapid.arrival_date_time = str_to_time_stamp("20131107T150500") journey_rapid.duration = 62 * 60 journey_rapid.nb_transfers = 2 journey_rapid.sections.add() journey_rapid.sections.add() journey_rapid.sections.add() journey_rapid.sections[0].type = response_pb2.STREET_NETWORK journey_rapid.sections[0].duration = 10 * 60 journey_rapid.sections[-1].type = response_pb2.STREET_NETWORK journey_rapid.sections[-1].duration = 10 * 60 journeys.append(journey_rapid) journey_health = response_pb2.Journey() journey_health.arrival_date_time = str_to_time_stamp("20131107T151000") journey_health.duration = 70 * 60 journey_health.nb_transfers = 1 journey_health.sections.add() journey_health.sections.add() journey_health.sections.add() journey_health.sections[0].type = response_pb2.STREET_NETWORK journey_health.sections[0].duration = 15 * 60 journey_health.sections[1].type = response_pb2.TRANSFER journey_health.sections[1].duration = 10 * 60 journey_health.sections[-1].type = response_pb2.STREET_NETWORK journey_health.sections[-1].duration = 10 * 60 journeys.append(journey_health) journey_confort = response_pb2.Journey() journey_confort.arrival_date_time = str_to_time_stamp("20131107T152000") journey_confort.duration = 80 * 60 journey_confort.nb_transfers = 1 journey_confort.sections.add() journey_confort.sections.add() journey_confort.sections.add() journey_confort.sections[0].type = response_pb2.STREET_NETWORK journey_confort.sections[0].duration = 5 * 60 journey_confort.sections[-1].type = response_pb2.STREET_NETWORK journey_confort.sections[-1].duration = 5 * 60 journeys.append(journey_confort) qualifier.qualifier_one(journeys, "departure") eq_(journey_standard.type, "fastest") # the standard should be the fastest eq_(journey_rapid.type, "rapid")