Closed mpadge closed 3 years ago
That fixes gtfs_route()
, but now re-opening to propagate same fix across to gtfs_isochrones()
.
Results prior to that implementation (git hash ac00105
), using internal code to directly access numbers of transfers, and starting at a station and time from which parallel trips exist and generate spurious/unnecessary transfers:
library(gtfsrouter)
gtfs <- extract_gtfs("vbb.zip")
#> ▶ Unzipping GTFS archive
#> ✔ Unzipped GTFS archive
#> ▶ Extracting GTFS feed✔ Extracted GTFS feed
#> ▶ Converting stop times to seconds✔ Converted stop times to seconds
#> ▶ Converting transfer times to seconds✔ Converted transfer times to seconds
gtfs <- gtfs_timetable (gtfs, day = "Monday")
from <- "Berlin, Amalienstr"
start_time <- 11 * 3600
end_time <- start_time + 15 * 60
#r <- gtfs_isochrone (gtfs, from = from, start_time = start_time, end_time = end_time)
# get numbers of transfers:
gtfs_cp <- data.table::copy (gtfs)
gtfs_cp$timetable <- gtfs_cp$timetable [departure_time >= start_time, ]
from_is_id <- FALSE
start_stns <- station_name_to_ids (from, gtfs_cp, from_is_id)
isotrips <- get_isotrips (gtfs_cp, start_stns, start_time, end_time)
vapply (isotrips$isotrips, function (i) {
index <- seq (nrow (i)) [-1]
length (which (i$trip_id [index - 1] != i$trip_id [index])) },
integer (1))
#> [1] 3 2 3 1 2 1 3 4 3 1 2 2 2 3 5 3 1 1 4 4 3 2
Created on 2020-10-26 by the reprex package (v0.3.0)
After implementing the above commit:
library (gtfsrouter)
gtfs <- extract_gtfs("vbb.zip")
#> ▶ Unzipping GTFS archive
#> ✔ Unzipped GTFS archive
#> ▶ Extracting GTFS feed✔ Extracted GTFS feed
#> ▶ Converting stop times to seconds✔ Converted stop times to seconds
#> ▶ Converting transfer times to seconds✔ Converted transfer times to seconds
gtfs <- gtfs_timetable (gtfs, day = "Monday")
from <- "Berlin, Amalienstr"
start_time <- 11 * 3600
end_time <- start_time + 15 * 60
#r <- gtfs_isochrone (gtfs, from = from, start_time = start_time, end_time = end_time)
# get numbers of transfers:
gtfs_cp <- data.table::copy (gtfs)
gtfs_cp$timetable <- gtfs_cp$timetable [departure_time >= start_time, ]
from_is_id <- FALSE
start_stns <- station_name_to_ids (from, gtfs_cp, from_is_id)
isotrips <- get_isotrips (gtfs_cp, start_stns, start_time, end_time)
vapply (isotrips$isotrips, function (i) {
index <- seq (nrow (i)) [-1]
length (which (i$trip_id [index - 1] != i$trip_id [index])) },
integer (1))
#> [1] 2 2 2 1 0 1 2 0 1 2 1 1 1 1 1 1 1 1 3 2
Created on 2020-10-26 by the reprex package (v0.3.0)
Example:
Created on 2020-10-25 by the reprex package (v0.3.0)
That route should remain on
route_name
284 the whole way, but changes toX83
for one stop before changing back again. That happens because the timetable for that section has the entry for theX83
service prior to the appropriate entry for the 284, and the route simply connects with first available service at all times. Function has to be fixed to avoid unnecessary transfers. Ping @AlexandraKapp