Skip to content

Commit 30bf505

Browse files
authored
Merge pull request #195 from PerfectFit-project/check-29-activity
check completion state of 29 activity
2 parents 8a4b56d + f1e989c commit 30bf505

File tree

2 files changed

+40
-3
lines changed

2 files changed

+40
-3
lines changed

scheduler/state_machine/controller.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from datetime import date, datetime, timedelta
44
from state_machine.state_machine_utils import (create_new_date, get_dialog_completion_state,
55
get_execution_week, get_intervention_component,
6+
get_activity_completion_state,
67
get_all_scheduled_occurrence,
78
get_last_component_state,
89
get_next_planned_date, get_next_scheduled_occurrence,
@@ -239,8 +240,9 @@ def on_new_day(self, current_date: date):
239240

240241
# at day 7 activity C2.9 has to be proposed
241242
start_date = get_start_date(self.user_id)
242-
ga_completed = get_dialog_completion_state(self.user_id, Components.GENERAL_ACTIVITY)
243-
if (current_date - start_date).days >= ACTIVITY_C2_9_DAY_TRIGGER and not ga_completed:
243+
choose_sport_completed = get_activity_completion_state(self.user_id, 29)
244+
if ((current_date - start_date).days >= ACTIVITY_C2_9_DAY_TRIGGER
245+
and not choose_sport_completed):
244246
plan_and_store(user_id=self.user_id,
245247
dialog=Components.GENERAL_ACTIVITY,
246248
phase_id=1)
@@ -332,7 +334,7 @@ def plan_execution_start_dialog(self):
332334
# this is the intro video to be sent the first time
333335
# the execution starts (not after lapse/relapse)
334336
quit_date = get_quit_date(self.user_id)
335-
planned_date = create_new_date(start_date=quit_date)
337+
planned_date = create_new_date(start_date=quit_date, minute=5)
336338

337339
plan_and_store(user_id=self.user_id,
338340
dialog=Components.EXECUTION_INTRODUCTION,

scheduler/state_machine/state_machine_utils.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from state_machine.const import (REDIS_URL, TIMEZONE, TRIGGER_COMPONENT,
77
SCHEDULE_TRIGGER_COMPONENT, TRIGGER_INTENT)
88
from virtual_coach_db.dbschema.models import (ClosedAnswers, DialogClosedAnswers, DialogQuestions,
9+
InterventionActivitiesPerformed,
910
InterventionComponents, InterventionPhases, Users,
1011
UserStateMachine, UserInterventionState)
1112
from virtual_coach_db.helper.definitions import Components, ComponentsTriggers, DialogQuestionsEnum
@@ -76,6 +77,40 @@ def create_new_date(start_date: date,
7677
return new_timedate
7778

7879

80+
def get_activity_completion_state(user_id: int, activity_id: int) -> Optional[bool]:
81+
"""
82+
Get the completion state of an intervention activity
83+
(they are completed in the general activity dialog)
84+
Args:
85+
user_id: the id of the user
86+
activity_id: id of the activity, as reported in the intervention_activity table
87+
88+
Returns: True if the activity has been completed, False otherwise
89+
90+
"""
91+
92+
session = get_db_session()
93+
94+
activities = (
95+
session.query(
96+
InterventionActivitiesPerformed
97+
)
98+
.filter(
99+
InterventionActivitiesPerformed.users_nicedayuid == user_id,
100+
InterventionActivitiesPerformed.intervention_activity_id == activity_id
101+
)
102+
.limit(1) # get only the first result
103+
.one_or_none()
104+
)
105+
106+
if activities is not None:
107+
session.close()
108+
return True
109+
110+
session.close()
111+
return False
112+
113+
79114
def get_all_scheduled_occurrence(user_id: int,
80115
intervention_component_id: int,
81116
current_date: datetime) -> Optional[UserInterventionState]:

0 commit comments

Comments
 (0)