Preferenser::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 4
dl 0
loc 7
ccs 0
cts 2
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * Klass Preferenser.
5
 * @author Niklas Dougherty
6
 */
7
8
declare(strict_types=1);
9
10
namespace Tips\Moduler\FANN;
11
12
use Tips\Klasser\Utdelning;
13
use Tips\Klasser\Prediktioner;
14
use Tips\Klasser\Matcher;
15
use Tips\Klasser\DBPreferenser;
16
use Tips\Egenskaper\Tick;
17
use Tips\Moduler\FANN\Konstanter;
18
19
/**
20
 * Klass Preferenser.
21
 */
22
class Preferenser {
23
	use Tick;
24
	use Konstanter;
25
26
	public DBPreferenser $db_preferenser;
27
	/**
28
	 * @var float[] $limiter
29
	 */
30
	public array $limiter = [-0.55, -0.05, 0.43]; // 1, 1X, X2, Monte Carlo
31
	protected int $fann_min = 10;
32
	public float $feltolerans = 0.16;
33
34
	public function __construct(
35
		public Utdelning $utdelning,
36
		public Prediktioner $odds,
37
		public Prediktioner $streck,
38
		public Matcher $matcher
39
	) {
40
			$this->db_preferenser = new DBPreferenser($this->odds->spel->db);
41
	}
42
43
	/**
44
	 * Uppdatera preferenser.
45
	 */
46
	protected function uppdatera_preferenser(): void {
47
		$this->db_preferenser->int_preferens_i_intervall(
48
			$this->fann_min,
49
			self::FANN_MIN,
0 ignored issues
show
Bug introduced by
The constant Tips\Moduler\FANN\Preferenser::FANN_MIN was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
50
			self::FANN_MAX,
0 ignored issues
show
Bug introduced by
The constant Tips\Moduler\FANN\Preferenser::FANN_MAX was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
51
			self::FANN_STD,
0 ignored issues
show
Bug introduced by
The constant Tips\Moduler\FANN\Preferenser::FANN_STD was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
52
			'fann.fann_min'
53
		);
54
55
		$this->db_preferenser->preferens_i_intervall(
56
			$this->feltolerans,
57
			self::FANN_FELTOLERANS_MIN,
0 ignored issues
show
Bug introduced by
The constant Tips\Moduler\FANN\Prefer...r::FANN_FELTOLERANS_MIN was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
58
			self::FANN_FELTOLERANS_MAX,
0 ignored issues
show
Bug introduced by
The constant Tips\Moduler\FANN\Prefer...r::FANN_FELTOLERANS_MAX was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
59
			self::FANN_FELTOLERANS_STD,
0 ignored issues
show
Bug introduced by
The constant Tips\Moduler\FANN\Prefer...r::FANN_FELTOLERANS_STD was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
60
			'fann.fann_feltolerans'
61
		);
62
63
		$this->db_preferenser->int_preferens_i_intervall(
64
			$this->attraktionsfaktor,
65
			AF_MIN,
66
			AF_MAX,
67
			AF_STD,
68
			'fann.attraktionsfaktor'
69
		);
70
71
		$parametrar = explode(',', $this->db_preferenser->hämta_preferens('fann.parametrar'));
72
		if (count($parametrar) === 3) {
73
			foreach ($parametrar as $i => $p) {
74
				$this->limiter[$i] = (float) filter_var($p, FILTER_VALIDATE_FLOAT);
75
			}
76
77
			return;
78
		}
79
80
		$parametrar = $this->limiter;
81
		$this->db_preferenser->spara_preferens("fann.parametrar", implode(',', $parametrar));
82
	}
83
}
84