summaryrefslogtreecommitdiff
path: root/master_thesis
diff options
context:
space:
mode:
authorNiclas Dobbertin <niclas.dobbertin@mailbox.org>2023-10-16 18:08:32 +0200
committerNiclas Dobbertin <niclas.dobbertin@mailbox.org>2023-10-16 18:08:32 +0200
commitc05a2a127449595f1e62b99adb7aa3a0ded8ec27 (patch)
treeb5e93e59364a29d3f5253b0c6a13df0884f8a82e /master_thesis
parent1840bf6f0f086b156552ef47bfb870a07be39821 (diff)
parent9ad4ebeccfb7ac7f86ac74faf646f4ec95910b7e (diff)
Merge branch 'master' into 1920x1080
Diffstat (limited to 'master_thesis')
-rw-r--r--master_thesis/frensch_task.py165
1 files changed, 143 insertions, 22 deletions
diff --git a/master_thesis/frensch_task.py b/master_thesis/frensch_task.py
index c6b9eae..fb68093 100644
--- a/master_thesis/frensch_task.py
+++ b/master_thesis/frensch_task.py
@@ -1,14 +1,15 @@
#!/usr/bin/env python3
from __future__ import annotations
-from psychopy import constants, core, event, gui, visual
-from collections import namedtuple
-import frensch_procedures
+import pickle
import random
+from collections import namedtuple
from pprint import pprint
+
import pandas as pd
-import pickle
+from psychopy import core, event, gui, visual
+import frensch_procedures
DisplayVariable = namedtuple("DisplayVariable", ["name", "values"])
DisplayProcedure = namedtuple("DisplayProcedure", ["procedure", "solution"])
@@ -112,6 +113,120 @@ def generate_all_watersamples(n):
return samples
+def run_blocked_trials(water_samples, procedure_keys):
+ results = {}
+ for proc_idx, proc in enumerate(procedure_keys):
+ for sample_idx, sample in enumerate(water_samples):
+ cur_key = f"train_{sample_idx}"
+ if not cur_key in results.keys():
+ results[cur_key] = {}
+ results[cur_key]["procedure_order"] = tuple(procedure_keys)
+ results[cur_key]["water_sample"] = sample.water_sample_dict()
+
+ solid = DisplayVariable("Mineralien", [sample.solid])
+ algae = DisplayVariable("Algen", [sample.algae])
+ lime = DisplayVariable("Sandstein", sample.lime)
+ toxin = DisplayVariable("Gifte", sample.toxin)
+ x_positions = [-800, -400, 400, 800]
+
+ stims = generate_variable_display([solid, algae, lime, toxin], x_positions)
+
+ procedures = sample.procedure_dict()
+
+ proc_x = -600
+ proc_y = -100
+ answ_x = 200
+ answ_y = -100
+ y_offset = 80
+
+ print(procedure_keys[:proc_idx])
+ for prev in procedure_keys[:proc_idx]:
+ print(prev)
+ if not prev:
+ continue
+ p = DisplayProcedure(procedures[prev][1], procedures[prev][0])
+ p = generate_procedure_display(p, (proc_x, proc_y))
+ stims.append(p)
+ proc_y -= y_offset
+
+ stim_answer_equals = visual.TextBox2(
+ WIN,
+ "=",
+ letterHeight=50,
+ pos=(answ_x - 100, answ_y),
+ size=[150, 70],
+ alignment="center",
+ )
+ stims.append(stim_answer_equals)
+
+ print(sample_idx)
+ stim_answer_box = visual.TextBox2(
+ WIN,
+ results[f"train_{sample_idx}"][prev]["answer"],
+ letterHeight=50,
+ pos=(answ_x, answ_y),
+ size=[150, 70],
+ editable=True,
+ fillColor="white",
+ color="black",
+ alignment="center",
+ )
+ stims.append(stim_answer_box)
+ answ_y -= y_offset
+
+ p = DisplayProcedure(procedures[proc][1], procedures[proc][0])
+ p = generate_procedure_display(p, (proc_x, proc_y))
+ stims.append(p)
+ proc_y -= y_offset
+
+ stim_answer_equals = visual.TextBox2(
+ WIN,
+ "=",
+ letterHeight=50,
+ pos=(answ_x - 100, answ_y),
+ size=[150, 70],
+ alignment="center",
+ )
+ stims.append(stim_answer_equals)
+
+ print(sample_idx)
+ stim_answer_box = visual.TextBox2(
+ WIN,
+ "",
+ letterHeight=50,
+ pos=(answ_x, answ_y),
+ size=[150, 70],
+ editable=True,
+ fillColor="white",
+ color="black",
+ alignment="center",
+ )
+ stims.append(stim_answer_box)
+ answ_y -= y_offset
+
+ not_finished = True
+ answer = "not answered"
+ start_time = core.monotonicClock.getTime()
+ while not_finished:
+ stim_answer_box.hasFocus = True
+ for stim in stims:
+ stim.draw()
+ WIN.flip()
+ answer = stim_answer_box.text
+ 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
+ answer = (answer.replace("\n", ""), answer_time)
+ results[cur_key][proc] = {"answer": answer[0], "time": answer[1]}
+
+ return results
+
+
def run_trial(water_sample, procedure_keys: list, condition):
water_sample.print_all()
@@ -190,6 +305,13 @@ def run_trial(water_sample, procedure_keys: list, condition):
return tuple(answers), tuple(procedure_keys)
+condition_dlg = gui.Dlg(title="Experiment Condition")
+condition_dlg.addText("Condition")
+condition_dlg.addField("condition")
+CONDITION = condition_dlg.show()[0]
+
+assert CONDITION in ORDER_CONDITIONS
+
pause = visual.TextBox2(
WIN,
"""Drücken Sie die Leertaste um mit der nächsten Wasserprobe fortzufahren""",
@@ -218,26 +340,25 @@ train_procedures = train_procedures[:-1]
train_procedures.append(PROCEDURE_KEYS[-1])
all_samples = generate_all_watersamples(TRAIN_TRIALS + TEST_TRIALS)
-pprint(all_samples)
-
-results = {}
-for i in range(TRAIN_TRIALS):
- print(train_procedures)
- answer, procedure_keys = run_trial(
- all_samples[i], train_procedures, ORDER_CONDITIONS[1]
- )
- answer_dict = {}
- answer_dict["procedure_order"] = procedure_keys
- answer_dict["water_sample"] = all_samples[i].water_sample_dict()
- for proc, key in zip(answer, procedure_keys):
- answer_dict[key] = {"answer": proc[0], "time": proc[1]}
+if CONDITION != "blocked":
+ results = {}
+ for i in range(TRAIN_TRIALS):
+ print(train_procedures)
+ answer, procedure_keys = run_trial(all_samples[i], train_procedures, CONDITION)
+ answer_dict = {}
+ answer_dict["procedure_order"] = procedure_keys
+ answer_dict["water_sample"] = all_samples[i].water_sample_dict()
+ for proc, key in zip(answer, procedure_keys):
+ answer_dict[key] = {"answer": proc[0], "time": proc[1]}
- results[f"train_{i}"] = answer_dict
+ results[f"train_{i}"] = answer_dict
- pause.draw()
- WIN.flip()
- event.waitKeys(keyList=["space"])
+ pause.draw()
+ WIN.flip()
+ event.waitKeys(keyList=["space"])
+else:
+ results = run_blocked_trials(all_samples[:TRAIN_TRIALS], train_procedures)
phase = visual.TextBox2(
@@ -256,7 +377,7 @@ train_procedures[2] = transfer_procedure
for i in range(TEST_TRIALS):
print(train_procedures)
answer, procedure_keys = run_trial(
- all_samples[TRAIN_TRIALS + i], train_procedures, ORDER_CONDITIONS[0]
+ all_samples[TRAIN_TRIALS + i], train_procedures, "fixed"
)
print(procedure_keys)
answer_dict = {}