def practiceTrial(window, workBook, audioDevice): instruction1 = visual.TextStim(window, text = textIntro, font = 'Arial', units = 'norm', pos=[0,0], height=0.10, wrapWidth=None) instruction1.draw() window.flip() common.waitforconfirm() time.sleep(0.5) common.fixationCross("large", 1, 0, window) window.flip() for runNumber in range(1,4): #1,2,3 testPratice(window, workBook, runNumber, audioDevice)
def practicetrial(window, workBook): instruction1 = visual.TextStim(window, text = textIntro, font = 'Arial', units = 'norm', pos=[0,0], height=0.10, wrapWidth=None) instruction1.draw() window.flip() common.waitforconfirm() time.sleep(0.5) common.fixationCross("small", 1, 0, window) for runNumber in range(1,7): #1-6 #for runNumber in range(6,7): testpractice(window,textStudyContains, textPersonIs, textThereAre, textLikelyToBe, runNumber, workBook)
def mainLoop(dict_values, window, audioFolder, audioDevice, excelNumber, output_file, tk): timer = core.Clock() tk.sendMessage("trial number: " + str(excelNumber-1)) prof_1 = dict_values["Profession1"] prof_2 = dict_values["Profession2"] attribute = dict_values["Attribute"] base_rate1 = dict_values["Baserate1"] base_rate2 = dict_values["Baserate2"] correctAnswer = dict_values["Correct"] likely_sound, likely_fs = sf.read("is_this_person_more_likely_a.wav") attribute_sound = attribute + ".wav" profession_sound = dict_values["wav_profession"] original_folder = os.getcwd() os.chdir(audioFolder) attribute_sound, attribute_fs = sf.read(attribute_sound) profession_sound, profession_fs = sf.read(profession_sound) os.chdir(original_folder) window.flip() time.sleep(0.5) common.fixationCross("large", 0, 0.5, window) tk.sendMessage('this_study_contains') frame1_studyContains = visual.TextStim(window, text = u"This study contains:", font = 'Arial', units = 'norm', pos = [0, 0.5], height = 0.07, wrapWidth=None) frame_1_profession1 = call_frame(prof_1, "Profession1", window) frame_1_profession2 = call_frame(prof_2, "Profession2", window) frames_list = [frame1_studyContains, frame_1_profession1, frame_1_profession2] for frame in frames_list: frame.draw() window.flip() time.sleep(1.8) common.fixationCross("large", 1, 0, window) tk.sendMessage('base_rate') frame_3_baserate1 = call_frame(base_rate1, "Baserate1", window) frame_3_baserate2 = call_frame(base_rate2, "Baserate2", window) frames_list = [frame_3_baserate1, frame_3_baserate2, frame_1_profession1, frame_1_profession2] for frame in frames_list: frame.draw() window.flip() time.sleep(3.6) tk.sendMessage('attribute_start') sd.play(attribute_sound, attribute_fs, device = audioDevice) common.fixationCross("large", 0, 3, window) tk.sendMessage('attribute_end') window.flip() time.sleep(0.2) tk.sendMessage('is_this_person_more_likely_a') sd.play(likely_sound, likely_fs, device = audioDevice) # lasts for two seconds common.fixationCross("large", 0, 3, window) sd.wait() sd.play(profession_sound, profession_fs, device = audioDevice) time.sleep(1.2) tk.sendMessage('Answer_start') timer.reset() startTime = timer.getTime() event.clearEvents() #if one accidentaly clicks a key before the selection process, it will not register while (startTime < 4): keys = event.getKeys() if (config.answer_left) in keys: if correctAnswer == "Answeroption1": output_file["E"+str(excelNumber)] = "1" else: output_file["E"+str(excelNumber)] = "0" #output_file["E"+str(excelNumber)] = "Answeroption1" output_file["F"+str(excelNumber)] = startTime break elif (config.answer_right) in keys: if correctAnswer == "Answeroption2": output_file["E"+str(excelNumber)] = "1" else: output_file["E"+str(excelNumber)] = "0" #output_file["E"+str(excelNumber)] = "Answeroption2" output_file["F"+str(excelNumber)] = startTime break core.wait(0.1) startTime += 0.1 #if time surpased the limit, we add a no response to the file if startTime > 4: output_file["E"+str(excelNumber)] = "No response" output_file["F"+str(excelNumber)] = 4 return tk.sendMessage('Answer_end') time_jitt = random.uniform(3,5) common.fixationCross("large", 0, time_jitt, window) window.flip() time.sleep(random.uniform(1,2.5))
def testpractice(window, textStudyContains, textPersonIs, textThereAre, textLikelyToBe, run_number, workBook): #start at practice trial 1, end at 6, which is the run_number timer = core.Clock() value_dict = { "Profession1": "", "Profession2": "", "Attribute": "", "Baserate1": "", "Baserate2": "", "Answeroption1": "", "Answeroption2": "", "Correct": "" } #Fetch values from excel for column in range(3, 11): #3-10, Profession1 - > Correct row_name = workBook.cell(row=1, column=column) #Profession1 - > Correct cell_name = workBook.cell(row=run_number + 1, column=column) #Americans -> Answeroption1/2 value_dict[row_name.value] = cell_name.value #Added if tests to remove text after iterations if (run_number > 1 and run_number < 6): textLikelyToBe = "?" if (run_number > 2): textThereAre = "" if (run_number > 3): textPersonIs = "" if (run_number == 6): textPersonIs = "" textThereAre = "" textLikelyToBe = "" common.fixationCross("small", 1, 0, window) #Professions: frame1 = visual.TextStim(window, text=textStudyContains, font='Arial', units='norm', pos=[0, 0.5], height=0.07, wrapWidth=None) frame1_profession1 = visual.TextStim(window, text=value_dict['Profession1'], font='Arial', units='norm', pos=[0.25, 0.2], height=0.07, wrapWidth=None) frame1_and = visual.TextStim(window, text="and", font='Arial', units='norm', pos=[0, 0.2], height=0.07, wrapWidth=None) frame1_profession2 = visual.TextStim(window, text=value_dict['Profession2'], font='Arial', units='norm', pos=[-0.25, 0.2], height=0.07, wrapWidth=None) frames_list = [frame1, frame1_profession1, frame1_and, frame1_profession2] for frames in frames_list: frames.draw() window.flip() time.sleep(1.8) common.fixationCross("small", 1, 0, window) #Attribute: frame2 = visual.TextStim(window, text=textPersonIs, font='Arial', units='norm', pos=[0, 0.5], height=0.07, wrapWidth=None) frame2_attribute = visual.TextStim(window, text=value_dict['Attribute'], font='Arial', units='norm', pos=[0, 0], height=0.07, wrapWidth=None) frame2.draw() frame2_attribute.draw() window.flip() time.sleep(1.799) common.fixationCross("small", 1, 0, window) #Frame 3 frame3 = visual.TextStim(window, text=textThereAre, font='Arial', units='norm', pos=[0, 0.5], height=0.07, wrapWidth=None) frame3_baserate1 = visual.TextStim(window, text=value_dict['Baserate1'], font='Arial', units='norm', pos=[0.25, -0.2], height=0.07, wrapWidth=None) frame3_baserate2 = visual.TextStim(window, text=value_dict['Baserate2'], font='Arial', units='norm', pos=[-0.25, -0.2], height=0.07, wrapWidth=None) frame1_profession1.pos = [0.25, 0.2] frame1_profession2.pos = [-0.25, 0.2] if run_number == 1: textTutorial_1 = u'This part will only be displayed once, so make sure you understand before moving on:' textTutorial_2 = u'The user has to chose between left and right, and can do that by using ' + config.answer_left + ' or ' + config.answer_right + ", try it out, and press enter when you are ready to move on to the next 5 practice trials" box_left = visual.ImageStim(window, image=config.left_image, units="pix", pos=(-0.28 * 1000, -0.05 * 1000)) box_right = visual.ImageStim(window, image=config.right_image, units="pix", pos=(0.28 * 1000, -0.05 * 1000)) frame_tut1 = visual.TextStim(window, text=textTutorial_1, font='Arial', units='norm', pos=[0, 0.7], height=0.07, wrapWidth=None) frame_tut2 = visual.TextStim(window, text=textTutorial_2, font='Arial', units='norm', pos=[0, -0.7], height=0.07, wrapWidth=None) frames_list = [ frame3, frame3_baserate1, frame3_baserate2, frame1_profession1, frame1_profession2, frame_tut1, frame_tut2 ] for frame in frames_list: frame.draw() window.flip() while 1: keys = event.getKeys() if config.answer_left in keys: window.flip() for frame in frames_list: frame.draw() box_left.draw() window.flip() elif config.answer_right in keys: window.flip() for frame in frames_list: frame.draw() box_right.draw() window.flip() elif config.key_confirm in keys: break else: frames_list = [ frame3, frame3_baserate1, frame3_baserate2, frame1_profession1, frame1_profession2 ] for frame in frames_list: frame.draw() window.flip() timer.reset() startTime = timer.getTime() event.clearEvents() #max 4 seconds to respond while (startTime < 4): keys = event.getKeys() if (config.answer_left) in keys: break elif (config.answer_right) in keys: break core.wait(0.1) startTime += 0.1 window.flip() time.sleep(2) #NEXT TRIAL if run_number < 6: frame5 = visual.TextStim(window, text=textNextTrail, font='Arial', units='norm', pos=[0, 0], height=0.10, wrapWidth=None) frame5.draw() window.flip() time.sleep(2)
def testPratice(window, workBook, runNumber, audioDevice): timer = core.Clock() value_dict = {"Trial": "", "Condition": "", "Profession1": "", "Profession2": "", "Attribute": "", "Baserate1": "", "Baserate2": "", "Answeroption1": "", "Answeroption2": "", "Correct": "", "wav_profession": ""} for column in range (1, 12): #1-11, Trial - > Correct row_name = workBook.cell(row = 1, column = column) #Condition - > Correct answer cell_name = workBook.cell(row = runNumber + 1, column = column) #Americans -> Answeroption1/2 value_dict[row_name.value] = cell_name.value #set value from excel file to dictionary likely_sound, likely_fs = sf.read("is_this_person_more_likely_a.wav") attribute_sound = value_dict["Attribute"] + ".wav" profession_sound = value_dict["wav_profession"] audio_folder = os.getcwd() + "\\audio_files" original_folder = os.getcwd() os.chdir(audio_folder) attribute_sound, attribute_fs = sf.read(attribute_sound) profession_sound, profession_fs = sf.read(profession_sound) os.chdir(original_folder) #Study contains frame1_studyContains = visual.TextStim(window, text = textStudyContains, font = 'Arial', units = 'norm', pos = [0, 0.5], height = 0.07, wrapWidth=None) frame1_profession1 = call_frame(value_dict["Profession1"], "Profession1", window) frame1_profession2 = call_frame(value_dict["Profession2"], "Profession2", window) frames_list = [frame1_studyContains, frame1_profession1, frame1_profession2] for frame in frames_list: frame.draw() window.flip() time.sleep(1.8) common.fixationCross("large", 1, 0, window) #Baserates frame2 = visual.TextStim(window, text = textThereAre, font = 'Arial', units = 'norm', pos = [0, 0.5], height = 0.07, wrapWidth=None) if runNumber > 2: frame2.text = " " frame2_baserate1 = call_frame(value_dict["Baserate1"], "Baserate1", window) frame2_baserate2 = call_frame(value_dict["Baserate2"], "Baserate2", window) frames_list = [frame2, frame2_baserate1, frame2_baserate2, frame1_profession1, frame1_profession2] for frame in frames_list: frame.draw() window.flip() time.sleep(3.6) #3.6? sd.play(attribute_sound, attribute_fs, device = audioDevice) common.fixationCross("large", 0, 3, window) window.flip() time.sleep(0.2) sd.play(likely_sound, likely_fs, device = audioDevice) common.fixationCross("large", 0, 3, window) sd.wait() sd.play(profession_sound, profession_fs, device = audioDevice) time.sleep(1.2) if runNumber == 1: textTutorial_1 = u'This part will only be displayed once, so make sure you understand before moving on:' textTutorial_2 = u'The user has to chose between YES and NO, and can do that by using ' + config.answer_left + ' for YES or ' + config.answer_right+ ' for NO. If understood, press ' + 'ENTER' + ' to continue ' frame_tut1 = visual.TextStim(window, text = textTutorial_1, font = 'Arial', units = 'norm', pos = [0, 0.7], height = 0.07, wrapWidth=None) frame_tut2 = visual.TextStim(window, text = textTutorial_2, font = 'Arial', units = 'norm', pos = [0, -0.7], height = 0.07, wrapWidth=None) frame_tut1.draw() frame_tut2.draw() window.flip() common.waitforconfirm() else: timer.reset() startTime = timer.getTime() event.clearEvents() while (startTime < 4): keys = event.getKeys() if (config.answer_left) in keys: break elif (config.answer_right) in keys: break core.wait(0.1) startTime += 0.1 if startTime > 4: return time_jitter = random.uniform(3,5) common.fixationCross("large", 0, time_jitter, window) window.flip() time.sleep(random.uniform(1,2.5))
def main_loop(dict_values, workbook_output, window, excel_number, tk): timer = core.Clock() tk.sendMessage("trial number: " + str(excel_number - 1)) prof_1 = dict_values["Profession1"] prof_2 = dict_values["Profession2"] attribute = dict_values["Attribute"] base_rate1 = dict_values["Baserate1"] base_rate2 = dict_values["Baserate2"] answer_1 = dict_values["Answeroption1"] answer_2 = dict_values["Answeroption2"] correctAnswer = dict_values["Correct"] time.sleep(2) tk.sendMessage('this_study_contains') common.fixationCross("small", 1, 0, window) frame1_studyContains = visual.TextStim(window, text=u"This study contains:", font='Arial', units='norm', pos=[0, 0.5], height=0.07, wrapWidth=None) frame_1_profession1 = call_frame(prof_1, "Profession1", window) frame_1_profession2 = call_frame(prof_2, "Profession2", window) frames_list = [ frame1_studyContains, frame_1_profession1, frame_1_profession2 ] for frame in frames_list: frame.draw() window.flip() time.sleep(1.8) common.fixationCross("small", 1, 0, window) tk.sendMessage('Attribute') frame_2_attribute = call_frame(attribute, "Attribute", window) frame_2_attribute.draw() window.flip() time.sleep(1.8) common.fixationCross("small", 1, 0, window) tk.sendMessage('Baserates') frame_3_baserate1 = call_frame(base_rate1, "Baserate1", window) frame_3_baserate2 = call_frame(base_rate2, "Baserate2", window) frames_list = [ frame_3_baserate1, frame_3_baserate2, frame_1_profession1, frame_1_profession2 ] for frame in frames_list: frame.draw() window.flip() time.sleep(3.6) common.fixationCross("small", 1, 0, window) tk.sendMessage('Answeroptions') frame_4_answer1 = call_frame(answer_1, "Answeroption1", window) frame_4_answer2 = call_frame(answer_2, "Answeroption2", window) frame_4_answer1.draw() frame_4_answer2.draw() window.flip() timer.reset() startTime = timer.getTime() event.clearEvents( ) #if one accidentaly clicks a key before the selection process, it will not register while (startTime < 4): keys = event.getKeys() if (config.answer_left) in keys: if correctAnswer == "Answeroption1": workbook_output["E" + str(excel_number)] = "Correct" else: workbook_output["E" + str(excel_number)] = "Wrong" #workbook_output["E"+str(excel_number)] = "Answeroption1" workbook_output["F" + str(excel_number)] = startTime break elif (config.answer_right) in keys: if correctAnswer == "Answeroption2": workbook_output["E" + str(excel_number)] = "Correct" else: workbook_output["E" + str(excel_number)] = "Wrong" #workbook_output["E"+str(excel_number)] = "Answeroption2" workbook_output["F" + str(excel_number)] = startTime break core.wait(0.1) startTime += 0.1 tk.sendMessage("Choice made") #if time surpased the limit, we add a no response to the file if startTime > 4: print("no response") workbook_output["E" + str(excel_number)] = "No response" workbook_output["F" + str(excel_number)] = 4 window.flip() time.sleep(2)