Ejemplo n.º 1
0
def _filter_odt_journeys_counter_clockwise(journeys, debug):
    """
    eliminates a journey that uses On Demand Transport if there is a public transport journey
    that depart later
    """
    # let's find the latest departure time among public transport journeys
    latest_departure_pt_journey = portable_min(
        (j for j in journeys
         if _contains_pt_section(j) and not _contains_odt(j)),
        key=lambda j: -1 * j.departure_date_time,
    )

    # no pt journey found, so there is nothing to filter
    if latest_departure_pt_journey is None:
        return

    # let's mark as dead all odt journeys that depart before latest_departure_pt_journey
    for journey in journeys:
        if (_contains_odt(journey) and journey.departure_date_time <=
                latest_departure_pt_journey.departure_date_time):
            mark_as_dead(
                journey,
                debug,
                'odt_departs_before_{other}'.format(
                    other=latest_departure_pt_journey.internal_id),
            )
Ejemplo n.º 2
0
def _filter_odt_journeys_clockwise(journeys, debug):
    """
    eliminates a journey that uses On Demand Transport if there is a public transport journey
    that arrive earlier
    """
    # let's find the earliest arrival time among public transport journeys
    earliest_arrival_pt_journey = portable_min(
        (j for j in journeys
         if _contains_pt_section(j) and not _contains_odt(j)),
        key=lambda j: j.arrival_date_time,
    )

    # no pt journey found, so there is nothing to filter
    if earliest_arrival_pt_journey is None:
        return

    # let's mark as dead all odt journeys that arrives after earliest_arrival_pt_journey
    for journey in journeys:
        if _contains_odt(
                journey
        ) and journey.arrival_date_time >= earliest_arrival_pt_journey.arrival_date_time:
            mark_as_dead(
                journey,
                debug,
                'odt_arrives_after_{other}'.format(
                    other=earliest_arrival_pt_journey.internal_id),
            )
Ejemplo n.º 3
0
def get_min_waiting(journey):
    """
    Returns min waiting time in a journey
    """
    return portable_min(
        (s.duration
         for s in journey.sections if s.type == response_pb2.WAITING),
        default=0)
Ejemplo n.º 4
0
def get_min_connections(journeys):
    """
    Returns min connection count among journeys
    Returns None if journeys empty
    """
    if not journeys:
        return None

    return portable_min((get_nb_connections(j) for j in journeys if not to_be_deleted(j)), default=0)