Take the evening EMA time question into account as non-answered session.

communication
junos 2021-06-09 17:29:42 +02:00
parent 151bbfe360
commit 04c069af47
2 changed files with 13 additions and 5 deletions

View File

@ -61,7 +61,7 @@ df_esm_preprocessed.columns
# One approach would be to count distinct session IDs which are incremented for each group of EMAs. However, since not every question answered counts as a fulfilled EMA, some unique session IDs should be eliminated first. # One approach would be to count distinct session IDs which are incremented for each group of EMAs. However, since not every question answered counts as a fulfilled EMA, some unique session IDs should be eliminated first.
# %% # %%
session_counts = df_esm_preprocessed.groupby(["participant_id", "esm_session"]).count()[ session_counts = df_esm_preprocessed.groupby(["participant_id", "device_id", "esm_session"]).count()[
"id" "id"
] ]
@ -82,7 +82,7 @@ df_session_counts = pd.DataFrame(session_counts).rename(
) )
df_session_1 = df_session_counts[(df_session_counts["esm_session_count"] == 1)] df_session_1 = df_session_counts[(df_session_counts["esm_session_count"] == 1)]
df_esm_unique_session = df_session_1.join( df_esm_unique_session = df_session_1.join(
df_esm_preprocessed.set_index(["participant_id", "esm_session"]) df_esm_preprocessed.set_index(["participant_id", "device_id", "esm_session"])
) )
# %% # %%
@ -141,6 +141,13 @@ df_esm_preprocessed.query("participant_id == 31 & esm_session == 77")[
["esm_trigger", "esm_instructions", "esm_user_answer"] ["esm_trigger", "esm_instructions", "esm_user_answer"]
] ]
# %%
df_esm_2 = df_session_counts[
df_session_counts["esm_session_count"] == 2
].reset_index().merge(df_esm_preprocessed, how="left", on=["participant_id", "device_id", "esm_session"])
with pd.option_context('display.max_rows', None, 'display.max_columns', None): # more options can be specified also
display(df_esm_2)
# %% [markdown] # %% [markdown]
# ### Long sessions # ### Long sessions
@ -208,7 +215,7 @@ df_session_counts.count()
# %% # %%
non_session = session_group_by.apply( non_session = session_group_by.apply(
lambda x: ( lambda x: (
(x.esm_user_answer == "DayFinished3421") | (x.esm_user_answer == "DayOff3421") (x.esm_user_answer == "DayFinished3421") | (x.esm_user_answer == "DayOff3421") | (x.esm_user_answer == "DayFinishedSetEvening")
).any() ).any()
) )
df_session_counts.loc[non_session, "session_response"] = "day_finished" df_session_counts.loc[non_session, "session_response"] = "day_finished"

View File

@ -89,8 +89,9 @@ def classify_sessions_adherence(df_esm_preprocessed: pd.DataFrame) -> pd.DataFra
non_session = sessions_grouped.apply( non_session = sessions_grouped.apply(
lambda x: ( lambda x: (
(x.esm_user_answer == "DayFinished3421") (x.esm_user_answer == "DayFinished3421") # I finished working for today.
| (x.esm_user_answer == "DayOff3421") | (x.esm_user_answer == "DayOff3421") # I am not going to work today.
| (x.esm_user_answer == "DayFinishedSetEvening") # When would you like to answer the evening EMA?
).any() ).any()
) )
df_session_counts.loc[non_session, "session_response"] = "day_finished" df_session_counts.loc[non_session, "session_response"] = "day_finished"