pull_sensor: Pull sensor volume and occupancy

Description Usage Arguments Value Examples

View source: R/loop_sensor_functions.R

Description

Create a tidy dataframe, containing volume and occupancy, for a single date and sensor. Use 'pull_sensor_ids' to obtain metro sensor IDs.

Usage

1
pull_sensor(sensor, pull_date, date_fmt = c("ymd", "dmy", "mdy"))

Arguments

sensor

an object of class integer or string which indicates the sensor ID. See documentation for 'pull_sensor_ids' to obtain metro sensor IDs.unction

pull_date

an object of class integer or string which indicates the date of data to pull. Can be in mdy, ymd, or dmy format, but format must be specified in the date_fmt argument. A vector of dates is accepted when used in tandem with the 'purrr::pmap()' function.

date_fmt

an object of class string which indicates the format of the 'pull_date' argument.

Value

dataframe containing variables volume, occupancy, sensor, date, time. Note that occupancy *can* be missing while volume data exists and vice versa. It is unknown how a loop could be monitoring volume and not occupancy. Also note that if you assign the output of pull_loops, the result is returned in-memory, and there must be sufficient space in-memory to do so.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
  # Simple example
  loop_data <- pull_sensor(5474, "20190101", "ymd")
  date_range <- c(20190101:20190201)
  loop_data <- pmap(list(8564, date_range, "ymd"), pull_sensor)
  loops_full <- rbindlist(loop_data)

  # Parallel mapping example; takes longer if only pulling one or two days because libraries have to be copied to each core
  library(parallel)
  cl <- makeCluster(detectCores() - 1) # Leaving one core unused
  params <- list(8564, date_range, "ymd")

  clusterSetRNGStream(cl, 1)
  loop_data <- params %>%
   lift(clusterMap, cl = cl)(fun = pull_sensor)
  stopCluster(cl)

  loops_full <- rbindlist(loop_data)

sullivannicole/tc.sensors documentation built on Nov. 22, 2021, 6:38 a.m.