-
Notifications
You must be signed in to change notification settings - Fork 0
/
set.py
111 lines (78 loc) · 2.5 KB
/
set.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
import time # Does not execute this command when launched from terminal
from commands import *
from ClockAideTime import *
from questionBank import QuestionBank
from keypad import *
from Motors import *
from DB import *
keypad = keypad()
motor = motors()
qBank = QuestionBank(databaseLocation)
DB clockAideDB = DB("ClockAideDB")
def set(id, sessionActive):
qBank.generateTime()
setTime = setModeTime(id)
numAttempts = 0
while (sessionActive && (numAttempts < 3)):
keypad.SendLine(modeLookUp["set"])
motor.SendLine(modeLookUp["set"])
time.sleep(2)
keypad.SendLine(setTime)
randomTime = qBank.getTimeTouple()
speakTime(randomTime[0],randomTime[1])
comm = COMMAND[str(keypad.read())]
if comm == "GET_TIME":
motor.SendLine(command["get_time"])
delay(2)
motorTime = motor.ReadLine()
if checkSetTime(motorTime, setTime):
numAttempts = 0
clockAideDB.addToStudentResponseTable(clockAideDB.getQuestionID(), keypadTime)
print(keypad.SendLine(command["good"]))
time.sleep(2)
print(keypad.SendLine(command["more"]))
#print(motor.SendLine(command["more"]))
response = keypad.ReadLine()
if response == command["ack"]:
qBank.generateTime()
setTime = setModeTime(id)
sessionActive = True
else:
sessionActive = False
#return modes[0]
else:
numAttempts++
clockAideDB.addToStudentResponseTable(clockAideDB.getQuestionID(), keypadTime)
print(keypad.SendLine(command["wrong"]))
time.sleep(2)
print(keypad.SendLine(command["more"]))
response = keypad.ReadLine()
if response == command["ack"]:
sessionActive = True
else:
sessionActive = False
return [sessionActive, modes[0]]
def setModeTime(ID):
# Get difficulty level that the student is on
# return time based on that level
global qBank
return qBank.getTimeString()
def checkSetTime(readTime, sentTime):
#Remove leading whitespaces:
readTime = re.sub("^0+","",readTime)
sentTime = re.sub("^0+","",sentTime)
#Convert To Integers
readHour = int(readTime.split(',')[0])
readMinute = int(readTime.split(',')[1])
sentHour = int(sentTime.split(',')[0])
sentMinute = int(sentTime.split(',')[1])
print "Check readTime entered"
print "Time received: " + str(readHour) + "," + str(readMinute)
print "Time sent: " + str(sentHour) + "," + str(sentMinute)
# compare entered time with time given to student
# return TRUE or False
if readHour == sentHour and readMinute == sentMinute:
return True
else:
return False
#return True