-
Notifications
You must be signed in to change notification settings - Fork 3
/
sb_poc.py
334 lines (319 loc) · 12.3 KB
/
sb_poc.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
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
import gc
import time
from microbit import display, Image, pin_logo, button_a, button_b
from music import play, POWER_UP
from speech import say
# Parts of a cell educational database
poc_ted = {
'nucleus': 'The nucleus controls the cell\'s operations.',
'cell membrane': 'The cell membrane controls what comes into and out of the cell.',
'cytoplasm': 'Cytoplasm is the fluid inside a cell surrounding the nucleus.',
'cell wall': 'A cell wall is a rigid layer outside of the plasma membrane.',
'central vacuole': 'A central vacuole is a watery fluid that maintains the life of a cell.',
'endoplasmic reticulum': 'Endoplasmic reticulum is the transportation system of a cell.',
'ribosome': 'A ribosome produces proteins with ribonucleic acid.',
'golgi body': 'A golgi body packages proteins into vesicles.',
'lysosome': 'A lysosome contains digestive enzymes.',
'chloroplast': 'A chloroplast makes energy for a cell.',
'mitochondria': 'Mitochondria provides energy that cells need to divide, move and contract.',
'cytoskeleton': 'A cytoskeleton is in animals only and is used for support.',
'centrioles': 'Centrioles helps in cell division in animals.'
}
# Parts of a cell talking educational fill in the blank quiz database
poc_teq_f = {
'What controls the cell\'s operations?': 'nucleus',
'What controls what comes into and out of the cell?': 'cell membrane',
'What is the fluid inside a cell surrounding the nucleus?': 'cytoplasm',
'What is a rigid layer outside of the plasma membrane?': 'cell wall',
'What is a watery fluid that maintains the life of a cell?': 'central vacuole',
'What produces proteins with ribonucleic acid?': 'ribosome',
'What contains digestive enzymes?': 'lysosome',
'What makes energy for a cell?': 'chloroplast',
'What is in animals only and is used for support?': 'cytoskeleton',
'What helps in cell division in animals?': 'centrioles'
}
# Parts of a cell talking educational multiple choice quiz database
poc_teq_m = {
'What controls the cell\'s operations?':
[
'nucleus',
'ribosome',
'lysosome',
0
],
'What controls what comes into and out of the cell?':
[
'cytoplasm',
'cell membrane',
'cytoskeleton',
1
],
'What is the fluid inside a cell surrounding the nucleus?':
[
'central vacuole',
'centrioles',
'cytoplasm',
2
],
'What is a rigid layer outside of the plasma membrane?':
[
'cell wall',
'cytoskeleton',
'cell membrane',
0
],
'What is a watery fluid that maintains the life of a cell?':
[
'chloroplast',
'central vacuole',
'chloroplast',
1
],
'What produces proteins with ribonucleic acid?':
[
'lysosome',
'centrioles',
'ribosome',
2
],
'What contains digestive enzymes?':
[
'lysosome',
'nucleus',
'chloroplast',
0
],
'What makes energy for a cell?':
[
'ribosome',
'chloroplast',
'cytoplasm',
1
],
'What is in animals only and is used for support?':
[
'cytoskeleton',
'cell wall',
'cell membrane',
0
],
'What helps in cell division in animals?':
[
'central vacuole',
'chloroplast',
'centrioles',
2
]
}
# Customize bot speaking speed
SPEED = 95
def bot(ted, question):
"""
Function to handle bot
Params:
ted: dict
question: str
"""
# Init LED happy image
display.show(Image.HAPPY)
# This is an advanced topic as well however this little function
# cleans out the unnecessary global objects or variables on what
# we call the heap area in memory
gc.collect()
# Init response object
response = ''
# We want to make sure that our dictionary database can
# find all values even if you use a capital letter
# so we convert everything to lowercase
question = question.lower()
# If you type something other than an empty string that means
# question has a value so the rest of the code will continue
# on
if question:
# This is a bit complicated do not worry about this for now
# all this is doing is looking through our dictionary database
# and seeing if our input value has the word or words which
# match an entry in the dictionary database and if it does
# put the value in the _response object
response = [val for key, val in ted.items() if key in question]
gc.collect()
# If our bot got a response from us then make sure
# we trigger the speaking or suprised image so our bot
# can open its mouth to talk and then have our bot
# talk to us in our REPL and by hearing it speak as well
# and if the user types in a trigger work that is not
# recognized then provide a custom default response
if response:
display.show(Image.SURPRISED)
print('BOT: {0}'.format(response[0]))
say(str(response[0]), speed=SPEED)
display.show(Image.HAPPY)
else:
display.show(Image.SURPRISED)
print('BOT: That is not something I am familiar with.')
say('That is not something I am familiar with.', speed=SPEED)
display.show(Image.HAPPY)
gc.collect()
def quiz_f(teq):
"""
Function to handle fill in the blank quiz
Params:
teq: dict
"""
# Init LED happy image
display.show(Image.HAPPY)
# This is an advanced topic as well however this little function
# cleans out the unnecessary global objects or variables on what
# we call the heap area in memory
gc.collect()
# Init score object
score = 0
# Here we iterate through our quiz database
for key in teq:
print(key)
say(str(key), speed=SPEED)
response = input('ANSWER: ')
response = response.lower()
correct_answer = teq[key].lower()
if response == correct_answer:
display.show(Image.SURPRISED)
print('CORRECT!')
say('CORRECT!', speed=SPEED)
display.show(Image.HAPPY)
score += 1
else:
display.show(Image.SURPRISED)
print('The correct answer is {0}.'.format(teq[key]))
say('The correct answer is', speed=SPEED)
say(str(teq[key]), speed=SPEED)
display.show(Image.HAPPY)
time.sleep(1)
gc.collect()
# Here we reply to the student their score
display.show(Image.SURPRISED)
print('You got {0} out of {1} correct!'.format(score, len(teq)))
say('You got', speed=SPEED)
say(str(score), speed=SPEED)
say('out of', speed=SPEED)
say(str(len(teq)), speed=SPEED)
say('correct!', speed=SPEED)
# If student got a perfect score respond appropriately
# or provide an encouring message to retry the quiz
if score == len(teq):
print('You got a perfect score!')
say('You got a perfect score!', speed=SPEED)
print('Well done!')
say('Well done!, ', speed=SPEED)
print('I am so proud of you!')
say('I am so proud of you!', speed=SPEED)
play(POWER_UP)
else:
print('You are doing a great job!')
say('You are doing a great job!', speed=SPEED)
print('I would LOVE for you to try again!')
say('I would LOVE for you to try again!', speed=SPEED)
# Display happy response at the end of the quiz
display.show(Image.HAPPY)
gc.collect()
def quiz_m(teq):
"""
Function to handle multiple choice quiz
Params:
teq: dict
"""
# Init LED happy image
display.show(Image.HAPPY)
# This is an advanced topic as well however this little function
# cleans out the unnecessary global objects or variables on what
# we call the heap area in memory
gc.collect()
# Init score object
score = 0
# Here we iterate through our quiz database with multiple
# choice items
for key in teq:
display.show(Image.SURPRISED)
print(key)
say(str(key), speed=SPEED)
display.show(Image.HAPPY)
time.sleep(1)
display.show(Image.SURPRISED)
print('Press A for {0}.'.format(teq[key][0]))
say('Press Ayyy for', speed=SPEED)
say(str(teq[key][0]), speed=SPEED)
display.show(Image.HAPPY)
time.sleep(1)
display.show(Image.SURPRISED)
print('Touch the logo for {0}.'.format(teq[key][1]))
say('Toch the logo for', speed=SPEED)
say(str(teq[key][1]), speed=SPEED)
display.show(Image.HAPPY)
time.sleep(1)
display.show(Image.SURPRISED)
print('Press B for {0}.'.format(teq[key][2]))
say('Press B for', speed=SPEED)
say(str(teq[key][2]), speed=SPEED)
display.show(Image.HAPPY)
while True:
if button_a.is_pressed():
response = 0
break
elif pin_logo.is_touched():
response = 1
break
elif button_b.is_pressed():
response = 2
break
else:
pass
correct_answer = teq[key][3]
display.show(Image.SURPRISED)
print('You selected {0}.'.format(teq[key][response]))
say('You selected', speed=SPEED)
say(str(teq[key][response]), speed=SPEED)
display.show(Image.HAPPY)
time.sleep(1)
if response == correct_answer:
display.show(Image.SURPRISED)
print('CORRECT!')
say('CORRECT!', speed=SPEED)
display.show(Image.HAPPY)
score += 1
else:
display.show(Image.SURPRISED)
print('The correct answer is {0}.'.format(teq[key][correct_answer]))
say('The correct answer is', speed=SPEED)
say(str(teq[key][correct_answer]), speed=SPEED)
display.show(Image.HAPPY)
time.sleep(1)
gc.collect()
# Here we reply to the student their score
display.show(Image.SURPRISED)
print('You got {0} out of {1} correct!'.format(score, len(teq)))
say('You got', speed=SPEED)
say(str(score), speed=SPEED)
say('out of', speed=SPEED)
say(str(len(teq)), speed=SPEED)
say('correct!', speed=SPEED)
display.show(Image.HAPPY)
time.sleep(1)
# If student got a perfect score respond appropriately
# or provide an encouring message to retry the quiz
display.show(Image.SURPRISED)
if score == len(teq):
print('You got a perfect score!')
say('You got a perfect score!', speed=SPEED)
print('Well done!')
say('Well done!', speed=SPEED)
print('I am so proud of you!')
say('I am so proud of you!', speed=SPEED)
play(POWER_UP)
else:
print('You are doing a great job!')
say('You are doing a great job!', speed=SPEED)
print('I would LOVE for you to try again!')
say('I would LOVE for you to try again!', speed=SPEED)
# Display happy response at the end of the quiz
display.show(Image.HAPPY)
time.sleep(1)
gc.collect()