Prepare a function to compile participants data.
It combines functions from container.Rlabels
parent
f9863ec622
commit
ab84109d55
|
@ -0,0 +1,52 @@
|
||||||
|
library(RPostgres)
|
||||||
|
library(magrittr)
|
||||||
|
library(tidyverse)
|
||||||
|
library(lubridate)
|
||||||
|
|
||||||
|
load_container_script <- function(stream_container){
|
||||||
|
language <- if_else(endsWith(tolower(stream_container), "py"), "python", "r")
|
||||||
|
if(language == "python"){
|
||||||
|
library(reticulate)
|
||||||
|
container <- import_from_path(gsub(pattern = "\\.py$", "", basename(stream_container)), path = dirname(stream_container))
|
||||||
|
if(!py_has_attr(container, "pull_data"))
|
||||||
|
stop(paste0("The following container.py script does not have a pull_data function: ", stream_container))
|
||||||
|
if(!py_has_attr(container, "infer_device_os"))
|
||||||
|
stop(paste0("The following container.py script does not have a infer_device_os function: ", stream_container))
|
||||||
|
return(list("infer_device_os" = container$infer_device_os, "pull_data" = container$pull_data))
|
||||||
|
} else if(language == "r"){
|
||||||
|
source(stream_container)
|
||||||
|
if(!exists("pull_data"))
|
||||||
|
stop(paste0("The following container.R script does not have a pull_data function: ", stream_container))
|
||||||
|
if(!exists("infer_device_os"))
|
||||||
|
stop(paste0("The following container.R script does not have a infer_device_os function: ", stream_container))
|
||||||
|
return(list("infer_device_os" = infer_device_os, "pull_data" = pull_data))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
prepare_participants_file <- function() {
|
||||||
|
#TODO Define appropriate arguments and pass them from config.yaml
|
||||||
|
stream_container <- snakemake@input[["stream_container"]]
|
||||||
|
container_functions <- load_container_script(stream_container)
|
||||||
|
|
||||||
|
pull_data_container <- container_functions$pull_data
|
||||||
|
# TODO Figure out how to use the functions in the container
|
||||||
|
|
||||||
|
participant_data <- pull_participants_ids("whatever", usernames, participants_container)
|
||||||
|
participant_data %<>%
|
||||||
|
rename(participant_id = id)
|
||||||
|
|
||||||
|
device_ids <- pull_participants_device_ids("whatever", participant_data$participant_id, device_id_container)
|
||||||
|
device_ids %<>%
|
||||||
|
group_by(participant_id) %>%
|
||||||
|
summarise(device_ids = list(unique(device_id)))
|
||||||
|
participant_data %<>%
|
||||||
|
left_join(device_ids, by = "participant_id")
|
||||||
|
|
||||||
|
start_end_datetimes <- pull_participants_start_end_dates("whatever", participant_data$participant_id, start_end_date_container)
|
||||||
|
participant_data %<>%
|
||||||
|
left_join(start_end_datetimes, by = "participant_id")
|
||||||
|
|
||||||
|
return(participant_data)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue