diff options
-rw-r--r-- | master_thesis/frensch_task.py | 107 |
1 files changed, 87 insertions, 20 deletions
diff --git a/master_thesis/frensch_task.py b/master_thesis/frensch_task.py index ad67ee5..e74117d 100644 --- a/master_thesis/frensch_task.py +++ b/master_thesis/frensch_task.py @@ -5,11 +5,24 @@ from psychopy import constants, core, event, gui, visual from collections import namedtuple import frensch_procedures import random +from pprint import pprint +import pandas as pd +import pickle DisplayVariable = namedtuple("DisplayVariable", ["name", "values"]) DisplayProcedure = namedtuple("DisplayProcedure", ["procedure", "solution"]) +intro_text = """Vielen Dank dass Sie bei unserem Experiment zum menschlichen Lernen teilnehmen! + +Im folgenden müssen sie verschiedene Rechenaufgaben lösen. +Verwenden Sie die gewohnten Rechenregeln und geben sie Ihre Lösung bitte immer als zweistellige Zahl ein, und bestätigen mit Enter. +Die Werte der Variablen werden oben am Bildschirm angezeigt. Manche Variablen haben mehrere mögliche Werte; "_2" besagt z.B. das der zweite Wert zu verwenden ist. + +Nach jeder Aufgabe können Sie kurz pausieren. + +Drücken Sie die Leertaste um zu beginnen""" + def experiment_shutdown(): WIN.close() @@ -18,8 +31,10 @@ def experiment_shutdown(): WIN = visual.Window((2560, 1440), fullscr=True, units="pix") MONITOR_FPS = 60 -TRAIN_TRIALS = 1 # 75 -TEST_TRIALS = 1 # 50 +# TRAIN_TRIALS = 1 +# TEST_TRIALS = 1 +TRAIN_TRIALS = 75 +TEST_TRIALS = 50 ORDER_CONDITIONS = ["fixed", "random", "blocked"] PROCEDURE_KEYS = ["1", "2", "3", "4", "5", "6", "overall"] @@ -76,8 +91,14 @@ def generate_procedure_display(procedure: DisplayProcedure, position): return stim_procedure -def run_trial(procedure_keys: list, condition): - water_sample = frensch_procedures.constrained_WaterSample() +def generate_all_watersamples(n): + samples = [] + for _ in range(n): + samples.append(frensch_procedures.constrained_WaterSample()) + return samples + + +def run_trial(water_sample, procedure_keys: list, condition): water_sample.print_all() if condition == "random": @@ -128,23 +149,29 @@ def run_trial(procedure_keys: list, condition): stim.draw() WIN.flip() answer = stim_answer_box.text - # TODO: prevent nondigits - # answer.replace("\n", "") - # if not answer.isdigit(): - # stim_answer_box.text = "" - # answer = "" - if "\n" in stim_answer_box.text: - not_finished = False + if "\n" in answer: + if answer[0].isdigit() and answer[1].isdigit(): + not_finished = False + else: + stim_answer_box.text = answer[:-1] + if len(answer) > 2: + stim_answer_box.text = stim_answer_box.text[:2] answer_time = core.monotonicClock.getTime() - start_time - print(f"time to answer: {answer_time}") - answers.append(answer.replace("\n", "")) + answers.append((answer.replace("\n", ""), answer_time)) event.waitKeys(keyList=["space"]) - return answers + return answers, procedure_keys -intro = visual.TextBox2(WIN, "Introduction") +pause = visual.TextBox2( + WIN, + """Drücken Sie die Leertaste um mit der nächsten Aufgabe fortzufahren""", + letterHeight=50, + alignment="center", +) + +intro = visual.TextBox2(WIN, intro_text, letterHeight=30, alignment="center") intro.draw() WIN.flip() event.waitKeys(keyList=["space"]) @@ -154,13 +181,53 @@ random.shuffle(train_procedures) transfer_procedure = train_procedures[-1] train_procedures = train_procedures[:-1] train_procedures.append(PROCEDURE_KEYS[-1]) +print("test/train") print(train_procedures) +test_procedures = train_procedures +test_procedures[2] = transfer_procedure +print(test_procedures) + +all_samples = generate_all_watersamples(TRAIN_TRIALS + TEST_TRIALS) +pprint(all_samples) -for _ in range(TRAIN_TRIALS): - print(f"Answer: {run_trial(train_procedures, ORDER_CONDITIONS[0])}") +results = {} +for i in range(TRAIN_TRIALS): + answer, procedure_keys = run_trial( + all_samples[i], train_procedures, ORDER_CONDITIONS[0] + ) + answer_dict = {} + answer_dict["procedure_order"] = procedure_keys + for proc, key in zip(answer, procedure_keys): + answer_dict[key] = {"answer": proc[0], "time": proc[1]} + + results[f"train_{i}"] = answer_dict + + pause.draw() + WIN.flip() + event.waitKeys(keyList=["space"]) + train_procedures[2] = transfer_procedure -print(train_procedures) -for _ in range(TEST_TRIALS): - print(f"Answer: {run_trial(train_procedures, ORDER_CONDITIONS[0])}") +for i in range(TEST_TRIALS): + answer, procedure_keys = run_trial( + all_samples[TRAIN_TRIALS + i], train_procedures, ORDER_CONDITIONS[0] + ) + answer_dict = {} + answer_dict["procedure_order"] = procedure_keys + for proc, key in zip(answer, procedure_keys): + answer_dict[key] = {"answer": proc[0], "time": proc[1]} + + results[f"test_{i}"] = answer_dict + + pause.draw() + WIN.flip() + event.waitKeys(keyList=["space"]) + +pprint(results) + +df = pd.DataFrame.from_dict(results, orient="index") +df.to_csv("vp_results.csv") + +with open("vp.pkl", "wb") as file: + pickle.dump(results, file) |