def testShowFeedbackETMoreRTData(self): inst_and_feedback_path = self.constructFilePath("default.txt") instruction_helper = asrt.InstructionHelper(inst_and_feedback_path) instruction_helper.read_insts_from_file() experiment = asrt.Experiment("") self.initWindow() experiment.mywindow = self.mywindow experiment.settings = asrt.ExperimentSettings("", "") experiment.person_data = asrt.PersonDataHandler( "", "", "", "", "", "eye-tracking") experiment.settings.experiment_type = 'eye-tracking' experiment.settings.key_quit = 'q' experiment.stimblock = {4: 10} experiment.last_N = 4 experiment.last_block_RTs = [ "0.512", "0.443", "0.335", "0.601", "0.213", "0.934", "0.912", "0.120" ] visual_mock = pvm.PsychoPyVisualMock() instruction_helper.feedback_ET(experiment) drawing_list = visual_mock.getListOfDrawings() self.assertEqual(len(drawing_list), 1) self.assertEqualWithEOL( drawing_list[0].text, "Most pihenhetsz egy kicsit.\n\n" "Az előző blokkokban mért átlagos reakcióidők:\n\n" "6. blokk: 0.601 másodperc.\n\n" "7. blokk: 0.213 másodperc.\n\n" "8. blokk: 0.934 másodperc.\n\n" "9. blokk: 0.912 másodperc.\n\n" "10. blokk: 0.120 másodperc.\n\n")
def testLotsOfInvalidData(self): experiment = asrt.Experiment("") experiment.person_data = asrt.PersonDataHandler("", "", "", "", "", "") experiment.settings = asrt.ExperimentSettings("", "") experiment.current_sampling_window = 24 experiment.last_N = 10 experiment.last_RSI = 400.0 experiment.trial_phase = "before_stimulus" gazeData = {} gazeData['left_gaze_point_on_display_area'] = (0.5, 0.5) gazeData['right_gaze_point_on_display_area'] = (0.5, 0.5) gazeData['left_gaze_point_validity'] = 1 gazeData['right_gaze_point_validity'] = 1 clock = core.Clock() for i in range(100): experiment.eye_data_callback(gazeData) self.assertEqual(len(experiment.gaze_data_list), experiment.current_sampling_window) gazeData = {} gazeData['left_gaze_point_on_display_area'] = (0.5, 0.5) gazeData['right_gaze_point_on_display_area'] = (0.5, 0.5) gazeData['left_gaze_point_validity'] = 0 gazeData['right_gaze_point_validity'] = 0 for i in range(100): experiment.eye_data_callback(gazeData) self.assertEqual(len(experiment.gaze_data_list), experiment.current_sampling_window)
def testSharedDataLock(self): experiment = asrt.Experiment("") experiment.person_data = asrt.PersonDataHandler("", "", "", "", "", "") experiment.settings = asrt.ExperimentSettings("", "") experiment.current_sampling_window = 24 experiment.last_N = 10 experiment.last_RSI = 400.0 experiment.trial_phase = "before_stimulus" with experiment.shared_data_lock: gazeData = {} gazeData['left_gaze_point_on_display_area'] = (0.5, 0.5) gazeData['right_gaze_point_on_display_area'] = (0.5, 0.5) gazeData['left_gaze_point_validity'] = 1 gazeData['right_gaze_point_validity'] = 1 thread = threading.Thread(target=experiment.eye_data_callback, args=(gazeData, )) thread.start() thread.join(3.0) self.assertTrue(thread.is_alive()) thread.join() self.assertTrue(not thread.is_alive())
def testDataListAppend(self): experiment = asrt.Experiment("") experiment.person_data = asrt.PersonDataHandler("", "", "", "", "", "") experiment.settings = asrt.ExperimentSettings("", "") experiment.current_sampling_window = 24 experiment.last_N = 10 experiment.last_RSI = 400.0 experiment.trial_phase = "before_stimulus" gazeData = {} gazeData['left_gaze_point_validity'] = 1 gazeData['right_gaze_point_validity'] = 1 for i in range(0, experiment.current_sampling_window): gazeData['right_gaze_point_on_display_area'] = (0.02 * i, 0.02 * i) gazeData['left_gaze_point_on_display_area'] = (0.03 * i, 0.03 * i) experiment.eye_data_callback(gazeData) self.assertEqual(len(experiment.gaze_data_list), experiment.current_sampling_window) for i in range(0, experiment.current_sampling_window): self.assertAlmostEqual(experiment.gaze_data_list[i][0], 0.05 * i / 2.0, delta=0.0001) self.assertAlmostEqual(experiment.gaze_data_list[i][1], 0.05 * i / 2.0, delta=0.0001)
def testInvalidEyeData(self): experiment = asrt.Experiment("") experiment.person_data = asrt.PersonDataHandler("", "", "", "", "", "") experiment.settings = asrt.ExperimentSettings("", "") experiment.current_sampling_window = 24 experiment.last_N = 10 experiment.last_RSI = 400.0 experiment.trial_phase = "before_stimulus" gazeData = {} gazeData['left_gaze_point_on_display_area'] = (0.5, 0.5) gazeData['right_gaze_point_on_display_area'] = (1.0, 1.0) gazeData['left_gaze_point_validity'] = 0 gazeData['right_gaze_point_validity'] = 0 experiment.eye_data_callback(gazeData) self.assertEqual(len(experiment.gaze_data_list), 1) self.assertEqual(experiment.gaze_data_list[0][0], None) self.assertEqual(experiment.gaze_data_list[0][1], None) gazeData['left_gaze_point_on_display_area'] = (0.5, 0.5) gazeData['right_gaze_point_on_display_area'] = (1.0, 1.0) gazeData['left_gaze_point_validity'] = 1 gazeData['right_gaze_point_validity'] = 1 experiment.eye_data_callback(gazeData) self.assertEqual(len(experiment.gaze_data_list), 2) self.assertEqual(experiment.gaze_data_list[1][0], 0.75) self.assertEqual(experiment.gaze_data_list[1][1], 0.75) gazeData['left_gaze_point_on_display_area'] = (0.5, 0.5) gazeData['right_gaze_point_on_display_area'] = (1.0, 1.0) gazeData['left_gaze_point_validity'] = 0 gazeData['right_gaze_point_validity'] = 1 experiment.eye_data_callback(gazeData) self.assertEqual(len(experiment.gaze_data_list), 3) self.assertEqual(experiment.gaze_data_list[2][0], 1.0) self.assertEqual(experiment.gaze_data_list[2][1], 1.0) gazeData['left_gaze_point_on_display_area'] = (0.5, 0.5) gazeData['right_gaze_point_on_display_area'] = (1.0, 1.0) gazeData['left_gaze_point_validity'] = 1 gazeData['right_gaze_point_validity'] = 0 experiment.eye_data_callback(gazeData) self.assertEqual(len(experiment.gaze_data_list), 4) self.assertEqual(experiment.gaze_data_list[3][0], 0.5) self.assertEqual(experiment.gaze_data_list[3][1], 0.5) gazeData['left_gaze_point_on_display_area'] = (0.5, 0.5) gazeData['right_gaze_point_on_display_area'] = (1.0, 1.0) gazeData['left_gaze_point_validity'] = 0 gazeData['right_gaze_point_validity'] = 0 experiment.eye_data_callback(gazeData) self.assertEqual(len(experiment.gaze_data_list), 5) self.assertEqual(experiment.gaze_data_list[4][0], None) self.assertEqual(experiment.gaze_data_list[4][1], None)
def testGazeDataCallback(self): experiment = asrt.Experiment("") experiment.person_data = asrt.PersonDataHandler("", "", "", "", "", "") experiment.settings = asrt.ExperimentSettings("", "") experiment.current_sampling_window = 36 gazeData = {} gazeData['left_gaze_point_on_display_area'] = (0.5, 0.5) gazeData['right_gaze_point_on_display_area'] = (0.5, 0.5) gazeData['left_gaze_point_validity'] = True gazeData['right_gaze_point_validity'] = True clock = core.Clock() for i in range(100): experiment.eye_data_callback(gazeData) run_time = clock.getTime() self.assertAlmostEqual(run_time, 0.0, delta=0.1)
def testUnlockMainLoopLock(self): experiment = asrt.Experiment("") experiment.person_data = asrt.PersonDataHandler("", "", "", "", "", "") experiment.settings = asrt.ExperimentSettings("", "") experiment.current_sampling_window = 24 experiment.last_N = 10 experiment.last_RSI = 400.0 experiment.trial_phase = "before_stimulus" experiment.main_loop_lock.acquire() self.assertTrue(experiment.main_loop_lock.locked()) gazeData = {} gazeData['left_gaze_point_on_display_area'] = (0.5, 0.5) gazeData['right_gaze_point_on_display_area'] = (0.5, 0.5) gazeData['left_gaze_point_validity'] = 1 gazeData['right_gaze_point_validity'] = 1 experiment.eye_data_callback(gazeData) self.assertTrue(not experiment.main_loop_lock.locked())
def testShowEndingET(self): inst_and_feedback_path = self.constructFilePath("default.txt") instruction_helper = asrt.InstructionHelper(inst_and_feedback_path) instruction_helper.read_insts_from_file() experiment = asrt.Experiment("") self.initWindow() experiment.mywindow = self.mywindow experiment.settings = asrt.ExperimentSettings("", "") experiment.person_data = asrt.PersonDataHandler( "", "", "", "", "", "eye-tracking") experiment.settings.experiment_type = 'eye-tracking' experiment.settings.key_quit = 'q' visual_mock = pvm.PsychoPyVisualMock() instruction_helper.show_ending(experiment) drawing_list = visual_mock.getListOfDrawings() self.assertEqual(len(drawing_list), 1) self.assertEqualWithEOL( drawing_list[0].text, "\r\n\r\nA feladat végetért. Köszönjük a részvételt!\r\n\r\n")
def testDisplayMoreInstructionsET(self): inst_and_feedback_path = self.constructFilePath("default.txt") instruction_helper = asrt.InstructionHelper(inst_and_feedback_path) instruction_helper.read_insts_from_file() experiment = asrt.Experiment("") self.initWindow() experiment.mywindow = self.mywindow experiment.settings = asrt.ExperimentSettings("", "") experiment.person_data = asrt.PersonDataHandler( "", "", "", "", "", "eye-tracking") experiment.settings.experiment_type = 'eye-tracking' experiment.settings.key_quit = 'q' experiment.fixation_cross_pos = (0.0, 0.0) experiment.fixation_cross = visual.TextStim( win=experiment.mywindow, text="+", height=3, units="cm", color='black', pos=experiment.fixation_cross_pos) experiment.settings.instruction_fixation_threshold = 36 experiment.current_sampling_window = 36 experiment.settings.dispersion_threshold = 2.0 experiment.settings.AOI_size = 1.0 experiment.settings.monitor_width = 47.6 experiment.monitor_settings() for i in range(0, experiment.settings.instruction_fixation_threshold): gazeData = {} gazeData['left_gaze_point_on_display_area'] = (0.5, 0.5) gazeData['right_gaze_point_on_display_area'] = (0.5, 0.5) gazeData['left_gaze_point_validity'] = True gazeData['right_gaze_point_validity'] = True gazeData['left_pupil_diameter'] = 3 gazeData['right_pupil_diameter'] = 3 gazeData['left_pupil_validity'] = True gazeData['right_pupil_validity'] = True experiment.eye_data_callback(gazeData) visual_mock = pvm.PsychoPyVisualMock() instruction_helper._InstructionHelper__show_message( instruction_helper.insts, experiment) drawing_list = visual_mock.getListOfDrawings() self.assertEqual(len(drawing_list), 6) self.assertEqualWithEOL(drawing_list[0].text, "+") self.assertEqualWithEOL( drawing_list[1].text, "\r\n\r\nÜdvözlünk a feladatban!\r\n\r\n" "A képernyőn négy kör lesz, a kör egyikén megjelenik egy kutya.\r\n\r\n" "Az a feladatod, hogy a kutya megjelenési helyének megfelelő gombot nyomd meg.\r\n\r\n" "A további instrukciók megtekintéséhez nyomd meg valamelyik válaszgombot!\r\n\r\n" ) self.assertEqualWithEOL(drawing_list[2].text, "+") self.assertEqualWithEOL( drawing_list[3].text, "\r\n\r\nA következő billenytűket kell használni: z, c, b, m\r\n\r\n" "Minél pontosabban és gyorsabban kövesd le a megjelenő ingereket!\r\n\r\n" "Ehhez mindkét kezedet használd, a középső és mutatóujjaidat.\r\n\r\n" "A kutya egymás után többször ugyanazon a helyen is megjelenhet.\r\n\r\n" "A további instrukciók megtekintéséhez nyomd meg valamelyik válaszgombot!\r\n\r\n" ) self.assertEqualWithEOL(drawing_list[4].text, "+") self.assertEqualWithEOL( drawing_list[5].text, "\r\n\r\nKb. percenként fogsz visszajelzést kapni arról,\r\n" "hogy mennyire voltál gyors és pontos - ez alapján tudsz módosítani.\r\n\r\n" "A feladat indításához nyomd meg valamelyik válaszgombot!\r\n\r\n")
def testDisplaySingleInstructionET(self): inst_and_feedback_path = self.constructFilePath("default.txt") instruction_helper = asrt.InstructionHelper(inst_and_feedback_path) instruction_helper.read_insts_from_file() experiment = asrt.Experiment("") self.initWindow() experiment.mywindow = self.mywindow experiment.settings = asrt.ExperimentSettings("", "") experiment.person_data = asrt.PersonDataHandler( "", "", "", "", "", "eye-tracking") experiment.settings.experiment_type = 'eye-tracking' experiment.settings.key_quit = 'q' experiment.fixation_cross_pos = (0.0, 0.0) experiment.fixation_cross = visual.TextStim( win=experiment.mywindow, text="+", height=3, units="cm", color='black', pos=experiment.fixation_cross_pos) experiment.settings.instruction_fixation_threshold = 36 experiment.current_sampling_window = 36 experiment.settings.AOI_size = 1.0 experiment.settings.dispersion_threshold = 2.0 experiment.settings.monitor_width = 47.6 experiment.monitor_settings() for i in range(0, experiment.settings.instruction_fixation_threshold): gazeData = {} gazeData['left_gaze_point_on_display_area'] = (0.5, 0.5) gazeData['right_gaze_point_on_display_area'] = (0.5, 0.5) gazeData['left_gaze_point_validity'] = True gazeData['right_gaze_point_validity'] = True gazeData['left_pupil_diameter'] = 3 gazeData['right_pupil_diameter'] = 3 gazeData['left_pupil_validity'] = True gazeData['right_pupil_validity'] = True experiment.eye_data_callback(gazeData) visual_mock = pvm.PsychoPyVisualMock() instruction_helper._InstructionHelper__show_message( instruction_helper.ending, experiment) drawing_list = visual_mock.getListOfDrawings() self.assertEqual(len(drawing_list), 2) # fixation cross fixation_cross = drawing_list[0] self.assertTrue(isinstance(fixation_cross, pvm.TextStim)) # size self.assertAlmostEqual(fixation_cross.height, 3, delta=0.001) # pos self.assertAlmostEqual(fixation_cross.pos[0], 0.0, delta=0.001) self.assertAlmostEqual(fixation_cross.pos[1], 0.0, delta=0.001) # color self.assertEqual(fixation_cross.color, "black") # text self.assertEqualWithEOL(fixation_cross.text, str("+")) instruction_text = drawing_list[1] self.assertTrue(isinstance(instruction_text, pvm.TextStim)) # size self.assertAlmostEqual(instruction_text.height, 0.8, delta=0.001) # pos self.assertAlmostEqual(instruction_text.pos[0], 0.0, delta=0.001) self.assertAlmostEqual(instruction_text.pos[1], 0.0, delta=0.001) # color self.assertEqual(instruction_text.color, "black") # text self.assertEqualWithEOL( instruction_text.text, str("\r\n\r\nA feladat végetért. Köszönjük a részvételt!\r\n\r\n"))
def testShowETFeedbackQuit(self): inst_and_feedback_path = self.constructFilePath("default.txt") experiment = asrt.Experiment("") experiment.instructions = asrt.InstructionHelper( inst_and_feedback_path) experiment.instructions.read_insts_from_file() with self.initWindow() as experiment.mywindow: experiment.settings = asrt.ExperimentSettings("", "") experiment.person_data = asrt.PersonDataHandler( "", "", "", "", "", "eye-tracking") experiment.settings.experiment_type = 'eye-tracking' experiment.stimblock = {4: 10} experiment.last_N = 4 experiment.last_block_RTs = [ "0,512", "0,443", "0,335", "0,601", "0,213", "0,934", "0,912", "0,120" ] experiment.fixation_cross_pos = (0.0, 0.0) experiment.fixation_cross = visual.TextStim( win=experiment.mywindow, text="+", height=3, units="cm", color='black', pos=experiment.fixation_cross_pos) experiment.settings.instruction_sampling_window = 36 experiment.current_sampling_window = 36 experiment.settings.AOI_size = 1.0 experiment.settings.monitor_width = 47.6 visual_mock = pvm.PsychoPyVisualMock() visual_mock.setReturnKeyList(['q']) RT_all_list = [ 0.65598639997188, 0.45464539993554354, 1.0849266999866813, 0.5534022999927402, 1.295695999986492, 0.5086965999798849, 0.5509545999811962, 0.49283529992680997, 1.306051000021398, 0.3599263000069186, 1.0645024999976158, 0.35126660007517785, 0.5442889999831095, 0.5597730999579653, 0.4632732999743894, 0.38760909996926785, 0.40207119996193796, 0.3861942000221461, 0.367133199935779, 0.3983248999575153, 0.3604499000357464, 0.34099430008791387, 0.35795259999576956, 0.3002517999848351, 0.40677210001740605, 0.36937460000626743, 0.5297788999741897, 0.30175390001386404, 0.3833951000124216, 0.32731279998552054, 0.32933780003804713, 0.3291419999441132, 0.35642329999245703, 0.42876619996968657, 0.07691950001753867, 0.6399777999613434, 0.6637531999731436, 0.38063269993290305, 0.3111947000725195, 0.4043739999178797, 0.3144469999242574, 0.33679540001321584, 0.34361800004262477, 0.25880250008776784, 0.5984262999845669, 0.36898319993633777, 0.4533040000824258, 0.5535239999881014, 0.38425100001040846, 0.31791740003973246, 0.3305279000196606, 0.32816859998274595, 0.5189762000227347, 0.3558485999237746, 0.3522320000920445, 0.36312330001965165, 0.37158000003546476, 0.2955864999676123, 0.4330413000425324, 0.3794643000001088, 0.45566460001282394, 0.3158706999383867, 0.34224989998620003, 0.3549642999423668, 0.3268801999511197, 0.36288769997190684, 0.40274560009129345, 0.2780501999659464, 0.3742851000279188, 0.3305659000761807, 0.3156298000831157, 0.36038500000722706, 0.3795830000890419, 0.6264467999571934, 0.41464949992951006, 0.41580979991704226, 0.31482500000856817, 0.38916250003967434, 0.2932135999435559, 0.4401645000325516, 0.3866993000265211, 0.5504634999670088, 0.38067620003130287, 0.33521519997157156, 0.40001529990695417, 0.3918521999148652, 0.43088040000293404, 0.3855049000121653, 0.3882131999125704, 0.3904447000240907, 0.36844549991656095 ] return_value = experiment.show_feedback_ET(RT_all_list, False) self.assertEqual(return_value, "quit") drawing_list = visual_mock.getListOfDrawings() self.assertEqual(len(drawing_list), 3) self.assertEqualWithEOL( drawing_list[0].text, "Most pihenhetsz egy kicsit.\n\n" "Az előző blokkokban mért átlagos reakcióidők:\n\n" "6. blokk: 0,213 másodperc.\n\n" "7. blokk: 0,934 másodperc.\n\n" "8. blokk: 0,912 másodperc.\n\n" "9. blokk: 0,120 másodperc.\n\n" "10. blokk: 0,432 másodperc.\n\n") self.assertEqualWithEOL(drawing_list[1].text, "+") self.assertEqualWithEOL( drawing_list[2].text, "A következő blokkra lépéshez néz a keresztre!")