Passed
Push — main ( f1b4ad...6ccac6 )
by N.
04:46
created

FANN   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
eloc 19
dl 0
loc 48
ccs 0
cts 17
cp 0
rs 10
c 0
b 0
f 0
wmc 7

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 1
A initiera_fann() 0 25 6
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
		if (defined('UPPMÄRKNING')) {
57
			$this->prediktera();
58
59
			if (isset($_REQUEST['generera'])) { // preparera för parallellisering
60
				$this->db_preferenser->spara_preferens('fann.utdata', implode(',', $this->utdata), 'temp');
61
			}
62
		}
63
64
		/**
65
		 * Parallellisering.
66
		 */
67
		if (!defined('UPPMÄRKNING')) {
68
			// parallellisering, nyttja befintlig prediktion för omgång
69
			$this->utdata = explode(',', $this->db_preferenser->hämta_preferens('fann.utdata', 'temp'));
70
		}
71
	}
72
}
73