From f3ca56cdbf22d7eed38f920889c4b19f49da7760 Mon Sep 17 00:00:00 2001 From: Primoz Date: Fri, 14 Oct 2022 14:46:28 +0000 Subject: [PATCH] Start with ERS logic integration within Snakemake. --- config.yaml | 3 +++ rules/preprocessing.smk | 21 +++++++++++++++++++ .../process_user_event_related_segments.py | 19 +++++++++++++++++ 3 files changed, 43 insertions(+) create mode 100644 src/data/process_user_event_related_segments.py diff --git a/config.yaml b/config.yaml index 454f8dae..55a626e8 100644 --- a/config.yaml +++ b/config.yaml @@ -24,6 +24,9 @@ TIME_SEGMENTS: &time_segments TYPE: EVENT # FREQUENCY, PERIODIC, EVENT FILE: "data/external/straw_events.csv" INCLUDE_PAST_PERIODIC_SEGMENTS: TRUE # Only relevant if TYPE=PERIODIC, see docs + TAILORED_EVENTS: # Only relevant if TYPE=EVENT + COMPUTE: True + PARAMETER_ONE: "something" # See https://www.rapids.science/latest/setup/configuration/#timezone-of-your-study TIMEZONE: diff --git a/rules/preprocessing.smk b/rules/preprocessing.smk index fb583459..c119434b 100644 --- a/rules/preprocessing.smk +++ b/rules/preprocessing.smk @@ -249,3 +249,24 @@ rule empatica_readable_datetime: "data/raw/{pid}/empatica_{sensor}_with_datetime.csv" script: "../src/data/datetime/readable_datetime.R" + + +rule extract_event_information_from_esm: + input: + esm_raw_input = "data/raw/{pid}/phone_esm_raw.csv" + params: + stage = "extract" + output: + "data/raw/ers/{pid}_ers.csv" + script: + "../src/data/process_user_event_related_segments.py" + +rule create_event_related_segments_file: + input: + ers_files = expand("data/raw/{pid}_ers.csv", pid=config["PIDS"]) + params: + stage = "merge" + output: + "data/external/straw_events.csv" + script: + "../src/data/process_user_event_related_segments.py" \ No newline at end of file diff --git a/src/data/process_user_event_related_segments.py b/src/data/process_user_event_related_segments.py new file mode 100644 index 00000000..bb138c7c --- /dev/null +++ b/src/data/process_user_event_related_segments.py @@ -0,0 +1,19 @@ +import pandas as pd +import numpy as np + +import sys + + +input_data_files = dict(snakemake.input) + +# TODO: potrebno preveriti kako se izvaja iskanje prek device_id -> na tem temelji tudi proces ekstrahiranja ERS + +if snakemake.params["stage"] == "extract": # TODO: najprej preveri ustreznost umeščenosti v RAPIDS pipelineu + extracted_ers = extract_ers_from_file(input_data_files[0]) + extracted_ers.to_csv(snakemake.output[0], index=False) +elif snakemake.params["stage"] == "merge": + pass # TODO: morda ta del raje naredi v drugi skripti (po principu utils/merge_sensor_features_for_all_participants.R) + + +def extract_ers_from_file(esm_file): # TODO: kako se bodo pridobili device_id? Bo torej potreben tudi p0??.yaml? + return None \ No newline at end of file