update lay vecto 512 ngam

This commit is contained in:
dongpd 2021-01-06 17:38:50 +07:00
parent 3b247f9f25
commit aa811a40dd
5 changed files with 162 additions and 35 deletions

View File

@ -91,7 +91,11 @@ class ApiController extends Controller {
$id_camera = intval($device_id->data); $id_camera = intval($device_id->data);
$logsInfo = CaptureLogs::findOne($logs); $logsInfo = CaptureLogs::findOne($logs);
$staffInfo = ListManagement::findOne($post['id']); $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' => [ 'http' => [
'header' => "Content-Type: application/json", 'header' => "Content-Type: application/json",
'method' => "POST", 'method' => "POST",
@ -231,14 +235,28 @@ class ApiController extends Controller {
public function actionAutoGenFeature() { public function actionAutoGenFeature() {
Yii::$app->response->format = "json"; 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(); $lists = ListManagement::find()->all();
$finish = $this->getCurrentTime();
$processTime["getAllLM"] = round(($finish - $start), 4);
$extract = false;
foreach ($lists as $key => $value) { foreach ($lists as $key => $value) {
$extract = false;
$images = json_decode($value->image, true); $images = json_decode($value->image, true);
$newImgs = []; $newImgs = [];
$temp = []; $temp = [];
@ -260,23 +278,20 @@ class ApiController extends Controller {
} }
if ($extract) { if ($extract) {
$processTime['extract'] = $temp; $processTime['extract'] = $temp;
$value->image = json_encode($newImgs);
$start = $this->getCurrentTime(); $start = $this->getCurrentTime();
$value->image = json_encode($newImgs);
$value->save(); $value->save();
$finish = $this->getCurrentTime(); $finish = $this->getCurrentTime();
$processTime["updateDB"] = round(($finish - $start), 4); $processTime["updateDB"] = round(($finish - $start), 4);
$txt = "\n" . json_encode($processTime); $txt = "\n" . json_encode($processTime);
file_put_contents(date('Ymd') . ".txt", $txt, FILE_APPEND); 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() { public function actionSync() {
@ -291,9 +306,14 @@ class ApiController extends Controller {
if ($device_id) if ($device_id)
$id_camera = intval($device_id->data); $id_camera = intval($device_id->data);
$ls = CaptureLogs::find()->andWhere(['sync_status' => null])->all(); $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) { foreach ($ls as $key => $value) {
$staffInfo = ListManagement::findOne($value->staff_id); $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' => [ 'http' => [
'header' => "Content-Type: application/json", 'header' => "Content-Type: application/json",
'method' => "POST", 'method' => "POST",
@ -333,19 +353,62 @@ class ApiController extends Controller {
} }
public function actionGetTotalFeature() { public function actionGetTotalFeature() {
Yii::$app->response->format = "json"; if (Yii::$app->request->isAjax) {
$lists = ListManagement::find()->all(); Yii::$app->response->format = "json";
$total128 = $total512 = 0; $start = $this->getCurrentTime();
foreach ($lists as $key => $value) { $statistics = ListManagement::statisticFeatures();
$images = json_decode($value->image, true); $finish = $this->getCurrentTime();
foreach ($images as $k => $v) { $processTime = round(($finish - $start), 4);
if (isset($v['features']) && count($v['features']) > 0) return [
$total128++; "statistics" => $statistics,
if (isset($v['features512']) && count($v['features512']) > 0) "processTime" => $processTime
$total512++; ];
} }
}
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];
} }
} }

View File

@ -63,6 +63,7 @@ class ListManagementController extends Controller {
// if (!is_object($last)) // if (!is_object($last))
// $last = (object) ['id' => 0]; // $last = (object) ['id' => 0];
// $idAuto = $data['data']['box_id'] . "_" . ($last->id + 1); // $idAuto = $data['data']['box_id'] . "_" . ($last->id + 1);
return $this->render('index', [ return $this->render('index', [
'searchModel' => $searchModel, 'searchModel' => $searchModel,
'dataProvider' => $dataProvider, 'dataProvider' => $dataProvider,
@ -71,7 +72,7 @@ class ListManagementController extends Controller {
'typeArray' => ListManagement::$typeArray, 'typeArray' => ListManagement::$typeArray,
'genderArray' => ListManagement::$genderArray, 'genderArray' => ListManagement::$genderArray,
// 'idAuto' => $idAuto, // 'idAuto' => $idAuto,
"staffArray" => ListManagement::staffArray() "staffArray" => ListManagement::staffArray(),
]); ]);
} }
@ -547,6 +548,7 @@ class ListManagementController extends Controller {
} }
$totalFinish = $this->getCurrentTime(); $totalFinish = $this->getCurrentTime();
$processTime["total"] = round(($totalFinish - $totalStart), 4); $processTime["total"] = round(($totalFinish - $totalStart), 4);
$processTime["id"] = strval($data['idStaff']);
return $processTime; //["status" => true]; return $processTime; //["status" => true];
} }
} }

View File

@ -128,4 +128,28 @@ class ListManagement extends \yii\db\ActiveRecord {
return $f; 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
];
}
} }

View File

@ -41,6 +41,7 @@
<input type="hidden" value="{Url::to(["/list-management/sync-feature-to-server"])}" name="sync_feature_to_server_url"> <input type="hidden" value="{Url::to(["/list-management/sync-feature-to-server"])}" name="sync_feature_to_server_url">
<input type="hidden" value="{Url::to(["/list-management/sync-feature-from-device"])}" name="sync_feature_from_device_url"> <input type="hidden" value="{Url::to(["/list-management/sync-feature-from-device"])}" name="sync_feature_from_device_url">
<input type="hidden" value="{Url::to(["/list-management/update-feature"])}" name="update_feature_url"> <input type="hidden" value="{Url::to(["/list-management/update-feature"])}" name="update_feature_url">
<input type="hidden" value="{Url::to(["/api/get-total-feature"])}" name="get_total_feature_url">
<div class="row"> <div class="row">
<div class="col-md-10" style="max-height: 850px;overflow-y: auto;"> <div class="col-md-10" style="max-height: 850px;overflow-y: auto;">
{GridView::widget([ {GridView::widget([
@ -189,6 +190,27 @@
</div> </div>
<span class="help-block hidden"></span> <span class="help-block hidden"></span>
</div> </div>
<hr style="border-top: 1px solid #000;">
<table class="table table-bordered" style="background: #fff;">
<tr>
<td>Số người có ảnh / tổng</td>
<td class="text-right" id="totalPeople">
{*<b class="text-red">{$statistics.totalImg}</b>/<b>{$statistics.total}</b>*}
</td>
</tr>
<tr>
<td>Đặc trưng 1</td>
<td class="text-right" id="total128">
{* <b class="text-red">{$statistics.128}</b>/<b>{$statistics.img}</b>*}
</td>
</tr>
<tr>
<td>Đặc trưng 2</td>
<td class="text-right" id="total512">
{* <b class="text-red">{$statistics.512}</b>/<b>{$statistics.img}</b>*}
</td>
</tr>
</table>
</div> </div>
</div> </div>
<div style="width: 300px;position: absolute;" id="menu" class="hidden"> <div style="width: 300px;position: absolute;" id="menu" class="hidden">

View File

@ -16,10 +16,10 @@ $(function () {
}); });
btnImage(); btnImage();
$("#Code").select2(); $("#Code").select2();
getTotalFeature();
}); });
function _search(e) { function _search(e) {
var location = $(e).attr("data-href");// + "?from=" + $("input[name='From']").val() + "&to=" + $("input[name='To']").val(); var location = $(e).attr("data-href"); // + "?from=" + $("input[name='From']").val() + "&to=" + $("input[name='To']").val();
location = location + "?id=" + $("input[name='IDSearch']").val(); location = location + "?id=" + $("input[name='IDSearch']").val();
location = location + "&name=" + $("input[name='NameSearch']").val(); location = location + "&name=" + $("input[name='NameSearch']").val();
location = location + "&type=" + $("select[name='TypeSearch']").val(); location = location + "&type=" + $("select[name='TypeSearch']").val();
@ -555,10 +555,11 @@ function syncFeatureToServer(id, fullData) {
id: id id: id
}, },
success: function (data) { success: function (data) {
if (data.status != 10000) { console.log(data);
error++; // if (data.status != 10000) {
console.log(error); // error++;
} // console.log(error);
// }
progressToServer++; progressToServer++;
$("#progress-current").html(parseInt($("#progress-current").html()) + 1); $("#progress-current").html(parseInt($("#progress-current").html()) + 1);
var percent = parseInt(progressToServer / totalsToServer * 100); var percent = parseInt(progressToServer / totalsToServer * 100);
@ -600,4 +601,19 @@ function removeFilters() {
$(".btn-select").removeClass("hidden"); $(".btn-select").removeClass("hidden");
$("#filter-from-server").val('').trigger('change'); $("#filter-from-server").val('').trigger('change');
checkAllSync(false); checkAllSync(false);
}
function getTotalFeature() {
$.ajax({
url: $("input[name='get_total_feature_url']").val(),
type: 'POST',
success: function (data) {
console.log(data);
$("#totalPeople").html(`<b class="text-red">` + data.statistics.totalImg + `</b>/<b>` + data.statistics.total + `</b>`);
$("#total128").html(`<b class="text-red">` + data.statistics["128"] + `</b>/<b>` + data.statistics.img + `</b>`);
$("#total512").html(`<b class="text-red">` + data.statistics["512"] + `</b>/<b>` + data.statistics.img + `</b>`);
},
error: function (jqXHR, textStatus, errorThrown) {
}
});
} }