Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Hey,
- I have a self-paced reading experiment: participants press a button when they have finished reading the current word and are then shown the next word. For this, I loop over pairs of showing a text canvas and collecting a response; one loop for each sentence.
- For some reason, in 90% of cases, the first response to the first item in a loop is ignored. I have no idea why. Any ideas?
- ```
- from openexp.keyboard import keyboard
- runs_keyboard = keyboard(exp, timeout=None)
- from openexp.canvas import canvas
- from openexp.sampler import sampler
- import random
- lines = """Tiere: Lachs Wolf Gnu;
- Kontinente: Afrika Amerika
- """
- lines = lines.replace("\n","").split(";")
- categories, memberlist = [], []
- for line in lines:
- category, ms = line.split(":")
- categories.append(category)
- memberlist.append(ms.strip(" ").split(" "))
- error_sound = sampler(exp, '/Users/jona/funk.wav')
- blank_canvas = canvas(exp)
- blank_canvas.text("")
- fdot_canvas = canvas(exp)
- fdot_canvas.fixdot()
- pre_canvas = canvas(exp)
- pre_canvas.text("Number of runs (*10)?")
- pre_canvas.show()
- rt, critposses = [], []
- maxruns, t = runs_keyboard.get_key()
- run = 0
- while run < int(maxruns)*10:
- blank_canvas.show()
- self.sleep(500)
- i = random.randint(0,len(categories)-1)
- category = categories[i]
- members = list(memberlist[i])
- members_old = list(members)
- random.shuffle(members)
- mismatch = bool(random.randint(0,1))
- mismatch_word = "xyz"
- if mismatch:
- miscats = memberlist[i+1:] + memberlist[:i]
- mismatching_words = [item for sublist in miscats for item in sublist]
- mismatch_word = random.choice(mismatching_words)
- mismatch_index = random.randint(0,len(members)-1)
- members[mismatch_index] = mismatch_word
- members.insert(-1,"und")
- members[-1] = "".join([members[-1],"."])
- words = ["Zur Kategorie", category, "gehören"]
- words.extend(members)
- w_i = 999
- for index, w in enumerate(words):
- if mismatch_word in w:
- w_i = index
- break
- print(w_i)
- cs = []
- for w in words:
- c = canvas(exp)
- c.text(w)
- cs.append(c)
- end = None
- rts = []
- iscorrects = []
- key = None
- continue_keyboard = keyboard(exp, timeout=None)
- continue_keyboard.flush()
- judge_keyboard = []
- judge_keyboard = keyboard(exp, timeout=None)
- judge_keyboard.flush()
- fdot_canvas.show()
- self.sleep(500)
- blank_canvas.show()
- self.sleep(250)
- for index, c in enumerate(cs):
- start = self.time()
- c.show()
- judge_keyboard = keyboard(exp, timeout=None)
- key, end = judge_keyboard.get_key()
- print(key)
- rts.append(str(end-start))
- if (key == "space" and index != w_i) or (key != "space" and index == w_i):
- iscorrects.append("1")
- else:
- iscorrects.append("0")
- blank_canvas.show()
- self.sleep(100)
- key = None
- run += 1
- judge_keyboard.flush()
- continue_keyboard.flush()
- ```
Advertisement
Add Comment
Please, Sign In to add comment