|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* Klass Fordelning. |
|
5
|
|
|
* @author Niklas Dougherty |
|
6
|
|
|
*/ |
|
7
|
|
|
|
|
8
|
|
|
declare(strict_types=1); |
|
9
|
|
|
|
|
10
|
|
|
namespace Tips\Moduler\HG; |
|
11
|
|
|
|
|
12
|
|
|
use Tips\Egenskaper\Eka; |
|
13
|
|
|
use Tips\Moduler\HG\Konstanter; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* Klass Fordelning. |
|
17
|
|
|
* Beräkna fördelning av antal rätt över alla omgångar. |
|
18
|
|
|
* Exvs. 13 r uppnås i 4 % av fallen, men i teorin bara 0.5 %. |
|
19
|
|
|
* HG 11 prickar 11 r i 44 % av alla fall, motsvarande 221184 rader. |
|
20
|
|
|
* Totala reduktionen för HG 11 motsvarar därmed två säkra. |
|
21
|
|
|
*/ |
|
22
|
|
|
class Fordelning extends Utdata { |
|
23
|
|
|
use Konstanter; |
|
24
|
|
|
use Eka; |
|
25
|
|
|
|
|
26
|
|
|
protected string $fördelning = ''; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* Beräkna fördelning. |
|
30
|
|
|
*/ |
|
31
|
1 |
|
protected function beräkna_fördelning(): void { |
|
32
|
1 |
|
$hg_vektor = $this->hg_vektor(); |
|
33
|
1 |
|
$hg_summa = array_sum($hg_vektor); |
|
34
|
|
|
|
|
35
|
1 |
|
$ackumulerad_andel = 0; |
|
36
|
1 |
|
$delsträng = ''; |
|
37
|
|
|
/** |
|
38
|
|
|
* Iterera över utfall i alla omgångar. |
|
39
|
|
|
*/ |
|
40
|
1 |
|
foreach ($hg_vektor as $hg_index => $antal) { |
|
41
|
1 |
|
$ackumulerad_andel += $andel = 100 * $antal / $hg_summa; |
|
42
|
1 |
|
[$antal_rader, $andel_teori] = self::HG_MATRIS[$hg_index]; |
|
|
|
|
|
|
43
|
1 |
|
$faktor = $ackumulerad_andel / $andel_teori; |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* Bilda tabellrad. |
|
47
|
|
|
*/ |
|
48
|
1 |
|
$delsträng .= <<< EOT |
|
49
|
1 |
|
<tr class="höger"> |
|
50
|
1 |
|
<td>$hg_index</td> |
|
51
|
1 |
|
<td>$antal_rader</td> |
|
52
|
1 |
|
<td{$this->eka(stil(1 - $andel / 100))}>{$this->eka(number_format($andel, 2))}</td> |
|
53
|
1 |
|
<td{$this->eka(stil(1 - $ackumulerad_andel / 100))}>{$this->eka(number_format($ackumulerad_andel, 2))}</td> |
|
54
|
1 |
|
<td>{$this->eka(number_format($andel_teori, 2))}</td> |
|
55
|
1 |
|
<td>{$this->eka(number_format($faktor, 2))}</td> |
|
56
|
|
|
</tr> |
|
57
|
|
|
|
|
58
|
1 |
|
EOT; |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* Bilda tabell. |
|
63
|
|
|
*/ |
|
64
|
1 |
|
$this->fördelning = <<< EOT |
|
65
|
1 |
|
<table id="hg-fördelning"> |
|
66
|
|
|
<tr> |
|
67
|
|
|
<th>HG rätt</th> |
|
68
|
|
|
<th>Rader</th> |
|
69
|
|
|
<th>Andel %</th> |
|
70
|
|
|
<th>Ack. %</th> |
|
71
|
|
|
<th>Teori %</th> |
|
72
|
|
|
<th>Faktor</th> |
|
73
|
|
|
</tr> |
|
74
|
1 |
|
$delsträng </table> |
|
75
|
1 |
|
EOT; |
|
76
|
|
|
|
|
77
|
|
|
/** |
|
78
|
|
|
* Spara fördelning. |
|
79
|
|
|
*/ |
|
80
|
1 |
|
$this->db_preferenser->spara_preferens('hg.fördelning', $this->fördelning); |
|
81
|
|
|
} |
|
82
|
|
|
} |
|
83
|
|
|
|