|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* Klass Hamta. |
|
5
|
|
|
* @author Niklas Dougherty |
|
6
|
|
|
*/ |
|
7
|
|
|
|
|
8
|
|
|
declare(strict_types=1); |
|
9
|
|
|
|
|
10
|
|
|
namespace Tips\Moduler\Distribution; |
|
11
|
|
|
|
|
12
|
|
|
use PDO; |
|
13
|
|
|
use Tips\Klasser\Utdelning; |
|
14
|
|
|
use Tips\Klasser\Prediktioner; |
|
15
|
|
|
use Tips\Klasser\Matcher; |
|
16
|
|
|
use Tips\Klasser\Graf; |
|
17
|
|
|
use Tips\Klasser\DBPreferenser; |
|
18
|
|
|
use Tips\Egenskaper\Tick; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* Klass Hamta. |
|
22
|
|
|
* Hämta och sätt grundvariabler. |
|
23
|
|
|
*/ |
|
24
|
|
|
class Hamta { |
|
25
|
|
|
use Tick; |
|
26
|
|
|
use Konstanter; |
|
27
|
|
|
|
|
28
|
|
|
public Graf $graf; |
|
29
|
|
|
public DBPreferenser $db_preferenser; |
|
30
|
|
|
public float $minsumma = 0; |
|
31
|
|
|
public float $maxsumma = 0; |
|
32
|
|
|
public float $oddssumma = 0; // summan av oddssannolikheter för vinnande rad |
|
33
|
|
|
public float $procentandel = 0; // vinnande rads procentposition i disten |
|
34
|
|
|
public float $minprocent; // andel av distributionen som ska täckas, fr.o.m. |
|
35
|
|
|
public float $maxprocent; // andel av distributionen som ska täckas, t.o.m. |
|
36
|
|
|
public float $grund_minprocent = self::DISTRIBUTION_GRUND_MIN_STD; // defaultvärde |
|
37
|
|
|
public float $grund_maxprocent = self::DISTRIBUTION_GRUND_MAX_STD; // defaultvärde |
|
38
|
|
|
public int $andelssumma = 0; |
|
39
|
|
|
public string $bildfil = ''; // filväg |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* Initiera. |
|
43
|
|
|
* Sätt en del grundvariabler. |
|
44
|
|
|
*/ |
|
45
|
|
|
public function __construct( |
|
46
|
|
|
protected Utdelning $utdelning, |
|
47
|
|
|
protected Prediktioner $odds, |
|
48
|
|
|
protected Prediktioner $streck, |
|
49
|
|
|
protected Matcher $matcher |
|
50
|
|
|
) { |
|
51
|
|
|
$this->db_preferenser = new DBPreferenser($this->odds->spel->db); |
|
52
|
|
|
$this->graf = new Graf(); |
|
53
|
|
|
$this->bildfil = DISTRIBUTION . "/{$this->odds->spel->filnamn}.png"; |
|
|
|
|
|
|
54
|
|
|
$this->uppdatera_preferenser(); |
|
55
|
|
|
$this->hämta_distribution(); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* Uppdatera preferenser. |
|
60
|
|
|
*/ |
|
61
|
|
|
public function uppdatera_preferenser(): void { |
|
62
|
|
|
/** |
|
63
|
|
|
* Säkerställ att attraktionsfaktor är inom tillåtna intervall. |
|
64
|
|
|
*/ |
|
65
|
|
|
$this->db_preferenser->int_preferens_i_intervall( |
|
66
|
|
|
$this->attraktionsfaktor, |
|
67
|
|
|
AF_MIN, |
|
|
|
|
|
|
68
|
|
|
AF_MAX, |
|
|
|
|
|
|
69
|
|
|
AF_STD, |
|
|
|
|
|
|
70
|
|
|
'distribution.attraktionsfaktor' |
|
71
|
|
|
); |
|
72
|
|
|
|
|
73
|
|
|
/** |
|
74
|
|
|
* Minprocent inom tillåtna intervall. |
|
75
|
|
|
*/ |
|
76
|
|
|
$this->db_preferenser->preferens_i_intervall( |
|
77
|
|
|
$this->grund_minprocent, |
|
78
|
|
|
self::DISTRIBUTION_GRUND_MIN_MIN, |
|
|
|
|
|
|
79
|
|
|
self::DISTRIBUTION_GRUND_MIN_MAX, |
|
|
|
|
|
|
80
|
|
|
self::DISTRIBUTION_GRUND_MIN_STD, |
|
|
|
|
|
|
81
|
|
|
'distribution.grund_minprocent' |
|
82
|
|
|
); |
|
83
|
|
|
|
|
84
|
|
|
/** |
|
85
|
|
|
* Maxprocent inom tillåtna intervall. |
|
86
|
|
|
*/ |
|
87
|
|
|
$this->db_preferenser->preferens_i_intervall( |
|
88
|
|
|
$this->grund_maxprocent, |
|
89
|
|
|
self::DISTRIBUTION_GRUND_MAX_MIN, |
|
|
|
|
|
|
90
|
|
|
self::DISTRIBUTION_GRUND_MAX_MAX, |
|
|
|
|
|
|
91
|
|
|
self::DISTRIBUTION_GRUND_MAX_STD, |
|
|
|
|
|
|
92
|
|
|
'distribution.grund_maxprocent' |
|
93
|
|
|
); |
|
94
|
|
|
|
|
95
|
|
|
/** |
|
96
|
|
|
* Min < max. |
|
97
|
|
|
*/ |
|
98
|
|
|
$this->db_preferenser->komparera_preferenser( |
|
99
|
|
|
$this->grund_minprocent, |
|
100
|
|
|
$this->grund_maxprocent, |
|
101
|
|
|
self::DISTRIBUTION_GRUND_MIN_STD, |
|
102
|
|
|
self::DISTRIBUTION_GRUND_MAX_STD, |
|
103
|
|
|
'distribution.grund_minprocent', |
|
104
|
|
|
'distribution.grund_maxprocent' |
|
105
|
|
|
); |
|
106
|
|
|
|
|
107
|
|
|
/** |
|
108
|
|
|
* Aktuella värden. |
|
109
|
|
|
*/ |
|
110
|
|
|
$this->minprocent = $this->grund_minprocent; |
|
111
|
|
|
$this->maxprocent = $this->grund_maxprocent; |
|
112
|
|
|
} |
|
113
|
|
|
|
|
114
|
|
|
/** |
|
115
|
|
|
* Hämta distribution. |
|
116
|
|
|
*/ |
|
117
|
|
|
protected function hämta_distribution(): void { |
|
118
|
|
|
/** |
|
119
|
|
|
* Hämta parametrar för distribution. |
|
120
|
|
|
*/ |
|
121
|
|
|
$sats = $this->odds->spel->db->instans->prepare('SELECT `minsumma`, `maxsumma`, |
|
122
|
|
|
`minprocent`, `maxprocent`, `oddssumma`, `procentandel`, `andelssumma` |
|
123
|
|
|
FROM `distribution` WHERE `omgång`=:omgang |
|
124
|
|
|
AND `speltyp`=:speltyp AND `sekvens`=:sekvens LIMIT 1'); |
|
125
|
|
|
$sats->bindValue(':omgang', $this->odds->spel->omgång, PDO::PARAM_INT); |
|
126
|
|
|
$sats->bindValue(':speltyp', $this->odds->spel->speltyp->value, PDO::PARAM_INT); |
|
127
|
|
|
$sats->bindValue(':sekvens', $this->odds->spel->sekvens, PDO::PARAM_INT); |
|
128
|
|
|
$sats->bindColumn('andelssumma', $this->andelssumma, PDO::PARAM_INT); |
|
129
|
|
|
$sats->execute(); |
|
130
|
|
|
|
|
131
|
|
|
/** |
|
132
|
|
|
* Populera parametrar. |
|
133
|
|
|
* Säkerställ att rad faktiskt finns. |
|
134
|
|
|
*/ |
|
135
|
|
|
$rad = $sats->fetchAll(PDO::FETCH_ASSOC); |
|
136
|
|
|
if (isset($rad[0])) { |
|
137
|
|
|
$rad = $rad[0]; |
|
138
|
|
|
$this->minsumma = (float) $rad['minsumma']; |
|
139
|
|
|
$this->maxsumma = (float) $rad['maxsumma']; |
|
140
|
|
|
$this->minprocent = (float) $rad['minprocent']; |
|
141
|
|
|
$this->maxprocent = (float) $rad['maxprocent']; |
|
142
|
|
|
$this->oddssumma = (float) $rad['oddssumma']; |
|
143
|
|
|
$this->procentandel = $rad['procentandel']; |
|
144
|
|
|
} |
|
145
|
|
|
} |
|
146
|
|
|
} |
|
147
|
|
|
|