17 Commits

Author SHA1 Message Date
5598e1f3ad auto sync list management from server 2021-06-09 13:36:11 +07:00
1e3f0bef13 fix filters multi people 2021-06-07 13:55:54 +07:00
821cf9463d fix send logs realtime 2021-06-04 11:24:03 +07:00
08266f3a5f update save serverKey, staff_id 2021-06-03 09:46:52 +07:00
9ceb3567c9 Update 'controllers/ApiController.php'
fix bug regenfeature
2021-05-19 10:31:09 +00:00
2c722a1ee9 Merge branch 'dev_DTD' of http://gitea.beetai.com/dongpd/BiFace_Server_Lite into dev_DTD 2021-04-26 14:23:04 +07:00
70d60ff51e fix bug token - version 2021-04-26 14:22:57 +07:00
c02733be18 Update 'config/params.php' 2021-04-26 03:48:02 +00:00
924d23dad0 fix bug confidence 2021-04-26 10:24:53 +07:00
b006af4e1f update confidence + version 2021-04-23 16:58:19 +07:00
1b1162f3c2 get config to gen 512 feature 2021-04-20 10:33:22 +07:00
bf93f6c9d0 update version 2021-03-15 09:45:50 +07:00
aaa6de6f9c fix bug reset thiet bi 2021-03-03 14:08:46 +07:00
e45e08f372 upda ngon ngu tieng Viet cho nhung cho tieng Anh 2021-02-18 17:44:18 +07:00
c353c25abf fix bug idStaff co dau cach 2021-02-04 17:59:25 +07:00
92541936d1 hien thi anh mau moi nhat 2021-01-27 10:26:05 +07:00
6d87d47d68 update new feature 2021-01-22 16:16:18 +07:00
16 changed files with 598 additions and 188 deletions

View File

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

View File

@@ -78,13 +78,13 @@ class ApiController extends Controller {
"Staff" => $post["id"],
"Time" => $time,
"Image" => $fileName,
"Confidence" => strval($post["confidence"])
"Confidence" => json_encode($post["confidence"])
]);
$server_ip = \app\models\SyncUrl::findOne(['key_config' => 'server_api']);
$ip = "https://dev-dc.beetai.com";
if ($server_ip)
$ip = $server_ip->data;
if ($this->is_connected($ip) && $logs) {
if ($this->is_connected() && $logs) {
$device_id = \app\models\SyncUrl::findOne(['key_config' => 'device_id']);
$id_camera = 209;
if ($device_id)
@@ -104,6 +104,7 @@ class ApiController extends Controller {
'camera_id' => strval($id_camera),
'frametime' => date("Y-m-d H:i:s", $time),
'idCard' => $staffInfo ? strval($staffInfo->code) : "0",
'idObject' => $staffInfo ? $staffInfo->staff_id : "",
"person_id" => "123",
"timezone" => "+7"
])
@@ -124,17 +125,30 @@ class ApiController extends Controller {
$allFeatures = [];
foreach ($listManagement as $key => $value) {
$features = json_decode($value->image, true);
$f = [];
// $f = [];
// foreach ($features as $k => $v) {
// $f[] = $v['features'];
// if (isset($v['features512']))
// if (count($v['features512']))
// $f[] = $v['features512'];
// }
// $allFeatures[] = [
// "id" => $value->id,
// "name" => $this->convert_vi_to_en($value->name),
// "features" => $f
// ];
$feature1 = $feature2 = [];
foreach ($features as $k => $v) {
$f[] = $v['features'];
$feature1[] = $v['features'];
if (isset($v['features512']))
if (count($v['features512']))
$f[] = $v['features512'];
$feature2[] = $v['features512'];
}
$allFeatures[] = [
"id" => $value->id,
"name" => $this->convert_vi_to_en($value->name),
"features" => $f
"feature1" => $feature1,
"feature2" => $feature2
];
}
Yii::$app->response->format = "json";
@@ -235,6 +249,8 @@ class ApiController extends Controller {
public function actionAutoGenFeature() {
Yii::$app->response->format = "json";
if (!$this->check512())
return ["status" => false];
$updating = \app\models\SyncUrl::findOne(['key_config' => 'updating']);
if (!$updating) {
$model = new \app\models\SyncUrl();
@@ -244,13 +260,21 @@ class ApiController extends Controller {
]);
$updating = \app\models\SyncUrl::findOne(['key_config' => 'updating']);
}
$currentCache = json_decode(file_get_contents("http://localhost:2305/current-cache"), true);
if ($updating->data === "true") {
if ($currentCache['n_128'] == $currentCache['n_512']) {
$updating->data = "false";
$updating->save();
$txt = "\n" . date("H:i:s d/m/Y") . " " . "success";
file_put_contents(date('Ymd') . "_logs.txt", $txt, FILE_APPEND);
return ["status" => false];
} else {
$txt = "\n" . date("H:i:s d/m/Y") . " " . "updating";
file_put_contents(date('Ymd') . "_logs.txt", $txt, FILE_APPEND);
return ["status" => false];
}
}
$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);
@@ -330,6 +354,7 @@ class ApiController extends Controller {
'camera_id' => strval($id_camera),
'frametime' => date("Y-m-d H:i:s", $value->time),
'idCard' => $staffInfo ? strval($staffInfo->code) : "0",
'idObject' => $staffInfo ? $staffInfo->staff_id : "",
"person_id" => "123",
"timezone" => "+7"
])
@@ -392,31 +417,66 @@ class ApiController extends Controller {
'data' => $post['token']
]);
}
$version = \app\models\SyncUrl::findOne(['key_config' => 'version']);
if ($version) {
$version->data = $post['version'];
$version->save();
} else {
$model = new \app\models\SyncUrl();
$model->create([
'key_config' => "version",
'data' => $post['version']
]);
}
Yii::$app->response->format = "json";
return ["status" => true];
}
}
public function check512() {
$tempConfig = json_decode(file_get_contents("http://localhost:4004/ReadEngineConfig", false, stream_context_create([
'http' => [
'header' => "Content-Type: application/json",
'method' => "POST"
]
])), true);
if (!$tempConfig['status'])
return false;
$engineConfig = json_decode($tempConfig['data'], true);
if (count($engineConfig['data']['engines']) == 0)
return false;
$checkConfig = json_decode(file_get_contents("http://localhost:4004/ReadConfig", false, stream_context_create([
'http' => [
'header' => "Content-Type: application/json",
'method' => "POST",
'content' => json_encode([
'path' => $engineConfig['data']['engines'][0]['path']
])
]
])), true);
if (!$checkConfig['status'])
return false;
$config_json = "";
if ($checkConfig['status']) {
$config_json = json_decode($checkConfig['data'], true);
$check512 = $config_json['feature']['type2']['enable'];
if ($check512 !== "0")
return true;
}
return false;
}
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();
// $updating = \app\models\SyncUrl::findOne(['key_config' => 'token']);
$updating = \app\models\SyncUrl::find()->all();
foreach ($updating as $key => $value) {
echo $value->key_config . " " . $value->data . "<br>";
}
exit();
}
public function actionReGenFeature() {
@@ -428,6 +488,14 @@ class ApiController extends Controller {
'data' => "false"
]);
} else {
if ($this->check512()) {
$currentCache = json_decode(file_get_contents("http://localhost:2305/current-cache"), true);
if ($currentCache['n_128'] == $currentCache['n_512']) {
$updating->data = "true";
} else {
$updating->data = "false";
}
} else
$updating->data = "false";
$updating->save();
}
@@ -435,4 +503,188 @@ class ApiController extends Controller {
return ["data" => "reset updating flag"];
}
public function actionCheckLogs() {
$server_ip = \app\models\SyncUrl::findOne(['key_config' => 'server_api']);
$ip = "https://dev-dc.beetai.com";
if ($server_ip)
$ip = $server_ip->data;
$device_id = \app\models\SyncUrl::findOne(['key_config' => 'device_id']);
$id_camera = 209;
if ($device_id)
$id_camera = intval($device_id->data);
$datas = json_decode(file_get_contents($ip . "/api/model/get_log_model", false, stream_context_create([
'http' => [
'header' => "Content-Type: application/json",
'method' => "POST",
'content' => json_encode([
"idCamera" => $id_camera
])
]
])), true);
if ($datas['status'] == 10000) {
$logs = $datas['data'];
$infomation = [];
foreach ($logs as $key => $value) {
if ($value['action'] == "insert_image")
$this->insertImage($value['images'][0], $value['id'], $value['files_name'][0]);
if ($value['action'] == "remove_image")
$this->removeImage($value['id'], $value['files_name'][0]);
if ($value['action'] == "insert_info")
$this->insertInfo($value);
if ($value['action'] == "remove_info")
$this->removeInfo($value);
if ($value['action'] == "reset_all") {
\Yii::$app->db->createCommand()->truncateTable('capture_logs')->execute();
\Yii::$app->db->createCommand()->truncateTable('list_management')->execute();
array_map('unlink', glob("/var/www/html/BiFace_Server_Lite/web/data/uploads/face/*.*"));
}
if (in_array($value['action'], ['insert_image', 'remove_image', 'insert_info', 'remove_info', 'reset_all'])) {
$infomation[] = [
"obj_Log" => $value['obj_Log'],
"action" => $value['action'],
"idCamera" => $id_camera
];
}
}
if (count($infomation) > 0)
file_get_contents($ip . "/api/model/set_log_model", false, stream_context_create([
'http' => [
'header' => "Content-Type: application/json",
'method' => "POST",
'content' => json_encode([
"infomation" => $infomation
])
]
]));
file_get_contents("http://localhost:2305/update-feature?total=" . ListManagement::find()->count());
}
Yii::$app->response->format = "json";
return ["data" => "check logs"];
}
public function insertImage($image, $staff_id, $files_name) {
$model = ListManagement::findOne(['staff_id' => $staff_id]);
$RootFolder = Yii::getAlias('@webroot') . "/data/uploads";
$targetPath = $RootFolder . "/face";
FileHelper::createDirectory($targetPath, 0777);
$ft = [];
$currentArr = [];
$currentImg = json_decode($model->image, true);
if ($currentImg) {
foreach ($currentImg as $key => $value) {
if (isset($value['serverKey']))
$currentArr[] = $value['serverKey'];
}
$ft = $currentImg;
}
if (!in_array($files_name, $currentArr)) {
$fileName = "face_" . $staff_id . "_" . common::generateRandomString() . "_" . time() . ".png";
$img = false;
try {
$img = file_get_contents(str_replace("&amp;", "&", $image));
} catch (\Exception $e) {
}
if ($img && $img !== "null") {
$fileTarget = $targetPath . "/" . $fileName;
if (!$this->resizeImg($img, $fileTarget)) {
file_put_contents($fileTarget, $img);
}
$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);
$ft[] = [
"serverKey" => $files_name,
"url" => $fileName,
"urlOld" => $fileName,
"features" => $features['results'][0]['feature'],
"features512" => []
];
$model->image = json_encode($ft);
$model->last_modified = time();
$model->save();
}
}
}
public function removeImage($staff_id, $files_name) {
$model = ListManagement::findOne(['staff_id' => $staff_id]);
$images = json_decode($model->image, true);
$ft = [];
foreach ($images as $key => $value) {
if ($value['serverKey'] !== $files_name)
$ft[] = $value;
else
unlink("/var/www/html/BiFace_Server_Lite/web/data/uploads/face/" . $value['url']);
}
$model->image = json_encode($ft);
$model->last_modified = time();
$model->save();
}
public function insertInfo($data) {
$model = ListManagement::findOne(['staff_id' => $data['id']]);
if ($model) {
$model->name = $data['name'];
$model->abbreviated_name = $data['abbreviated_name'];
$model->code = $data['code'];
$model->address = $data['department'];
$model->last_modified = time();
$model->save();
} else {
$model = new ListManagement();
$model->create([
'staff_id' => $data['id'],
'code' => $data['code'],
'type' => 'wl',
'name' => $data['name'],
'image' => json_encode([]),
'gender' => "Male",
'birthday' => "",
'telephone' => "",
'address' => $data['department'],
'abbreviated_name' => $data['abbreviated_name'],
]);
}
}
public function removeInfo($data) {
$model = ListManagement::findOne(['staff_id' => $data['id']]);
if ($model) {
$images = json_decode($model->image, true);
foreach ($images as $k => $v) {
unlink("/var/www/html/BiFace_Server_Lite/web/data/uploads/face/" . $v['url']);
}
$model->delete();
}
return;
}
public function resizeImg($img, $fileTarget) {
$im = imagecreatefromstring($img);
$width = imagesx($im);
$height = imagesy($im);
$newwidth = 224;
$newheight = 224;
if ($width > $newwidth && $height > $newheight) {
$thumb = imagecreatetruecolor($newwidth, $newheight);
imagecopyresized($thumb, $im, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
imagejpeg($thumb, $fileTarget);
imagedestroy($thumb);
imagedestroy($im);
return true;
}
return false;
}
}

View File

@@ -339,7 +339,29 @@ class ConfigController extends Controller {
try {
file_get_contents("http://localhost:2305/update-feature");
} catch (\Exception $exc) {
// echo $exc->getTraceAsString();
}
$server_ip = \app\models\SyncUrl::findOne(['key_config' => 'server_api']);
$ip = "https://dev-dc.beetai.com";
if ($server_ip)
$ip = $server_ip->data;
$device_id = \app\models\SyncUrl::findOne(['key_config' => 'device_id']);
$id_camera = 209;
if ($device_id)
$id_camera = intval($device_id->data);
try {
file_get_contents($ip . "/api/model/reset_log_model", false, stream_context_create([
'http' => [
'header' => "Content-Type: application/json",
'method' => "POST",
'content' => json_encode([
"idCamera" => $id_camera,
"isCloud" => 0
])
]
]));
} catch (Exception $ex) {
}
}
return Url::to(['/config']);

View File

@@ -150,6 +150,7 @@ class ListManagementController extends Controller {
];
$listManagement->type = $data['type'];
$listManagement->name = $data['name'];
$listManagement->abbreviated_name = $data['abbreviated_name'];
$listManagement->gender = $data['gender'];
$listManagement->birthday = $data['birthday'] === "" ? 0 : date_format(date_create_from_format('d/m/Y', $data['birthday']), 'U');
$listManagement->telephone = $data['telephone'];
@@ -206,6 +207,7 @@ class ListManagementController extends Controller {
"type" => $ListManagement->type,
"code" => $ListManagement->code,
"name" => $ListManagement->name,
"abbreviated_name" => $ListManagement->abbreviated_name,
"gender" => $ListManagement->gender,
"birthday" => date("d/m/Y", $ListManagement->birthday),
"telephone" => $ListManagement->telephone,
@@ -250,6 +252,7 @@ class ListManagementController extends Controller {
$model->code = $data['code'];
$model->type = $data['type'];
$model->name = $data['name'];
$model->abbreviated_name = $data['abbreviated_name'];
$model->gender = $data['gender'];
$model->birthday = $data['birthday'] === "" ? 0 : date_format(date_create_from_format('d/m/Y', $data['birthday']), 'U');
$model->telephone = $data['telephone'];
@@ -414,13 +417,14 @@ class ListManagementController extends Controller {
'method' => "POST",
'content' => json_encode([
"id_camera" => $id_camera,
"ids_staff" => []
"ids_staff" => [],
"objs_staff" => []
])
]
])), true);
$filters = [];
foreach ($datas['data'] as $key => $value) {
$filters[$value['code']] = $value['code'] . " - " . $value['name'] . " - " . $value['department'];
$filters[$value['id']] = $value['code'] . " - " . $value['name'] . " - " . $value['department'];
}
Yii::$app->response->format = "json";
return [
@@ -440,49 +444,27 @@ class ListManagementController extends Controller {
return $time[1] + $time[0];
}
public function actionSyncFeature() {
if (Yii::$app->request->post()) {
Yii::$app->response->format = "json";
$processTime = [];
$totalStart = $this->getCurrentTime();
$totals = intval(Yii::$app->request->post("totals"));
// $server_ip = \app\models\SyncUrl::findOne(['key_config' => 'server_api']);
// $ip = "https://dev-dc.beetai.com";
// if ($server_ip)
// $ip = $server_ip->data;
// $device_id = \app\models\SyncUrl::findOne(['key_config' => 'device_id']);
// $id_camera = 209;
// if ($device_id)
// $id_camera = intval($device_id->data);
// $start = $this->getCurrentTime();
// $res = json_decode(file_get_contents($ip . "/api/oem/get_all_image", false, stream_context_create([
// 'http' => [
// 'header' => "Content-Type: application/json",
// 'method' => "POST",
// 'content' => json_encode([
// "id_camera" => $id_camera,
// "ids_staff" => [strval(Yii::$app->request->post("id"))]
// ])
// ]
// ])), true);
// $finish = $this->getCurrentTime();
// $processTime["requestToAPI"] = round(($finish - $start), 4);
$data = Yii::$app->request->post("id"); //$res['data'][0];
$ft = [];
public function extractFeature($images, $files_name, $staff_id, $currentImg = false) {
$RootFolder = Yii::getAlias('@webroot') . "/data/uploads";
$targetPath = $RootFolder . "/face";
FileHelper::createDirectory($targetPath, 0777);
$extractFeature = [];
if (isset($data['images'])) {
foreach ($data['images'] as $key => $value) {
if ($key < Yii::$app->params['maxPicture']) {
$fileName = "face_" . common::generateRandomString() . "_" . time() . ".png";
$ft = [];
$currentArr = [];
if ($currentImg) {
foreach ($currentImg as $key => $value) {
if (isset($value['serverKey']))
$currentArr[] = $value['serverKey'];
}
$ft = $currentImg;
}
foreach ($images as $key => $value) {
if ($key < Yii::$app->params['maxPicture'] && !in_array($files_name[$key], $currentArr)) {
$fileName = "face_" . $staff_id . "_" . common::generateRandomString() . "_" . time() . ".png";
$start = $this->getCurrentTime();
$img = false;
try {
$img = file_get_contents(str_replace("&amp;", "&", $value));
// $img = file_get_contents($value);
} catch (\Exception $e) {
}
@@ -506,6 +488,7 @@ class ListManagementController extends Controller {
$finish = $this->getCurrentTime();
$temp["extract"] = round(($finish - $start), 4);
$ft[] = [
"serverKey" => $files_name[$key],
"url" => $fileName,
"urlOld" => $fileName,
"features" => $features['results'][0]['feature'],
@@ -515,32 +498,61 @@ class ListManagementController extends Controller {
$extractFeature[] = $temp;
}
}
return [
"time" => $extractFeature,
"features" => $ft
];
}
$processTime["extractFeature"] = $extractFeature;
public function actionSyncFeature() {
if (Yii::$app->request->post()) {
Yii::$app->response->format = "json";
$processTime = [];
$totalStart = $this->getCurrentTime();
$totals = intval(Yii::$app->request->post("totals"));
$data = Yii::$app->request->post("id"); //$res['data'][0];
$start = $this->getCurrentTime();
$model = ListManagement::findOne(['code' => $data['idStaff']]);
$model = ListManagement::findOne(['staff_id' => $data['id']]);
$finish = $this->getCurrentTime();
$processTime["getLM"] = round(($finish - $start), 4);
$ft = [];
if ($model) {
if (isset($data['images'])) {
$extractFeature = $this->extractFeature($data['images'], $data['files_name'], $data['id'], json_decode($model->image, true));
$processTime["extractFeature"] = $extractFeature['time'];
$ft = $extractFeature['features'];
}
$model->abbreviated_name = $data['abbreviated_name'];
$model->code = $data['code'];
$model->name = $data['name'];
$model->address = $data['department'];
$model->image = json_encode($ft);
$model->last_modified = time();
$model->save();
if ($totals <= 10)
common::updateFeature([
"cmd" => "update",
"id" => $model->id,
"name" => common::convert_vi_to_en($model->name),
"features" => $model->allFeatures
]);
// if ($totals <= 10)
// common::updateFeature([
// "cmd" => "update",
// "id" => $model->id,
// "name" => common::convert_vi_to_en($model->name),
// "features" => $model->allFeatures
// ]);
} else {
if (isset($data['images'])) {
$extractFeature = $this->extractFeature($data['images'], $data['files_name'], $data['id']);
$processTime["extractFeature"] = $extractFeature['time'];
$ft = $extractFeature['features'];
}
$start = $this->getCurrentTime();
$model = new ListManagement();
$model->create([
'code' => strval($data['idStaff']),
'code' => strval($data['code']),
'type' => "wl",
'name' => $data['name'],
'abbreviated_name' => $data['abbreviated_name'],
'staff_id' => $data['id'],
'image' => json_encode($ft),
'gender' => "Male",
'birthday' => "",
@@ -549,17 +561,17 @@ class ListManagementController extends Controller {
]);
$finish = $this->getCurrentTime();
$processTime["insertDB"] = round(($finish - $start), 4);
if ($totals <= 10)
common::updateFeature([
"cmd" => "create",
"id" => $model->id,
"name" => common::convert_vi_to_en($model->name),
"features" => $model->allFeatures
]);
// if ($totals <= 10)
// common::updateFeature([
// "cmd" => "create",
// "id" => $model->id,
// "name" => common::convert_vi_to_en($model->name),
// "features" => $model->allFeatures
// ]);
}
$totalFinish = $this->getCurrentTime();
$processTime["total"] = round(($totalFinish - $totalStart), 4);
$processTime["id"] = strval($data['idStaff']);
$processTime["id"] = strval($data['code']);
return $processTime; //["status" => true];
}
}
@@ -578,7 +590,8 @@ class ListManagementController extends Controller {
])), true);
foreach ($results as $key => $value) {
$images = [];
foreach ($value['images'] as $k => $v) {
$imagesReverse = array_reverse($value['images']);
foreach ($imagesReverse as $k => $v) {
if ($k < Yii::$app->params['maxPicture']) {
$key = common::generateRandomString();
$RootFolder = Yii::getAlias('@webroot') . "/data/uploads";
@@ -655,7 +668,8 @@ class ListManagementController extends Controller {
"gender" => $staff->gender,
"birthday" => date("d/m/Y", $staff->birthday),
"telephone" => $staff->telephone,
"department" => $staff->address
"department" => $staff->address,
"abbreviated_name" => $staff->abbreviated_name
];
}
}
@@ -666,7 +680,7 @@ class ListManagementController extends Controller {
$datas = ListManagement::find()->orderBy(["code" => SORT_ASC])->all();
$filters = [];
foreach ($datas as $key => $value) {
$filters[$value->code] = $value->code . " - " . $value->name . " - " . $value->address;
$filters[$value->staff_id] = $value->code . " - " . $value->name . " - " . $value->address;
}
return [
"title" => "<i class='fa fa-upload'></i> Đồng bộ lên máy chủ",
@@ -690,18 +704,25 @@ class ListManagementController extends Controller {
if ($device_id)
$id_camera = intval($device_id->data);
$StaffInfo = ListManagement::findOne(["code" => Yii::$app->request->post("id")]);
$StaffInfo = ListManagement::findOne(["staff_id" => Yii::$app->request->post("id")]);
$lsImgs = json_decode($StaffInfo->image, true);
$images = [];
foreach ($lsImgs as $key => $value) {
if (!isset($value['serverKey']) || (isset($value['serverKey']) && $value['serverKey'] == "")) {
try {
$images[] = base64_encode(file_get_contents("/var/www/html/BiFace_Server_Lite/web/data/uploads/face/" . $value['url']));
} catch (\Exception $e) {
}
}
}
if (count($images) == 0)
return ["status" => true, "text" => "Dữ liệu không đổi"];
$items = [
"id" => $StaffInfo->staff_id,
"name" => $StaffInfo->name,
"abbreviated_name" => $StaffInfo->abbreviated_name,
"code" => $StaffInfo->code,
"department" => $StaffInfo->address,
"birthday" => date("Y-m-d", $StaffInfo->birthday),
@@ -721,6 +742,14 @@ class ListManagementController extends Controller {
])
]
])), true);
if ($res['status'] == 10000) {
$resData = $res['data'];
for ($i = 0; $i < count($lsImgs); $i++) {
$lsImgs[$i]['serverKey'] = isset($resData[$i]) ? $resData[$i] : "";
}
$StaffInfo->image = json_encode($lsImgs);
$StaffInfo->save();
}
} catch (\Exception $e) {
}

BIN
db/app.db

Binary file not shown.

View File

@@ -63,11 +63,62 @@ class CaptureLogsGrid {
public static function confidence() {
return function($model) {
return number_format($model->confidence, 2);
$confidence = json_decode($model->confidence, true);
// $person1_html = $person2_html = "";
// $person1 = \app\models\ListManagement::findOne($confidence['id1']);
// if ($person1) {
// $images = json_decode($person1->image, true);
// $person1_html = "<div class='feature-img'>" . Html::img("/data/uploads/face/" . $images[0]['url'], [
// "class" => "img-thumbnail",
// "style" => "width: 100px;height:100px;"
// ]) . "<br>" . $person1->name . " [" . $confidence['percent1'] . "]" . "</div>";
// }
// if ($confidence['id2'] !== "0" && $confidence['id2'] != $confidence['id1']) {
// $person2 = \app\models\ListManagement::findOne($confidence['id2']);
// if ($person2) {
// $images = json_decode($person2->image, true);
// $person2_html = "<div class='feature-img'>" . Html::img("/data/uploads/face/" . $images[0]['url'], [
// "class" => "img-thumbnail",
// "style" => "width: 100px;height:100px;"
// ]) . "<br>" . $person2->name . " [" . $confidence['percent2'] . "]" . "</div>";
// }
// }
return $confidence['percent1']; //$person1_html . $person2_html;
};
}
public static function confidenceControlLogs() {
return function($model) {
$confidence = json_decode($model->confidence, true);
return $confidence['percent1'] . ($confidence['percent2'] > 0 ? " [" . $confidence['percent2'] . "]" : "");
};
}
public static function rows() {
return function($model, $index, $widget, $grid) {
$confidence = json_decode($model->confidence, true);
$person = \app\models\ListManagement::findOne($confidence['id1']);
$images = false;
if ($person) {
$images = json_decode($person->image, true);
}
return [
"ondblclick" => "_form(this);",
"style" => "cursor: pointer;",
"data" => [
"id" => $model->id,
"img" => "/data/uploads/face/" . $model->image,
"confidence" => json_encode([
"name" => $person ? $person->name : "",
"score" => $confidence['percent1'],
"img" => isset($images[0]) ? "/data/uploads/face/" . $images[0]['url'] : ""
])
]
];
};
}
public static function rowsControlLogs() {
return function($model, $index, $widget, $grid) {
return [
"ondblclick" => "_form(this);",

View File

@@ -8,9 +8,11 @@ use Yii;
* This is the model class for table "list_management".
*
* @property int $id
* @property string $staff_id
* @property string $code
* @property string $type
* @property string $name
* @property string $abbreviated_name
* @property string $image
* @property string $gender
* @property int $birthday
@@ -33,7 +35,7 @@ class ListManagement extends \yii\db\ActiveRecord {
*/
public function rules() {
return [
[['type', 'name', 'gender', 'telephone', 'address', 'image', 'code'], 'string'],
[['type', 'name', 'gender', 'telephone', 'address', 'image', 'code', 'abbreviated_name', 'staff_id'], 'string'],
[['birthday', 'time', 'last_modified'], 'integer'],
];
}
@@ -53,12 +55,15 @@ class ListManagement extends \yii\db\ActiveRecord {
'telephone' => 'Điện thoại',
'address' => 'Đơn vị',
'time' => 'Thời gian đăng kí',
'last_modified' => 'Last Modified'
'last_modified' => 'Last Modified',
'abbreviated_name' => 'Tên hiển thị',
'staff_id' => 'ID'
];
}
public function create($data) {
$r = $this->load([
'staff_id' => $data['staff_id'],
'code' => $data['code'],
'type' => $data['type'],
'name' => $data['name'],
@@ -67,6 +72,7 @@ class ListManagement extends \yii\db\ActiveRecord {
'birthday' => $data['birthday'] === "" ? 0 : date_format(date_create_from_format('d/m/Y', $data['birthday']), 'U'),
'telephone' => $data['telephone'],
'address' => $data['address'],
'abbreviated_name' => $data['abbreviated_name'],
'time' => time(),
'last_modified' => time()
], '');
@@ -102,7 +108,7 @@ class ListManagement extends \yii\db\ActiveRecord {
$res = [];
$ls = self::find()->all();
foreach ($ls as $key => $value) {
$res[] = $value->code;
$res[] = $value->staff_id;
}
return $res;
}
@@ -118,14 +124,24 @@ class ListManagement extends \yii\db\ActiveRecord {
public function getAllFeatures() {
$features = json_decode($this->image, true);
$f = [];
// $f = [];
// foreach ($features as $k => $v) {
// $f[] = $v['features'];
// if (isset($v['features512']))
// if (count($v['features512']))
// $f[] = $v['features512'];
// }
$feature1 = $feature2 = [];
foreach ($features as $k => $v) {
$f[] = $v['features'];
$feature1[] = $v['features'];
if (isset($v['features512']))
if (count($v['features512']))
$f[] = $v['features512'];
$feature2[] = $v['features512'];
}
return $f;
return [
"feature1" => $feature1,
"feature2" => $feature2
];
}
public static function statisticFeatures() {

View File

@@ -4,5 +4,5 @@ copy.src.target=
remote.connection=BiFace-99bab6
remote.directory=/BiFace_Server_Lite
remote.upload=ON_SAVE
run.as=LOCAL
run.as=REMOTE
url=http://localhost/

View File

@@ -1,7 +1,7 @@
<?php
use yii\widgets\Breadcrumbs;
use dmstr\widgets\Alert;
?>
<div class="content-wrapper">
<!-- <section class="content-header">
@@ -10,7 +10,8 @@ use dmstr\widgets\Alert;
[
'links' => isset($this->params['breadcrumbs']) ? $this->params['breadcrumbs'] : [],
]
) ?>
)
?>
</section>-->
<section class="content" style="padding: 0 0 15px 0;">
@@ -21,8 +22,12 @@ use dmstr\widgets\Alert;
</div>
<footer class="main-footer">
<div class="pull-right hidden-xs" style="margin-top: 10px;">
<!--<b>Hotline</b> <a href="tel:0912461556">091.246.1556</a>-->
<div class="pull-right hidden-xs">
<b>Version: </b>
<?php
$version = \app\models\SyncUrl::findOne(['key_config' => 'version']);
echo $version ? $version->data : Yii::$app->params["version"];
?>
</div>
<!--<strong>Copyright &copy; 2020 <a href="https://beetinnovators.com/"><img src="/images/BI_Logo.png" width="80px"></a> & <a href="https://tctech.vn/"><img src="/images/TCTech.jpg" width="80px"></a>.</strong> All rights reserved.-->
<strong>Copyright &copy; 2020 <a href="https://beetinnovators.com/">BEETINNOVATORS</a>.</strong> All rights reserved.

View File

@@ -55,6 +55,7 @@
'attribute' => 'confidence',
'contentOptions' => ['class' => 'text-center'],
'headerOptions' => ['class' => 'text-center'],
'format' => "raw",
'value' => \app\helpers\CaptureLogsGrid::confidence()
],
[
@@ -89,17 +90,22 @@
<div style="width: 500px;position: absolute;right:0;top: 250px;" id='form' class="hidden">
<div class="panel panel-info">
<div class="panel-heading text-bold">
List management
Quản lý mẫu
<i class="fa fa-remove pull-right" style="cursor: pointer;" onclick="_close();"></i>
</div>
<div class="panel-body">
<div class="row">
<div class="col-md-4 text-center">
<img src="" class="img-thumbnail" id="FaceImage" style="width: 150px;height: 150px;">
<div class='feature-img'>
<img src="" class="img-thumbnail" id="closest-img" style="width: 100px;height:100px;">
<br>
<i id="closest-name"></i>
</div>
</div>
<div class="col-md-8">
<div class="row">
<div class="col-md-4 text-right">Type</div>
<div class="col-md-4 text-right">Danh sách</div>
<div class="col-md-8">
<select style="width: 100%;height: 26px;" name="Type">
<option value="wl">White list</option>
@@ -117,34 +123,40 @@
</div>
</div>
<div class="row">
<div class="col-md-4 text-right">Name</div>
<div class="col-md-4 text-right">Tên</div>
<div class="col-md-8">
<input type="text" name="Name">
</div>
</div>
<div class="row">
<div class="col-md-4 text-right">Gender</div>
<div class="col-md-4 text-right">Tên hiển thị</div>
<div class="col-md-8">
<input type="text" name="AbbreviatedName">
</div>
</div>
<div class="row">
<div class="col-md-4 text-right">Giới tính</div>
<div class="col-md-8">
<select style="width: 100%;height: 26px;" name="Gender">
<option value="Male">Male</option>
<option value="Female">Female</option>
<option value="Male">Nam</option>
<option value="Female">Nữ</option>
</select>
</div>
</div>
<div class="row">
<div class="col-md-4 text-right">Birthday</div>
<div class="col-md-4 text-right">Ngày sinh</div>
<div class="col-md-8">
<input type="text" name="Birthday" id="birthday">
</div>
</div>
<div class="row">
<div class="col-md-4 text-right">Telephone</div>
<div class="col-md-4 text-right">Điện thoại</div>
<div class="col-md-8">
<input type="text" name="Telephone">
</div>
</div>
<div class="row">
<div class="col-md-4 text-right">Department</div>
<div class="col-md-4 text-right">Đơn vị</div>
<div class="col-md-8">
<input type="text" name="Address">
</div>
@@ -153,8 +165,8 @@
</div>
<div class="text-center">
<input type="hidden" value="" name="CaptureLogsID">
<button onclick="_save(this);" data-href='{Url::to(["/list-management/create"])}'>Save</button>
<button onclick="_close();">Cancel</button>
<button onclick="_save(this);" data-href='{Url::to(["/list-management/create"])}'>Lưu</button>
<button onclick="_close();">Hủy</button>
</div>
</div>
</div>

View File

@@ -31,7 +31,7 @@
'class' => 'table table-striped table-bordered',
'style' => 'background:#fff;min-width:700px;'
],
'rowOptions' => \app\helpers\CaptureLogsGrid::rows(),
'rowOptions' => \app\helpers\CaptureLogsGrid::rowsControlLogs(),
'columns' => [
[
'attribute' => 'id',
@@ -62,7 +62,7 @@
'attribute' => 'confidence',
'contentOptions' => ['class' => 'text-center'],
'headerOptions' => ['class' => 'text-center'],
'value' => \app\helpers\CaptureLogsGrid::confidence()
'value' => \app\helpers\CaptureLogsGrid::confidenceControlLogs()
],
'listManagement.name',
'listManagement.gender',

View File

@@ -66,7 +66,10 @@
],
[
'attribute' => 'name',
'contentOptions' => ['class' => 'text-center'],
'headerOptions' => ['class' => 'text-center']
],
[
'attribute' => 'abbreviated_name',
'headerOptions' => ['class' => 'text-center']
],
[
@@ -86,12 +89,6 @@
'headerOptions' => ['class' => 'text-center'],
'value' => \app\helpers\ListManagementGrid::time()
],
[
'attribute' => 'birthday',
'contentOptions' => ['class' => 'text-center'],
'headerOptions' => ['class' => 'text-center'],
'value' => \app\helpers\ListManagementGrid::birthday()
],
[
'attribute' => 'telephone',
'contentOptions' => ['class' => 'text-center'],
@@ -218,22 +215,22 @@
</table>
</div>
</div>
<div style="width: 300px;position: absolute;" id="menu" class="hidden">
<div style="width: 200px;position: absolute;" id="menu" class="hidden">
<div class="panel panel-info">
<div class="panel-heading text-bold">
Operation menu
Thao tác
<i class="fa fa-remove pull-right" style="cursor: pointer;" onclick="_closeMenu();"></i>
</div>
<div class="panel-body text-center">
<button onclick="_formModified(this);" data-href='{Url::to(["/list-management/form-update"])}'>Modified list</button>
<button onclick="_delete(this);" data-href="{Url::to(["/list-management/delete"])}">Delete list</button>
<button onclick="_formModified(this);" data-href='{Url::to(["/list-management/form-update"])}'>Sửa</button>
<button onclick="_delete(this);" data-href="{Url::to(["/list-management/delete"])}">Xóa</button>
</div>
</div>
</div>
<div style="width: 500px;position: absolute;right:0;top: 250px;" id='form' class="hidden">
<div class="panel panel-info">
<div class="panel-heading text-bold">
List management
Quản lý mẫu
<i class="fa fa-remove pull-right" style="cursor: pointer;" onclick="_close();"></i>
</div>
<div class="panel-body">
@@ -248,7 +245,7 @@
</div>
<div class="col-md-8">
<div class="row">
<div class="col-md-4 text-right">Type</div>
<div class="col-md-4 text-right">Danh sách</div>
<div class="col-md-8">
<select style="width: 100%;height: 26px;" name="Type">
{html_options options=$typeArray}
@@ -265,13 +262,19 @@
</div>
</div>
<div class="row">
<div class="col-md-4 text-right">Name</div>
<div class="col-md-4 text-right">Tên</div>
<div class="col-md-8">
<input type="text" name="Name">
</div>
</div>
<div class="row">
<div class="col-md-4 text-right">Gender</div>
<div class="col-md-4 text-right">Tên hiển thị</div>
<div class="col-md-8">
<input type="text" name="AbbreviatedName">
</div>
</div>
<div class="row">
<div class="col-md-4 text-right">Giới tính</div>
<div class="col-md-8">
<select style="width: 100%;height: 26px;" name="Gender">
{html_options options=$genderArray}
@@ -279,19 +282,19 @@
</div>
</div>
<div class="row">
<div class="col-md-4 text-right">Birthday</div>
<div class="col-md-4 text-right">Ngày sinh</div>
<div class="col-md-8">
<input type="text" name="Birthday" id="birthday">
</div>
</div>
<div class="row">
<div class="col-md-4 text-right">Telephone</div>
<div class="col-md-4 text-right">Điện thoại</div>
<div class="col-md-8">
<input type="text" name="Telephone">
</div>
</div>
<div class="row">
<div class="col-md-4 text-right">Department</div>
<div class="col-md-4 text-right">Đơn vị</div>
<div class="col-md-8">
<input type="text" name="Address">
</div>
@@ -300,8 +303,8 @@
</div>
<div class="text-center">
<input type="hidden" value="" name="ListManagementID">
<button onclick="_update(this);" data-href='{Url::to(["/list-management/update"])}' id="save-btn">Save</button>
<button onclick="_close();">Cancel</button>
<button onclick="_update(this);" data-href='{Url::to(["/list-management/update"])}' id="save-btn">Lưu</button>
<button onclick="_close();">Hủy</button>
</div>
</div>
</div>

View File

@@ -22,23 +22,24 @@
<tr>
<th>ID</th>
<th>Tên</th>
<th>Tên hiển thị</th>
<th>Đơn vị</th>
<th>Hình ảnh đăng kí</th>
<th>Code</th>
<th>Company ID</th>
</tr>
</thead>
<tbody id="sync-lists">
{foreach from=$datas item=arr}
<tr id="filters-{$arr.code}" onclick="choooseToSync(this);" style="cursor: pointer;" class="filters {if !in_array($arr.idStaff,$allID)}not-in-list{/if}" data-stt="false" data-id="{trim($arr.idStaff)}">
<tr id="filters-{$arr.id}" onclick="choooseToSync(this);" style="cursor: pointer;" class="filters {if !in_array($arr.id,$allID)}not-in-list{/if}" data-stt="false" data-id="{trim($arr.id)}">
<td>
<div id="full-data-{trim($arr.idStaff)}" class="hidden">{json_encode($arr)}</div>
{$arr.idStaff}
{if in_array($arr.idStaff,$allID)}
<div id="full-data-{trim($arr.id)}" class="hidden">{json_encode($arr)}</div>
{$arr.code}
{if in_array($arr.id,$allID)}
<i class="fa fa-check-circle text-green"></i>
{/if}
</td>
<td>{$arr.name}</td>
<td>{$arr.abbreviated_name}</td>
<td>{$arr.department}</td>
<td>
{foreach from=$arr.images item=img key=k}
@@ -49,7 +50,6 @@
{/if}
{/foreach}
</td>
<td>{$arr.code}</td>
<td>{$arr.id_company}</td>
</tr>
{/foreach}

View File

@@ -22,6 +22,7 @@
<tr>
<th>ID</th>
<th>Tên</th>
<th>Tên hiển thị</th>
<th>Giới tính</th>
<th>Hình ảnh đăng kí</th>
<th>Ngày sinh</th>
@@ -31,9 +32,10 @@
</thead>
<tbody id="sync-lists">
{foreach from=$datas item=arr}
<tr id="filters-{$arr.code}" class="filters" onclick="choooseToSync(this);" style="cursor: pointer;" data-stt="false" data-id="{$arr->code}">
<tr id="filters-{$arr.staff_id}" class="filters" onclick="choooseToSync(this);" style="cursor: pointer;" data-stt="false" data-id="{$arr->staff_id}">
<td>{$arr->code}</td>
<td>{$arr->name}</td>
<td>{$arr.abbreviated_name}</td>
<td>{$arr->gender}</td>
<td>
{$images = json_decode($arr->image, true)}

View File

@@ -23,6 +23,9 @@ function _form(e) {
$("#form").removeClass("hidden");
$("input[name='CaptureLogsID']").val($(e).attr("data-id"));
$("#FaceImage").attr("src", $(e).attr("data-img"));
var confidence = JSON.parse($(e).attr("data-confidence"));
$("#closest-img").attr("src", confidence.img);
$("#closest-name").html(confidence.name + " [" + confidence.score + "]");
}
function _close() {
@@ -40,6 +43,11 @@ function _save(e) {
alert("Hãy nhập tên!");
return;
}
var abbreviated_name = $("input[name='AbbreviatedName']").val();
if (abbreviated_name === "") {
alert("Hãy nhập tên hiển thị!");
return;
}
common.modalBlock(true);
$.ajax({
url: $(e).attr("data-href"),
@@ -47,6 +55,7 @@ function _save(e) {
data: {
code: code,
name: name,
abbreviated_name: abbreviated_name,
type: $("select[name='Type']").val(),
gender: $("select[name='Gender']").val(),
birthday: $("input[name='Birthday']").val(),
@@ -81,6 +90,7 @@ function chooseStaff(e) {
success: function (data) {
common.modalBlock(false);
$("input[name='Name']").val(data.name);
$("input[name='AbbreviatedName']").val(data.abbreviated_name);
$("select[name='Gender']").val(data.gender);
$("input[name='Birthday']").val(data.birthday);
$("input[name='Telephone']").val(data.telephone);

View File

@@ -68,6 +68,7 @@ function _formModified(e) {
$("select[name='Type']").val(data.type);
$("select[name='Code']").val(data.code);
$("input[name='Name']").val(data.name);
$("input[name='AbbreviatedName']").val(data.abbreviated_name);
$("select[name='Gender']").val(data.gender);
$("input[name='Birthday']").val(data.birthday);
$("input[name='Telephone']").val(data.telephone);
@@ -94,6 +95,11 @@ function _update(e) {
alert("Hãy nhập tên!");
return;
}
var abbreviated_name = $("input[name='AbbreviatedName']").val();
if (abbreviated_name === "") {
alert("Hãy nhập tên hiển thị!");
return;
}
common.modalBlock(true);
$.ajax({
url: $(e).attr("data-href"),
@@ -101,6 +107,7 @@ function _update(e) {
data: {
code: code,
name: name,
abbreviated_name: abbreviated_name,
type: $("select[name='Type']").val(),
gender: $("select[name='Gender']").val(),
birthday: $("input[name='Birthday']").val(),
@@ -586,12 +593,12 @@ function filters(e) {
if (id === "") {
$(".filters").removeClass("hidden");
$(".btn-select").removeClass("hidden");
checkAllSync(false);
// checkAllSync(false);
} else {
$(".filters").addClass("hidden");
$("#filters-" + id).removeClass("hidden");
$(".btn-select").addClass("hidden");
checkAllSync(false);
// checkAllSync(false);
choooseToSync($("#filters-" + id));
}
}
@@ -600,7 +607,7 @@ function removeFilters() {
$(".filters").removeClass("hidden");
$(".btn-select").removeClass("hidden");
$("#filter-from-server").val('').trigger('change');
checkAllSync(false);
// checkAllSync(false);
}
function getTotalFeature() {