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

FANN   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
eloc 17
dl 0
loc 42
ccs 0
cts 15
cp 0
rs 10
c 0
b 0
f 0
wmc 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A initiera_fann() 0 19 4
A __construct() 0 9 1
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