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], [comfort_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 = get_ASAP_journey(resp.journeys, req) if best is not None: best.type = "best"
def get_best_pt_journey_connections(journeys, request): """ Returns the nb of connection of the best pt_journey Returns None if journeys empty """ if not journeys: return None best = get_ASAP_journey((j for j in journeys if 'non_pt' not in j.tags), request) return get_nb_connections(best) if best else None