r-transit / tidytransit

R package for working with GTFS data
https://r-transit.github.io/tidytransit/
150 stars 22 forks source link

update raptor() and travel_times(), add interpolate_stop_times() #204

Closed polettif closed 1 year ago

polettif commented 1 year ago

This PR slightly changes how journey calculations in raptor work by changing some implicit assumptions.

General improvements

library(tidytransit)

# find travel_times for trips departing on 2019-08-26 between 2 PM and 3:30 PM from 
# Campus Dr at Arts Annex
gtfs_duke |>
  interpolate_stop_times() |>
  filter_feed_by_date("2019-08-26") |> # or filter_stop_times
  travel_times(c("Campus Dr at Arts Annex (WB)", "Campus Dr at Arts Annex (EB)"),
               time_range = c("14:00:00", "15:30:00"))
#> # A tibble: 62 × 8
#>    from_stop_name               to_stop_name  travel_time journey_departure_time
#>    <chr>                        <chr>               <dbl> <time>                
#>  1 Campus Dr at Arts Annex (WB) Campus Dr at…           0 14:00                 
#>  2 Campus Dr at Arts Annex (EB) Campus Dr at…           0 14:00                 
#>  3 Campus Dr at Arts Annex (EB) Campus Dr at…          60 14:04                 
#>  4 Campus Dr at Arts Annex (WB) Campus Dr at…          60 14:01                 
#>  5 Campus Dr at Arts Annex (WB) Campus Dr at…         120 14:01                 
#>  6 Campus Dr at Arts Annex (EB) Maxwell Ave …         120 14:05                 
#>  7 Campus Dr at Arts Annex (EB) East Campus …         180 14:04                 
#>  8 Campus Dr at Arts Annex (WB) Campus Dr at…         180 14:01                 
#>  9 Campus Dr at Arts Annex (WB) Campus Dr at…         240 14:01                 
#> 10 Campus Dr at Arts Annex (WB) West Campus …         360 14:01                 
#> # ℹ 52 more rows
#> # ℹ 4 more variables: journey_arrival_time <time>, transfers <int>,
#> #   from_stop_id <chr>, to_stop_id <chr>

# Find trips arriving between 6 and 7 PM
gtfs_duke |>
  interpolate_stop_times() |>
  filter_stop_times("2019-08-26") |>
  raptor(stop_ids = c("778060", "778061"),
         time_range = c("18:00:00", "19:00:00"), arrival = TRUE)
#>      from_stop_id to_stop_id travel_time journey_departure_time
#>   1:       778057     778060          31                  68129
#>   2:       778058     778060          60                  68100
#>   3:       778063     778061          60                  67980
#>   4:       778065     778061          60                  67980
#>   5:       778067     778061         120                  67920
#>  ---                                                           
#> 443:       778118     778061        8460                  56580
#> 444:      2326138     778061        8640                  56460
#> 445:      2326138     778061        8580                  56460
#> 446:       778060     778060           0                  64800
#> 447:       778061     778061           0                  64800
#>      journey_arrival_time transfers
#>   1:                68160         0
#>   2:                68160         0
#>   3:                68040         0
#>   4:                68040         0
#>   5:                68040         0
#>  ---                               
#> 443:                65040         2
#> 444:                65100         2
#> 445:                65040         2
#> 446:                64800         0
#> 447:                64800         0

Created on 2023-06-19 with reprex v2.0.2

Possibly breaking changes in raptor

This PR also adds examples and updates the documentation.