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 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 4
dl 0
loc 7
ccs 2
cts 2
cp 1
crap 1
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\Andel;
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
18
/**
19
 * Klass Preferenser.
20
 * Kontrollera inställningar.
21
 */
22
class Preferenser {
23
	use Tick;
24
25
	protected DBPreferenser $db_preferenser;
26
	protected int $andel_1_min = 0;
27
	protected int $andel_1_max = 0;
28
	protected int $andel_x_min = 0;
29
	protected int $andel_x_max = 0;
30
	protected int $andel_2_min = 0;
31
	protected int $andel_2_max = 0;
32
33
	/**
34
	 * Initiera.
35
	 */
36 20
	public function __construct(
37
		protected Utdelning $utdelning,
38
		protected Prediktioner $odds,
39
		protected Prediktioner $streck,
40
		protected Matcher $matcher
41
	) {
42 20
		$this->db_preferenser = new DBPreferenser($this->utdelning->spel->db);
43
	}
44
45
	/**
46
	 * Uppdatera preferenser.
47
	 */
48 20
	protected function uppdatera_preferenser(): void {
49
		/**
50
		 * Attraktionsfaktor mellan 1 och 3^13.
51
		 */
52 20
		$this->db_preferenser->int_preferens_i_intervall(
53 20
			$this->attraktionsfaktor,
54 20
			AF_MIN,
55 20
			AF_MAX,
56 20
			AF_STD,
57 20
			'andel.attraktionsfaktor'
58 20
		);
59
60
		/**
61
		 * Andel tecken mellan 0 och 13.
62
		 */
63 20
		$this->db_preferenser->int_preferens_i_intervall(
64 20
			$this->andel_1_min,
65 20
			0,
66 20
			13,
67 20
			3,
68 20
			'andel.andel_1_min'
69 20
		);
70
71 20
		$this->db_preferenser->int_preferens_i_intervall(
72 20
			$this->andel_1_max,
73 20
			0,
74 20
			13,
75 20
			8,
76 20
			'andel.andel_1_max'
77 20
		);
78
79 20
		$this->db_preferenser->int_preferens_i_intervall(
80 20
			$this->andel_x_min,
81 20
			0,
82 20
			13,
83 20
			1,
84 20
			'andel.andel_x_min'
85 20
		);
86
87 20
		$this->db_preferenser->int_preferens_i_intervall(
88 20
			$this->andel_x_max,
89 20
			0,
90 20
			13,
91 20
			6,
92 20
			'andel.andel_x_max'
93 20
		);
94
95 20
		$this->db_preferenser->int_preferens_i_intervall(
96 20
			$this->andel_2_min,
97 20
			0,
98 20
			13,
99 20
			2,
100 20
			'andel.andel_2_min'
101 20
		);
102
103 20
		$this->db_preferenser->int_preferens_i_intervall(
104 20
			$this->andel_2_max,
105 20
			0,
106 20
			13,
107 20
			7,
108 20
			'andel.andel_2_max'
109 20
		);
110
111
		/**
112
		 * Jämför andelar.
113
		 */
114 20
		$this->db_preferenser->int_komparera_preferenser(
115 20
			$this->andel_1_min,
116 20
			$this->andel_1_max,
117 20
			3,
118 20
			8,
119 20
			'andel.andel_1_min',
120 20
			'andel.andel_1_max'
121 20
		);
122
123 20
		$this->db_preferenser->int_komparera_preferenser(
124 20
			$this->andel_x_min,
125 20
			$this->andel_x_max,
126 20
			1,
127 20
			6,
128 20
			'andel.andel_x_min',
129 20
			'andel.andel_x_max'
130 20
		);
131
132 20
		$this->db_preferenser->int_komparera_preferenser(
133 20
			$this->andel_2_min,
134 20
			$this->andel_2_max,
135 20
			2,
136 20
			7,
137 20
			'andel.andel_2_min',
138 20
			'andel.andel_2_max'
139 20
		);
140
	}
141
}
142