-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdsst.py
executable file
·229 lines (189 loc) · 6.34 KB
/
dsst.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
from appJar import gui
import random
import time
import datetime
import sys
import statistics
#clear log file
open('log.txt', 'w').close()
win = gui("DSST")
win.showSplash("DSST - Loading","Gray", "Lightblue", "Black")
win.setBg("Gray")
win.setFont(20)
#win.setSize("800x500")
win.setResizable(False)
pressed_list = []
correct_list = []
result_list = []
correct = None
YN = None
current_status = "0/0"
start_status = 0
time_list = []
times = []
start_time = None
shuffled = [1, 2, 3, 4, 5, 6, 7, 8, 9]
def launch(app):
win.showSubWindow(app)
def change_pic():
# Change game pic
global correct
im_path = "pic/znak_"
im_num = str(random.randint(1, 9))
win.setImage("Znak", im_path + im_num + ".gif")
correct = int(im_num)
def new_task_table():
# Add new task table signs
global shuffled
random.shuffle(shuffled)
for i in range(0, 9):
im_name = "Znak" + str(i)
im_path = "pic/znak_"
im_num = str(shuffled[i])
win.setImage(im_name, im_path + im_num + ".gif")
def stop():
win.enableButton("Start")
win.setImage("Znak", "pic/znak_blank.gif")
for i in range(0, 9):
im_name = "Znak" + str(i)
win.setImage(im_name, "pic/znak_blank.gif")
start_status = 0
win.setLabel("Meann", str(round((statistics.mean(times)), 3)))
win.setLabel("Startinfo", "Press spacebar to START !")
win.bindKey("<space>", space_press)
# log all merurements through sesion
file = open("log.txt", "a")
file.write("\nTime of test," + str(datetime.datetime.now().strftime("%H:%M %d %m %Y")))
file.write("\nTime (sec), Correct (T/F-1/0)")
for k in range(len(times)):
file.write("\n" + str(times[k]) + "," + str(result_list[k]))
file.close()
# autosave data
f_name = "./results/dsst-" + str(datetime.datetime.now().strftime("%d-%m-%y-%H%M%S") + ".cvs")
file = open(f_name, "w")
file.write("\nTime of test," + str(datetime.datetime.now().strftime("%H:%M %d %m %Y")))
file.write("\nTime (sec), Correct (T/F-1/0)")
for k in range(len(times)):
file.write("\n" + str(times[k]) + "," + str(result_list[k]))
file.close()
def press(name):
global start_status, pressed_list, correct_list, result_list, time_list, times, start_time
# Buttons
if name == "Exit":
win.stop()
elif name == "Start":
pressed_list = []
correct_list = []
result_list = []
time_list = []
times = []
win.setLabel("CS", "0/0")
win.setLabel("Times", "0")
win.setLabel("Stat", "")
win.setMeter("progress",0)
win.setImage("Status", "pic/znak_blank_gray.gif")
win.setLabel("Meann", "0")
start_status = 1
win.disableButton("Start")
win.unbindKey("<space>")
win.setLabel("Startinfo", " ")
new_task_table()
change_pic()
start_time = time.time()
time_list.append(time.time())
elif name == "About":
win.infoBox("About", "DSST - Digit Symbol Substitution Test\n\nMade by: Martin Barton\nEmail: ma.barton@seznam.cz\nYear: 2018\nUniversity: CTU FBMI\nPlace: Kladno, Czech Republic\nGit: https://github.com/mabartcz/DSST")
elif name == "Control":
launch(name)
elif name == "Stop":
stop()
def answer_press(key):
global start_status
if start_status == 1: # If start was pressed
# Game key press (1 - 9) than ->
global pressed_list, time_list, correct_list
pressed = shuffled[key-1]
pressed_list.append(str(pressed))
correct_list.append(str(correct))
if pressed == correct:
win.setImage("Status", "pic/Yes.gif")
result_list.append(1)
YN = 1
else:
win.setImage("Status", "pic/No.gif")
result_list.append(0)
YN = 0
time_list.append(time.time())
times.append((round((time_list[-1]-time_list[-2]), 3)))
# show statistic
current_status = str(sum(result_list)) + "/" + str(len(result_list))
win.setLabel("CS", current_status )
win.setLabel("Times", times[-1] )
win.setMeter("progress",(sum(result_list)/len(result_list))*100 )
change_pic()
new_task_table()
if time.time() > start_time+duration:
stop()
def space_press(key):
win.setLabel("Startinfo", " ")
press("Start")
try:
file = open("opt_duration.txt", "r")
duration = int(file.read())
file.close()
if duration < 1 or duration > 60 * 60:
sys.exit("Extended test duration time, in file opt_duration.txt change test duration from '1 to 3600' (sec)")
except:
duration = 90
# Add menu
fileMenus = ["Control", "About", "-", "Exit"]
win.addMenuList("File", fileMenus, press)
# Add headline
win.addLabel("lb1", "Digit Symbol Substitution Test", 0, 0, 9)
win.setLabelBg("lb1", "lightblue")
win.setLabelFg("lb1", "black")
win.addLabel("Stat", "", 1, 0, 9)
win.addLabel("Space5", "", 2, 0, 9)
# Add image widgets
for i in range(9):
im_name = "Znak"+str(i)
im_path = "pic/znak_blank"
win.addImage(im_name, im_path+".gif", 3, i)
# Add image lables
for j in range(1,10):
lb_name = "Z"+str(j)
win.addLabel(lb_name, str(j), 4, j-1)
win.addLabel("Space2", "", 5, 0, 9)
win.addLabel("Space3", "", 6, 0, 9)
win.addImage("Znak", "pic/znak_blank.gif", 7, 0, 9)
win.addLabel("Space4", "", 8, 0, 9)
win.addLabel("Startinfo", "Press spacebar to START !", 9, 0, 9)
# Bind key actions
for k in range(1, 10):
win.bindKey(k, answer_press)
win.bindKey("<space>", space_press)
# Set Control window
win.startSubWindow("Control")
win.setBg("Gray")
win.setFont(20)
win.addLabel("l1", "DSST - Control window", 0, 0, 3)
win.setLabelBg("l1", "lightblue")
win.setLabelFg("l1", "black")
win.addLabel("Space22", "", 1)
win.addLabel("DD", "Duration:", 2, 0)
win.addLabel("DD2",str(duration) + " (sec)", 2, 1)
win.addLabel("l2", "Current: ", 3, 0)
win.addImage("Status", "pic/znak_blank_gray.gif", 3, 1)
win.addSplitMeter("progress", 4, 0, 3)
win.setMeterFill("progress", ["green", "red"])
win.addLabel("CS1", "Correct/All: " , 5, 0)
win.addLabel("CS", current_status, 5, 1)
win.addLabel("Space55", "", 6, 0)
win.addLabel("Time", "Time: ", 7, 0)
win.addLabel("Times", "0", 7, 1)
win.addLabel("Mean", "Mean time: ", 8, 0)
win.addLabel("Meann", "0", 8, 1)
win.button("Start", press, 9, 0 )
win.button("Stop", press, 9, 1)
win.stopSubWindow()
win.go()