UrbanAnalyst / gtfsrouter

Routing and analysis engine for GTFS (General Transit Feed Specification) data
https://urbananalyst.github.io/gtfsrouter/
81 stars 17 forks source link

Service's descriptions in Calendar_dates aren't taken into account #20

Closed Maxime2506 closed 4 years ago

Maxime2506 commented 4 years ago

Hello,

I'm working on a GTFS (RATP - subway in Paris, France) which doesn't define the weekly services by default in Calendar, but defines it day-by-day in Calendar_dates. The function filter_by_day is only looking at Calendar and stops with an error (no service selected)

. The other functions are calling filter_by_day and doesn't work either. Did I miss something?

Maxime

PS : GTFS elements and command

ratp$calendar

A tibble: 4,926 x 10

service_id monday tuesday wednesday thursday friday saturday sunday start_date end_date

1 1132941 0 0 0 0 0 0 0 2019-10-03 2019-12-31 2 12755436 0 0 0 0 0 0 0 2019-10-28 2019-10-28 3 12773209 0 0 0 0 0 0 0 2019-10-07 2019-12-30 4 12773210 0 0 0 0 0 0 0 2019-11-02 2019-11-11 5 12773214 0 0 0 0 0 0 0 2019-10-22 2019-12-27 6 12773215 0 0 0 0 0 0 0 2019-12-31 2019-12-31 7 12773216 0 0 0 0 0 0 0 2019-10-04 2019-12-20 8 12773217 0 0 0 0 0 0 0 2019-10-06 2019-12-29 9 12773219 0 0 0 0 0 0 0 2019-10-05 2019-12-21 10 12773221 0 0 0 0 0 0 0 2020-01-01 2020-01-01 ratp$calendar_dates # A tibble: 60,420 x 3 service_id date exception_type 1 1132941 2019-10-03 1 2 1132941 2019-10-04 1 3 1132941 2019-10-07 1 4 1132941 2019-10-08 1 5 1132941 2019-10-09 1 6 1132941 2019-10-10 1 7 1132941 2019-10-11 1 8 1132941 2019-10-14 1 9 1132941 2019-10-15 1 10 1132941 2019-10-16 1 console : >gtfs_timetable(ratp, day = 4) Error in !attr(gtfs_cp, "filtered") : invalid argument type >attr (ratp, "filtered") <- FALSE >gtfs_timetable(ratp, day = 4) Error in get(i) : object 'wednesday' not found > traceback() 11: get(i) 10: check_names_df(j, x) 9: `[.tbl_df`(gtfs$calendar, , get(i)) 8: NextMethod(`[`) 7: `[.spec_tbl_df`(gtfs$calendar, , get(i)) 6: gtfs$calendar[, get(i)] 5: which(gtfs$calendar[, get(i)] == 1) 4: FUN(X[[i]], ...) 3: lapply(day, function(i) which(gtfs$calendar[, get(i)] == 1)) 2: filter_by_day(gtfs_cp, day, quiet = quiet) 1: gtfs_timetable(ratp, day = 4)
mpadge commented 4 years ago

Ah yes, thanks @Maxime2506 - i see that this feed implements the alternative yet permitted version of calendar_dates. The package currently can not handle that usage, so I'll have to fix it asap. I'll let you know when it's done ...

Maxime2506 commented 4 years ago

Thanks. I think a code to filter_by_date would be useful. I'm writing one ad hoc for my issue, but a general solution is missing.

M.

Le jeu. 17 oct. 2019 à 15:09, mark padgham notifications@github.com a écrit :

Ah yes, thanks @Maxime2506 https://github.com/Maxime2506 - i see that this feed implements the alternative yet permitted version of calendar_dates https://developers.google.com/transit/gtfs/reference/#calendar_datestxt. The package currently can not handle that usage, so I'll have to fix it asap. I'll let you know when it's done ...

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/ATFutures/gtfs-router/issues/20?email_source=notifications&email_token=ANDRGEYL4Z2F6XCSL7SRVOLQPBPXZA5CNFSM4JBYXDS2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEBQBC5Q#issuecomment-543166838, or unsubscribe https://github.com/notifications/unsubscribe-auth/ANDRGEYEZLVIK4W5Y7RGJXTQPBPXZANCNFSM4JBYXDSQ .

mpadge commented 4 years ago

@Maxime2506 the commit referenced above implements a date parameter for gtfs_timetable, so you can do the following (noting this won't be enduringly reproducible, because the "latest" version is downloaded, with dates only extended from approximately now in to the future, so the value of date will have to be updated to repeat in future cases):

library (gtfsrouter)
url <- "https://transitfeeds.com/p/regie-autonome-des-transports-parisiens/413/latest/download"
f <- "paris-gtfs.zip"
if (!file.exists (f)) download.file (url, destfile = f)
gtfs <- extract_gtfs (f)
gtfs <- gtfs_timetable (gtfs, date = 20191030)
gtfs_route (gtfs, from = "Olympiades", to = "République", start_time = c (9, 0))
#>    route_name trip_name                        stop_name arrival_time
#> 1          14       205                       Olympiades     09:01:00
#> 2          14       205 Bibliothèque-François Mitterrand     09:02:00
#> 3          14       205               Cour Saint-Emilion     09:03:00
#> 4          14       205                            Bercy     09:05:00
#> 5          14       205                     Gare de Lyon     09:06:00
#> 6          14       205                         Châtelet     09:10:00
#> 7          11       202                         Châtelet     09:17:00
#> 8          11       202                   Hôtel de Ville     09:18:00
#> 9          11       202                        Rambuteau     09:19:00
#> 10         11       202                  Arts-et-Métiers     09:20:00
#> 11         11       202                       République     09:22:00
#>    departure_time
#> 1        09:01:00
#> 2        09:02:00
#> 3        09:03:00
#> 4        09:05:00
#> 5        09:06:00
#> 6        09:10:00
#> 7        09:17:00
#> 8        09:18:00
#> 9        09:19:00
#> 10       09:20:00
#> 11       09:22:00

Created on 2019-10-17 by the reprex package (v0.3.0)

I'll re-open the issue straight away, to ensure that gtfs_route without first running gtfs_timetable issues an appropriate message about needing to filter with an explicit date. Other than that, does that now work for you? Thanks for finding this little glitch :smile:

mpadge commented 4 years ago

This commit ensures that an appropriate error message is issued for feeds which use "calendar_dates" instead of "calendar":

library(gtfsrouter)
url <- "https://transitfeeds.com/p/regie-autonome-des-transports-parisiens/413/latest/download"
f <- "paris-gtfs.zip"
if (!file.exists (f)) download.file (url, destfile = f)
gtfs <- extract_gtfs (f)
gtfs_route (gtfs, from = "Olympiades", to = "République", start_time = c (9, 0))
#> Error: This appears to be a GTFS feed which uses a 'calendar_dates' table instead of 'calendar'.
#> Please first construct timetable for a particular date using 'gtfs_timetable(gtfs, date = <date>)'
#> See https://developers.google.com/transit/gtfs/reference/#calendar_datestxt for details.

gtfs <- gtfs_timetable (gtfs, date = 20191030)
gtfs_route (gtfs, from = "Olympiades", to = "République", start_time = c (9, 0))
#>    route_name trip_name                        stop_name arrival_time
#> 1          14       205                       Olympiades     09:01:00
#> 2          14       205 Bibliothèque-François Mitterrand     09:02:00
#> 3          14       205               Cour Saint-Emilion     09:03:00
#> 4          14       205                            Bercy     09:05:00
#> 5          14       205                     Gare de Lyon     09:06:00
#> 6          14       205                         Châtelet     09:10:00
#> 7          11       202                         Châtelet     09:17:00
#> 8          11       202                   Hôtel de Ville     09:18:00
#> 9          11       202                        Rambuteau     09:19:00
#> 10         11       202                  Arts-et-Métiers     09:20:00
#> 11         11       202                       République     09:22:00
#>    departure_time
#> 1        09:01:00
#> 2        09:02:00
#> 3        09:03:00
#> 4        09:05:00
#> 5        09:06:00
#> 6        09:10:00
#> 7        09:17:00
#> 8        09:18:00
#> 9        09:19:00
#> 10       09:20:00
#> 11       09:22:00

Created on 2019-10-18 by the reprex package (v0.3.0)