Exemple #1
0
def type_journeys(resp, req):
    """
    Set the type of the journeys
    """
    best_crit = arrival_crit if req["clockwise"] else departure_crit
    # first, we want a type for every journey. Just pick "rapid" by default.
    for j in resp.journeys:
        j.type = "rapid"

    # Then, we want something like the old types
    trip_caracs = [
        # comfort tends to limit the number of transfers and fallback
        ("comfort", trip_carac([has_no_car], [transfers_crit, nonTC_crit, best_crit, duration_crit])),
        # for car we want at most one journey, the earliest one
        (
            "car",
            trip_carac(
                [has_car, has_pt],  # We don't want car only solution, we MUST have PT
                [best_crit, transfers_crit, nonTC_crit, duration_crit],
            ),
        ),
        # less_fallback tends to limit the fallback while walking
        (
            "less_fallback_walk",
            trip_carac([has_no_car, has_no_bike], [nonTC_crit, transfers_crit, duration_crit, best_crit]),
        ),
        # less_fallback tends to limit the fallback for biking and bss
        (
            "less_fallback_bike",
            trip_carac(
                [has_no_car, has_bike, has_no_bss], [nonTC_crit, transfers_crit, duration_crit, best_crit]
            ),
        ),
        # less_fallback tends to limit the fallback for biking and bss
        (
            "less_fallback_bss",
            trip_carac([has_no_car, has_bss], [nonTC_crit, transfers_crit, duration_crit, best_crit]),
        ),
        # the fastest is quite explicit
        ("fastest", trip_carac([has_no_car], [duration_crit, transfers_crit, nonTC_crit, best_crit])),
        # the non_pt journeys is the earliest journey without any public transport
        ("non_pt_walk", trip_carac([non_pt_journey, has_no_car, has_walk], [best_crit])),
        # the non_pt journey is the earliest journey without any public transport
        # only walking, biking or driving
        ("non_pt_bike", trip_carac([non_pt_journey, has_no_car, has_bike], [best_crit])),
        ("non_pt_bss", trip_carac([non_pt_journey, has_no_car, has_bss], [best_crit])),
        ("non_pt_car", trip_carac([non_pt_journey, has_car], [best_crit])),
    ]

    for name, carac in trip_caracs:
        sublist = list(filter(and_filters(carac.constraints), resp.journeys))
        best = min_from_criteria(sublist, carac.criteria)
        if best is not None:
            best.type = name

    # Finally, we want exactly one best, the ASAP one
    best = min_from_criteria(resp.journeys, [best_crit, duration_crit, transfers_crit, nonTC_crit])
    if best is not None:
        best.type = "best"
Exemple #2
0
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
    assert best.nb_transfers == 1
    assert best.arrival_date_time == str_to_time_stamp("20131107T100000")
    def check_next_datetime_link(dt, response, clockwise):
        if not response.get('journeys'):
            return
        """default next behaviour is 1s after the best or the soonest"""
        j_to_compare = min_from_criteria(generate_pt_journeys(response),
                                         new_default_pagination_journey_comparator(clockwise=clockwise))

        j_departure = get_valid_datetime(j_to_compare['departure_date_time'])
        eq_(j_departure + timedelta(seconds=1), dt)
    def check_previous_datetime_link(dt, response, clockwise):
        if not response.get('journeys'):
            return
        """default previous behaviour is 1s before the best or the latest """
        j_to_compare = min_from_criteria(
            generate_pt_journeys(response),
            new_default_pagination_journey_comparator(clockwise=clockwise))

        j_departure = get_valid_datetime(j_to_compare['arrival_date_time'])
        eq_(j_departure - timedelta(seconds=1), dt)
Exemple #5
0
 def __get_best_for_criteria(journeys, criteria):
     return min_from_criteria(filter(has_pt, journeys), [criteria, duration_crit, transfers_crit, nonTC_crit])