Skip to content

Commit

Permalink
Merge pull request #136 from PerfectFit-project/403-remove-hrs-prepar…
Browse files Browse the repository at this point in the history
…ation

403 remove hrs preparation
  • Loading branch information
wbaccinelli authored Jul 31, 2023
2 parents 22c3fbc + 5ba7823 commit aba942b
Show file tree
Hide file tree
Showing 8 changed files with 128 additions and 171 deletions.
69 changes: 54 additions & 15 deletions Rasa_Bot/actions/actions_idle_commands.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
from celery import Celery
from rasa_sdk import Action
from .helper import dialog_to_be_completed, get_dialog_completion_state
from rasa_sdk.events import FollowupAction

from .helper import dialog_to_be_completed,get_current_user_phase, get_dialog_completion_state
from virtual_coach_db.helper.definitions import Components
from .definitions import REDIS_URL
from .definitions import REDIS_URL, FsmStates

celery = Celery(broker=REDIS_URL)

Expand All @@ -16,7 +18,14 @@ def name(self):
async def run(self, dispatcher, tracker, domain):
user_id = tracker.current_state()['sender_id']

celery.send_task('celery_tasks.user_trigger_dialog', (user_id, Components.RELAPSE_DIALOG))
phase = get_current_user_phase(user_id)

# check if the dialog can be executed (the use is in the execution phase)
if phase != FsmStates.EXECUTION_RUN:
return [FollowupAction('utter_help_not_available')]

celery.send_task('celery_tasks.user_trigger_dialog',
(user_id, Components.RELAPSE_DIALOG))


class ActionTriggerFirstAidDialog(Action):
Expand All @@ -28,7 +37,14 @@ def name(self):
async def run(self, dispatcher, tracker, domain):
user_id = tracker.current_state()['sender_id']

celery.send_task('celery_tasks.user_trigger_dialog', (user_id, Components.FIRST_AID_KIT))
ehbo_enabled = get_dialog_completion_state(user_id, Components.FIRST_AID_KIT_VIDEO)
# if the first aid kit is available, trigger it
if ehbo_enabled:
celery.send_task('celery_tasks.user_trigger_dialog',
(user_id, Components.FIRST_AID_KIT))
# if the first aid kit is not yet available, show the menu
else:
return[FollowupAction('utter_ehbo_not_available')]


class ActionTriggerExplainFirstAidVideoDialog(Action):
Expand All @@ -40,8 +56,14 @@ def name(self):
async def run(self, dispatcher, tracker, domain):
user_id = tracker.current_state()['sender_id']

celery.send_task('celery_tasks.user_trigger_dialog', (user_id,
Components.FIRST_AID_KIT_VIDEO))
ehbo_enabled = get_dialog_completion_state(user_id, Components.FIRST_AID_KIT_VIDEO)
# if the first aid kit is available, trigger it
if ehbo_enabled:
celery.send_task('celery_tasks.user_trigger_dialog',
(user_id, Components.FIRST_AID_KIT_VIDEO))
# if the first aid kit is not yet available, show the menu
else:
return [FollowupAction('utter_ehbo_not_available')]


class ActionTriggerGeneralActivityDialog(Action):
Expand Down Expand Up @@ -83,14 +105,32 @@ async def run(self, dispatcher, tracker, domain):
# is the ehbo option to be shown (the explanatory video has been shown)
show_ehbo = get_dialog_completion_state(user_id, Components.FIRST_AID_KIT_VIDEO)

if complete_dialog and show_ehbo:
dispatcher.utter_message(response="utter_central_mode_options")
elif not complete_dialog and show_ehbo:
dispatcher.utter_message(response="utter_central_mode_options_without_verder")
elif complete_dialog and not show_ehbo:
dispatcher.utter_message(response="utter_central_mode_options_no_ehbo")
# the help command is shown just in the execution
phase = get_current_user_phase(user_id)

if phase != FsmStates.EXECUTION_RUN:
show_help = False
else:
dispatcher.utter_message(response="utter_central_mode_options_without_verder_no_ehbo")
show_help = True

# select the utterances

# show the verder command
if complete_dialog:
dispatcher.utter_message(response="utter_central_mode_options_verder")
# show the help command
if show_help:
dispatcher.utter_message(response="utter_central_mode_options_help")
# show the ehbo command
if show_ehbo:
dispatcher.utter_message(response="utter_central_mode_options_ehbo")

# show the exercise command
dispatcher.utter_message(response="utter_central_mode_options_oefening")
# show the medication video command
dispatcher.utter_message(response="utter_central_mode_options_medicatie")
# show the last general statement
dispatcher.utter_message(response="utter_central_mode_options_outro")


class ActionTriggerUncompletedDialog(Action):
Expand All @@ -107,5 +147,4 @@ async def run(self, dispatcher, tracker, domain):
celery.send_task('celery_tasks.user_trigger_dialog',
(user_id, Components.CONTINUE_UNCOMPLETED_DIALOG))
else:
dispatcher.utter_message(response="utter_no_valid_uncompleted_dialog")
dispatcher.utter_message(response="utter_central_mode_options_without_verder")
return [FollowupAction('utter_no_valid_uncompleted_dialog')]
39 changes: 0 additions & 39 deletions Rasa_Bot/data/rules/rules.yml

This file was deleted.

50 changes: 24 additions & 26 deletions Rasa_Bot/data/rules/rules_idle_commands.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,30 @@ rules:
- action: action_select_menu
- action: action_end_dialog

- rule: trigger the menu options externally
steps:
- intent: EXTERNAL_central_options
- action: action_select_menu
- action: action_end_dialog

- rule: trigger the menu options if ehbo is not available
steps:
- action: utter_ehbo_not_available
- action: action_select_menu
- action: action_end_dialog

- rule: trigger the menu options if verder not available
steps:
- action: utter_no_valid_uncompleted_dialog
- action: action_select_menu
- action: action_end_dialog

- rule: trigger the menu options if hrs not available
steps:
- action: utter_help_not_available
- action: action_select_menu
- action: action_end_dialog

- rule: help command
steps:
- intent: help_intent
Expand Down Expand Up @@ -39,29 +63,3 @@ rules:
steps:
- intent: continue_dialog_intent
- action: action_trigger_uncompleted_dialog

- rule: central mode with all options
steps:
- intent: EXTERNAL_central_options
- action: utter_central_mode_options
- action: action_end_dialog

- rule: central mode without ehbo
steps:
- intent: EXTERNAL_central_options_no_ehbo
- action: utter_central_mode_options_no_ehbo
- action: action_end_dialog

- rule: no valid uncompleted dialog with ehbo
steps:
- intent: EXTERNAL_no_valid_uncompleted_dialog
- action: utter_no_valid_uncompleted_dialog
- action: utter_central_mode_options_without_verder
- action: action_end_dialog

- rule: no valid uncompleted dialog without ehbo
steps:
- intent: EXTERNAL_no_valid_uncompleted_dialog_no_ehbo
- action: utter_no_valid_uncompleted_dialog
- action: utter_central_mode_options_without_verder_no_ehbo
- action: action_end_dialog
77 changes: 23 additions & 54 deletions Rasa_Bot/domain/domain_common.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,61 +39,30 @@ responses:
utter_file_sent:
- text: "Here is your file"

# We present the user with the options from the central mode
utter_central_mode_options:
- text: "Typ 'help' als je zin hebt om te roken, hebt gerookt of het lastig vindt om in beweging te komen. ✋🏽
\n\n
Typ 'ehbo' als je je EHBO-doos wilt openen om een bewaarde oefening te bekijken of opnieuw te doen. 🧰
Wil je opnieuw uitleg over hoe de EHBO-doos werkt? Typ dan 'uitleg'. ℹ️
\n\n
Typ 'oefening' als je een oefening wilt doen. 📱
\n\n
Typ 'medicatie' om de video over nicotinevervangende middelen en medicatie opnieuw te bekijken. 💊
\n\n
Typ 'verder' om een onafgemaakte dialoog af te ronden. ✔
\n\n
Heb je behoefte om iemand te spreken? Je kunt altijd een afspraak maken met je huisarts. 🩺
Je kunt ook altijd bellen met de gratis Stoppen met roken telefoonlijn (0800-1995).📞
De Stoplijn is van maandag t/m vrijdag bereikbaar van 9 tot 17 uur."
utter_central_mode_options_help:
- text: "Typ 'help' als je zin hebt om te roken, hebt gerookt of het lastig vindt om in beweging te komen. ✋🏽"

# We present the user with the options from the central mode when the ehbo is not available
utter_central_mode_options_no_ehbo:
- text: "Typ 'help' als je zin hebt om te roken, hebt gerookt of het lastig vindt om in beweging te komen. ✋🏽
\n\n
Typ 'oefening' als je een oefening wilt doen. 📱
\n\n
Typ 'medicatie' om de video over nicotinevervangende middelen en medicatie opnieuw te bekijken. 💊
\n\n
Typ 'verder' om een onafgemaakte dialoog af te ronden. ✔
\n\n
Heb je behoefte om iemand te spreken? Je kunt altijd een afspraak maken met je huisarts. 🩺
Je kunt ook altijd bellen met de gratis Stoppen met roken telefoonlijn (0800-1995).📞
De Stoplijn is van maandag t/m vrijdag bereikbaar van 9 tot 17 uur."

# Print this when there is no uncompleted dialog to finish after informing the user
# that there is none (i.e., do not mention the "verder"-option again then)
utter_central_mode_options_without_verder:
- text: "Typ 'help' als je zin hebt om te roken, hebt gerookt of het lastig vindt om in beweging te komen. ✋🏽
\n\n
Typ 'ehbo' als je je EHBO-doos wilt openen om een bewaarde oefening te bekijken of opnieuw te doen. 🧰
Wil je opnieuw uitleg over hoe de EHBO-doos werkt? Typ dan 'uitleg'. ℹ️
\n\n
Typ 'oefening' als je een oefening wilt doen. 📱
\n\n
Typ 'medicatie' om de video over nicotinevervangende middelen en medicatie opnieuw te bekijken. 💊
\n\n
Heb je behoefte om iemand te spreken? Je kunt altijd een afspraak maken met je huisarts. 🩺
Je kunt ook altijd bellen met de gratis Stoppen met roken telefoonlijn (0800-1995).📞
De Stoplijn is van maandag t/m vrijdag bereikbaar van 9 tot 17 uur."
utter_central_mode_options_ehbo:
- text: "Typ 'ehbo' als je je EHBO-doos wilt openen om een bewaarde oefening te bekijken of opnieuw te doen. 🧰
Wil je opnieuw uitleg over hoe de EHBO-doos werkt? Typ dan 'uitleg'. ℹ"

# Print this when there is no uncompleted dialog to finish and the ehbo is not yet active
utter_central_mode_options_without_verder_no_ehbo:
- text: "Typ 'help' als je zin hebt om te roken, hebt gerookt of het lastig vindt om in beweging te komen. ✋🏽
\n\n
Typ 'oefening' als je een oefening wilt doen. 📱
\n\n
Typ 'medicatie' om de video over nicotinevervangende middelen en medicatie opnieuw te bekijken. 💊
\n\n
Heb je behoefte om iemand te spreken? Je kunt altijd een afspraak maken met je huisarts. 🩺
utter_central_mode_options_oefening:
- text: "Typ 'oefening' als je een oefening wilt doen. 📱"

utter_central_mode_options_medicatie:
- text: "Typ 'medicatie' om de video over nicotinevervangende middelen en medicatie opnieuw te bekijken. 💊"

utter_central_mode_options_verder:
- text: "Typ 'verder' om een onafgemaakte dialoog af te ronden. ✔"

utter_central_mode_options_outro:
- text: "Heb je behoefte om iemand te spreken? Je kunt altijd een afspraak maken met je huisarts. 🩺
Je kunt ook altijd bellen met de gratis Stoppen met roken telefoonlijn (0800-1995).📞
De Stoplijn is van maandag t/m vrijdag bereikbaar van 9 tot 17 uur."

utter_help_not_available:
- text: "Je bent nu in de voorbereidingsfase. Je kunt ‘help’ gebruiken tijdens de uitvoeringsfase."


utter_ehbo_not_available:
- text: "Je bent nu in de voorbereidingsfase. Je kunt 'ehbo' gebruiken tijdens de uitvoeringsfase."
2 changes: 1 addition & 1 deletion Rasa_Bot/domain/domain_idle_commands.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ responses:
# For low next action confidence, "utter_default" is automatically called.
# For low NLU confidence, we have defined a rule.
utter_default:
- text: "Sorry, ik begrijp (nog) niet wat je bedoelt, kun je me het op een andere manier duidelijk maken?"
- text: "Goed om van je te horen! Er zijn verschillende dingen die je kunt doen:"

# There is no valid uncompleted dialog
utter_no_valid_uncompleted_dialog:
Expand Down
Binary file not shown.
34 changes: 18 additions & 16 deletions scheduler/state_machine/controller.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import logging
from celery import Celery
from datetime import date, datetime, timedelta
from state_machine.state_machine_utils import (create_new_date, dialog_to_be_completed,
get_dialog_completion_state,
from state_machine.state_machine_utils import (create_new_date, get_dialog_completion_state,
get_execution_week, get_intervention_component,
get_next_planned_date, get_next_scheduled_occurrence,
get_quit_date, get_pa_group, get_start_date,
Expand Down Expand Up @@ -91,15 +90,13 @@ def on_dialog_rescheduled(self, dialog, new_date):
phase=1)

def on_user_trigger(self, dialog):
if dialog in (Components.FIRST_AID_KIT, dialog == Components.FIRST_AID_KIT_VIDEO):
if dialog in (Components.FIRST_AID_KIT,
Components.FIRST_AID_KIT_VIDEO,
Components.RELAPSE_DIALOG):
# dialog not available in this phase
if dialog_to_be_completed(self.user_id) is None:
complete = False
else:
complete = True
run_option_menu(user_id=self.user_id, ehbo=False, complete_dialog=complete)
run_option_menu(user_id=self.user_id)
elif dialog == Components.CONTINUE_UNCOMPLETED_DIALOG:
run_uncompleted_dialog(self.user_id, show_ehbo=False)
run_uncompleted_dialog(self.user_id)
else:
plan_and_store(user_id=self.user_id,
dialog=dialog,
Expand Down Expand Up @@ -178,13 +175,12 @@ def on_user_trigger(self, dialog):
and not get_dialog_completion_state(self.user_id, Components.FIRST_AID_KIT_VIDEO):
# if the introductory video of the first aid kit has not been executed,
# the first aid kit cannot be executed
if dialog_to_be_completed(self.user_id) is None:
complete = False
else:
complete = True
run_option_menu(self.user_id, ehbo=False, complete_dialog=complete)
run_option_menu(self.user_id)
elif dialog == Components.RELAPSE_DIALOG:
# the relapse dialog is not available in this phase
run_option_menu(self.user_id)
elif dialog == Components.CONTINUE_UNCOMPLETED_DIALOG:
run_uncompleted_dialog(self.user_id, show_ehbo=False)
run_uncompleted_dialog(self.user_id)
else:
plan_and_store(user_id=self.user_id,
dialog=dialog,
Expand Down Expand Up @@ -254,9 +250,12 @@ def on_dialog_rescheduled(self, dialog, new_date):
phase=1)

def on_user_trigger(self, dialog):
# in this phase a dialog can be continued
# the relapse dialog is not available in this phase
if dialog == Components.CONTINUE_UNCOMPLETED_DIALOG:
run_uncompleted_dialog(self.user_id)
# in this phase a dialog can be continued
elif dialog == Components.RELAPSE_DIALOG:
run_option_menu(self.user_id)
else:
plan_and_store(user_id=self.user_id,
dialog=dialog,
Expand Down Expand Up @@ -365,6 +364,9 @@ def on_new_day(self, current_date: date):
def on_user_trigger(self, dialog: str):
if dialog == Components.CONTINUE_UNCOMPLETED_DIALOG:
run_uncompleted_dialog(self.user_id)
# the relapse dialog is not available in this phase
elif dialog == Components.RELAPSE_DIALOG:
run_option_menu(self.user_id)
else:
plan_and_store(user_id=self.user_id,
dialog=dialog,
Expand Down
Loading

0 comments on commit aba942b

Please sign in to comment.