Fix OS specific dependcies

pull/128/head
JulioV 2021-03-08 18:19:53 -05:00
parent 7372fca0dd
commit 8c79cfc56f
2 changed files with 20 additions and 16 deletions

View File

@ -51,7 +51,7 @@ def pull_phone_data_input_with_mutation_scripts(wilcards):
if sensor not in schema: if sensor not in schema:
raise ValueError("{sensor} is not defined in the schema {schema}".format(sensor=sensor, schema=input.get("stream_format"))) raise ValueError("{sensor} is not defined in the schema {schema}".format(sensor=sensor, schema=input.get("stream_format")))
for device_os in ["ANDROID", "IOS"]: for device_os in schema[sensor].keys():
scripts = schema[sensor][device_os]["MUTATION_SCRIPTS"] scripts = schema[sensor][device_os]["MUTATION_SCRIPTS"]
if isinstance(scripts, list): if isinstance(scripts, list):
for idx, script in enumerate(scripts): for idx, script in enumerate(scripts):

View File

@ -59,23 +59,27 @@ rename_columns <- function(name_maps, data){
} }
validate_expected_columns_mapping <- function(schema, rapids_schema, sensor, rapids_schema_file, stream_format){ validate_expected_columns_mapping <- function(schema, rapids_schema, sensor, rapids_schema_file, stream_format){
android_columns <- names(schema[[sensor]][["ANDROID"]][["COLUMN_MAPPINGS"]])
android_columns <- android_columns[(android_columns != "FLAG_AS_EXTRA")]
ios_columns <- names(schema[[sensor]][["IOS"]][["COLUMN_MAPPINGS"]])
ios_columns <- ios_columns[(ios_columns != "FLAG_AS_EXTRA")]
rapids_columns <- rapids_schema[[sensor]] rapids_columns <- rapids_schema[[sensor]]
if(is.null(rapids_columns)) if(is.null(rapids_columns))
stop(paste(sensor, " columns are not listed in RAPIDS' column specification. If you are adding support for a new phone sensor, add any mandatory columns in ", rapids_schema_file)) stop(paste(sensor, " columns are not listed in RAPIDS' column specification. If you are adding support for a new phone sensor, add any mandatory columns in ", rapids_schema_file))
if(length(setdiff(rapids_columns, android_columns)) > 0)
stop(paste(sensor," mappings are missing one or more mandatory columns for ANDROID. The missing column mappings are for ", paste(setdiff(rapids_columns, android_columns), collapse=","),"in", stream_format, " (the mappings are case sensitive)")) if("ANDROID" %in% schema[[sensor]]){
if(length(setdiff(rapids_columns, ios_columns)) > 0) android_columns <- names(schema[[sensor]][["ANDROID"]][["COLUMN_MAPPINGS"]])
stop(paste(sensor," mappings are missing one or more mandatory columns for IOS. The missing column mappings are for ", paste(setdiff(rapids_columns, ios_columns), collapse=","),"in", stream_format, " (the mappings are case sensitive)")) android_columns <- android_columns[(android_columns != "FLAG_AS_EXTRA")]
if(length(setdiff(android_columns, rapids_columns)) > 0) if(length(setdiff(rapids_columns, android_columns)) > 0)
stop(paste(sensor," mappings have one or more columns than required for ANDROID, add them as FLAG_AS_EXTRA instead. The extra column mappings are for ", paste(setdiff(android_columns, rapids_columns), collapse=","),"in", stream_format, " (the mappings are case sensitive)")) stop(paste(sensor," mappings are missing one or more mandatory columns for ANDROID. The missing column mappings are for ", paste(setdiff(rapids_columns, android_columns), collapse=","),"in", stream_format, " (the mappings are case sensitive)"))
if(length(setdiff(ios_columns, rapids_columns)) > 0) if(length(setdiff(android_columns, rapids_columns)) > 0)
stop(paste(sensor," mappings have one or more columns than required for IOS, add them as FLAG_AS_EXTRA instead. The extra column mappings are for ", paste(setdiff(ios_columns, rapids_columns), collapse=","),"in", stream_format, " (the mappings are case sensitive)")) stop(paste(sensor," mappings have one or more columns than required for ANDROID, add them as FLAG_AS_EXTRA instead. The extra column mappings are for ", paste(setdiff(android_columns, rapids_columns), collapse=","),"in", stream_format, " (the mappings are case sensitive)"))
}
if("IOS" %in% schema[[sensor]]){
ios_columns <- names(schema[[sensor]][["IOS"]][["COLUMN_MAPPINGS"]])
ios_columns <- ios_columns[(ios_columns != "FLAG_AS_EXTRA")]
if(length(setdiff(rapids_columns, ios_columns)) > 0)
stop(paste(sensor," mappings are missing one or more mandatory columns for IOS. The missing column mappings are for ", paste(setdiff(rapids_columns, ios_columns), collapse=","),"in", stream_format, " (the mappings are case sensitive)"))
if(length(setdiff(ios_columns, rapids_columns)) > 0)
stop(paste(sensor," mappings have one or more columns than required for IOS, add them as FLAG_AS_EXTRA instead. The extra column mappings are for ", paste(setdiff(ios_columns, rapids_columns), collapse=","),"in", stream_format, " (the mappings are case sensitive)"))
}
} }
load_container_script <- function(stream_container){ load_container_script <- function(stream_container){
@ -121,7 +125,7 @@ pull_phone_data <- function(){
validate_expected_columns_mapping(stream_schema, rapids_schema, sensor, rapids_schema_file, stream_format) 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) # ANDROID or IOS COLUMN_MAPPINGS are guaranteed to be the same at this point (see validate_expected_columns_mapping function)
expected_columns <- tolower(names(stream_schema[[sensor]][["ANDROID"]][["COLUMN_MAPPINGS"]])) expected_columns <- tolower(rapids_schema[[sensor]])
expected_columns <- expected_columns[(expected_columns != "flag_extra")] expected_columns <- expected_columns[(expected_columns != "flag_extra")]
participant_data <- setNames(data.frame(matrix(ncol = length(expected_columns), nrow = 0)), expected_columns) participant_data <- setNames(data.frame(matrix(ncol = length(expected_columns), nrow = 0)), expected_columns)