o2g/gtfs/gtfs_dummy.py
def _create_dummy_trip_stoptimes(trip_id, stops, first_service_time):
    """Create station stop times for each trip."""
    waiting = datetime.timedelta(seconds=30)
    arrival = first_service_time
    last_departure = first_service_time
    last_departure_hour = (arrival + waiting).hour
    last_stop = None

    departure_hour = None
    arrival_hour = None
    for stop_sequence, stop in enumerate(stops):

        # Avoid time travels
        arrival = last_departure + get_time_from_last_stop(last_stop, stop)
        departure = arrival + waiting

        # Cover the case when the arrival time falls into the next day
        if arrival.hour < last_departure_hour:
            diff = last_departure_hour
            arrival_hour = arrival.hour + diff
            departure_hour = departure.hour + diff
            last_departure_hour = departure.hour + diff
        else:
            arrival_hour = arrival.hour
            departure_hour = departure.hour
            last_departure_hour = departure.hour

        # Cover the case when adding waiting time to the arrival time
        # falls into the next day
        if departure.hour < arrival.hour:
            diff = last_departure_hour
            departure_hour = departure.hour + diff
            last_departure_hour = departure.hour + diff

        yield {'trip_id': trip_id,
               'arrival_time': '{:02}:{}'.format(
                   arrival_hour,
                   arrival.strftime('%M:%S')),
               'departure_time': '{:02}:{}'.format(
                   departure_hour,
                   departure.strftime('%M:%S')),
               'stop_id': stop.stop_id,
               'stop_sequence': stop_sequence}

        last_stop = stop
        last_departure = departure
def _create_dummy_trip_stoptimes(trip_id, stops, first_service_time):
    """Create station stop times for each trip."""
    waiting = datetime.timedelta(seconds=30)
    arrival = first_service_time
    last_departure = first_service_time
    last_departure_hour = (arrival + waiting).hour
    last_stop = None

    departure_hour = None
    arrival_hour = None
    for stop_sequence, stop in enumerate(stops):

        # Avoid time travels
        arrival = last_departure + get_time_from_last_stop(last_stop, stop)
        departure = arrival + waiting

        # Cover the case when the arrival time falls into the next day
        if arrival.hour < last_departure_hour:
            diff = last_departure_hour
            arrival_hour = arrival.hour + diff
            departure_hour = departure.hour + diff
            last_departure_hour = departure.hour + diff
        else:
            arrival_hour = arrival.hour
            departure_hour = departure.hour
            last_departure_hour = departure.hour

        # Cover the case when adding waiting time to the arrival time
        # falls into the next day
        if departure.hour < arrival.hour:
            diff = last_departure_hour
            departure_hour = departure.hour + diff
            last_departure_hour = departure.hour + diff

        yield {'trip_id': trip_id,
               'arrival_time': '{:02}:{}'.format(
                   arrival_hour,
                   arrival.strftime('%M:%S')),
               'departure_time': '{:02}:{}'.format(
                   departure_hour,
                   departure.strftime('%M:%S')),
               'stop_id': stop.stop_id,
               'stop_sequence': stop_sequence}

        last_stop = stop
        last_departure = departure
Create station stop times for each trip.