-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathintents.py
160 lines (143 loc) · 4.03 KB
/
intents.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
import logging
import random
from flask_ask import Ask, statement, question, request, session
from settings import table
MOOD_QUESTION = 'On a scale from 1 to 5, how positive was your mood today?'
PRODUCTIVITY_QUESTION = 'On a scale from 1 to 5, how good was your productivity today?'
SLEEP_QUESTION = 'On a scale from 1 to 5, how well did you sleep?'
EXERCISE_QUESTION = 'Did you exercise today?'
ENTERTAINMENT_QUESTION = 'Did you consume any entertainment during the day?'
SCHOOLWORK_QUESTION = 'Was there any homework completed today?'
SOCIALIZE_QUESTION = 'Did you socialize with anyone today?'
CONFLICT_QUESTION = 'Did you get into a conflict with someone today?'
def _current_intent(state, response):
logging.critical("%d state", state)
if state == 0:
curr_intent = mood_intent(response)
elif state == 1:
curr_intent = productivity_intent(response)
elif state == 2:
curr_intent = sleep_intent(response)
elif state == 3:
curr_intent = exercise_intent(response)
elif state == 4:
curr_intent = entertainment_intent(response)
elif state == 5:
curr_intent = schoolwork_intent(response)
elif state == 6:
curr_intent = socialize_intent(response)
elif state == 7:
curr_intent = conflict_intent(response)
else:
curr_intent = end_session_and_save
return curr_intent
def end_session_and_save():
try:
data = session.attributes['data']
data.update({
'dayOfWeek': 'Monday',
'sleepWell': True,
'sessionID': "12313",
'userID': "123123",
'readingTS': '1:00'
})
table.put_item(Item=data)
except Exception as e:
logging.error(session.attributes['data'])
logging.error(e)
return statement("Your response have been saved!")
def _int_intent(general_level, next_question, error_question, reprompt_question, lower, upper, stat):
try:
general_level = int(general_level)
if general_level < lower or general_level > upper:
raise ValueError("Attribute out of range")
except Exception as e:
# lol
general_level = random.choice(range(1,6))
session.attributes['state'] += 1
session.attributes['data'][stat] = general_level
return lambda: question(next_question).reprompt(next_question)
def _bool_intent(boolean_level, next_question, error_question, reprompt_question, stat):
boolean = None
if str(boolean_level).lower() == 'true':
boolean = True
elif str(boolean_level).lower() == 'false':
boolean = False
else:
# lol
boolean = random.choice([True, False])
session.attributes['state'] += 1
session.attributes['data'][stat] = boolean
if session.attributes['state'] > 7:
return end_session_and_save
return lambda: question(next_question).reprompt(next_question)
def mood_intent(mood_level):
return _int_intent(
mood_level,
PRODUCTIVITY_QUESTION,
"From 1 to 5, how was your mood today?",
MOOD_QUESTION,
1,
5,
'mood'
)
def productivity_intent(productivity_level):
return _int_intent(
productivity_level,
SLEEP_QUESTION,
"Please give a number between 1 and 5 for your productivity",
PRODUCTIVITY_QUESTION,
1,
5,
'productivity'
)
def sleep_intent(sleep_level):
return _int_intent(
sleep_level,
EXERCISE_QUESTION,
"From 1 to 5, how well did you sleep today?",
SLEEP_QUESTION,
1,
24,
'sleepHrs'
)
def exercise_intent(exercise_level):
return _bool_intent(
exercise_level,
ENTERTAINMENT_QUESTION,
"Did you exercise today?",
EXERCISE_QUESTION,
'exercise'
)
def entertainment_intent(entertainment):
return _bool_intent(
entertainment,
SCHOOLWORK_QUESTION,
"Did you consume any entertainment?",
ENTERTAINMENT_QUESTION,
'entertainment'
)
def schoolwork_intent(school):
return _bool_intent(
school,
SOCIALIZE_QUESTION,
"Was any school work done?",
SCHOOLWORK_QUESTION,
'schoolwork'
)
def socialize_intent(socialize):
return _bool_intent(
socialize,
CONFLICT_QUESTION,
"Did you socialized with anyone today?",
SOCIALIZE_QUESTION,
'socialized'
)
def conflict_intent(conflict):
return _bool_intent(
conflict,
'DONE',
"Did you get into a conflict with another student, friend, or family member today?",
CONFLICT_QUESTION,
'conflict'
)