diff --git a/controllers/ApiController.php b/controllers/ApiController.php index 72079475..5bb098a7 100644 --- a/controllers/ApiController.php +++ b/controllers/ApiController.php @@ -91,7 +91,11 @@ class ApiController extends Controller { $id_camera = intval($device_id->data); $logsInfo = CaptureLogs::findOne($logs); $staffInfo = ListManagement::findOne($post['id']); - $res = json_decode(file_get_contents($ip . "/api/oem/face_recognition", false, stream_context_create([ + $tk = ""; + $token = \app\models\SyncUrl::findOne(['key_config' => 'token']); + if ($token) + $tk = $token->data; + $res = json_decode(file_get_contents($ip . "/api/oem/face_recognition?token=" . $tk, false, stream_context_create([ 'http' => [ 'header' => "Content-Type: application/json", 'method' => "POST", @@ -231,14 +235,28 @@ class ApiController extends Controller { public function actionAutoGenFeature() { Yii::$app->response->format = "json"; - $processTime = []; + $updating = \app\models\SyncUrl::findOne(['key_config' => 'updating']); + if ($updating->data === "true") { + $txt = "\n" . date("H:i:s d/m/Y") . " " . "updating"; + file_put_contents(date('Ymd') . "_logs.txt", $txt, FILE_APPEND); + return ["status" => false]; + } - $start = $this->getCurrentTime(); + $currentCache = json_decode(file_get_contents("http://localhost:2305/current-cache"), true); + if ($currentCache['n_128'] == $currentCache['n_512']) { + $txt = "\n" . date("H:i:s d/m/Y") . " " . "success"; + file_put_contents(date('Ymd') . "_logs.txt", $txt, FILE_APPEND); + return ["status" => false]; + } + + $updating->data = "true"; + $updating->save(); + + $processTime = []; + set_time_limit(0); $lists = ListManagement::find()->all(); - $finish = $this->getCurrentTime(); - $processTime["getAllLM"] = round(($finish - $start), 4); - $extract = false; foreach ($lists as $key => $value) { + $extract = false; $images = json_decode($value->image, true); $newImgs = []; $temp = []; @@ -260,23 +278,20 @@ class ApiController extends Controller { } if ($extract) { $processTime['extract'] = $temp; - $value->image = json_encode($newImgs); $start = $this->getCurrentTime(); + $value->image = json_encode($newImgs); $value->save(); $finish = $this->getCurrentTime(); $processTime["updateDB"] = round(($finish - $start), 4); $txt = "\n" . json_encode($processTime); file_put_contents(date('Ymd') . ".txt", $txt, FILE_APPEND); - common::updateFeature([ - "cmd" => "update", - "id" => $value->id, - "name" => common::convert_vi_to_en($value->name), - "features" => $value->allFeatures - ]); - return ["status" => true, "time" => $processTime]; } } - return ["status" => false]; + + file_get_contents("http://localhost:2305/update-feature"); + $updating->data = "false"; + $updating->save(); + return ["status" => true]; } public function actionSync() { @@ -291,9 +306,14 @@ class ApiController extends Controller { if ($device_id) $id_camera = intval($device_id->data); $ls = CaptureLogs::find()->andWhere(['sync_status' => null])->all(); + + $tk = ""; + $token = \app\models\SyncUrl::findOne(['key_config' => 'token']); + if ($token) + $tk = $token->data; foreach ($ls as $key => $value) { $staffInfo = ListManagement::findOne($value->staff_id); - $res = json_decode(file_get_contents($ip . "/api/oem/face_recognition", false, stream_context_create([ + $res = json_decode(file_get_contents($ip . "/api/oem/face_recognition?token=" . $tk, false, stream_context_create([ 'http' => [ 'header' => "Content-Type: application/json", 'method' => "POST", @@ -333,19 +353,62 @@ class ApiController extends Controller { } public function actionGetTotalFeature() { - Yii::$app->response->format = "json"; - $lists = ListManagement::find()->all(); - $total128 = $total512 = 0; - foreach ($lists as $key => $value) { - $images = json_decode($value->image, true); - foreach ($images as $k => $v) { - if (isset($v['features']) && count($v['features']) > 0) - $total128++; - if (isset($v['features512']) && count($v['features512']) > 0) - $total512++; - } + if (Yii::$app->request->isAjax) { + Yii::$app->response->format = "json"; + $start = $this->getCurrentTime(); + $statistics = ListManagement::statisticFeatures(); + $finish = $this->getCurrentTime(); + $processTime = round(($finish - $start), 4); + return [ + "statistics" => $statistics, + "processTime" => $processTime + ]; + } + } + + public function actionCurrentCache() { + return file_get_contents("http://localhost:2305/current-cache"); + } + + public function actionSaveToken() { + if (Yii::$app->request->post()) { + $post = Yii::$app->request->bodyParams; + $token = \app\models\SyncUrl::findOne(['key_config' => 'token']); + if ($token) { + $token->data = $post['token']; + $token->save(); + } else { + $model = new \app\models\SyncUrl(); + $model->create([ + 'key_config' => "token", + 'data' => $post['token'] + ]); + } + Yii::$app->response->format = "json"; + return ["status" => true]; + } + } + + public function actionTest() { + $check = \app\models\SyncUrl::findOne(['key_config' => 'updating']); + $check->data = "false"; + $check->save(); + return var_dump($check); +// file_get_contents("http://localhost:2305/update-feature"); +// return; + set_time_limit(0); + $lists = ListManagement::find()->all(); + foreach ($lists as $key => $value) { + $extract = false; + $images = json_decode($value->image, true); + $newImgs = []; + foreach ($images as $k => $v) { + $v['features512'] = []; + $newImgs[] = $v; + } + $value->image = json_encode($newImgs); + $value->save(); } - return ["total" => count($lists), "128" => $total128, "512" => $total512]; } } diff --git a/controllers/ListManagementController.php b/controllers/ListManagementController.php index a284ae1d..0200105f 100644 --- a/controllers/ListManagementController.php +++ b/controllers/ListManagementController.php @@ -63,6 +63,7 @@ class ListManagementController extends Controller { // if (!is_object($last)) // $last = (object) ['id' => 0]; // $idAuto = $data['data']['box_id'] . "_" . ($last->id + 1); + return $this->render('index', [ 'searchModel' => $searchModel, 'dataProvider' => $dataProvider, @@ -71,7 +72,7 @@ class ListManagementController extends Controller { 'typeArray' => ListManagement::$typeArray, 'genderArray' => ListManagement::$genderArray, // 'idAuto' => $idAuto, - "staffArray" => ListManagement::staffArray() + "staffArray" => ListManagement::staffArray(), ]); } @@ -547,6 +548,7 @@ class ListManagementController extends Controller { } $totalFinish = $this->getCurrentTime(); $processTime["total"] = round(($totalFinish - $totalStart), 4); + $processTime["id"] = strval($data['idStaff']); return $processTime; //["status" => true]; } } diff --git a/models/ListManagement.php b/models/ListManagement.php index 696c507c..8cca0fb0 100644 --- a/models/ListManagement.php +++ b/models/ListManagement.php @@ -128,4 +128,28 @@ class ListManagement extends \yii\db\ActiveRecord { return $f; } + public static function statisticFeatures() { + $lists = self::find()->all(); + $total128 = $total512 = $totalImg = $img = 0; + foreach ($lists as $key => $value) { + $images = json_decode($value->image, true); + if (count($images) > 0) + $totalImg++; + $img += count($images); + foreach ($images as $k => $v) { + if (isset($v['features']) && count($v['features']) > 0) + $total128++; + if (isset($v['features512']) && count($v['features512']) > 0) + $total512++; + } + } + return [ + "total" => count($lists), + "totalImg" => $totalImg, + "img" => $img, + "128" => $total128, + "512" => $total512 + ]; + } + } diff --git a/views/list-management/index.tpl b/views/list-management/index.tpl index 56e48e5d..feaf53fe 100644 --- a/views/list-management/index.tpl +++ b/views/list-management/index.tpl @@ -41,6 +41,7 @@ +
{GridView::widget([ @@ -189,6 +190,27 @@
+
+ + + + + + + + + + + + + +
Số người có ảnh / tổng + {*{$statistics.totalImg}/{$statistics.total}*} +
Đặc trưng 1 +{* {$statistics.128}/{$statistics.img}*} +
Đặc trưng 2 +{* {$statistics.512}/{$statistics.img}*} +