-
Notifications
You must be signed in to change notification settings - Fork 0
/
behaviour_exercise.py
251 lines (188 loc) · 6.16 KB
/
behaviour_exercise.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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
import numpy as np
import time
from array import *
''''
In this file we realaborate from the input received by the user hopw to behave kubo in the gym.
Basically we try to map any situation to a number and call the proper function.
We separated the speed in 3 ranges, so we have:
- low speed, when the speed is lowere than low_speed_limit
- medium spedd, when the speed is bounded between low_speed_limit and high_speed_limit
- high speed when it is higher than high_speed_limit
WUsing the same logic we create two group for the weight:
- low weight, when it is lower than low_weight_limit
- high weight, when it is higher than the low_weight_limit
another information received from the user is the type of motivation he prefers, we divide the users in two main groups,
- intrinsic
- extrinsic
we get this information by some survey based on the type of user we have kubo play different sounds...
all this variable for now are set as static but of course they dipende by the user's history during his exercises.
'''
low_speed_limit = 0.2
high_speed_limit = 0.25
low_weight_limit = 20
repetition_counter = 3
num_speed = 3 # number of total renges for the speed we have low - medium - high, in total are 3 for the moment
num_weight = 2
num_weightspeed_combination = num_speed*num_weight
counter = array('b', [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) # array which count how many repetition with the same speed and same weight are executed by the user
class Behaviour_exercise(object):
def __init__(self, kubo):
self.speed = 0
self.weight = 0
self.motivation = 1
self.relax = 0
self.message_flag = 0
self.kubo = kubo
def get_message_flag(self):
return self.message_flag
def set_speed(self, value):
self.speed = value
def set_weight(self, value):
self.weight = value
def set_motivation(self, value):
self.motivation = value
def set_relax(self,value):
self.relax = value
def get_speed(self):
return self.speed
def get_weight(self):
return self.weight
def get_motivation(self):
return self.motivation
def get_relax(self):
return self.relax
def set_message_flag(self):
self.message_flag = 1
def reset_message_flag(self):
self.message_flag = 0
#from_parametrs_to_number:
#map the different value of the states into a integer value bounded between 0 and (num_speed*num_weight*num_motivation - 1)
def from_parameters_to_number(self):
if (self.get_speed() < low_speed_limit):
parameter_speed = 0
elif (self.get_speed() > high_speed_limit):
parameter_speed = 2
else:
parameter_speed = 1
if (self.get_weight() < low_weight_limit):
parameter_weight = 0
else:
parameter_weight = 1
if (self.get_relax()==1):
count_len = int(len(counter))
return count_len + self.get_motivation()
else:
print 'parameter weight: ', parameter_weight
print 'parameter speed: ', parameter_speed
print 'speed: ', self.get_speed()
number = (parameter_weight * num_speed + parameter_speed) + (self.get_motivation() * num_weightspeed_combination)
return number
'''
update_behaviour_exercise
call the proper function related with the actual situation of the exercise
'''
def update_behaviour_exercise(self):
switcher = {
0: intr_lowweight_lowspeed,
1: intr_lowweight_medspeed,
2: intr_lowweight_highspeed,
3: intr_highweight_lowspeed,
4: intr_highweight_medspeed,
5: intr_highweight_highspeed,
6: extr_lowweight_lowspeed,
7: extr_lowweight_medspeed,
8: extr_lowweight_highspeed,
9: extr_highweight_lowspeed,
10: extr_highweight_medspeed,
11: extr_highweight_highspeed,
12: intr_relax,
13: extr_relax,
} # Get the function from switcher dictionary
status = self.from_parameters_to_number()
self.reset_message_flag()
update_counter(status)
func = switcher.get(status, lambda: "nothing")
print "func: ", func
return func(status,self)
# List of function for the different situation
def intr_lowweight_lowspeed(status, be):
print "status: ", status
if (counter[status] == repetition_counter):
be.kubo.say('i_l_l.mp3')
be.set_message_flag()
return
def intr_lowweight_medspeed(status, be):
if (counter[status] == repetition_counter):
be.kubo.say('i_l_m.mp3')
be.set_message_flag()
return
def intr_lowweight_highspeed(status, be):
if (counter[status] == repetition_counter):
be.kubo.say('i_l_h.mp3')
be.set_message_flag()
return
def intr_highweight_lowspeed(status, be):
if (counter[status] == repetition_counter):
be.kubo.say('i_h_l.mp3')
be.set_message_flag()
return
def intr_highweight_medspeed(status, be):
if (counter[status] == repetition_counter):
be.kubo.say('i_h_m.mp3')
be.set_message_flag()
return
def intr_highweight_highspeed(status, be):
if (counter[status] == repetition_counter):
be.kubo.say('i_h_h.mp3')
be.set_message_flag()
return
def extr_lowweight_lowspeed(status, be):
if (counter[status] == repetition_counter):
be.kubo.say('e_l_l.mp3')
be.set_message_flag()
return
def extr_lowweight_medspeed(status, be):
if (counter[status] == repetition_counter):
be.kubo.say('e_l_m.mp3')
be.set_message_flag()
return
def extr_lowweight_highspeed(status, be):
if (counter[status] == repetition_counter):
be.kubo.say('e_l_h.mp3')
be.set_message_flag()
return
def extr_highweight_lowspeed(status, be):
if (counter[status] == repetition_counter):
be.kubo.say('e_h_l.mp3')
be.set_message_flag()
return
def extr_highweight_medspeed(status, be):
if (counter[status] == repetition_counter):
be.kubo.say('e_h_m.mp3')
return
def extr_highweight_highspeed(status, be):
if (counter[status] == repetition_counter):
be.kubo.say('e_h_h.mp3')
be.set_message_flag()
return
def extr_relax(status, be):
be.kubo.say('i_relax.mp3')
be.set_message_flag()
return
def intr_relax(status, be):
be.kubo.say('i_relax.mp3')
be.set_message_flag()
return
'''
Everytime the trainer conclude a repetition of the exercise we update the counter array
after three times he repeat the same exercise 3 times Kubo react give some suggestions to the user
'''
def update_counter(status):
i = 0
while (i < len(counter)):
if (i == status):
counter[status] = counter[status] + 1
else:
counter[i] = 0
i=i+1
return