1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @copyright Copyright (c) 2017-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\Controller; |
25
|
|
|
|
26
|
|
|
use OCP\IRequest; |
27
|
|
|
use OCP\AppFramework\Http\JSONResponse; |
28
|
|
|
use OCP\AppFramework\Controller; |
29
|
|
|
|
30
|
|
|
use OCA\FaceRecognition\Db\ImageMapper; |
31
|
|
|
|
32
|
|
|
use OCA\FaceRecognition\Service\SettingsService; |
33
|
|
|
|
34
|
|
|
class ProcessController extends Controller { |
35
|
|
|
|
36
|
|
|
/** @var ImageMapper */ |
37
|
|
|
private $imageMapper; |
38
|
|
|
|
39
|
|
|
/** @var SettingsService */ |
40
|
|
|
private $settingsService; |
41
|
|
|
|
42
|
|
|
/** @var string */ |
43
|
|
|
private $userId; |
44
|
|
|
|
45
|
|
|
public function __construct($AppName, |
46
|
|
|
IRequest $request, |
47
|
|
|
ImageMapper $imageMapper, |
48
|
|
|
SettingsService $settingsService, |
49
|
|
|
$UserId) |
50
|
|
|
{ |
51
|
|
|
parent::__construct($AppName, $request); |
52
|
|
|
|
53
|
|
|
$this->imageMapper = $imageMapper; |
54
|
|
|
$this->settingsService = $settingsService; |
55
|
|
|
$this->userId = $UserId; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* Just print a global status of the analysis. |
60
|
|
|
* |
61
|
|
|
* @return JSONResponse |
62
|
|
|
*/ |
63
|
|
|
public function index(): JSONResponse { |
64
|
|
|
|
65
|
|
|
$model = $this->settingsService->getCurrentFaceModel(); |
66
|
|
|
|
67
|
|
|
$totalImages = $this->imageMapper->countImages($model); |
68
|
|
|
$processedImages = $this->imageMapper->countProcessedImages($model); |
69
|
|
|
$avgProcessingTime = $this->imageMapper->avgProcessingDuration($model); |
70
|
|
|
|
71
|
|
|
// TODO: How to know the real state of the process? |
72
|
|
|
$status = ($processedImages > 0); |
73
|
|
|
|
74
|
|
|
$estimatedTime = ($totalImages - $processedImages) * $avgProcessingTime/1000; |
75
|
|
|
|
76
|
|
|
$estimatedFinalize = $estimatedTime; |
77
|
|
|
|
78
|
|
|
$params = array( |
79
|
|
|
'status' => $status, |
80
|
|
|
'estimatedFinalize' => $estimatedFinalize, |
81
|
|
|
'totalImages' => $totalImages, |
82
|
|
|
'processedImages' => $processedImages |
83
|
|
|
); |
84
|
|
|
|
85
|
|
|
return new JSONResponse($params); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
} |
89
|
|
|
|