7 |
# A jython test program for papers |
# A jython test program for papers |
8 |
# Load using gldemo.py |
# Load using gldemo.py |
9 |
|
|
10 |
seed = 33555 # shuffling |
seed = 5225 # shuffling |
11 |
seed0 = 123456 # "old" textures |
seed0 = 1435 # "old" textures |
12 |
seed1 = 33456789 # "new" textures |
seed1 = 54134 # "new" textures |
13 |
|
|
14 |
numtex0 = 50 # Number of different "old" textures |
numtex0 = 30 # Number of different "old" textures |
15 |
numtex1 = 250 # Number of different "new" textures |
numtex1 = 100 # Number of different "new" textures |
16 |
|
|
17 |
feedbackduration = 1500 |
showtex0 = 100 |
18 |
|
|
19 |
colorfeedback = 0 # Show green/red color for correct/incorrect |
feedbackduration = 3000 |
20 |
|
|
21 |
|
colorfeedback = 1 # Show green/red color for correct/incorrect |
22 |
|
|
23 |
outfile = open("psyko.dat", "a") |
outfile = open("psyko.dat", "a") |
24 |
|
|
48 |
if dupes(tex0 + tex1): continue |
if dupes(tex0 + tex1): continue |
49 |
break |
break |
50 |
|
|
|
words = {} |
|
|
for i in range(0, len(tex0)): |
|
|
words[tex0[i]] = "(" + str(i) + ")" |
|
|
|
|
|
for seed in tex1: words[seed] = "----" |
|
|
|
|
|
seen = {} |
|
|
for seed in tex0 + tex1: seen[seed] = None |
|
|
|
|
51 |
|
|
52 |
log("textures0 seed: " + str(seed0)) |
log("textures0 seed: " + str(seed0)) |
53 |
log("textures0: " + js(tex0)) |
log("textures0: " + js(tex0)) |
57 |
|
|
58 |
log("shuffling seed: " + str(seed)) |
log("shuffling seed: " + str(seed)) |
59 |
|
|
60 |
zoom = [100, 500, 650, 800, 2000] |
|
61 |
|
execfile("gfx/demo/zipf.py") |
62 |
|
|
63 |
|
|
64 |
|
probs = getZipfDistribution(numtex0) |
65 |
|
|
66 |
|
learninglist = ( |
67 |
|
reduce(lambda x,y: x+y, |
68 |
|
[ [ tex0[i] for foo in range(0, int(round(probs[i] * numtex1))) ] |
69 |
|
for i in range(0,numtex0)] ) |
70 |
|
) |
71 |
|
learninglist = learninglist[0:showtex0] |
72 |
|
|
73 |
|
onlinelist = ( |
74 |
|
reduce(lambda x,y: x+y, |
75 |
|
[ [ tex0[i] for foo in range(0, int(round(probs[i] * numtex1))) ] |
76 |
|
for i in range(0,numtex0)] ) |
77 |
|
+ tex1 |
78 |
|
) |
79 |
|
|
80 |
|
words = {} |
81 |
|
for i in range(0, len(tex0)): |
82 |
|
words[tex0[i]] = str(i) |
83 |
|
|
84 |
|
for seed in tex1: words[seed] = "-" |
85 |
|
|
86 |
|
seen = {} |
87 |
|
for seed in tex0 + tex1: seen[seed] = None |
88 |
|
for seed in learninglist: seen[seed] = "learning phase" |
89 |
|
|
90 |
|
|
91 |
|
zoom = [60, 500, 650, 800, 2000] |
92 |
paperzoom = [0.05, 0.2, 1, 3] |
paperzoom = [0.05, 0.2, 1, 3] |
93 |
|
|
94 |
def globalkey(k): |
def globalkey(k): |
95 |
global currentScene |
global currentScene |
96 |
if k == "F1": |
if k == "F1": |
97 |
|
LearningScene().start() |
98 |
|
if k == "F2": |
99 |
OnlineTestScene().start() |
OnlineTestScene().start() |
100 |
if k == "r": |
if k == "r": |
101 |
loadscenes() |
loadscenes() |
136 |
|
|
137 |
execfile("gfx/libpaper/papermill.py") |
execfile("gfx/libpaper/papermill.py") |
138 |
|
|
|
execfile("gfx/demo/zipf.py") |
|
|
|
|
139 |
|
|
140 |
next_toid = 1 |
next_toid = 1 |
141 |
|
|
152 |
print str(System.currentTimeMillis()) + " Cancelled TIMEOUT ", scene.toid |
print str(System.currentTimeMillis()) + " Cancelled TIMEOUT ", scene.toid |
153 |
scene.toid = None |
scene.toid = None |
154 |
|
|
155 |
|
class LearningScene: |
156 |
|
def __init__(self): |
157 |
|
self.bgcolor = (0.7, 0.8, 0.6) |
158 |
|
|
159 |
|
log("Learning phase") |
160 |
|
|
161 |
|
self.seed = None |
162 |
|
self.trial = 0 |
163 |
|
self.toid = None |
164 |
|
|
165 |
|
self.list = learninglist |
166 |
|
shuffle(self.list, rng.nextFloat) |
167 |
|
|
168 |
|
def prepareNextTrial(self): |
169 |
|
if self.trial < len(self.list): |
170 |
|
self.seed = self.list[self.trial] |
171 |
|
self.pq = getpaper(self.seed) |
172 |
|
else: |
173 |
|
self.seed = None |
174 |
|
|
175 |
|
|
176 |
|
def nextTrial(self): |
177 |
|
global currentScene |
178 |
|
if self.seed != None: |
179 |
|
if self.seed != self.list[self.trial]: |
180 |
|
self.prepareNextTrial() |
181 |
|
|
182 |
|
setTimeout(self, 1000) |
183 |
|
self.trial = self.trial + 1 |
184 |
|
self.word = words[self.seed] |
185 |
|
log("Trial %(trial)s: %(seed)s %(word)s" % vars(self)) |
186 |
|
else: |
187 |
|
currentScene = MenuScene() |
188 |
|
AbstractUpdateManager.setNoAnimation() |
189 |
|
AbstractUpdateManager.chg() |
190 |
|
|
191 |
|
def key(self, k): |
192 |
|
pass |
193 |
|
|
194 |
|
def timeout(self, o): |
195 |
|
global currentScene |
196 |
|
if o != self.toid: return |
197 |
|
self.nextTrial() |
198 |
|
|
199 |
|
def start(self): |
200 |
|
global currentScene |
201 |
|
currentScene = FeedBackScene(self, 2) |
202 |
|
AbstractUpdateManager.setNoAnimation() |
203 |
|
AbstractUpdateManager.chg() |
204 |
|
|
205 |
|
def scene(self, vs): |
206 |
|
putnoc(vs, background(self.bgcolor)) |
207 |
|
|
208 |
|
cs1 = vs.coords.affineCoordsys("1", 10, 800, 600, 800, 0, 0, 600) |
209 |
|
scale = zoom[0] / paperzoom[0] |
210 |
|
cs2 = vs.coords.affineCoordsys("tex", 1, 400, 400, scale, 0, 0, scale) |
211 |
|
|
212 |
|
pscale = zoom[0] |
213 |
|
|
214 |
|
print "Seed: ",self.seed," pq ",self.pq |
215 |
|
vs.map.put(self.pq, cs1, cs2) |
216 |
|
|
217 |
|
if 0: |
218 |
|
cs1 = vs.coords.affineCoordsys("msg", 10, 570, 450, 1, 0, 0, 1) |
219 |
|
putText(vs, cs1, words[self.seed], color=(0,0,0),w=4,h=4) |
220 |
|
|
221 |
|
return vs |
222 |
|
|
223 |
|
|
224 |
class OnlineTestScene: |
class OnlineTestScene: |
236 |
"Control_R" : "old" |
"Control_R" : "old" |
237 |
} |
} |
238 |
|
|
239 |
self.probs = getZipfDistribution(numtex0) |
self.list = onlinelist |
|
|
|
|
self.list = ( |
|
|
reduce(lambda x,y: x+y, |
|
|
[ [ tex0[i] for foo in range(0, int(round(self.probs[i] * len(tex1)))) ] |
|
|
for i in range(0,numtex0)] ) |
|
|
+ tex1) |
|
|
|
|
240 |
shuffle(self.list, rng.nextFloat) |
shuffle(self.list, rng.nextFloat) |
241 |
|
|
242 |
def prepareNextTrial(self): |
def prepareNextTrial(self): |
243 |
if self.trial < len(self.list): |
if self.trial < len(self.list): |
244 |
self.seed = self.list[self.trial] |
self.seed = self.list[self.trial] |
245 |
#if self.seed in tex0: |
if self.seed in tex0: |
246 |
if seen[self.seed] != None: |
#if seen[self.seed] != None: |
247 |
self.correct = "old" |
self.correct = "old" |
248 |
else: |
else: |
249 |
self.correct = "new" |
self.correct = "new" |
257 |
self.prepareNextTrial() |
self.prepareNextTrial() |
258 |
|
|
259 |
#setTimeout(self, 5000) |
#setTimeout(self, 5000) |
|
if seen[self.seed] != None: |
|
|
self.seen = seen[self.seed] + 1 |
|
|
else: |
|
|
self.seen = None |
|
260 |
self.trial = self.trial + 1 |
self.trial = self.trial + 1 |
261 |
self.word = words[self.seed] |
self.word = words[self.seed] |
262 |
log("Trial %(trial)s: %(seed)s %(word)s (seen at trial %(seen)s)" |
self.seen = seen[self.seed] |
263 |
|
log("Trial %(trial)s: %(seed)s %(word)s (seen in %(seen)s)" |
264 |
% vars(self)) |
% vars(self)) |
265 |
self.reactstart = System.currentTimeMillis() |
self.reactstart = System.currentTimeMillis() |
266 |
else: |
else: |
270 |
AbstractUpdateManager.chg() |
AbstractUpdateManager.chg() |
271 |
|
|
272 |
def endTrial(self, answer): |
def endTrial(self, answer): |
273 |
|
global currentScene |
274 |
if answer != None: |
if answer != None: |
275 |
self.answer = answer |
self.answer = answer |
276 |
correct = (self.answer == self.correct) |
correct = (self.answer == self.correct) |
277 |
log("Trial %(trial)s: RT %(reacttime)s %(answer)s" % vars(self) + |
log("Trial %(trial)s: RT %(reacttime)s %(answer)s" % vars(self) + |
278 |
" (" + ["Incorrect", "Correct"][correct] + ")") |
" (" + ["Incorrect", "Correct"][correct] + ")") |
279 |
|
#currentScene = FeedBackScene(self, correct) |
280 |
else: |
else: |
281 |
log("Trial %(trial)s: Timeout" % vars(self)) |
log("Trial %(trial)s: Timeout" % vars(self)) |
282 |
currentScene = FeedBackScene(self, 2) |
#currentScene = FeedBackScene(self, 2) |
283 |
|
|
284 |
self.state = 1 |
self.state = 1 |
285 |
setTimeout(self, feedbackduration) |
setTimeout(self, feedbackduration) |
316 |
def scene(self, vs): |
def scene(self, vs): |
317 |
putnoc(vs, background(self.bgcolor)) |
putnoc(vs, background(self.bgcolor)) |
318 |
|
|
319 |
cs1 = vs.coords.affineCoordsys("1", 10, 600, 450, 290, 0, 0, 290) |
cs1 = vs.coords.affineCoordsys("1", 10, 800, 600, 800, 0, 0, 600) |
320 |
scale = zoom[0] / paperzoom[0] |
scale = zoom[0] / paperzoom[0] |
321 |
cs2 = vs.coords.affineCoordsys("tex", 1, 400, 400, scale, 0, 0, scale) |
cs2 = vs.coords.affineCoordsys("tex", 1, 400, 400, scale, 0, 0, scale) |
322 |
|
|
325 |
print "Seed: ",self.seed," pq ",self.pq |
print "Seed: ",self.seed," pq ",self.pq |
326 |
vs.map.put(self.pq, cs1, cs2) |
vs.map.put(self.pq, cs1, cs2) |
327 |
|
|
328 |
seen[self.seed] = self.trial |
seen[self.seed] = "trial" + str(self.trial) |
329 |
|
|
330 |
if self.state == 1: |
if self.state == 1: |
331 |
cs1 = vs.coords.affineCoordsys("msg", 10, 570, 450, 1, 0, 0, 1) |
if self.answer == self.correct: |
332 |
putText(vs, cs1, words[self.seed], color=(0,0,0)) |
msg = "Oikein" |
333 |
|
else: |
334 |
|
msg = "Väärin" |
335 |
|
if self.seed in tex0: |
336 |
|
msg2 = "Oli nähty" |
337 |
|
else: |
338 |
|
msg2 = "Ei ollut nähty" |
339 |
|
|
340 |
|
cs1 = vs.coords.affineCoordsys("msg", 10, 350, 350, 1, 0, 0, 1) |
341 |
|
putText(vs, cs1, msg, color=(0,0,0),w=1,h=1,x=100) |
342 |
|
putText(vs, cs1, msg2, color=(0,0,0),w=1,h=1, y=400) |
343 |
#self.prepareNextTrial() |
#self.prepareNextTrial() |
344 |
|
|
345 |
return vs |
return vs |
399 |
putText(vs, cs1, "seed = " + str(self.seed), color=(0,1,0), y = 100) |
putText(vs, cs1, "seed = " + str(self.seed), color=(0,1,0), y = 100) |
400 |
|
|
401 |
if self.pq != None: |
if self.pq != None: |
402 |
cs1 = vs.coords.affineCoordsys("1", 10, 800, 450, 290, 0, 0, 290) |
cs1 = vs.coords.affineCoordsys("1", 10, 800, 450, 390, 0, 0, 390) |
403 |
scale = zoom[0] / paperzoom[0] |
scale = zoom[0] / paperzoom[0] |
404 |
cs2 = vs.coords.affineCoordsys("tex", 1, 400, 400, scale, 0, 0, scale) |
cs2 = vs.coords.affineCoordsys("tex", 1, 400, 400, scale, 0, 0, scale) |
405 |
vs.map.put(self.pq, cs1, cs2) |
vs.map.put(self.pq, cs1, cs2) |
432 |
# GZZGL.startContext() |
# GZZGL.startContext() |
433 |
global font |
global font |
434 |
if font == None: |
if font == None: |
435 |
font = GZZGL.createFont("gfx/fonts/a010013l.pfb", 40) |
font = GZZGL.createFont("gfx/fonts/a010013l.pfb", 100) |
436 |
|
|
437 |
return GZZGL.createHorizText(font, text, x, y, z, w,h) |
return GZZGL.createHorizText(font, text, x, y, z, w,h) |
438 |
# GZZGL.endContext() |
# GZZGL.endContext() |