Add stream_parameters arg to phone and empatica mutation scripts

pull/128/head
JulioV 2021-03-09 11:28:33 -05:00
parent 1063b4ca65
commit 58ef276179
4 changed files with 11 additions and 11 deletions

View File

@ -53,6 +53,6 @@ unify_ios_activity_recognition <- function(ios_gar){
return(ios_gar)
}
main <- function(data){
main <- function(data, stream_parameters){
return(unify_ios_activity_recognition(data))
}

View File

@ -14,6 +14,6 @@ unify_ios_conversation <- function(conversation){
}
return(conversation)
}
main <- function(data){
main <- function(data, stream_parameters){
return(unify_ios_conversation(data))
}

View File

@ -4,7 +4,7 @@ library(yaml)
library(dplyr)
library(readr)
# we use reticulate but only load it if we are going to use it to minimize the case when old RAPIDS deployments need to update ther renv
mutate_data <- function(scripts, data){
mutate_data <- function(scripts, data, data_configuration){
for(script in scripts){
if(grepl("\\.(R)$", script)){
myEnv <- new.env()
@ -12,7 +12,7 @@ mutate_data <- function(scripts, data){
attach(myEnv, name="sourced_scripts_rapids")
if(exists("main", myEnv)){
message(paste("Applying mutation script", script))
data <- main(data)
data <- main(data, data_configuration)
} else{
stop(paste0("The following mutation script does not have main function: ", script))
}
@ -24,7 +24,7 @@ mutate_data <- function(scripts, data){
script_functions <- import_from_path(module, path = dirname(script))
if(py_has_attr(script_functions, "main")){
message(paste("Applying mutation script", script))
data <- script_functions$main(data)
data <- script_functions$main(data, data_configuration)
} else{
stop(paste0("The following mutation script does not have a main function: ", script))
}
@ -107,7 +107,7 @@ pull_empatica_data_main <- function(){
renamed_data <- rename_columns(columns_to_rename, data)
mutation_scripts <- stream_schema[[sensor]][["MUTATION_SCRIPTS"]]
mutated_data <- mutate_data(mutation_scripts, renamed_data)
mutated_data <- mutate_data(mutation_scripts, renamed_data, data_configuration)
if(length(setdiff(expected_columns, colnames(mutated_data))) > 0)
stop(paste("The mutated data for", device, "is missing these columns expected by RAPIDS: [", paste(setdiff(expected_columns, colnames(mutated_data)), collapse=","),"]. One ore more mutation scripts in [", sensor,"][",toupper(device_os), "]","[MUTATION_SCRIPTS] are removing or not adding these columns"))

View File

@ -22,7 +22,7 @@ validate_inferred_os <- function(stream_container, participant_file, device, dev
stop(paste0("We tried to infer the OS for ", device, " but 'infer_device_os' function inside '",stream_container,"' returned '",device_os,"' instead of 'android' or 'ios'. You can assign the OS manually in the participant file or report this bug on GitHub.\nParticipant file ", participant_file))
}
mutate_data <- function(scripts, data){
mutate_data <- function(scripts, data, data_configuration){
for(script in scripts){
if(grepl("\\.(R)$", script)){
myEnv <- new.env()
@ -30,7 +30,7 @@ mutate_data <- function(scripts, data){
attach(myEnv, name="sourced_scripts_rapids")
if(exists("main", myEnv)){
message(paste("Applying mutation script", script))
data <- main(data)
data <- main(data, data_configuration)
} else{
stop(paste0("The following mutation script does not have main function: ", script))
}
@ -42,7 +42,7 @@ mutate_data <- function(scripts, data){
script_functions <- import_from_path(module, path = dirname(script))
if(py_has_attr(script_functions, "main")){
message(paste("Applying mutation script", script))
data <- script_functions$main(data)
data <- script_functions$main(data, data_configuration)
} else{
stop(paste0("The following mutation script does not have a main function: ", script))
}
@ -126,7 +126,7 @@ pull_phone_data <- function(){
validate_expected_columns_mapping(stream_schema, rapids_schema, sensor, rapids_schema_file, stream_format)
# ANDROID or IOS COLUMN_MAPPINGS are guaranteed to be the same at this point (see validate_expected_columns_mapping function)
expected_columns <- tolower(rapids_schema[[sensor]])
expected_columns <- expected_columns[(expected_columns != "flag_extra")]
expected_columns <- expected_columns[(expected_columns != "flag_as_extra")]
participant_data <- setNames(data.frame(matrix(ncol = length(expected_columns), nrow = 0)), expected_columns)
container_functions <- load_container_script(stream_container)
@ -155,7 +155,7 @@ pull_phone_data <- function(){
renamed_data <- rename_columns(columns_to_rename, data)
mutation_scripts <- stream_schema[[sensor]][[toupper(device_os)]][["MUTATION_SCRIPTS"]]
mutated_data <- mutate_data(mutation_scripts, renamed_data)
mutated_data <- mutate_data(mutation_scripts, renamed_data, data_configuration)
if(length(setdiff(expected_columns, colnames(mutated_data))) > 0)
stop(paste("The mutated data for", device, "is missing these columns expected by RAPIDS: [", paste(setdiff(expected_columns, colnames(mutated_data)), collapse=","),"]. One ore more mutation scripts in [", sensor,"][",toupper(device_os), "]","[MUTATION_SCRIPTS] are removing or not adding these columns"))