Fix formatting.

communication
junos 2021-07-04 14:34:57 +02:00
parent 92a5787d62
commit 48d7be780c
4 changed files with 65 additions and 20 deletions

View File

@ -232,17 +232,19 @@ class ESM(Base, AWAREsensor):
esm_session = Column(Integer, nullable=False)
esm_notification_id = Column(Integer, nullable=False)
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}
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):

View File

@ -49,8 +49,7 @@ df_esm_PANAS_clean = clean_up_esm(df_esm_PANAS)
# %%
df_esm_PANAS_daily_means = (
df_esm_PANAS_clean.groupby(
["participant_id", "date_lj", "questionnaire_id"])
df_esm_PANAS_clean.groupby(["participant_id", "date_lj", "questionnaire_id"])
.esm_user_answer_numeric.agg("mean")
.reset_index()
.rename(columns={"esm_user_answer_numeric": "esm_numeric_mean"})
@ -81,7 +80,10 @@ sns.displot(
# %%
sns.displot(
data=df_esm_PANAS_summary_participant, x="median", hue="PANAS_subscale", binwidth=0.2
data=df_esm_PANAS_summary_participant,
x="median",
hue="PANAS_subscale",
binwidth=0.2,
)
# %%
@ -91,3 +93,31 @@ sns.displot(
# %%
df_esm_PANAS_summary_participant[df_esm_PANAS_summary_participant["std"] < 0.1]
# %% [markdown]
# # Stress appraisal measure
# %%
df_esm_SAM = df_esm_preprocessed[
(df_esm_preprocessed["questionnaire_id"] >= 87)
& (df_esm_preprocessed["questionnaire_id"] <= 93)
]
# %%
clean_up_esm(df_esm_SAM)[["esm_user_answer", "esm_user_answer_numeric"]].head(9)
# %%
df_esm_PANAS_clean[["esm_user_answer", "esm_user_answer_numeric"]].head(n=10)
# %%
df_esm_SAM[
[
"esm_instructions",
"question_id",
"questionnaire_id",
"esm_user_answer",
"esm_type",
]
].head(n=10)
# %%

View File

@ -250,10 +250,14 @@ def clean_up_esm(df_esm_preprocessed: pd.DataFrame) -> pd.DataFrame:
)
]
df_esm_clean["esm_user_answer_numeric"] = np.nan
esm_type_numeric = [ESM.ESM_TYPE.get("radio"),
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.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(
int
)

View File

@ -242,8 +242,17 @@ df_session_workday[df_session_workday.time_diff_minutes < 30]
# %%
df_esm_preprocessed.loc[
(df_esm_preprocessed.participant_id == 35) & (df_esm_preprocessed.esm_session == 7) & (df_esm_preprocessed.device_id == "62a44038-3ccb-401e-a69c-6f22152c54a6"),
["esm_trigger", "esm_session", "datetime_lj", "esm_instructions", "device_id", "_id"],
(df_esm_preprocessed.participant_id == 35)
& (df_esm_preprocessed.esm_session == 7)
& (df_esm_preprocessed.device_id == "62a44038-3ccb-401e-a69c-6f22152c54a6"),
[
"esm_trigger",
"esm_session",
"datetime_lj",
"esm_instructions",
"device_id",
"_id",
],
]
# %%