mixing custom transfers and transers.txt produces weird results
AlexandraKapp opened this issue · 2 comments
I'm not sure if I have a major mistake in thinking here:
The idea - there is a transfers.txt
but it does not necessarily cover all possible transfers, so I want to also add close by stops as transfers via gtfs_transfer_table()
.
So I combine both transfer data tables, using transfer times from transfers.txt
if present, otherwise the custom ones.
Now I get for some cases impossible fast results with the combination that are not returned if only using each single one of the transfer data tables.
How is that possible? (Or is there a reason why I cannot proceed like that?)
I am using the Frankfurt GTFS from DELFI (I'll send it to you). The 3 minutes travel time in the last result are not possible and I did not find the route / transfer that it is based on.
library(gtfsrouter)
gtfs <- extract_gtfs("gtfs.zip")
#> > Unzipping GTFS archivev Unzipped GTFS archive
#> > Extracting GTFS feedv Extracted GTFS feed
#> > Converting stop times to secondsv Converted stop times to seconds
#> > Converting transfer times to secondsv Converted transfer times to seconds
gtfs$calendar[1,]
#> service_id monday tuesday wednesday thursday friday saturday sunday
#> 1: 1 0 0 0 0 1 1 0
#> start_date end_date
#> 1: 20201218 20211211
ttable <- gtfs_timetable(gtfs, day = "tuesday")
ttimes <- gtfs_traveltimes(ttable, "D_de:06412:1008", from_is_id = T, start_time = 8*3600)
ttimes[grepl("Frankfurt \\(Main\\) Hauptbahnhof/M", ttimes$stop_name),]
#> duration ntransfers stop_id
#> 2538 00:18:00 2 de:06412:8:2:2
#> 7317 00:15:00 1 de:06412:8:1
#> 7596 00:18:00 2 000010000803
#> 7597 00:18:00 2 000010000804
#> stop_name stop_lon stop_lat
#> 2538 Frankfurt (Main) Hauptbahnhof/M<U+00C3><U+00BC>nchener Stra<U+00C3><U+0178>e 8.665997 50.10694
#> 7317 Frankfurt (Main) Hauptbahnhof/M<U+00C3><U+00BC>nchener Stra<U+00C3><U+0178>e 8.666445 50.10691
#> 7596 Frankfurt (Main) Hauptbahnhof/M<U+00C3><U+00BC>nchener Stra<U+00C3><U+0178>e 8.665997 50.10693
#> 7597 Frankfurt (Main) Hauptbahnhof/M<U+00C3><U+00BC>nchener Stra<U+00C3><U+0178>e 8.666444 50.10703
gtfs_route(ttable, "D_de:06412:1008", "de:06412:8:1", from_to_are_ids = T, start_time = 8*3600 + 5*60)
#> route_name trip_name
#> 1 RE4 Frankfurt (Main) Hauptbahnhof
#> 2 RE4 Frankfurt (Main) Hauptbahnhof
#> 3 14 Frankfurt (Main) Ernst-May-Platz
#> 4 14 Frankfurt (Main) Ernst-May-Platz
#> stop_name arrival_time departure_time
#> 1 Frankfurt (Main) H<U+00C3><U+00B6>chst Bahnhof 08:13:00 08:14:00
#> 2 Frankfurt (Main) Hauptbahnhof 08:23:00 08:23:00
#> 3 Frankfurt (Main) Hauptbahnhof 08:30:00 08:30:00
#> 4 Frankfurt (Main) Hauptbahnhof/M<U+00C3><U+00BC>nchener Stra<U+00C3><U+0178>e 08:31:00 08:31:00
gtfs_transfers <- gtfs$transfers[, c("from_stop_id", "to_stop_id", "transfer_type", "min_transfer_time")]
custom_transfers <- gtfsrouter::gtfs_transfer_table(gtfs, network_times = FALSE)
#> > Finding neighbouring services for each stop
#> Loading required namespace: geodist
#> Loading required namespace: pbapply
#> v Found neighbouring services for each stop
#> > Expanding to include in-place transfers
#> v Expanded to include in-place transfers
gtfs$transfers <- custom_transfers
ttable <- gtfs_timetable(gtfs, day = "tuesday")
ttimes <- gtfs_traveltimes(ttable, "D_de:06412:1008", from_is_id = T, start_time = 8*3600)
ttimes[grepl("Frankfurt \\(Main\\) Hauptbahnhof/M", ttimes$stop_name),]
#> duration ntransfers stop_id
#> 6 00:13:00 2 de:06412:8
#> 2538 00:24:00 3 de:06412:8:2:2
#> 7317 00:14:00 1 de:06412:8:1
#> 7596 00:13:51 2 000010000803
#> 7597 00:14:13 2 000010000804
#> stop_name stop_lon stop_lat
#> 6 Frankfurt (Main) Hauptbahnhof/M<U+00C3><U+00BC>nchener Stra<U+00C3><U+0178>e 8.666221 50.10693
#> 2538 Frankfurt (Main) Hauptbahnhof/M<U+00C3><U+00BC>nchener Stra<U+00C3><U+0178>e 8.665997 50.10694
#> 7317 Frankfurt (Main) Hauptbahnhof/M<U+00C3><U+00BC>nchener Stra<U+00C3><U+0178>e 8.666445 50.10691
#> 7596 Frankfurt (Main) Hauptbahnhof/M<U+00C3><U+00BC>nchener Stra<U+00C3><U+0178>e 8.665997 50.10693
#> 7597 Frankfurt (Main) Hauptbahnhof/M<U+00C3><U+00BC>nchener Stra<U+00C3><U+0178>e 8.666444 50.10703
gtfs_route(ttable, "D_de:06412:1008", "de:06412:8:1", from_to_are_ids = T, start_time = 8*3600 + 5*60)
#> route_name trip_name
#> 1 RE4 Frankfurt (Main) Hauptbahnhof
#> 2 RE4 Frankfurt (Main) Hauptbahnhof
#> 3 11 Frankfurt (Main) Schie<U+00C3><U+0178>h<U+00C3><U+00BC>ttenstra<U+00C3><U+0178>e
#> 4 11 Frankfurt (Main) Schie<U+00C3><U+0178>h<U+00C3><U+00BC>ttenstra<U+00C3><U+0178>e
#> stop_name arrival_time departure_time
#> 1 Frankfurt (Main) H<U+00C3><U+00B6>chst Bahnhof 08:13:00 08:14:00
#> 2 Frankfurt (Main) Hauptbahnhof 08:23:00 08:23:00
#> 3 Frankfurt (Main) Hauptbahnhof 08:27:00 08:27:00
#> 4 Frankfurt (Main) Hauptbahnhof/M<U+00C3><U+00BC>nchener Stra<U+00C3><U+0178>e 08:28:00 08:28:00
mixed_transfers <- dplyr::distinct(rbind(gtfs_transfers, custom_transfers), from_stop_id, to_stop_id, transfer_type, .keep_all = T)
gtfs$transfers <- mixed_transfers
ttable <- gtfs_timetable(gtfs, day = "tuesday")
ttimes <- gtfs_traveltimes(ttable, "D_de:06412:1008", from_is_id = T, start_time = 8*3600)
ttimes[grepl("Frankfurt \\(Main\\) Hauptbahnhof/M", ttimes$stop_name),]
#> duration ntransfers stop_id
#> 6 00:05:00 2 de:06412:8
#> 2538 00:06:00 2 de:06412:8:2:2
#> 7317 00:03:00 1 de:06412:8:1
#> 7596 00:06:00 2 000010000803
#> 7597 00:06:00 2 000010000804
#> stop_name stop_lon stop_lat
#> 6 Frankfurt (Main) Hauptbahnhof/M<U+00C3><U+00BC>nchener Stra<U+00C3><U+0178>e 8.666221 50.10693
#> 2538 Frankfurt (Main) Hauptbahnhof/M<U+00C3><U+00BC>nchener Stra<U+00C3><U+0178>e 8.665997 50.10694
#> 7317 Frankfurt (Main) Hauptbahnhof/M<U+00C3><U+00BC>nchener Stra<U+00C3><U+0178>e 8.666445 50.10691
#> 7596 Frankfurt (Main) Hauptbahnhof/M<U+00C3><U+00BC>nchener Stra<U+00C3><U+0178>e 8.665997 50.10693
#> 7597 Frankfurt (Main) Hauptbahnhof/M<U+00C3><U+00BC>nchener Stra<U+00C3><U+0178>e 8.666444 50.10703
gtfs_route(ttable, "D_de:06412:1008", "de:06412:8:1", from_to_are_ids = T, start_time = 8*3600 + 5*60)
#> route_name trip_name
#> 1 S2 Dietzenbach Bahnhof
#> 2 S2 Dietzenbach Bahnhof
#> 3 S2 Dietzenbach Bahnhof
#> 4 S2 Dietzenbach Bahnhof
#> 5 11 Frankfurt (Main) Schie<U+00C3><U+0178>h<U+00C3><U+00BC>ttenstra<U+00C3><U+0178>e
#> 6 11 Frankfurt (Main) Schie<U+00C3><U+0178>h<U+00C3><U+00BC>ttenstra<U+00C3><U+0178>e
#> stop_name arrival_time departure_time
#> 1 Frankfurt (Main) H<U+00C3><U+00B6>chst Bahnhof 08:13:00 08:14:00
#> 2 Frankfurt (Main) Nied Bahnhof 08:16:00 08:16:00
#> 3 Frankfurt (Main) Griesheim Bahnhof 08:19:00 08:19:00
#> 4 Frankfurt (Main) Hauptbahnhof tief 08:23:00 08:24:00
#> 5 Frankfurt (Main) Hauptbahnhof 08:27:00 08:27:00
#> 6 Frankfurt (Main) Hauptbahnhof/M<U+00C3><U+00BC>nchener Stra<U+00C3><U+0178>e 08:28:00 08:28:00
Created on 2021-02-12 by the reprex package (v0.3.0)
I just checked - this issue seemed to have been solved with this fix #77 (comment)
library(gtfsrouter)
packageVersion("gtfsrouter")
#> [1] '0.0.4.186'
gtfs <- extract_gtfs("C:/Users/AlexandraKapp/Documents/03_GitHub/travel_time_index/data/Frankfurt/gtfs.zip")
#> > Unzipping GTFS archivev Unzipped GTFS archive
#> > Extracting GTFS feedv Extracted GTFS feed
#> > Converting stop times to secondsv Converted stop times to seconds
#> > Converting transfer times to secondsv Converted transfer times to seconds
gtfs$calendar[1,]
#> service_id monday tuesday wednesday thursday friday saturday sunday
#> 1: 1 0 0 0 0 1 1 0
#> start_date end_date
#> 1: 20201218 20211211
ttable <- gtfs_timetable(gtfs, day = "tuesday")
ttimes <- gtfs_traveltimes(ttable, "D_de:06412:1008", from_is_id = T, start_time = 8*3600)
ttimes[grepl("Frankfurt \\(Main\\) Hauptbahnhof/M", ttimes$stop_name),]
#> start_time duration ntransfers stop_id
#> 2538 08:25:00 00:22:00 2 de:06412:8:2:2
#> 7317 08:20:00 00:15:00 1 de:06412:8:1
#> stop_name stop_lon stop_lat
#> 2538 Frankfurt (Main) Hauptbahnhof/Münchener Straße 8.665997 50.10694
#> 7317 Frankfurt (Main) Hauptbahnhof/Münchener Straße 8.666445 50.10691
gtfs_transfers <- gtfs$transfers[, c("from_stop_id", "to_stop_id", "transfer_type", "min_transfer_time")]
custom_transfers <- gtfsrouter::gtfs_transfer_table(gtfs, network_times = FALSE)
#> > Finding neighbouring services for each stop
#> Loading required namespace: geodist
#> Loading required namespace: pbapply
#> v Found neighbouring services for each stop
#> > Expanding to include in-place transfers
#> v Expanded to include in-place transfers
gtfs$transfers <- custom_transfers
ttable <- gtfs_timetable(gtfs, day = "tuesday")
ttimes <- gtfs_traveltimes(ttable, "D_de:06412:1008", from_is_id = T, start_time = 8*3600)
ttimes[grepl("Frankfurt \\(Main\\) Hauptbahnhof/M", ttimes$stop_name),]
#> start_time duration ntransfers stop_id
#> 2538 08:09:00 00:29:00 2 de:06412:8:2:2
#> 7317 08:14:00 00:14:00 1 de:06412:8:1
#> stop_name stop_lon stop_lat
#> 2538 Frankfurt (Main) Hauptbahnhof/Münchener Straße 8.665997 50.10694
#> 7317 Frankfurt (Main) Hauptbahnhof/Münchener Straße 8.666445 50.10691
mixed_transfers <- dplyr::distinct(rbind(gtfs_transfers, custom_transfers), from_stop_id, to_stop_id, transfer_type, .keep_all = T)
gtfs$transfers <- mixed_transfers
ttable <- gtfs_timetable(gtfs, day = "tuesday")
ttimes <- gtfs_traveltimes(ttable, "D_de:06412:1008", from_is_id = T, start_time = 8*3600)
ttimes[grepl("Frankfurt \\(Main\\) Hauptbahnhof/M", ttimes$stop_name),]
#> start_time duration ntransfers stop_id
#> 2538 08:14:00 00:20:00 2 de:06412:8:2:2
#> 7317 08:14:00 00:14:00 1 de:06412:8:1
#> stop_name stop_lon stop_lat
#> 2538 Frankfurt (Main) Hauptbahnhof/Münchener Straße 8.665997 50.10694
#> 7317 Frankfurt (Main) Hauptbahnhof/Münchener Straße 8.666445 50.10691
<sup>Created on 2021-03-04 by the [reprex package](https://reprex.tidyverse.org) (v0.3.0)</sup>
That's great, thanks for checking. Do you want to close then? Slowly getting all of these done, on the way to CRAN update asap.