Passed
Push — self-contained-model ( 6fc33a...d2c701 )
by Matias
04:01
created

ModelManager::getModel()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 13
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 11
nc 3
nop 1
dl 0
loc 13
ccs 0
cts 10
cp 0
crap 12
rs 9.9
c 1
b 0
f 0
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\DlibCnnModel\DlibCnnModel;
32
33
use OCA\FaceRecognition\Model\DlibCnnModel\DlibCnn68Model;
34
use OCA\FaceRecognition\Model\DlibCnnModel\DlibCnn5Model;
35
36
class ModelManager {
37
38
	/** Defines ID for default face model */
39
	const DEFAULT_FACE_MODEL_ID = 1;
40
41
	/** @var DlibCnn5Model */
42
	private $dlibCnn5Model;
43
44
	/** @var DlibCnn68Model */
45
	private $dlibCnn68Model;
46
47
	/**
48
	 * @param DlibCnn5Model $model
49
	 * @param DlibCnn68Model $model
50
	 */
51
	public function __construct(DlibCnn5Model  $dlibCnn5Model,
52
	                            DlibCnn68Model $dlibCnn68Model)
53
	{
54
		$this->dlibCnn5Model  = $dlibCnn5Model;
55
		$this->dlibCnn68Model = $dlibCnn68Model;
56
	}
57
58
	/**
59
	 * @param int $version model version
60
	 * @return DlibCnnModel|null
61
	 */
62
	public function getModel(int $version): ?DlibCnnModel {
63
		switch ($version) {
64
			case 1:
65
				$model = $this->dlibCnn5Model;
66
				break;
67
			case 2:
68
				$model = $this->dlibCnn68Model;
69
				break;
70
			default:
71
				$model = null;
72
				break;
73
		}
74
		return $model;
75
	}
76
77
}