#!/usr/bin/env python3 import random import frensch_procedures class Stimuli: # 6 = overall procedure_ids = ["1", "2", "3", "4", "5", "6"] current_stimulus_id = -1 order_list = [] training_order_list = [] test_order_list = [] def __init__(self, condition, training_N=75, test_N=50): self.condition = condition self.training_N = training_N self.test_N = test_N self.training_order = random.sample( self.procedure_ids, k=len(self.procedure_ids) ) self.test_proc = self.training_order[-1] self.training_order = self.training_order[:-1] self.training_order.append("overall") self.test_order = self.training_order.copy() self.test_order[2] = self.test_proc def generate_stimuli(self): self.training_samples = [] for _ in range(self.training_N): self.training_samples.append(frensch_procedures.constrained_WaterSample()) self.training_stimuli = self.generate_environments( self.training_samples, self.training_order ) self.test_samples = [] for _ in range(self.test_N): self.test_samples.append(frensch_procedures.constrained_WaterSample()) self.test_stimuli = self.generate_environments( self.test_samples, self.test_order ) if self.condition == "random": self.training_order_list = self.order_list[:self.training_N] self.test_order_list = self.order_list[self.training_N:] def next_stimulus(self): self.current_stimulus_id += 1 if self.current_stimulus_id < self.training_N: return self.training_stimuli[self.current_stimulus_id] else: return self.test_stimuli[self.current_stimulus_id - self.training_N] def update_current_stimulus(self, key, value): if self.current_stimulus_id < self.training_N: self.training_stimuli[self.current_stimulus_id][key]["text"] = value return self.training_stimuli[self.current_stimulus_id] else: self.test_stimuli[self.current_stimulus_id - self.training_N][key][ "text" ] = value return self.test_stimuli[self.current_stimulus_id - self.training_N] def generate_environments(self, water_samples, order): envs = [] for sample in water_samples: screen = {} self.generate_variables(screen, sample) if self.condition == "random": order_cut = order[:-1] random.shuffle(order_cut) order_cut.append(order[-1]) order = order_cut self.order_list.append(order) else: self.order_list.append(order) self.generate_procedures(screen, order) envs.append(screen) return envs def generate_procedures(self, screen, order): procs = ["proc1", "proc2", "proc3", "proc4", "proc5", "proc6"] screen["Procedures"] = {"text": "Formeln", "position": (0, 100)} screen["Procedure1"] = {"text": procs[int(order[0]) - 1], "position": (0, 200)} screen["Procedure2"] = {"text": procs[int(order[1]) - 1], "position": (0, 300)} screen["Procedure3"] = {"text": procs[int(order[2]) - 1], "position": (0, 400)} screen["Procedure4"] = {"text": procs[int(order[3]) - 1], "position": (0, 500)} screen["Procedure5"] = {"text": procs[int(order[4]) - 1], "position": (0, 600)} screen["ProcedureOverall"] = {"text": "proc_overall", "position": (0, 700)} screen["Answers"] = {"text": "Kennwerte", "position": (100, 100)} screen["Answer1"] = {"text": "null", "position": (100, 200)} screen["Answer2"] = {"text": "null", "position": (100, 300)} screen["Answer3"] = {"text": "null", "position": (100, 400)} screen["Answer4"] = {"text": "null", "position": (100, 500)} screen["Answer5"] = {"text": "null", "position": (100, 600)} # Answer overall screen["Answer6"] = {"text": "null", "position": (100, 700)} def generate_variables(self, screen, sample): # Variables screen["Algen"] = {"text": "Algen", "position": (400, 100)} screen["AlgenVar"] = {"text": sample.algae, "position": (400, 200)} screen["Mineralien"] = {"text": "Mineralien", "position": (500, 100)} screen["MineralienVar"] = {"text": sample.solid, "position": (500, 200)} screen["Gifte"] = {"text": "Gifte", "position": (600, 100)} screen["GifteVar1"] = {"text": sample.toxin[0], "position": (600, 200)} screen["GifteVar2"] = {"text": sample.toxin[1], "position": (600, 300)} screen["GifteVar3"] = {"text": sample.toxin[2], "position": (600, 400)} screen["GifteVar4"] = {"text": sample.toxin[3], "position": (600, 500)} screen["Sandstein"] = {"text": "Sandstein", "position": (700, 100)} screen["SandsteinVar1"] = {"text": sample.lime[0], "position": (700, 200)} screen["SandsteinVar2"] = {"text": sample.lime[1], "position": (700, 300)} screen["SandsteinVar3"] = {"text": sample.lime[2], "position": (700, 400)} screen["SandsteinVar4"] = {"text": sample.lime[3], "position": (700, 500)}