def experiment(human=False): actr.reset() items = actr.permute_list([ "B", "C", "D", "F", "G", "H", "J", "K", "L", "M", "N", "P", "Q", "R", "S", "T", "V", "W", "X", "Y", "Z" ]) text1 = items[0] window = actr.open_exp_window("Letter recognition") actr.add_text_to_exp_window(window, text1, x=125, y=150) actr.add_command("demo2-key-press", respond_to_key_press, "Demo2 task output-key monitor") actr.monitor_command("output-key", "demo2-key-press") global response response = False if human == True: while response == False: actr.process_events() else: actr.install_device(window) actr.run(10, True) actr.remove_command_monitor("output-key", "demo2-key-press") actr.remove_command("demo2-key-press") return response
def show_human_results(own_cards, others_cards, own_result, others_result): win = actr.open_exp_window('Human') actr.add_text_to_exp_window(win, 'You', x=50, y=20) actr.add_text_to_exp_window(win, 'Model', x=200, y=20) for i in range(2): for j in range(3): actr.add_text_to_exp_window(win, "C%d" % (j + 1), x=(25 + (j * 30) + (i * 150)), y=40, width=20) if i == 0: if j < len(own_cards): actr.add_text_to_exp_window(win, str(own_cards[j]), x=(25 + (j * 30) + (i * 150)), y=60, width=20) else: if j < len(others_cards): actr.add_text_to_exp_window(win, str(others_cards[j]), x=(25 + (j * 30) + (i * 150)), y=60, width=20) actr.add_text_to_exp_window(win, own_result, x=50, y=85) actr.add_text_to_exp_window(win, others_result, x=200, y=85) start_time = actr.get_time(False) while (actr.get_time(False) - start_time) < 10000: actr.process_events()
def wait_for_human(): while not (done): actr.process_events() start = actr.get_time(False) while (actr.get_time(False) - start) < 1000: actr.process_events()
def person(): global response window = actr.open_exp_window("Choice Experiment", visible=True) actr.add_command("choice-response", respond_to_key_press, "Choice task key response") actr.monitor_command("output-key", "choice-response") actr.add_text_to_exp_window(window, 'choose', x=50, y=100) response = '' while response == '': actr.process_events() actr.clear_exp_window(window) if actr.random(1.0) < .9: answer = 'heads' else: answer = 'tails' actr.add_text_to_exp_window(window, answer, x=50, y=100) start = actr.get_time(False) while (actr.get_time(False) - start) < 1000: actr.process_events() actr.remove_command_monitor("output-key", "choice-response") actr.remove_command("choice-response") return response
def do_experiment(size, trials, human): actr.reset() result = [] model = not (human) window = actr.open_exp_window("Paired-Associate Experiment", visible=human) if model: actr.install_device(window) for i in range(trials): score = 0 time = 0 for prompt, associate in actr.permute_list(pairs[20 - size:]): actr.clear_exp_window(window) actr.add_text_to_exp_window(window, prompt, x=150, y=150) global response response = '' start = actr.get_time(model) if model: actr.run_full_time(5) else: while (actr.get_time(False) - start) < 5000: actr.process_events() if response == associate: score += 1 time += response_time - start actr.clear_exp_window(window) actr.add_text_to_exp_window(window, associate, x=150, y=150) start = actr.get_time(model) if model: actr.run_full_time(5) else: while (actr.get_time(False) - start) < 5000: actr.process_events() if score > 0: average_time = time / score / 1000.0 else: average_time = 0 result.append((score / size, average_time)) return result
def experiment(human=False): actr.reset() items = actr.permute_list([ "B", "C", "D", "F", "G", "H", "J", "K", "L", "M", "N", "P", "Q", "R", "S", "T", "V", "W", "X", "Y", "Z" ]) target = items[0] foil = items[1] window = actr.open_exp_window("Letter difference") text1 = foil text2 = foil text3 = foil index = actr.random(3) if index == 0: text1 = target elif index == 1: text2 = target else: text3 = target actr.add_text_to_exp_window(window, text1, x=125, y=75) actr.add_text_to_exp_window(window, text2, x=75, y=175) actr.add_text_to_exp_window(window, text3, x=175, y=175) actr.add_command("unit2-key-press", respond_to_key_press, "Assignment 2 task output-key monitor") actr.monitor_command("output-key", "unit2-key-press") global response response = '' if human == True: while response == '': actr.process_events() else: actr.install_device(window) actr.run(10, True) actr.remove_command_monitor("output-key", "unit2-key-press") actr.remove_command("unit2-key-press") if response.lower() == target.lower(): return True else: return False
def experiment(human=False): global response response = False if human == True: while response == False: actr.process_events() else: actr.install_device(window) actr.start_hand_at_mouse() actr.run(10, True) actr.remove_command_monitor("output-key", "sp-key-press") actr.remove_command("sp-key-press") print(actr.get_time(model_time=True)) actr.run_n_events(2, real_time=False) return response
def collect_responses(count): global results results = [] actr.add_command("zbrodoff-response", respond_to_key_press, "Zbrodoff task key press response monitor") actr.monitor_command("output-key", "zbrodoff-response") present_trial(trials[0]) if run_model: actr.run(10 * count) else: while len(results) < count: actr.process_events() actr.remove_command_monitor("output-key", "zbrodoff-response") actr.remove_command("zbrodoff-response")
def play_human(cards, oc1): win = actr.open_exp_window('Human') actr.add_text_to_exp_window(win, 'You', x=50, y=20) actr.add_text_to_exp_window(win, 'Model', x=200, y=20) for i in range(2): for j in range(3): actr.add_text_to_exp_window(win, "C%d" % (j + 1), x=(25 + (j * 30) + (i * 150)), y=40, width=20) if i == 0 and j < 2: actr.add_text_to_exp_window(win, str(cards[j]), x=(25 + (j * 30) + (i * 150)), y=60, width=20) if i == 1 and j == 0: actr.add_text_to_exp_window(win, str(oc1), x=(25 + (j * 30) + (i * 150)), y=60, width=20) global human_action human_action = None start_time = actr.get_time(False) while (actr.get_time(False) - start_time) < 10000: actr.process_events() if human_action: return human_action else: return 's'
def experiment(human=False): # I guess setting response to false globally global response, light1Color, light2Color, window, text1,text2,text3,text4, \ light1_obj,light2_obj,gauge1_obj,temp1_y,gauge1_startx,gauge1_starty, \ gauge2_startx,gauge2_startx # some default parameters # for lights text1 = "A" text2 = "B" light1Color = "green" light2Color = "black" light1_obj = None light2_obj = None # for gauges text3 = "C" text4 = "D" gauge1_startx = 60 gauge1_starty = 200 gauge2_startx = 110 gauge2_starty = 200 gauge1_rate = 2 gauge2_rate = 2 fps = 5 actr.reset() window = actr.open_exp_window("hello world", width=400, height=400, x=400, y=400) # adding commands actr.add_command("demo2-key-press", respond_to_key_press, "Demo2 task output-key monitor") actr.add_command("gauge_1_move", gauge_1_move) actr.add_command("gauge_2_move", gauge_2_move) actr.add_command("light1_off", light1_off) actr.add_command("light2_off", light2_off) actr.add_command("delayed_print_visicon", delayed_print_visicon) actr.add_command("move_y", move_y) # monitoring for key board actr.monitor_command("output-key", "demo2-key-press") # putting the initial screen onto the window intialize_screen(window, text1, text2, text3, text4, gauge1_startx, gauge1_starty, gauge2_startx, gauge2_starty) response = False # human = participant. Good for testing if human == True: if actr.visible_virtuals_available(): # puts time.sleep(0) # I guess it lets the program run # maybe will need to change in the future while response == False: actr.process_events() else: actr.install_device(window) light1 = 1 light2 = 1 time1 = 0 count = 0 for event in range(0, df.shape[0]): time1 = df["time"][event] count += 1 if df["event"][event] == ( " 'Green (First) Light Script-triggered Fault'" ) and light1 == 1: #actr.schedule_event(time1-.1,"delayed_print_visicon",params=[],maintenance=True) actr.schedule_event(time1, "light1_off", params=[window, text1, "exp"], maintenance=True) event_times.append(time1) event_type.append("light1_off") #actr.schedule_event(time1+.1,"delayed_print_visicon",params=[],maintenance=True) elif df["event"][event] == ( " 'Red (Second) Light Script-triggered Fault'" ) and light2 == 1: actr.schedule_event(time1, "light2_off", params=[window, text2, "exp"], maintenance=True) event_times.append(time1) event_type.append("light2_off") # parameters for gauges temp1_y = gauge1_starty temp2_y = gauge2_starty time1 = 0 first_time_exceeded_gauge1 = 0 first_time_exceeded_gauge2 = 0 gauges_on = 1 # if gauges_on == 1: for event in range(0, round(df["time"][len(df["time"]) - 1] * fps)): time1 = time1 + (1 / fps) temp1_y = temp1_y + gauge1_rate temp2_y = temp2_y + (gauge2_rate * -1) if temp1_y < 150 or temp1_y > 250: gauge1_color = "red" if first_time_exceeded_gauge1 == 0: first_time_exceeded_gauge1 += 1 actr.schedule_event(time1, "delayed_print_visicon", params=[], maintenance=True) actr.schedule_event(time1 + .1, "delayed_print_visicon", params=[], maintenance=True) else: gauge1_color = "black" first_time_exceeded_gauge1 = 0 if temp2_y < 150 or temp2_y > 250: gauge2_color = "red" if first_time_exceeded_gauge2 == 0: first_time_exceeded_gauge2 += 1 else: gauge2_color = "black" first_time_exceeded_gauge2 = 0 if temp1_y < 125 or temp1_y > 275: gauge1_rate = gauge1_rate * -1 if first_time_exceeded_gauge1 == 1: event_times.append(time1) event_type.append("gauge1_off") if temp2_y < 125 or temp2_y > 275: gauge2_rate = gauge2_rate * -1 if first_time_exceeded_gauge2 == 1: event_times.append(time1) event_type.append("gauge2_off") #actr.schedule_event(time1-.1,"delayed_print_visicon",params=[],maintenance=True) actr.schedule_event(time1, "gauge_1_move", params=[ window, text3, gauge1_startx, temp1_y, gauge1_color ], maintenance=True) actr.schedule_event(time1, "gauge_2_move", params=[ window, text4, gauge2_startx, temp2_y, gauge2_color ], maintenance=True) #actr.schedule_event(time1+.1,"delayed_print_visicon",params=[],maintenance=True) #actr.run(df["time"][len(df["time"])-1]) actr.run(15, True) # pause actr # removing commands and things actr.remove_command_monitor("output-key", "demo2-key-press") actr.remove_command("gauge_1_move") actr.remove_command("gauge_2_move") actr.remove_command("light1_off") actr.remove_command("light2_off") actr.remove_command("move_y") # printing some things print("respones", responses) print("response_times", times) print("event_times", event_times) print("event_type", event_type)