ipeaGIT / gtfs2gps

Convert GTFS data into a data.table with GPS-like records in R
https://ipeagit.github.io/gtfs2gps/
Other
71 stars 9 forks source link

Small issues with data.table::as.ITime #25

Closed Joaobazzo closed 4 years ago

Joaobazzo commented 5 years ago

The as.ITime function seems to have an issue with non-integer values

> data.table::as.ITime(0.5)
[1] "00:00:00"
 > data.table::as.ITime(0.89)
[1] "00:00:00"
> data.table::as.ITime(0.99)
[1] "00:00:00"
> data.table::as.ITime(2.90)
[1] "00:00:02"

Perhaps we should use in all scripts (such as gtfs2gps_dt_parellel.R) the function round inside it

> data.table::as.ITime(round(0.5)) # still with problems
[1] "00:00:00"
> data.table::as.ITime(round(0.99))
[1] "00:00:01"
> data.table::as.ITime(round(2.8))
[1] "00:00:03"
rafapereirabr commented 5 years ago

Indeed, this happens because iTime only accepts integer values so the smaller unit is seconds. This idea of using round() seems like a good suggestion to me. @pedro-andrade-inpe , what do you think ?

> data.table::as.ITime(1) + data.table::as.ITime(1)
[1] "00:00:02"
> 
> 
> data.table::as.ITime(0) + data.table::as.ITime(1)
[1] "00:00:01"
> 
> 
> data.table::as.ITime(.5) + data.table::as.ITime(.5)
[1] "00:00:00"
pedro-andrade-inpe commented 5 years ago

I thing round() is a good idea. My only concern is that, as we are going to compute the average speed, having zero values for time is always unwanted, as it will produce infinite speeds. Additionally, if considering a distance of 15 meters, the maximum speed will be 54km/h if the travel time takes one second, but there are speeds higher than this value in some gtfs data that we use. Possibly it will be better to compute the speeds using the original values before converting to ITime.

rafapereirabr commented 5 years ago

Arredondar dentro do parenteses na linha 189 desse script https://github.com/ipeaGIT/gtfs2gps/blob/9fb6909aeedd1001bef6731e5cf00280db07309f/R/gtfs2gps_dt_parallel.R

pedro-andrade-inpe commented 4 years ago

Every convertion to ITimes in mod_updates that involves an arithmetical operation already uses round. Therefore this issue can be considered finished.