Use zonar_get_schedules to retrieve the time each bus
(asset) reaches a route anchor (zone) from the
Zonar API
Usage
zonar_get_schedules(
start,
end,
by = c("time", "zone", "asset"),
zones = NULL,
assets = NULL,
timezone = "America/New_York",
reformat = FALSE,
include_geometry = FALSE,
cachedir = NULL,
omit_categories = NULL,
test = FALSE
)Arguments
- start
Character vector of length one giving the start time in yyyy-mm-dd hh:mm:ss format.
- end
Character vector of length one giving the end time in yyyy-mm-dd hh:mm:ss format.
- by
Whether to split requests by time or zone under the hood. By default a reasonable value is chosen based on the amount of data you request (i.e., the size of the interval between
startandend.- zones
Character vector of zone names (not IDs!) to retrieve. If
NULL(the default) retrieve all zones.- assets
Integer vector of giving the Zonar asset IDs (not names) of the asset to retrieve.
- timezone
Defaults to "America/New_York"
- reformat
If
TRUEcleanup and re-format the data such that each row represents a "Zone event", i.e., a discrete entry into and/or exit from a zone. Otherwise leave the date in the original format returned by Zonar. Defaults toFALSE.- include_geometry
If
TRUEalso return the geographic polygon showing the location and extent of each Zone. Defaults toFALSE.- cachedir
Ignored, always uses .zonarCache now.
- omit_categories
Character vector containing zone categories to skip/omit.
- test
Set to
TRUEfor testing purposes, otherwise it will be too slow.
Details
The Zonar schedule report API can give us that information, but not all at once. Using this R wrapper makes it easy to retrieve bulk schedule reports from the Zonar API in a convenient format that can easily be saved to a database or spreadsheet.
Note that retrieving data for short intervals (one day or less) will generally
be faster when setting by = "time", while bulk retrieval of weeks or months
of data will be faster when setting by = "zone". By default zonar_get_shedules_all
will try to pick the best setting for you depending on the start and end
parameters you give it.
The default is to retrieve all zones and all assets for the time period specified
by start and end. You can retrieve a specified list of zones or assets
via the zones and assets arguments. However, due to the way the Zonar API
works you cannot specify both. Note that zones must be specified by name, but
assets must be specified by ID; see zonar_get_assets() if you need to look
up IDs from asset names.
Examples
library(RZonar)
## use by="time" for short duration, e.g. < 1 day
schedtest1 <- zonar_get_schedules(
start = "2022-11-30 08:00:00",
end = "2022-11-30 08:40:00",
by = "time")
dplyr::glimpse(schedtest1)
#> Rows: 2,626
#> Columns: 11
#> $ zoneID <int> 2272, 2272, 2272, 2272, 2290, 2290, 2290, 2290, 229…
#> $ Zone <chr> "100 Desoto Rd", "100 Desoto Rd", "100 Desoto Rd", …
#> $ category <chr> "WATCH", "WATCH", "WATCH", "WATCH", "WATCH", "WATCH…
#> $ `Asset ID` <chr> "1521", "1521", "161", "161", "1051", "1051", "538"…
#> $ Asset <chr> "HS521", "HS521", "HS381", "HS381", "B433", "B433",…
#> $ Time <dttm> 2022-11-30 08:11:17, 2022-11-30 08:12:05, 2022-11-…
#> $ `IN/OUT` <chr> "IN", "OUT", "IN", "OUT", "IN", "OUT", "IN", "OUT",…
#> $ `Time In Zone` <chr> NA, "00:00:48", NA, "00:00:30", NA, "00:00:36", NA,…
#> $ Duration <chr> "00:00:00", "00:00:48", "00:00:00", "00:00:30", "00…
#> $ `Duration Total` <chr> "00:00:00", "00:00:48", "00:00:00", "00:00:30", "00…
#> $ `Distance (Miles)` <chr> "0.0", "0.1", "0.0", "0.1", "0.0", "0.1", "0.0", "0…
## use by="zone" for bulk retrieval (e.g. weeks or months of data)
schedtest2 <- zonar_get_schedules(
start = "2022-11-20 08:00:00",
end = "2022-11-28 08:30:00",
by = "zone",
zones = c("Adams", "Burke") # not required, leave out for all zones
)
dplyr::glimpse(schedtest2)
#> Rows: 0
#> Columns: 0
## use by="zone" for bulk retrieval (e.g. weeks or months of data)
schedtest3 <- zonar_get_schedules(
start = "2022-11-20 08:00:00",
end = "2022-11-28 08:30:00",
assets = c("1024", "1030") # not required, leave out for all assets
)
dplyr::glimpse(schedtest3)
#> Rows: 248
#> Columns: 11
#> $ zoneID <int> 2290, 2290, 2290, 2290, 2290, 2290, 2290, 2290, 227…
#> $ Zone <chr> "100 S Huntington", "100 S Huntington", "100 S Hunt…
#> $ category <chr> "WATCH", "WATCH", "WATCH", "WATCH", "WATCH", "WATCH…
#> $ Asset <chr> "B412", "B412", "B412", "B412", "B412", "B412", "B4…
#> $ `Asset ID` <chr> "1030", "1030", "1030", "1030", "1030", "1030", "10…
#> $ Time <dttm> 2022-11-21 06:18:34, 2022-11-21 06:19:11, 2022-11-…
#> $ `IN/OUT` <chr> "IN", "OUT", "IN", "OUT", "IN", "OUT", "IN", "OUT",…
#> $ `Time In Zone` <chr> NA, "00:00:37", NA, "00:00:42", NA, "00:00:53", NA,…
#> $ Duration <chr> "00:37:12", "00:00:37", "00:48:55", "00:00:42", "00…
#> $ `Duration Total` <chr> "01:00:49", "01:01:26", "25:00:49", "25:01:31", "49…
#> $ `Distance (Miles)` <chr> "12.6", "12.8", "76.6", "76.8", "137.7", "137.8", "…