Only convert some answers to numeric.

communication
junos 2021-07-04 14:34:13 +02:00
parent 3bb66e3838
commit 92a5787d62
3 changed files with 18 additions and 3 deletions

View File

@ -232,6 +232,17 @@ class ESM(Base, AWAREsensor):
esm_session = Column(Integer, nullable=False) esm_session = Column(Integer, nullable=False)
esm_notification_id = Column(Integer, nullable=False) esm_notification_id = Column(Integer, nullable=False)
esm_expiration_threshold = Column(SmallInteger) esm_expiration_threshold = Column(SmallInteger)
ESM_TYPE = {'text': 1,
'radio': 2,
'checkbox': 3,
'likert': 4,
'quick_answers': 5,
'scale': 6,
'datetime': 7,
'pam': 8,
'number': 9,
'web': 10,
'date': 11}
class Imperfection(Base): class Imperfection(Base):

View File

@ -184,7 +184,7 @@ import numpy as np
df_session_counts = pd.DataFrame(session_counts_device).rename( df_session_counts = pd.DataFrame(session_counts_device).rename(
columns={"id": "esm_session_count"} columns={"id": "esm_session_count"}
) )
df_session_counts["session_response"] = np.NaN df_session_counts["session_response"] = np.nan
session_group_by = df_esm_preprocessed.groupby( session_group_by = df_esm_preprocessed.groupby(
["participant_id", "device_id", "esm_session"] ["participant_id", "device_id", "esm_session"]
) )

View File

@ -116,7 +116,7 @@ def classify_sessions_by_completion(df_esm_preprocessed: pd.DataFrame) -> pd.Dat
df_session_counts = pd.DataFrame(sessions_grouped.count()["id"]).rename( df_session_counts = pd.DataFrame(sessions_grouped.count()["id"]).rename(
columns={"id": "esm_session_count"} columns={"id": "esm_session_count"}
) )
df_session_counts["session_response"] = np.NaN df_session_counts["session_response"] = np.nan
# 1. Identify all ESMs with status other than answered. # 1. Identify all ESMs with status other than answered.
esm_not_answered = sessions_grouped.apply( esm_not_answered = sessions_grouped.apply(
@ -249,7 +249,11 @@ def clean_up_esm(df_esm_preprocessed: pd.DataFrame) -> pd.DataFrame:
[ANSWER_DAY_FINISHED, ANSWER_DAY_OFF, ANSWER_SET_EVENING] [ANSWER_DAY_FINISHED, ANSWER_DAY_OFF, ANSWER_SET_EVENING]
) )
] ]
df_esm_clean = df_esm_clean.assign( df_esm_clean["esm_user_answer_numeric"] = np.nan
esm_type_numeric = [ESM.ESM_TYPE.get("radio"),
ESM.ESM_TYPE.get("scale"),
ESM.ESM_TYPE.get("number")]
df_esm_clean[df_esm_clean["esm_type"].isin(esm_type_numeric)] = df_esm_clean[df_esm_clean["esm_type"].isin(esm_type_numeric)].assign(
esm_user_answer_numeric=lambda x: x.esm_user_answer.str.slice(stop=1).astype( esm_user_answer_numeric=lambda x: x.esm_user_answer.str.slice(stop=1).astype(
int int
) )