diff --git a/Snakefile b/Snakefile index 98f99230..413438de 100644 --- a/Snakefile +++ b/Snakefile @@ -14,6 +14,15 @@ if len(config["PIDS"]) == 0: for provider in config["PHONE_DATA_YIELD"]["PROVIDERS"].keys(): if config["PHONE_DATA_YIELD"]["PROVIDERS"][provider]["COMPUTE"]: + + allowed_phone_sensors = get_phone_sensor_names() + if not (set(config["PHONE_DATA_YIELD"]["SENSORS"]) <= set(allowed_phone_sensors)): + raise ValueError('\nInvalid sensor(s) for PHONE_DATA_YIELD. config["PHONE_DATA_YIELD"]["SENSORS"] can have ' + 'one or more of the following phone sensors: {}.\nInstead you provided "{}".\n' + 'Keep in mind that the sensors\' TABLE attribute must point to a valid database table'\ + .format(', '.join(allowed_phone_sensors), + ', '.join(set(config["PHONE_DATA_YIELD"]["SENSORS"]) - set(allowed_phone_sensors)))) + files_to_compute.extend(expand("data/raw/{pid}/{sensor}_raw.csv", pid=config["PIDS"], sensor=map(str.lower, config["PHONE_DATA_YIELD"]["SENSORS"]))) files_to_compute.extend(expand("data/interim/{pid}/phone_yielded_timestamps.csv", pid=config["PIDS"])) files_to_compute.extend(expand("data/interim/{pid}/phone_yielded_timestamps_with_datetime.csv", pid=config["PIDS"])) diff --git a/rules/common.smk b/rules/common.smk index daf5cffa..a496be7f 100644 --- a/rules/common.smk +++ b/rules/common.smk @@ -22,3 +22,11 @@ def input_merge_sensor_features_for_individual_participants(wildcards): break return feature_files +def get_phone_sensor_names(): + phone_sensor_names = [] + for config_key in config.keys(): + if config_key.startswith(("PHONE")) and "PROVIDERS" in config[config_key]: + if config_key != "PHONE_DATA_YIELD" and config_key not in phone_sensor_names: + phone_sensor_names.append(config_key) + return phone_sensor_names +