2022-03-16 16:49:28 +01:00
|
|
|
from esm_preprocess import *
|
2022-03-16 18:55:30 +01:00
|
|
|
from esm_JCQ import reverse_jcq_demand_control_scoring
|
2022-03-09 18:38:46 +01:00
|
|
|
|
2022-04-05 18:14:37 +02:00
|
|
|
requested_scales = snakemake.params["scales"]
|
2022-03-16 17:55:44 +01:00
|
|
|
|
2022-03-09 18:38:46 +01:00
|
|
|
df_esm = pd.read_csv(snakemake.input[0])
|
|
|
|
df_esm_preprocessed = preprocess_esm(df_esm)
|
|
|
|
|
2022-04-05 18:02:31 +02:00
|
|
|
if not all([scale in QUESTIONNAIRE_IDS for scale in requested_scales]):
|
|
|
|
unknown_scales = set(requested_scales) - set(QUESTIONNAIRE_IDS.keys())
|
2022-03-16 18:28:57 +01:00
|
|
|
print("The requested questionnaire name should be one of the following:")
|
|
|
|
print(QUESTIONNAIRE_IDS.keys())
|
2022-04-05 18:02:31 +02:00
|
|
|
raise ValueError("You requested scales not collected: ", unknown_scales)
|
|
|
|
|
|
|
|
df_esm_clean = clean_up_esm(df_esm_preprocessed)
|
|
|
|
df_esm_clean["esm_user_score"] = df_esm_clean["esm_user_answer_numeric"]
|
|
|
|
|
|
|
|
for scale in requested_scales:
|
|
|
|
questionnaire_id = QUESTIONNAIRE_IDS[scale]
|
|
|
|
mask = df_esm_clean["questionnaire_id"] == questionnaire_id
|
|
|
|
if scale.startswith("JCQ"):
|
|
|
|
df_esm_clean.loc[mask] = reverse_jcq_demand_control_scoring(df_esm_clean.loc[mask])
|
2022-04-05 18:14:37 +02:00
|
|
|
#TODO Reverse other questionnaires if needed and/or adapt esm_user_score to original scoring.
|
2022-04-05 18:02:31 +02:00
|
|
|
|
2022-04-05 18:14:37 +02:00
|
|
|
df_esm_clean.to_csv(snakemake.output[0], index=False)
|