Add a function to get participants' IDs.
parent
ed193d2290
commit
8b2717122d
|
@ -29,6 +29,7 @@ library(RPostgres)
|
|||
# <stdin>:1:10: fatal error: libpq-fe.h: No such file or directory
|
||||
# compilation terminated.
|
||||
|
||||
library(dbplyr)
|
||||
library(yaml)
|
||||
|
||||
#' @description
|
||||
|
@ -105,3 +106,30 @@ pull_data <- function(stream_parameters, device, sensor, sensor_container, colum
|
|||
return(sensor_data)
|
||||
}
|
||||
|
||||
#' @description
|
||||
#' Gets participants' IDs for specified usernames.
|
||||
#'
|
||||
#' @param stream_parameters The PHONE_STREAM_PARAMETERS key in config.yaml. If you need specific parameters add them there.
|
||||
#' @param usernames A vector of usernames
|
||||
#' @param participants_container The name of the database table containing participants data, such as their username.
|
||||
#' @return A dataframe with the sensor data for device
|
||||
|
||||
pull_participants_ids <- function(stream_parameters, usernames, participants_container) {
|
||||
dbEngine <- get_db_engine(stream_parameters$DATABASE_GROUP)
|
||||
|
||||
query_participant_id <- tbl(dbEngine, participants_container) %>%
|
||||
filter(username %in% usernames) %>%
|
||||
select(username, id)
|
||||
|
||||
message(paste0("Executing the following query to get the participant's id: \n", sql_render(query_participant_id)))
|
||||
|
||||
participant_data <- query_participant_id %>% collect()
|
||||
|
||||
dbDisconnect(dbEngine)
|
||||
|
||||
if(nrow(participant_data) == 0)
|
||||
warning(paste("We could not find requested usernames (", usernames, ") in ", participants_container))
|
||||
|
||||
return(participant_data)
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue