Detect whether event was work related.
parent
c4f7b6459d
commit
0f5af21f71
|
@ -47,6 +47,15 @@ def extract_stressful_events(df_esm: pd.DataFrame) -> pd.DataFrame:
|
|||
)
|
||||
|
||||
# 3.
|
||||
df_esm_event_work_related = detect_event_work_related(df_esm_sam_clean)
|
||||
|
||||
df_esm_events = df_esm_events.join(
|
||||
df_esm_event_work_related[
|
||||
GROUP_QUESTIONNAIRES_BY.append("event_work_related")
|
||||
].set_index(GROUP_QUESTIONNAIRES_BY)
|
||||
)
|
||||
|
||||
# 4.
|
||||
df_esm_event_time = convert_event_time(df_esm_sam_clean)
|
||||
|
||||
df_esm_events = df_esm_events.join(
|
||||
|
@ -55,7 +64,7 @@ def extract_stressful_events(df_esm: pd.DataFrame) -> pd.DataFrame:
|
|||
)
|
||||
)
|
||||
|
||||
# 4.
|
||||
# 5.
|
||||
df_esm_event_duration = extract_event_duration(df_esm_sam_clean)
|
||||
|
||||
df_esm_events = df_esm_events.join(
|
||||
|
@ -118,6 +127,17 @@ def detect_stressful_event(df_esm_sam_clean: pd.DataFrame) -> pd.DataFrame:
|
|||
return df_esm_event_stress
|
||||
|
||||
|
||||
def detect_event_work_related(df_esm_sam_clean: pd.DataFrame) -> pd.DataFrame:
|
||||
df_esm_event_stress = df_esm_sam_clean[
|
||||
df_esm_sam_clean["questionnaire_id"]
|
||||
== QUESTIONNAIRE_ID_SAM.get("event_work_related")
|
||||
]
|
||||
df_esm_event_stress = df_esm_event_stress.assign(
|
||||
event_work_related=lambda x: x.esm_user_answer_numeric > 0
|
||||
)
|
||||
return df_esm_event_stress
|
||||
|
||||
|
||||
def convert_event_time(df_esm_sam_clean: pd.DataFrame) -> pd.DataFrame:
|
||||
df_esm_event_time = df_esm_sam_clean[
|
||||
df_esm_sam_clean["questionnaire_id"] == QUESTIONNAIRE_ID_SAM.get("event_time")
|
||||
|
@ -151,9 +171,7 @@ def extract_event_duration(df_esm_sam_clean: pd.DataFrame) -> pd.DataFrame:
|
|||
df_esm_event_duration[
|
||||
df_esm_event_duration.event_duration.isna()
|
||||
] = df_esm_event_duration[df_esm_event_duration.event_duration.isna()].assign(
|
||||
event_duration_info=lambda x: x.esm_user_answer.str.slice(stop=1).astype(
|
||||
int
|
||||
)
|
||||
event_duration_info=lambda x: x.esm_user_answer.str.slice(stop=1).astype(int)
|
||||
)
|
||||
|
||||
return df_esm_event_duration
|
||||
|
|
Loading…
Reference in New Issue