Guest User

Untitled

a guest
Mar 5th, 2015
222
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.08 KB | None | 0 0
  1. Hey,
  2.  
  3. 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.
  4. 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?
  5.  
  6. ```
  7. from openexp.keyboard import keyboard
  8. runs_keyboard = keyboard(exp, timeout=None)
  9.  
  10. from openexp.canvas import canvas
  11. from openexp.sampler import sampler
  12.  
  13. import random
  14.  
  15. lines = """Tiere: Lachs Wolf Gnu;
  16. Kontinente: Afrika Amerika
  17. """
  18.  
  19. lines = lines.replace("\n","").split(";")
  20.  
  21. categories, memberlist = [], []
  22. for line in lines:
  23. category, ms = line.split(":")
  24. categories.append(category)
  25. memberlist.append(ms.strip(" ").split(" "))
  26.  
  27. error_sound = sampler(exp, '/Users/jona/funk.wav')
  28.  
  29. blank_canvas = canvas(exp)
  30. blank_canvas.text("")
  31.  
  32. fdot_canvas = canvas(exp)
  33. fdot_canvas.fixdot()
  34.  
  35. pre_canvas = canvas(exp)
  36. pre_canvas.text("Number of runs (*10)?")
  37. pre_canvas.show()
  38.  
  39. rt, critposses = [], []
  40.  
  41. maxruns, t = runs_keyboard.get_key()
  42.  
  43. run = 0
  44. while run < int(maxruns)*10:
  45. blank_canvas.show()
  46. self.sleep(500)
  47. i = random.randint(0,len(categories)-1)
  48. category = categories[i]
  49.  
  50. members = list(memberlist[i])
  51. members_old = list(members)
  52. random.shuffle(members)
  53. mismatch = bool(random.randint(0,1))
  54.  
  55. mismatch_word = "xyz"
  56. if mismatch:
  57. miscats = memberlist[i+1:] + memberlist[:i]
  58. mismatching_words = [item for sublist in miscats for item in sublist]
  59. mismatch_word = random.choice(mismatching_words)
  60. mismatch_index = random.randint(0,len(members)-1)
  61. members[mismatch_index] = mismatch_word
  62.  
  63. members.insert(-1,"und")
  64. members[-1] = "".join([members[-1],"."])
  65.  
  66. words = ["Zur Kategorie", category, "gehören"]
  67. words.extend(members)
  68.  
  69. w_i = 999
  70. for index, w in enumerate(words):
  71. if mismatch_word in w:
  72. w_i = index
  73. break
  74.  
  75. print(w_i)
  76. cs = []
  77. for w in words:
  78. c = canvas(exp)
  79. c.text(w)
  80. cs.append(c)
  81.  
  82. end = None
  83. rts = []
  84. iscorrects = []
  85. key = None
  86.  
  87. continue_keyboard = keyboard(exp, timeout=None)
  88. continue_keyboard.flush()
  89.  
  90. judge_keyboard = []
  91. judge_keyboard = keyboard(exp, timeout=None)
  92. judge_keyboard.flush()
  93.  
  94. fdot_canvas.show()
  95. self.sleep(500)
  96. blank_canvas.show()
  97. self.sleep(250)
  98. for index, c in enumerate(cs):
  99. start = self.time()
  100. c.show()
  101. judge_keyboard = keyboard(exp, timeout=None)
  102. key, end = judge_keyboard.get_key()
  103. print(key)
  104. rts.append(str(end-start))
  105. if (key == "space" and index != w_i) or (key != "space" and index == w_i):
  106. iscorrects.append("1")
  107. else:
  108. iscorrects.append("0")
  109. blank_canvas.show()
  110. self.sleep(100)
  111. key = None
  112. run += 1
  113.  
  114. judge_keyboard.flush()
  115. continue_keyboard.flush()
  116. ```
Advertisement
Add Comment
Please, Sign In to add comment