From dd95b4f941b22886f6760404777eebc19954e899 Mon Sep 17 00:00:00 2001 From: JulioV Date: Mon, 14 Dec 2020 13:42:22 -0500 Subject: [PATCH] Start support for phone_keyboard --- Snakefile | 9 +++++ config.yaml | 9 +++++ rules/features.smk | 26 ++++++++++++++ src/features/phone_keyboard/rapids/main.py | 40 ++++++++++++++++++++++ 4 files changed, 84 insertions(+) create mode 100644 src/features/phone_keyboard/rapids/main.py diff --git a/Snakefile b/Snakefile index 04882a79..d9ab9c1b 100644 --- a/Snakefile +++ b/Snakefile @@ -100,6 +100,15 @@ for provider in config["PHONE_LIGHT"]["PROVIDERS"].keys(): files_to_compute.extend(expand("data/processed/features/{pid}/all_sensor_features.csv", pid=config["PIDS"])) files_to_compute.append("data/processed/features/all_participants/all_sensor_features.csv") +for provider in config["PHONE_KEYBOARD"]["PROVIDERS"].keys(): + if config["PHONE_KEYBOARD"]["PROVIDERS"][provider]["COMPUTE"]: + files_to_compute.extend(expand("data/raw/{pid}/phone_keyboard_raw.csv", pid=config["PIDS"])) + files_to_compute.extend(expand("data/raw/{pid}/phone_keyboard_with_datetime.csv", pid=config["PIDS"])) + files_to_compute.extend(expand("data/interim/{pid}/phone_keyboard_features/phone_keyboard_{language}_{provider_key}.csv", pid=config["PIDS"], language=config["PHONE_KEYBOARD"]["PROVIDERS"][provider]["SRC_LANGUAGE"].lower(), provider_key=provider.lower())) + files_to_compute.extend(expand("data/processed/features/{pid}/phone_keyboard.csv", pid=config["PIDS"],)) + files_to_compute.extend(expand("data/processed/features/{pid}/all_sensor_features.csv", pid=config["PIDS"])) + files_to_compute.append("data/processed/features/all_participants/all_sensor_features.csv") + for provider in config["PHONE_ACCELEROMETER"]["PROVIDERS"].keys(): if config["PHONE_ACCELEROMETER"]["PROVIDERS"][provider]["COMPUTE"]: files_to_compute.extend(expand("data/raw/{pid}/phone_accelerometer_raw.csv", pid=config["PIDS"])) diff --git a/config.yaml b/config.yaml index b216b5d1..dabf5b2c 100644 --- a/config.yaml +++ b/config.yaml @@ -189,6 +189,15 @@ PHONE_DATA_YIELD: SRC_LANGUAGE: "r" SRC_FOLDER: "rapids" # inside src/features/phone_data_yield +PHONE_KEYBOARD: + TABLE: keyboard + PROVIDERS: + RAPIDS: + COMPUTE: True + FEATURES: [] + SRC_FOLDER: "rapids" # inside src/features/phone_keyboard + SRC_LANGUAGE: "python" + # See https://www.rapids.science/latest/features/phone-light/ PHONE_LIGHT: TABLE: light diff --git a/rules/features.smk b/rules/features.smk index c106912f..bcfd72fe 100644 --- a/rules/features.smk +++ b/rules/features.smk @@ -262,6 +262,32 @@ rule phone_light_r_features: script: "../src/features/entry.R" +rule phone_keyboard_python_features: + input: + sensor_data = "data/raw/{pid}/phone_keyboard_with_datetime.csv", + time_segments_labels = "data/interim/time_segments/{pid}_time_segments_labels.csv" + params: + provider = lambda wildcards: config["PHONE_KEYBOARD"]["PROVIDERS"][wildcards.provider_key.upper()], + provider_key = "{provider_key}", + sensor_key = "phone_keyboard" + output: + "data/interim/{pid}/phone_keyboard_features/phone_keyboard_python_{provider_key}.csv" + script: + "../src/features/entry.py" + +rule phone_keyboard_r_features: + input: + sensor_data = "data/raw/{pid}/phone_keyboard_with_datetime.csv", + time_segments_labels = "data/interim/time_segments/{pid}_time_segments_labels.csv" + params: + provider = lambda wildcards: config["PHONE_KEYBOARD"]["PROVIDERS"][wildcards.provider_key.upper()], + provider_key = "{provider_key}", + sensor_key = "phone_keyboard" + output: + "data/interim/{pid}/phone_keyboard_features/phone_keyboard_r_{provider_key}.csv" + script: + "../src/features/entry.R" + rule phone_locations_python_features: input: sensor_data = "data/interim/{pid}/phone_locations_processed_with_datetime.csv", diff --git a/src/features/phone_keyboard/rapids/main.py b/src/features/phone_keyboard/rapids/main.py new file mode 100644 index 00000000..52dd4339 --- /dev/null +++ b/src/features/phone_keyboard/rapids/main.py @@ -0,0 +1,40 @@ +import pandas as pd +import numpy as np + +def rapids_features(sensor_data_files, time_segment, provider, filter_data_by_segment, *args, **kwargs): + + # I copied this from light, modify it to make it work for keyboard + + light_data = pd.read_csv(sensor_data_files["sensor_data"]) + print(light_data) + raise ValueError("Test") + requested_features = provider["FEATURES"] + # name of the features this function can compute + base_features_names = ["count", "maxlux", "minlux", "avglux", "medianlux", "stdlux"] + # the subset of requested features this function can compute + features_to_compute = list(set(requested_features) & set(base_features_names)) + + light_features = pd.DataFrame(columns=["local_segment"] + features_to_compute) + if not light_data.empty: + light_data = filter_data_by_segment(light_data, time_segment) + + if not light_data.empty: + light_features = pd.DataFrame() + if "count" in features_to_compute: + light_features["count"] = light_data.groupby(["local_segment"]).count()["timestamp"] + + # get light ambient luminance related features + if "maxlux" in features_to_compute: + light_features["maxlux"] = light_data.groupby(["local_segment"])["double_light_lux"].max() + if "minlux" in features_to_compute: + light_features["minlux"] = light_data.groupby(["local_segment"])["double_light_lux"].min() + if "avglux" in features_to_compute: + light_features["avglux"] = light_data.groupby(["local_segment"])["double_light_lux"].mean() + if "medianlux" in features_to_compute: + light_features["medianlux"] = light_data.groupby(["local_segment"])["double_light_lux"].median() + if "stdlux" in features_to_compute: + light_features["stdlux"] = light_data.groupby(["local_segment"])["double_light_lux"].std() + + light_features = light_features.reset_index() + + return light_features \ No newline at end of file