Passed
Push — main ( 38376b...7b37bf )
by N.
03:15
created

TTRKod::garanti()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 3
ccs 3
cts 3
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * Enum TTRKod.
5
 * @author Niklas Dougherty
6
 */
7
8
declare(strict_types=1);
9
10
namespace Tips\Moduler\TT;
11
12
/**
13
 * Enum TTRKod.
14
 * @author Niklas Dougherty
15
 * @SuppressWarnings("PHPMD.ExcessiveMethodLength")
16
 */
17
enum TTRKod: string {
18
	case R_8_0_486_1 = 'R_8_0_486_1';
19
20
	case R_7_1_333_1 = 'R_7_1_333_1';
21
	case R_7_0_186_1 = 'R_7_0_186_1';
22
23
	case R_6_2_252_1 = 'R_6_2_252_1';
24
	case R_6_1_132_1 = 'R_6_1_132_1';
25
	case R_6_0_73_1 = 'R_6_0_73_1';
26
27
	case R_5_3_168_1 = 'R_5_3_168_1';
28
	case R_5_2_96_1 = 'R_5_2_96_1';
29
	case R_5_1_54_1 = 'R_5_1_54_1';
30
	case R_5_0_27_1 = 'R_5_0_27_1';
31
32
	case R_4_4_128_1 = 'R_4_4_128_1';
33
	case R_4_3_72_1 = 'R_4_3_72_1';
34
	case R_4_2_36_1 = 'R_4_2_36_1';
35
	case R_4_1_18_1 = 'R_4_1_18_1';
36
	case R_4_0_9_1 = 'R_4_0_9_1';
37
38
	case R_3_5_92_1 = 'R_3_5_92_1';
39
	case R_3_4_48_1 = 'R_3_4_48_1';
40
	case R_3_3_24_1 = 'R_3_3_24_1';
41
	case R_3_2_16_1 = 'R_3_2_16_1';
42
	case R_3_1_9_1 = 'R_3_1_9_1';
43
	case R_3_0_5_1 = 'R_3_0_5_1';
44
45
	case R_2_6_64_1 = 'R_2_6_64_1';
46
	case R_2_5_36_1 = 'R_2_5_36_1';
47
	case R_2_4_20_1 = 'R_2_4_20_1';
48
	case R_2_3_12_1 = 'R_2_3_12_1';
49
	case R_2_2_6_1 = 'R_2_2_6_1';
50
	case R_2_1_4_1 = 'R_2_1_4_1';
51
	case R_2_0_3_1 = 'R_2_0_3_1';
52
53
	case R_1_7_48_1 = 'R_1_7_48_1';
54
	case R_1_6_24_1 = 'R_1_6_24_1';
55
	case R_1_5_16_1 = 'R_1_5_16_1';
56
	case R_1_4_8_1 = 'R_1_4_8_1';
57
	case R_1_3_6_1 = 'R_1_3_6_1';
58
	case R_1_2_3_1 = 'R_1_2_3_1';
59
	case R_1_1_2_1 = 'R_1_1_2_1';
60
	case R_1_0_1_1 = 'R_1_0_1_1';
61
62
	case R_0_8_32_1 = 'R_0_8_32_1';
63
	case R_0_7_16_1 = 'R_0_7_16_1';
64
	case R_0_6_12_1 = 'R_0_6_12_1';
65
	case R_0_5_7_1 = 'R_0_5_7_1';
66
	case R_0_4_4_1 = 'R_0_4_4_1';
67
	case R_0_3_2_1 = 'R_0_3_2_1';
68
	case R_0_2_2_1 = 'R_0_2_2_1';
69
	case R_0_1_1_1 = 'R_0_1_1_1';
70
71
	case R_8_0_81_2 = 'R_8_0_81_2';
72
73
	case R_7_1_54_2 = 'R_7_1_54_2';
74
	case R_7_0_34_2 = 'R_7_0_34_2';
75
76
	case R_6_2_48_2 = 'R_6_2_48_2';
77
	case R_6_1_27_2 = 'R_6_1_27_2';
78
	case R_6_0_17_2 = 'R_6_0_17_2';
79
80
	case R_5_3_36_2 = 'R_5_3_36_2';
81
	case R_5_2_21_2 = 'R_5_2_21_2';
82
	case R_5_1_12_2 = 'R_5_1_12_2';
83
	case R_5_0_8_2 = 'R_5_0_8_2';
84
85
	case R_4_4_24_2 = 'R_4_4_24_2';
86
	case R_4_3_18_2 = 'R_4_3_18_2';
87
	case R_4_2_10_2 = 'R_4_2_10_2';
88
	case R_4_1_6_2 = 'R_4_1_6_2';
89
	case R_4_0_3_2 = 'R_4_0_3_2';
90
91
	case R_3_5_23_2 = 'R_3_5_23_2';
92
	case R_3_4_13_2 = 'R_3_4_13_2';
93
	case R_3_3_8_2 = 'R_3_3_8_2';
94
	case R_3_2_5_2 = 'R_3_2_5_2';
95
	case R_3_1_3_2 = 'R_3_1_3_2';
96
	case R_3_0_3_2 = 'R_3_0_3_2';
97
98
	case R_2_6_16_2 = 'R_2_6_16_2';
99
	case R_2_5_11_2 = 'R_2_5_11_2';
100
	case R_2_4_6_2 = 'R_2_4_6_2';
101
	case R_2_3_4_2 = 'R_2_3_4_2';
102
	case R_2_2_3_2 = 'R_2_2_3_2';
103
	case R_2_1_2_2 = 'R_2_1_2_2';
104
	case R_2_0_1_2 = 'R_2_0_1_2';
105
106
	case R_1_7_12_2 = 'R_1_7_12_2';
107
	case R_1_6_8_2 = 'R_1_6_8_2';
108
	case R_1_5_6_2 = 'R_1_5_6_2';
109
	case R_1_4_3_2 = 'R_1_4_3_2';
110
	case R_1_3_2_2 = 'R_1_3_2_2';
111
	case R_1_2_2_2 = 'R_1_2_2_2';
112
	case R_1_1_1_2 = 'R_1_1_1_2';
113
114
	case R_0_8_12_2 = 'R_0_8_12_2';
115
	case R_0_7_7_2 = 'R_0_7_7_2';
116
	case R_0_6_4_2 = 'R_0_6_4_2';
117
	case R_0_5_2_2 = 'R_0_5_2_2';
118
	case R_0_4_2_2 = 'R_0_4_2_2';
119
	case R_0_3_2_2 = 'R_0_3_2_2';
120
	case R_0_2_1_2 = 'R_0_2_1_2';
121
122
	public const GARANTITABELL = [
123
		'R_8_0_486_1' => [7.4, 100.0, 100.0, 100.0],
124
125
		'R_7_1_333_1' => [7.6, 99.0, 100.0, 100.0],
126
		'R_7_0_186_1' => [8.5, 96.3, 98.6, 100.0],
127
128
		'R_6_2_252_1' => [8.6, 98.5, 100.0, 100.0],
129
		'R_6_1_132_1' => [9.1, 100.0, 95.9, 100.0],
130
		'R_6_0_73_1' => [10.0, 96.0, 99.2, 100.0],
131
132
		'R_5_3_168_1' => [8.6, 95.4, 100.0, 100.0],
133
		'R_5_2_96_1' => [9.9, 96.9, 96.3, 100.0],
134
		'R_5_1_54_1' => [11.1, 100.0, 100.0, 100.0],
135
		'R_5_0_27_1' => [11.1, 88.9, 100.0, 100.0],
136
137
		'R_4_4_128_1' => [9.9, 94.1, 98.8, 100.0],
138
		'R_4_3_72_1' => [11.1, 100.0, 94.4, 100.0],
139
		'R_4_2_36_1' => [11.1, 100.0, 100.0, 100.0],
140
		'R_4_1_18_1' => [11.1, 88.9, 100.0, 100.0],
141
		'R_4_0_9_1' => [11.1, 88.9, 88.9, 100.0],
142
143
		'R_3_5_92_1' => [10.6, 95.8, 98.6, 100.0],
144
		'R_3_4_48_1' => [11.1, 94.4, 100.0, 100.0],
145
		'R_3_3_24_1' => [11.1, 94.4, 94.4, 100.0],
146
		'R_3_2_16_1' => [14.8, 92.6, 100.0, 100.0],
147
		'R_3_1_9_1' => [16.7, 83.3, 100.0, 100.0],
148
		'R_3_0_5_1' => [18.5, 81.5, 81.5, 100.0],
149
150
		'R_2_6_64_1' => [11.1, 97.2, 97.2, 100.0],
151
		'R_2_5_36_1' => [12.5, 98.6, 93.1, 100.0],
152
		'R_2_4_20_1' => [13.9, 91.7, 94.4, 100.0],
153
		'R_2_3_12_1' => [16.7, 91.7, 94.4, 100.0],
154
		'R_2_2_6_1' => [16.7, 83.3, 100.0, 94.4],
155
		'R_2_1_4_1' => [22.2, 100.0, 77.8, 66.7],
156
		'R_2_0_3_1' => [33.3, 100.0, 66.7, 0.0],
157
158
		'R_1_7_48_1' => [12.5, 88.5, 99.5, 100.0],
159
		'R_1_6_24_1' => [12.5, 95.8, 87.5, 100.0],
160
		'R_1_5_16_1' => [16.7, 95.8, 96.9, 100.0],
161
		'R_1_4_8_1' => [16.7, 83.3, 95.8, 100.0],
162
		'R_1_3_6_1' => [25.0, 83.3, 95.8, 87.5],
163
		'R_1_2_3_1' => [25.0, 91.7, 75.0, 41.7],
164
		'R_1_1_2_1' => [33.3, 100.0, 66.7, 0.0],
165
		'R_1_0_1_1' => [33.3, 66.7, 0.0, 0.0],
166
167
		'R_0_8_32_1' => [12.5, 89.1, 98.4, 100.0],
168
		'R_0_7_16_1' => [12.5, 87.5, 87.5, 100.0],
169
		'R_0_6_12_1' => [18.8, 90.6, 96.9, 100.0],
170
		'R_0_5_7_1' => [21.9, 87.5, 93.8, 93.8],
171
		'R_0_4_4_1' => [25.0, 100.0, 75.0, 100.0],
172
		'R_0_3_2_1' => [25.0, 75.0, 75.0, 25.0],
173
		'R_0_2_2_1' => [50.0, 100.0, 50.0, 0],
174
		'R_0_1_1_1' => [50.0, 50.0, 0, 0],
175
176
		'R_8_0_81_2' => [1.2, 19.8, 88.9, 100.0],
177
178
		'R_7_1_54_2' => [1.2, 18.5, 97.5, 98.8],
179
		'R_7_0_34_2' => [1.6, 21.6, 94.2, 99.2],
180
181
		'R_6_2_48_2' => [1.6, 19.8, 91.8, 97.5],
182
		'R_6_1_27_2' => [1.9, 22.8, 92.8, 98.4],
183
		'R_6_0_17_2' => [2.3, 28.0, 90.4, 99.9],
184
185
		'R_5_3_36_2' => [1.9, 23.5, 89.5, 97.5],
186
		'R_5_2_21_2' => [2.2, 24.7, 91.4, 98.5],
187
		'R_5_1_12_2' => [2.5, 27.2, 93.0, 96.7],
188
		'R_5_0_8_2' => [3.3, 29.2, 84.8, 88.5],
189
190
		'R_4_4_24_2' => [1.9, 22.2, 75.9, 96.3],
191
		'R_4_3_18_2' => [2.8, 30.6, 88.9, 100.0],
192
		'R_4_2_10_2' => [3.1, 30.2, 92.0, 94.4],
193
		'R_4_1_6_2' => [3.7, 30.9, 84.0, 86.4],
194
		'R_4_0_3_2' => [3.7, 29.6, 66.7, 74.1],
195
196
		'R_3_5_23_2' => [2.7, 28.5, 76.5, 87.0],
197
		'R_3_4_13_2' => [3.0, 27.8, 86.8, 100.0],
198
		'R_3_3_8_2' => [3.7, 32.4, 84.3, 99.1],
199
		'R_3_2_5_2' => [4.6, 37.0, 88.0, 97.2],
200
		'R_3_1_3_2' => [5.6, 38.9, 66.7, 75.9],
201
		'R_3_0_3_2' => [11.1, 63.0, 81.5, 66.7],
202
203
		'R_2_6_16_2' => [2.8, 27.8, 86.1, 98.6],
204
		'R_2_5_11_2' => [3.8, 34.4, 87.8, 98.6],
205
		'R_2_4_6_2' => [4.2, 30.6, 83.3, 94.4],
206
		'R_2_3_4_2' => [5.6, 38.9, 77.8, 88.9],
207
		'R_2_2_3_2' => [8.3, 47.2, 72.2, 75.0],
208
		'R_2_1_2_2' => [11.1, 55.6, 88.9, 44.4],
209
		'R_2_0_1_2' => [11.1, 44.4, 44.4, 0.0],
210
211
		'R_1_7_12_2' => [3.1, 28.1, 84.4, 100.0],
212
		'R_1_6_8_2' => [4.2, 32.3, 85.4, 91.7],
213
		'R_1_5_6_2' => [6.3, 35.4, 89.6, 87.5],
214
		'R_1_4_3_2' => [6.3, 35.4, 79.2, 65.5],
215
		'R_1_3_2_2' => [8.3, 41.7, 50.0, 58.3],
216
		'R_1_2_2_2' => [16.7, 66.7, 83.3, 33.3],
217
		'R_1_1_1_2' => [16.7, 50.0, 33.3, 0.0],
218
219
		'R_0_8_12_2' => [4.7, 32.0, 84.4, 99.2],
220
		'R_0_7_7_2' => [5.5, 35.2, 87.5, 89.8],
221
		'R_0_6_4_2' => [6.3, 37.5, 93.8, 62.5],
222
		'R_0_5_2_2' => [6.3, 31.3, 62.5, 62.5],
223
		'R_0_4_2_2' => [12.5, 50.0, 37.5, 50.0],
224
		'R_0_3_2_2' => [25.0, 75.0, 75.0, 25.0],
225
		'R_0_2_1_2' => [25.0, 50.0, 25.0, 0.0],
226
	];
227
228 1
	public function garanti(): string {
229 1
		return number_format(100 * intval(explode('_', $this->name)[3]) / pow(3, intval(explode('_', $this->name)[1])) /
0 ignored issues
show
Bug Best Practice introduced by
The property name does not exist on Tips\Moduler\TT\TTRKod. Did you maybe forget to declare it?
Loading history...
230 1
			pow(2, intval(explode('_', $this->name)[2])), 2) . ' %';
231
	}
232
233
	/**
234
	 * @return float[]
235
	 * @SuppressWarnings("PHPMD.ExcessiveMethodLength")
236
	 */
237 2
	public function garantitabell(): array {
238 2
		return self::GARANTITABELL[$this->name];
0 ignored issues
show
Bug Best Practice introduced by
The property name does not exist on Tips\Moduler\TT\TTRKod. Did you maybe forget to declare it?
Loading history...
Bug introduced by
The constant Tips\Moduler\TT\TTRKod::GARANTITABELL was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
239
	}
240
241
	/**
242
	 * Visa antal helgarderingar för aktuell kod.
243
	 */
244 2
	public function helgarderingar(): int {
245 2
		return intval(explode('_', $this->name)[1]);
0 ignored issues
show
Bug Best Practice introduced by
The property name does not exist on Tips\Moduler\TT\TTRKod. Did you maybe forget to declare it?
Loading history...
246
	}
247
248
	/**
249
	 * Visa antal halvgarderingar för aktuell kod.
250
	 */
251 2
	public function halvgarderingar(): int {
252 2
		return intval(explode('_', $this->name)[2]);
0 ignored issues
show
Bug Best Practice introduced by
The property name does not exist on Tips\Moduler\TT\TTRKod. Did you maybe forget to declare it?
Loading history...
253
	}
254
255
	/**
256
	 * Visa antal rader för aktuell kod.
257
	 */
258 2
	public function antal_rader(): string {
259 2
		return explode('_', $this->name)[3];
0 ignored issues
show
Bug Best Practice introduced by
The property name does not exist on Tips\Moduler\TT\TTRKod. Did you maybe forget to declare it?
Loading history...
260
	}
261
262
	/**
263
	 * Visa allmänna data för aktuell kod.
264
	 */
265 1
	public function koddata(): string {
266 1
		$rymd = pow(3, $this->helgarderingar()) * pow(2, $this->halvgarderingar());
267 1
		$reduktion = number_format(fdiv($rymd, (int) $this->antal_rader()), 2);
268 1
		$fält = '𝔽₃' . n_exponent($this->helgarderingar()) . ' ⨯ 𝔽₂' . n_exponent($this->halvgarderingar());
269 1
		$antal = count($this->kod());
270 1
		$kontroll = $antal . ' vektorer med vardera ' . strlen($this->kod()[0]) . ' bitar.';
271 1
		$reduktion2 = number_format(fdiv($rymd, $antal), 2);
272 1
		$rymd = number_format($rymd, 0, '.', ' ');
273 1
		$täckning = intval(explode('_', $this->name)[4]);
0 ignored issues
show
Bug Best Practice introduced by
The property name does not exist on Tips\Moduler\TT\TTRKod. Did you maybe forget to declare it?
Loading history...
274
275 1
		return <<< EOT
276 1
							<h2>Reducerad kod:</h2>
277 1
							<p class="större">{$this->name}<br>
278 1
								Kod K({$this->helgarderingar()}₃, {$this->halvgarderingar()}₂, <span class="vinst10">R = $täckning</span>) över $fält<br>
279 1
								Rymd: $rymd; rader: {$this->antal_rader()}; reduktion: $reduktion<br>
280 1
								Kontroll: $kontroll; reduktion: $reduktion2<br>
281 1
								Vinstchans 8 r: {$this->garanti()}</p>
282
							<p class="större">Garantitabell:<br>
283 1
								8 r: {$this->garantitabell()[0]} %<br>
284 1
								7 r: {$this->garantitabell()[1]} %<br>
285 1
								6 r: {$this->garantitabell()[2]} %<br>
286 1
								5 r: {$this->garantitabell()[3]} %</p>
287 1
							<input type="hidden" class="antal_helgarderingar" value="{$this->helgarderingar()}">
288 1
							<input type="hidden" class="antal_halvgarderingar" value="{$this->halvgarderingar()}">
289 1
EOT;
290
	}
291
292
	/**
293
	 * Visa kodnamn.
294
	 * @return string[]
295
	 */
296 3
	public function kod(): array {
297 3
		$mapp = 'R' . explode('_', $this->name)[4];
0 ignored issues
show
Bug Best Practice introduced by
The property name does not exist on Tips\Moduler\TT\TTRKod. Did you maybe forget to declare it?
Loading history...
298 3
		$klass = "\\Tips\\Koder\\$mapp\\" . $this->name;
299 3
		$system = new $klass();
300 3
		return property_exists($system, 'kod') ? $system->kod : [];
301
	}
302
}
303