Passed
Push — self-contained-model ( bde79d...83cd40 )
by Matias
03:59
created

ModelManager   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 3
Bugs 0 Features 0
Metric Value
eloc 22
c 3
b 0
f 0
dl 0
loc 48
ccs 0
cts 18
cp 0
rs 10
wmc 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A getModel() 0 16 4
1
<?php
2
/**
3
 * @copyright Copyright (c) 2020, Matias De lellis <[email protected]>
4
 *
5
 * @author Matias De lellis <[email protected]>
6
 *
7
 * @license GNU AGPL version 3 or any later version
8
 *
9
 * This program is free software: you can redistribute it and/or modify
10
 * it under the terms of the GNU Affero General Public License as
11
 * published by the Free Software Foundation, either version 3 of the
12
 * License, or (at your option) any later version.
13
 *
14
 * This program is distributed in the hope that it will be useful,
15
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
 * GNU Affero General Public License for more details.
18
 *
19
 * You should have received a copy of the GNU Affero General Public License
20
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
21
 *
22
 */
23
24
namespace OCA\FaceRecognition\Model;
25
26
use OCP\IConfig;
27
use OCP\Files\IAppData;
28
use OCP\Files\IRootFolder;
29
use OCP\Files\NotFoundException;
30
31
use OCA\FaceRecognition\Model\IModel;
32
33
use OCA\FaceRecognition\Model\DlibCnnModel\DlibCnn68Model;
34
use OCA\FaceRecognition\Model\DlibCnnModel\DlibCnn5Model;
35
36
use OCA\FaceRecognition\Model\DlibHogModel\DlibHogModel;
37
38
class ModelManager {
39
40
	/** Defines ID for default face model */
41
	const DEFAULT_FACE_MODEL_ID = 1;
42
43
	/** @var DlibCnn5Model */
44
	private $dlibCnn5Model;
45
46
	/** @var DlibCnn68Model */
47
	private $dlibCnn68Model;
48
49
	/** @var DlibHogModel */
50
	private $dlibHogModel;
51
52
	/**
53
	 * @param DlibCnn5Model $dlibCnn5Model
54
	 * @param DlibCnn68Model $dlibCnn68Model
55
	 * @param DlibHogModel $dlibHogModel
56
	 */
57
	public function __construct(DlibCnn5Model  $dlibCnn5Model,
58
	                            DlibCnn68Model $dlibCnn68Model,
59
	                            DlibHogModel   $dlibHogModel)
60
	{
61
		$this->dlibCnn5Model  = $dlibCnn5Model;
62
		$this->dlibCnn68Model = $dlibCnn68Model;
63
		$this->dlibHogModel   = $dlibHogModel;
64
	}
65
66
	/**
67
	 * @param int $version model version
68
	 * @return IModel|null
69
	 */
70
	public function getModel(int $version): ?IModel {
71
		switch ($version) {
72
			case 1:
73
				$model = $this->dlibCnn5Model;
74
				break;
75
			case 2:
76
				$model = $this->dlibCnn68Model;
77
				break;
78
			case 3:
79
				$model = $this->dlibHogModel;
80
				break;
81
			default:
82
				$model = null;
83
				break;
84
		}
85
		return $model;
86
	}
87
88
}