Make small corrections in ERS file.

imputation_and_cleaning
Primoz 2022-11-08 14:44:24 +00:00
parent 2d83f7ddec
commit 0b3e9226b3
1 changed files with 3 additions and 10 deletions

View File

@ -39,16 +39,9 @@ def extract_ers_from_file(esm_df, device_id):
esm_df = esm_preprocessed.loc[(esm_preprocessed['device_id'].isin(esm_filtered_sessions['device_id'])) & (esm_preprocessed['esm_session'].isin(esm_filtered_sessions['esm_session']))] esm_df = esm_preprocessed.loc[(esm_preprocessed['device_id'].isin(esm_filtered_sessions['device_id'])) & (esm_preprocessed['esm_session'].isin(esm_filtered_sessions['esm_session']))]
# Problem ne bo ekstrahiranje posameznih začetkov in trajanj stresnih dogodkov - večji problem je pridobitev ustreznega targeta,
# tako da bo poravnan s tem dogodkom, saj se lahko zgodi, da je timestamp zabeležene intenzitete stresnega dogodka ne pade v okno stresnega dogodka.
# Edina izjema tega so, če je označen odgovor "1 - Še vedno traja" pri vprašanju appraisal_event_duration
# Extract time-relevant information
targets_method = config["TIME_SEGMENTS"]["TAILORED_EVENTS"]["TARGETS_METHOD"] targets_method = config["TIME_SEGMENTS"]["TAILORED_EVENTS"]["TARGETS_METHOD"]
if targets_method in ["30_before", "90_before"]: # takes 30-minute peroid before the questionnaire + the duration of the questionnaire if targets_method in ["30_before", "90_before"]: # takes 30-minute peroid before the questionnaire + the duration of the questionnaire
# Extract time-relevant information
extracted_ers = esm_df.groupby(["device_id", "esm_session"])['timestamp'].apply(lambda x: math.ceil((x.max() - x.min()) / 1000)).reset_index() # is rounded up in seconds extracted_ers = esm_df.groupby(["device_id", "esm_session"])['timestamp'].apply(lambda x: math.ceil((x.max() - x.min()) / 1000)).reset_index() # is rounded up in seconds
extracted_ers["label"] = f"straw_event_{targets_method}_" + snakemake.params["pid"] + "_" + extracted_ers.index.astype(str).str.zfill(3) extracted_ers["label"] = f"straw_event_{targets_method}_" + snakemake.params["pid"] + "_" + extracted_ers.index.astype(str).str.zfill(3)
extracted_ers[['event_timestamp', 'device_id']] = esm_df.groupby(["device_id", "esm_session"])['timestamp'].min().reset_index()[['timestamp', 'device_id']] extracted_ers[['event_timestamp', 'device_id']] = esm_df.groupby(["device_id", "esm_session"])['timestamp'].min().reset_index()[['timestamp', 'device_id']]
@ -75,7 +68,7 @@ def extract_ers_from_file(esm_df, device_id):
extracted_ers["length"] = (extracted_ers["timestamp"] + extracted_ers["diffs"]).apply(lambda x: format_timestamp(x)) extracted_ers["length"] = (extracted_ers["timestamp"] + extracted_ers["diffs"]).apply(lambda x: format_timestamp(x))
extracted_ers["shift"] = extracted_ers["diffs"].apply(lambda x: format_timestamp(x)) extracted_ers["shift"] = extracted_ers["diffs"].apply(lambda x: format_timestamp(x))
elif targets_method == "stress_events": elif targets_method == "stress_event":
pass pass
# VV Testiranje različnih povpraševanj za VV # VV Testiranje različnih povpraševanj za VV
# print(esm_df[esm_df.questionnaire_id == 87]) # print(esm_df[esm_df.questionnaire_id == 87])