Passed
Push — main ( a92fbe...d29be2 )
by N.
05:41 queued 01:24
created

FANN::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 4
dl 0
loc 9
ccs 0
cts 4
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * Klass FANN.
5
 * @author Niklas Dougherty
6
 */
7
8
declare(strict_types=1);
9
10
namespace Tips\Moduler;
11
12
use Tips\Klasser\Utdelning;
13
use Tips\Klasser\Prediktioner;
14
use Tips\Klasser\Matcher;
15
use Tips\Moduler\FANNGenerera\Generera;
16
use Tips\Moduler\FANN\Konstanter;
17
use Tips\Moduler\FANN\Visa;
18
19
/**
20
 * Klass FANN.
21
 */
22
final class FANN extends Visa {
23
	use Konstanter;
24
25
	public string $indatafil = self::FANN . '/indata.txt';
26
	public string $utdatafil = self::FANN . '/utdata.txt';
27
28
	/**
29
	 * Initiera med uppdaterad konstruktor.
30
	 */
31
	public function __construct(
32
		public Utdelning $utdelning,
33
		public Prediktioner $odds,
34
		public Prediktioner $streck,
35
		public Matcher $matcher
36
	) {
37
		parent::__construct($utdelning, $odds, $streck, $matcher);
38
		$this->uppdatera_preferenser();
39
		$this->initiera_fann();
40
	}
41
42
	/**
43
	 * Starta upp FANN.
44
	 */
45
	private function initiera_fann(): void {
46
		if (isset($_REQUEST['generera_fann'])) {
47
			new Generera($this);
48
			$this->odds->spel->db->logg->logga(self::class . ': ✅ Genererade FANN.');
49
			$this->uppdatera_preferenser();
50
		}
51
52
		if ($this->exists_fann = file_exists($this->utdatafil)) {
53
			$this->fann = fann_create_from_file($this->utdatafil);
54
		}
55
56
		$this->prediktera();
57
58
		if (isset($_REQUEST['generera'])) { // preparera för parallellisering
59
			$this->db_preferenser->spara_preferens('fann.utdata', implode(',', $this->utdata), 'temp');
60
		}
61
62
		// parallellisering, nyttja befintlig prediktion för omgång
63
		$this->utdata = explode(',', $this->db_preferenser->hämta_preferens('fann.utdata', 'temp'));
64
	}
65
}
66