-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfsm.py
161 lines (132 loc) · 5.5 KB
/
fsm.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
161
from transitions.extensions import GraphMachine
from utils import send_text_message, send_image_message
import random
height = 175.8
weight = 89.7
bmi = 29.1
remind_data = [
"The weather is cold, put some more clothes to keep yourself warm.\nend of remind mode, please enter start",
"It's cold out, make sure you're warm.\nend of remind mode, please enter start",
"The weather is cold please much adds clothes.\nend of remind mode, please enter start",
"It's getting cold outside, keep yourself warm.\nend of remind mode, please enter start",
"The weather became cold, remembering more a clothes.\nend of remind mode, please enter start"
]
cheerup_data = [
"https://i.imgur.com/qAJQbJo.jpg",
"https://i.imgur.com/i07HQNi.jpg",
"https://i.imgur.com/b886Q2g.jpg",
"https://i.imgur.com/dtXebGA.jpg",
]
class TocMachine(GraphMachine):
def __init__(self, **machine_configs):
self.machine = GraphMachine(model=self, **machine_configs)
def is_going_to_start(self, event):
text = event.message.text
return text.lower() == "start"
def is_going_to_military(self, event):
text = event.message.text
return text.lower() == "military"
def is_going_to_female(self, event):
text = event.message.text
return text.lower() == "female"
def is_going_to_male(self, event):
text = event.message.text
return text.lower() == "male"
def is_going_to_tall(self, event):
text = event.message.text
height = float(text)
print(height)
return (height > 157 and height < 196)
def is_going_to_tall_ex(self, event):
text = event.message.text
height = float(text)
print(height)
return not(height > 157 and height < 196)
def is_going_to_Military_service(self, event):
text = event.message.text
weight = float(text)
print(weight)
bmi = weight / (height/100) / (height/100)
print(bmi)
return (bmi >= 17 and bmi <= 31)
def is_going_to_Alternative(self, event):
text = event.message.text
weight = float(text)
print(weight)
bmi = weight / (height/100) / (height/100)
print(bmi)
return ((bmi > 31 and bmi <= 31.5) or (bmi >= 16.5 and bmi < 17))
def is_going_to_Exemption(self, event):
text = event.message.text
weight = float(text)
print(weight)
bmi = weight / (height/100) / (height/100)
print(bmi)
return (bmi > 31.5 or bmi < 16.5)
def is_going_to_remind(self, event):
text = event.message.text
return text.lower() == "remind"
def is_going_to_cheerup(self, event):
text = event.message.text
return text.lower() == "cheerup"
# on enter function
def on_enter_start(self, event):
print("I'm entering start")
reply_token = event.reply_token
send_text_message(
reply_token, "Start! please choose the mode \n1. Enter military\n2. Enter remind\n3. Enter cheerup")
def on_enter_military(self, event):
print("I'm entering military")
reply_token = event.reply_token
send_text_message(
reply_token, "Welcome to the military mode!\nWhat's your gender? female/male")
def on_enter_female(self, event):
print("I'm entering female")
reply_token = event.reply_token
send_text_message(
reply_token, "CONGRATULATIONS!! You don't need to do the mandatory military service\nend of military mode, please enter start")
self.go_back()
def on_enter_male(self, event):
print("I'm entering male")
reply_token = event.reply_token
send_text_message(reply_token, "How tall are you?")
def on_enter_tall(self, event):
print("I'm entering tall")
reply_token = event.reply_token
send_text_message(reply_token, "What is your weight?")
def on_enter_tall_ex(self, event):
print("I'm entering tall_ex")
reply_token = event.reply_token
send_text_message(
reply_token, "CONGRATULATIONS!! You don't need to do the mandatory military service\nend of military mode, please enter start")
self.go_back()
def on_enter_Military_service(self, event):
print("I'm entering Military_service")
reply_token = event.reply_token
send_text_message(
reply_token, "OH NO!!! You should do the mandatory military service\nend of military mode, please enter start")
self.go_back()
def on_enter_Alternative(self, event):
print("I'm entering Alternative")
reply_token = event.reply_token
send_text_message(
reply_token, "OKAY! You should do the Alternative military service\nend of military mode, please enter start")
self.go_back()
def on_enter_Exemption(self, event):
print("I'm entering Exemption")
reply_token = event.reply_token
send_text_message(
reply_token, "CONGRATULATIONS!! You are exemption from military service\nend of military mode, please enter start")
self.go_back()
def on_enter_remind(self, event):
print("I'm entering remind")
reply_token = event.reply_token
send_text_message(
reply_token, remind_data[random.randint(0, 4)])
self.go_back()
def on_enter_cheerup(self, event):
print("I'm entering cheerup")
reply_token = event.reply_token
send_image_message(
reply_token, cheerup_data[random.randint(0, 3)])
self.go_back()