|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* Klass Generera. |
|
5
|
|
|
* @author Niklas Dougherty |
|
6
|
|
|
*/ |
|
7
|
|
|
|
|
8
|
|
|
declare(strict_types=1); |
|
9
|
|
|
|
|
10
|
|
|
namespace Tips\Moduler\DistributionGenerera; |
|
11
|
|
|
|
|
12
|
|
|
use PDO; |
|
13
|
|
|
use Tips\Klasser\Tips; |
|
14
|
|
|
use Tips\Moduler\Distribution; |
|
15
|
|
|
use Tips\Egenskaper\Varden; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* Klass Generera. |
|
19
|
|
|
*/ |
|
20
|
|
|
final class Generera extends Graf { |
|
21
|
|
|
use Varden; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* @var int[] $distribution |
|
25
|
|
|
*/ |
|
26
|
|
|
protected array $distribution = []; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* Init. |
|
30
|
|
|
*/ |
|
31
|
2 |
|
public function __construct(protected Tips $tips, protected Distribution $dist) { |
|
32
|
2 |
|
parent::__construct($tips, $dist); |
|
33
|
2 |
|
$this->hämta_värden($tips->spel->db); |
|
34
|
2 |
|
$this->parallellisera(); |
|
35
|
2 |
|
$this->uppdatera_graf(); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* Behandla distributionsberäkning med parallellisering. |
|
40
|
|
|
* @return array<string, int> |
|
41
|
|
|
*/ |
|
42
|
2 |
|
private function behandla_parallellisering(): array { |
|
43
|
2 |
|
$this->tips->parallellisering->vänta_på_databas(); |
|
44
|
|
|
|
|
45
|
2 |
|
$dist = []; |
|
46
|
2 |
|
$sats = $this->tips->odds->spel->db->temp->query("SELECT `val` FROM `parallellisering`"); |
|
47
|
2 |
|
if ($sats !== false) { |
|
48
|
2 |
|
foreach ($sats->fetchAll(PDO::FETCH_ASSOC) as $rad) { |
|
49
|
2 |
|
$distribution = array_chunk(explode(',', $rad['val']), 2); |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* Uppdatera distribution för enskild punkt. |
|
53
|
|
|
*/ |
|
54
|
2 |
|
foreach ($distribution as [$summa, $antal_rader]) { |
|
55
|
2 |
|
match (isset($dist[$summa])) { |
|
56
|
2 |
|
true => $dist[$summa] += $antal_rader, |
|
57
|
2 |
|
false => $dist[$summa] = $antal_rader |
|
58
|
2 |
|
}; |
|
59
|
|
|
} |
|
60
|
|
|
} |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
2 |
|
$this->tips->odds->spel->db->temp->exec("DELETE FROM `parallellisering`"); |
|
64
|
2 |
|
return $dist; |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* Parallellisera. |
|
69
|
|
|
*/ |
|
70
|
2 |
|
private function parallellisera(): void { |
|
71
|
2 |
|
if (!$this->tips->odds->komplett) { |
|
72
|
|
|
return; |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
2 |
|
$this->tips->parallellisering->parallellisera(PARALLELLISERING . '/PDistribution.php'); |
|
76
|
2 |
|
$this->distribution = $this->behandla_parallellisering(); |
|
77
|
2 |
|
krsort($this->distribution); // distribution av sannolikhetssummor för odds |
|
78
|
|
|
} |
|
79
|
|
|
} |
|
80
|
|
|
|