Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

potentially wrong handling of GTFS Time values #7

Closed
derhuerst opened this issue Dec 7, 2021 · 1 comment
Closed

potentially wrong handling of GTFS Time values #7

derhuerst opened this issue Dec 7, 2021 · 1 comment

Comments

@derhuerst
Copy link

GTFS Time is not defined relative to midnight, but relative to noon - 12h. While that makes "writing" GTFS feeds easier, it makes processing a lot harder.

Expected functionality

As explained in my note about GTFS Time values, with the Europe/Berlin time zone (+1h standard time to +2 DST shift occurs at 2021-03-28T02:00+01:00), I expect

  • the departure_time of 00:30 of a trip running on 2021-03-28 to happen at 1616884200/2021-03-28T00:30+02:00, not at 1616887800/2021-03-28T00:30+01:00;
  • the departure_time of 06:30 of a trip running on 2021-03-28 to happen at 1616905800/2021-03-28T06:30+02:00, not at 1616909400/2021-03-28T06:30+01:00.

Describe the bug

I'm not familiar with this code base (just a random stranger dropping by to poke around 🙈), but it seems that combine_gtfs_feeds is affected by this problem on those days that the DST <-> standard time switch occurs on.

I'm not entirely sure how that actually manifests in combine_gtfs_feeds' output, but I assume that wrong headway-based stop_times will be calculated.

I tried to find some places in the code base:

  • def convert_to_seconds(value):
    """
    Converts hh:mm:ss format to number
    of seconds after midnight.
    """
    h, m, s = value.split(':')
    return int(h) * 3600 + int(m) * 60 + int(s)
  • stop_times_update['arrival_time_secs'] = stop_times_update[
    'arrival_time'].apply(convert_to_seconds)
    stop_times_update['departure_time_secs'] = stop_times_update[
    'departure_time'].apply(convert_to_seconds)
    stop_times_update = stop_times_update.loc[
    stop_times_update.index.repeat(
    stop_times_update['total_trips'])].reset_index(drop=True)
    stop_times_update['counter'] = stop_times_update.groupby(
    ['trip_id', 'stop_id']).cumcount()
    stop_times_update['departure_time_secs'] = stop_times_update[
    'departure_time_secs'] + (stop_times_update[
    'counter'] * stop_times_update['headway_secs'])
    stop_times_update['arrival_time_secs'] = stop_times_update[
    'arrival_time_secs'] + (stop_times_update[
    'counter'] * stop_times_update['headway_secs'])
    stop_times_update['departure_time'] = stop_times_update[
    'departure_time_secs'].apply(to_hhmmss)
    stop_times_update['arrival_time'] = stop_times_update[
    'arrival_time_secs'].apply(to_hhmmss)

related: google/transit#15

@stefancoe
Copy link
Contributor

This library does not make any changes to the schedule that is published in the input GTFS feeds. In other words, the output stop_times.txt reflects what is in the input GTFS feeds in the output, for the trips that are kept.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants