summaryrefslogtreecommitdiff
path: root/modeling/frensch_procedures.py
blob: 9dcbf36a52dd3103b704cac3af29cdbaf84f4622 (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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
#!/usr/bin/env python3

from __future__ import annotations
import random


class WaterSample:
    def __init__(
        self,
        solid: int,
        algae: int,
        lime: tuple[int, int, int, int],
        toxin: tuple[int, int, int, int],
    ):
        self.solid = solid
        self.algae = algae
        self.lime = lime
        self.toxin = toxin

    def procedure_dict(self):
        procedures = {
            "1": (self.index1(), self.index1_str()),
            "2": (self.index2(), self.index2_str()),
            "3": (self.index3(), self.index3_str()),
            "4": (self.index4(), self.index4_str()),
            "5": (self.index5(), self.index5_str()),
            "6": (self.index6(), self.index6_str()),
            "overall": (self.overall(), self.overall_str()),
        }

        return procedures

    def water_sample_dict(self):
        sample = {
            "1": (self.index1(), self.index1_str()),
            "2": (self.index2(), self.index2_str()),
            "3": (self.index3(), self.index3_str()),
            "4": (self.index4(), self.index4_str()),
            "5": (self.index5(), self.index5_str()),
            "6": (self.index6(), self.index6_str()),
            "overall": (self.overall(), self.overall_str()),
            "solid": self.solid,
            "algae": self.algae,
            "lime": self.lime,
            "toxin": self.toxin,
        }
        return sample

    def select_procedures(self):
        procedures = [
            (self.index1, self.index1_str),
            (self.index2, self.index2_str),
            (self.index3, self.index3_str),
            (self.index4, self.index4_str),
            (self.index5, self.index5_str),
            (self.index6, self.index6_str),
        ]
        random.shuffle(procedures)
        training_procedures = procedures[:-1]
        training_procedures.append((self.overall, self.overall_str))

        return training_procedures, procedures[-1]

    def index1(self):
        return (self.lime[3] - self.lime[1]) * self.solid

    def index1_str(self):
        return "(Sandstein_4 - Sandstein_2) * Mineralien"

    def index2(self):
        return (2 * self.algae) + min(self.lime)

    def index2_str(self):
        return "(2 * Algen) + Sandstein_min"

    def index3(self):
        return max(self.toxin) + min(self.toxin)

    def index3_str(self):
        return "Gifte_max + Gifte_min"

    def index4(self):
        return (self.solid * 2) - self.toxin[3]

    def index4_str(self):
        return "(Mineralien * 2) - Gifte_4"

    def index5(self):
        return max(self.lime[2], (self.toxin[2] - self.toxin[1]))

    def index5_str(self):
        return "Das Höhere von (Gifte_3 - Gifte_2), (Sandstein_3)"

    def index6(self):
        return min(self.algae, (self.lime[0] + self.toxin[0]))

    def index6_str(self):
        return "Das Kleinere von (Sandstein_1 + Gifte_1), (Algen)"

    def overall(self):
        return 100 - max(
            self.index1(), self.index2(), self.index3(), self.index4(), self.index5()
        )

    def overall_str(self):
        return "100 - dem Höchstem aller Ergebnisse"

    def print_all(self):
        print(f"Solid: {self.solid}")
        print(f"Algae: {self.algae}")
        print(f"Lime: {self.lime}")
        print(f"Toxin: {self.toxin}")
        print(f"Index 1: {self.index1_str()} = {self.index1()}")
        print(f"Index 2: {self.index2_str()} = {self.index2()}")
        print(f"Index 3: {self.index3_str()} = {self.index3()}")
        print(f"Index 4: {self.index4_str()} = {self.index4()}")
        print(f"Index 5: {self.index5_str()} = {self.index5()}")
        print(f"Index 6: {self.index6_str()} = {self.index6()}")
        print(f"Overall Quality: {self.overall_str()} = {self.overall()}")


# No step should produce a negative number, greater/lesser of comparisons should not
# use equal numbers
def constrained_WaterSample():
    water_sample = random_WaterSample()
    resample = True
    while resample:
        water_sample = random_WaterSample()
        resample = False
        # check for negative results
        for proc in water_sample.procedure_dict().keys():
            if water_sample.procedure_dict()[proc][0] < 0:
                resample = True
        # check for negative intermediate result
        if (water_sample.lime[3] - water_sample.lime[1]) < 0:
            resample = True
        if (water_sample.toxin[2] - water_sample.toxin[1]) < 0:
            resample = True
        # check for greater/lesser equality
        # procedure 5
        if (water_sample.toxin[2] - water_sample.toxin[1]) == water_sample.lime[2]:
            resample = True
        # procedure 6
        if (water_sample.lime[0] + water_sample.toxin[0]) == water_sample.algae:
            resample = True
    return water_sample


def random_WaterSample():
    solid = random.randint(1, 9)
    algae = random.randint(1, 9)
    lime = tuple(random.randint(1, 9) for _ in range(4))
    toxin = tuple(random.randint(1, 9) for _ in range(4))

    return WaterSample(solid, algae, lime, toxin)