summaryrefslogtreecommitdiff
path: root/modeling/model_env.py
blob: 45b320731efb6146224b59860ed22b14b72a4f76 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#!/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 = []

    current_proc_id = 1
    current_phase = "train"

    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.condition != "blocked":
            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]
        elif self.condition == "blocked":
            if self.current_stimulus_id > 6 * self.training_N:
                return self.test_stimuli[self.current_stimulus_id % 6 - self.training_N]
            else:
                return self.training_stimuli[self.current_stimulus_id % 6]

    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)}