From f13a91044d884a690d162ce5828fa8dfcfdfeb2c Mon Sep 17 00:00:00 2001 From: junos Date: Tue, 1 Mar 2022 11:39:58 +0100 Subject: [PATCH] Write questionnaire data to data/interim. --- rules/models.smk | 3 ++- src/data/baseline_features.py | 12 +++++++----- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/rules/models.smk b/rules/models.smk index 92b4a935..6d4b0bb8 100644 --- a/rules/models.smk +++ b/rules/models.smk @@ -23,6 +23,7 @@ rule baseline_features: features=config["PARAMS_FOR_ANALYSIS"]["BASELINE"]["FEATURES"], question_filename=config["PARAMS_FOR_ANALYSIS"]["BASELINE"]["FOLDER"] + "/" + config["PARAMS_FOR_ANALYSIS"]["BASELINE"]["QUESTION_LIST"] output: - "data/processed/features/{pid}/baseline_features.csv" + interim="data/interim/{pid}/baseline_questionnaires.csv", + features="data/processed/features/{pid}/baseline_features.csv" script: "../src/data/baseline_features.py" diff --git a/src/data/baseline_features.py b/src/data/baseline_features.py index 116607c8..61ea6eb7 100644 --- a/src/data/baseline_features.py +++ b/src/data/baseline_features.py @@ -3,6 +3,7 @@ import pandas as pd pid = snakemake.params["pid"] requested_features = snakemake.params["features"] +baseline_interim = pd.DataFrame(columns=["qid", "question", "score_original", "score"]) baseline_features = pd.DataFrame(columns=requested_features) question_filename = snakemake.params["question_filename"] @@ -93,7 +94,7 @@ if not participant_info.empty: + LIMESURVEY_JCQ_MIN - limesurvey_demand.loc[rows_demand_reverse, "score_original"] ) - # TODO Write to data/interim + pd.concat([baseline_interim, limesurvey_demand], axis=0, ignore_index=True) if "demand" in requested_features: baseline_features.loc[0, "limesurvey_demand"] = limesurvey_demand[ "score" @@ -126,7 +127,7 @@ if not participant_info.empty: + LIMESURVEY_JCQ_MIN - limesurvey_control.loc[rows_control_reverse, "score_original"] ) - # TODO Write to data/interim + pd.concat([baseline_interim, limesurvey_control], axis=0, ignore_index=True) if "control" in requested_features: baseline_features.loc[0, "limesurvey_control"] = limesurvey_control[ "score" @@ -170,6 +171,7 @@ if not participant_info.empty: 0, "limesurvey_demand_control_ratio_quartile" ] = limesurvey_quartile -baseline_features.to_csv( - snakemake.output[0], index=False, encoding="utf-8", -) +if not baseline_interim.empty: + baseline_interim.to_csv(snakemake.output["interim"], index=False, encoding="utf-8") + +baseline_features.to_csv(snakemake.output["features"], index=False, encoding="utf-8")