toi uu xu ly dong bo du lieu tu may chu

This commit is contained in:
dongpd 2020-12-29 13:33:29 +07:00
parent ddcf67ba9c
commit c9d0c24218
5 changed files with 78 additions and 42 deletions

View File

@ -3,5 +3,5 @@
return [ return [
'adminEmail' => 'admin@example.com', 'adminEmail' => 'admin@example.com',
"maxLogs" => 100000, "maxLogs" => 100000,
"maxPicture" => 5 "maxPicture" => 2
]; ];

View File

@ -82,7 +82,7 @@ class ControlLogsController 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"]; 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; $add = true;
foreach ($images as $key => $value) { foreach ($images as $key => $value) {
if ($value['urlOld'] === $url) if (isset($value['urlOld']) && $value['urlOld'] === $url)
$add = false; $add = false;
} }
if ($add) { if ($add) {

View File

@ -410,57 +410,86 @@ class ListManagementController extends Controller {
} }
} }
public function getCurrentTime() {
$time = microtime();
$time = explode(' ', $time);
return $time[1] + $time[0];
}
public function actionSyncFeature() { public function actionSyncFeature() {
if (Yii::$app->request->post()) { if (Yii::$app->request->post()) {
Yii::$app->response->format = "json"; Yii::$app->response->format = "json";
$processTime = [];
$totalStart = $this->getCurrentTime();
$totals = intval(Yii::$app->request->post("totals")); $totals = intval(Yii::$app->request->post("totals"));
$server_ip = \app\models\SyncUrl::findOne(['key_config' => 'server_api']); // $server_ip = \app\models\SyncUrl::findOne(['key_config' => 'server_api']);
$ip = "dev-dc.beetai.com"; // $ip = "dev-dc.beetai.com";
if ($server_ip) // if ($server_ip)
$ip = $server_ip->data; // $ip = $server_ip->data;
$device_id = \app\models\SyncUrl::findOne(['key_config' => 'device_id']); // $device_id = \app\models\SyncUrl::findOne(['key_config' => 'device_id']);
$id_camera = 209; // $id_camera = 209;
if ($device_id) // if ($device_id)
$id_camera = intval($device_id->data); // $id_camera = intval($device_id->data);
$res = json_decode(file_get_contents("https://" . $ip . "/api/oem/get_all_image", false, stream_context_create([ // $start = $this->getCurrentTime();
'http' => [ // $res = json_decode(file_get_contents("https://" . $ip . "/api/oem/get_all_image", false, stream_context_create([
'header' => "Content-Type: application/json", // 'http' => [
'method' => "POST", // 'header' => "Content-Type: application/json",
'content' => json_encode([ // 'method' => "POST",
"id_camera" => $id_camera, // 'content' => json_encode([
"ids_staff" => [strval(Yii::$app->request->post("id"))] // "id_camera" => $id_camera,
]) // "ids_staff" => [strval(Yii::$app->request->post("id"))]
] // ])
])), true); // ]
$data = $res['data'][0]; // ])), true);
// $finish = $this->getCurrentTime();
// $processTime["requestToAPI"] = round(($finish - $start), 4);
$data = Yii::$app->request->post("id"); //$res['data'][0];
$ft = []; $ft = [];
$RootFolder = Yii::getAlias('@webroot') . "/data/uploads"; $RootFolder = Yii::getAlias('@webroot') . "/data/uploads";
$targetPath = $RootFolder . "/face"; $targetPath = $RootFolder . "/face";
FileHelper::createDirectory($targetPath, 0777); FileHelper::createDirectory($targetPath, 0777);
foreach ($data['images'] as $key => $value) { $extractFeature = [];
if ($key < Yii::$app->params['maxPicture']) { if (isset($data['images'])) {
$fileName = "face_" . common::generateRandomString() . "_" . time() . ".png"; foreach ($data['images'] as $key => $value) {
$img = file_get_contents($value); if ($key < Yii::$app->params['maxPicture']) {
if ($img !== "null") { $fileName = "face_" . common::generateRandomString() . "_" . time() . ".png";
$fileTarget = $targetPath . "/" . $fileName; $start = $this->getCurrentTime();
if (!$this->resizeImg($img, $fileTarget)) { $img = file_get_contents($value);
file_put_contents($fileTarget, $img); $finish = $this->getCurrentTime();
$temp["getIMG"] = round(($finish - $start), 4);
if ($img !== "null") {
$fileTarget = $targetPath . "/" . $fileName;
$start = $this->getCurrentTime();
if (!$this->resizeImg($img, $fileTarget)) {
file_put_contents($fileTarget, $img);
}
$finish = $this->getCurrentTime();
$temp["saveIMG"] = round(($finish - $start), 4);
$start = $this->getCurrentTime();
$features = json_decode(common::requestToEngine("/get-feature", [
"image_paths" => [
["url" => "/var/www/html/BiFace_Server_Lite/web/data/uploads/face/" . $fileName, "type" => "raw"]
]
]), true);
$finish = $this->getCurrentTime();
$temp["extract"] = round(($finish - $start), 4);
$ft[] = [
"url" => $fileName,
"urlOld" => $fileName,
"features" => $features['results'][0]['feature'],
"features512" => isset($features['results'][0]['feature512']) ? $features['results'][0]['feature512'] : []
];
} }
$features = json_decode(common::requestToEngine("/get-feature", [ $extractFeature[] = $temp;
"image_paths" => [
["url" => "/var/www/html/BiFace_Server_Lite/web/data/uploads/face/" . $fileName, "type" => "raw"]
]
]), true);
$ft[] = [
"url" => $fileName,
"urlOld" => $fileName,
"features" => $features['results'][0]['feature'],
"features512" => isset($features['results'][0]['feature512']) ? $features['results'][0]['feature512'] : []
];
} }
} }
} }
$processTime["extractFeature"] = $extractFeature;
$start = $this->getCurrentTime();
$model = ListManagement::findOne(['code' => $data['idStaff']]); $model = ListManagement::findOne(['code' => $data['idStaff']]);
$finish = $this->getCurrentTime();
$processTime["getLM"] = round(($finish - $start), 4);
if ($model) { if ($model) {
$model->name = $data['name']; $model->name = $data['name'];
$model->address = $data['department']; $model->address = $data['department'];
@ -475,6 +504,7 @@ class ListManagementController extends Controller {
"features" => $model->allFeatures "features" => $model->allFeatures
]); ]);
} else { } else {
$start = $this->getCurrentTime();
$model = new ListManagement(); $model = new ListManagement();
$model->create([ $model->create([
'code' => strval($data['idStaff']), 'code' => strval($data['idStaff']),
@ -486,6 +516,8 @@ class ListManagementController extends Controller {
'telephone' => "", 'telephone' => "",
'address' => $data['department'] 'address' => $data['department']
]); ]);
$finish = $this->getCurrentTime();
$processTime["insertDB"] = round(($finish - $start), 4);
if ($totals <= 10) if ($totals <= 10)
common::updateFeature([ common::updateFeature([
"cmd" => "create", "cmd" => "create",
@ -494,7 +526,9 @@ class ListManagementController extends Controller {
"features" => $model->allFeatures "features" => $model->allFeatures
]); ]);
} }
return ["status" => true]; $totalFinish = $this->getCurrentTime();
$processTime["total"] = round(($totalFinish - $totalStart), 4);
return $processTime; //["status" => true];
} }
} }

View File

@ -14,6 +14,7 @@
{foreach from=$datas item=arr} {foreach from=$datas item=arr}
<tr onclick="choooseToSync(this);" style="cursor: pointer;" class="{if !in_array($arr.idStaff,$allID)}not-in-list{/if}" data-stt="false" data-id="{$arr.idStaff}"> <tr onclick="choooseToSync(this);" style="cursor: pointer;" class="{if !in_array($arr.idStaff,$allID)}not-in-list{/if}" data-stt="false" data-id="{$arr.idStaff}">
<td> <td>
<div id="full-data-{$arr.idStaff}" class="hidden">{json_encode($arr)}</div>
{$arr.idStaff} {$arr.idStaff}
{if in_array($arr.idStaff,$allID)} {if in_array($arr.idStaff,$allID)}
<i class="fa fa-check-circle text-green"></i> <i class="fa fa-check-circle text-green"></i>

View File

@ -421,7 +421,8 @@ function _syncFromServerForm(e) {
function _syncFromServer() { function _syncFromServer() {
var lists = []; var lists = [];
$.each($("#sync-lists").find(".success"), function () { $.each($("#sync-lists").find(".success"), function () {
lists.push($(this).attr("data-id")); var id = $(this).attr("data-id");
lists.push(JSON.parse($("#full-data-" + id).html()));
}); });
if (lists.length == 0) { if (lists.length == 0) {
alert("Không có dữ liệu đồng bộ!"); alert("Không có dữ liệu đồng bộ!");