From 09604d1cb851b4c40f4836a9e02ae442b4e3cc30 Mon Sep 17 00:00:00 2001 From: dongpd Date: Wed, 30 Dec 2020 11:43:03 +0700 Subject: [PATCH] filter dong bo du lieu giua cac thiet bi --- controllers/ApiController.php | 74 +++++++++++++++++++++++- controllers/ListManagementController.php | 12 +++- views/list-management/list.tpl | 24 +++++++- web/js/list-management.js | 5 +- 4 files changed, 107 insertions(+), 8 deletions(-) diff --git a/controllers/ApiController.php b/controllers/ApiController.php index 8fccbeb4..091697ae 100644 --- a/controllers/ApiController.php +++ b/controllers/ApiController.php @@ -18,7 +18,7 @@ class ApiController extends Controller { /** * {@inheritdoc} */ - public function behaviors() { + public function behaviors() { return [ 'verbs' => [ 'class' => VerbFilter::className(), @@ -223,6 +223,62 @@ class ApiController extends Controller { return $str; } + public function getCurrentTime() { + $time = microtime(); + $time = explode(' ', $time); + return $time[1] + $time[0]; + } + + public function actionAutoGenFeature() { + Yii::$app->response->format = "json"; + $processTime = []; + + $start = $this->getCurrentTime(); + $lists = ListManagement::find()->all(); + $finish = $this->getCurrentTime(); + $processTime["getAllLM"] = round(($finish - $start), 4); + $extract = false; + foreach ($lists as $key => $value) { + $images = json_decode($value->image, true); + $newImgs = []; + $temp = []; + foreach ($images as $k => $v) { + if (!isset($v['features512']) || (isset($v['features512']) && count($v['features512']) == 0)) { + $start = $this->getCurrentTime(); + $features = json_decode(common::requestToEngine("/get-feature", [ + "image_paths" => [ + ["url" => "/var/www/html/BiFace_Server_Lite/web/data/uploads/face/" . $v['url'], "type" => "raw"] + ], + "type" => "512" + ]), true); + $finish = $this->getCurrentTime(); + $temp[] = round(($finish - $start), 4); + $v['features512'] = $features['results'][0]['feature512']; + $extract = true; + } + $newImgs[] = $v; + } + if ($extract) { + $processTime['extract'] = $temp; + $value->image = json_encode($newImgs); + $start = $this->getCurrentTime(); + $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]; + } + public function actionSync() { Yii::$app->response->format = "json"; if ($this->is_connected()) { @@ -276,4 +332,20 @@ class ApiController extends Controller { return ListManagement::find()->count(); } + 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++; + } + } + return ["total" => count($lists), "128" => $total128, "512" => $total512]; + } + } diff --git a/controllers/ListManagementController.php b/controllers/ListManagementController.php index 57664930..baeb2431 100644 --- a/controllers/ListManagementController.php +++ b/controllers/ListManagementController.php @@ -114,7 +114,7 @@ class ListManagementController extends Controller { return ["status" => false, "text" => "Mỗi đối tượng chỉ nhận tối đa " . \Yii::$app->params['maxPicture'] . " hình ảnh mẫu"]; $add = true; foreach ($images as $key => $value) { - if ($value['urlOld'] === $url) + if (isset($value['urlOld']) && $value['urlOld'] === $url) $add = false; } if ($add) { @@ -368,12 +368,17 @@ class ListManagementController extends Controller { 'content' => json_encode(ListManagement::nameArray()) ] ])), true); + $filters = []; + foreach ($results as $key => $value) { + $filters[$value['code']] = $value['code'] . " - " . $value['name'] . " - " . $value['address']; + } Yii::$app->response->format = "json"; return [ "title" => $data['ip'], "form" => $this->renderPartial("list", [ "results" => $results, "typeArray" => ListManagement::$typeArray, + "filters" => $filters, "ip" => $data['ip'] ]) ]; @@ -477,7 +482,8 @@ class ListManagementController extends Controller { $features = json_decode(common::requestToEngine("/get-feature", [ "image_paths" => [ ["url" => "/var/www/html/BiFace_Server_Lite/web/data/uploads/face/" . $fileName, "type" => "raw"] - ] + ], + "type" => "128" ]), true); $finish = $this->getCurrentTime(); $temp["extract"] = round(($finish - $start), 4); @@ -575,7 +581,7 @@ class ListManagementController extends Controller { $model->name = $value['name']; $model->image = json_encode($images); $model->gender = $value['gender']; - $model->birthday = date("d/m/Y", $value['birthday']); + $model->birthday = $value['birthday']; $model->telephone = $value['telephone']; $model->address = $value['department']; $model->save(); diff --git a/views/list-management/list.tpl b/views/list-management/list.tpl index 265398b8..85c05bf1 100644 --- a/views/list-management/list.tpl +++ b/views/list-management/list.tpl @@ -1,3 +1,21 @@ +
+
+
+
+
Tìm kiếm
+ +
+ +
+
+
+
+
@@ -15,7 +33,7 @@ {foreach from=$results item=arr} - + @@ -53,10 +71,10 @@
- -
{$arr.code} {$typeArray[$arr.type]} {$arr.name}