Improve filtering by esm_session and device_id.

imputation_and_cleaning
Primoz 2022-11-03 13:51:18 +00:00
parent 02264b21fd
commit 35c1a762e7
1 changed files with 6 additions and 5 deletions

View File

@ -22,10 +22,9 @@ def format_timestamp(x):
return tstring
def extract_ers_from_file(esm_df, device_id):
pd.set_option("display.max_rows", None)
# pd.set_option("display.max_rows", None)
pd.set_option("display.max_columns", None)
with open('config.yaml', 'r') as stream:
@ -37,9 +36,10 @@ def extract_ers_from_file(esm_df, device_id):
# Take only ema_completed sessions responses
classified = classify_sessions_by_completion_time(esm_preprocessed)
esm_filtered_sessions = classified[classified["session_response"] == 'ema_completed'].reset_index()['esm_session']
esm_df = esm_preprocessed[esm_preprocessed["esm_session"].isin(esm_filtered_sessions)]
esm_filtered_sessions = classified[classified["session_response"] == 'ema_completed'].reset_index()[['device_id', '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']))]
# Kako ugotoviti, kje je bilo vprašanje na distressed?
# Extract time-relevant information
time_before_questionnaire = 30 * 60 # in seconds (30 minutes)
@ -53,6 +53,7 @@ def extract_ers_from_file(esm_df, device_id):
extracted_ers["shift"] = extracted_ers["shift"].apply(lambda x: format_timestamp(x))
extracted_ers["shift_direction"] = -1
# sys.exit()
return extracted_ers[["label", "event_timestamp", "length", "shift", "shift_direction", "device_id"]]
if snakemake.params["stage"] == "extract":