Closed rafapereirabr closed 4 years ago
Hi Joao. I've created the function test_gtfs_freq.R
to test whether a GTFS feed is frequency based or whether it's a simple feed with a detailed stop_times.txt
file. This should help solving this issue
After merging the functions:
There are basically two scripts,gtfs2gps_single_dt.R
and mod_updates.R
, which will be pulled today @pedro-andrade-inpe . Here's the approach
gtfs2gps_single_dt.R
gtfs2gps_dt_single <- function(gtfszip, filepath, spatial_resolution = 15, week_days = TRUE){ - 1) read GTFS - 2) convert into sf object
# Core function
corefun <- function(shapeid){ - 3) spatial interpolation
# test data type
if(test_gtfs_freq(gtfs_data)=="frequency"){ _- 4.1) update newstoptimes based on
update_freq(all_tripids)
else - 4.2) update newstoptimes based onupdate_dt(all_tripids)
_ }5) write object }
6) future.apply for all shapeids
return(output) }
mod_updates.R
update_freq <- function(tripid,new_stoptimes){ 1) build 'id' vector all speed between stop sequences 2) speed estimation 3) update departure times 4) get freq info for that trip
# start frequencies functions
update_newstoptimes_freq(starttimes,freq_temp){update_departure_stoptimes(i,dt_list){ 5.1) update departure stoptimes return(dt_list)
_5.2) function to update stoptimes of each departure (
update_departure_stoptimes
)_ _5.3) apply function and return the stop times of all departures from that period (update_departure_stoptimes
)_ return(departure_stoptimes)6) update newstoptimes frequency return(new_stoptimes)
the simple data frame behaves similarly
update_dt <- function(tripid,new_stoptimes){ 1) build 'id' vector all speed between stop sequences 2) speed estimation 3) update departure times 4) recalculate time stamps return(new_stoptimes)
This issue was already solved by https://github.com/ipeaGIT/gtfs2gps/pull/36, https://github.com/ipeaGIT/gtfs2gps/pull/48, and 4f37503d2eccad70ddf975c55ef4259fcbd3012a.
The scripts
gtfs2gps_dt_parallel.R
andgtfs2gps_dt_parallel_freq.R
basically do the same thing. Both convert a GTFS feed to a "GPS format". The difference is that the former works on a standard GTFS feed, while the latter works on a frequency-based GTFS. Ideally, both functions shuld be combined into a single function.