filter dong bo du lieu giua cac thiet bi

This commit is contained in:
2020-12-30 11:43:03 +07:00
parent d296533184
commit 09604d1cb8
4 changed files with 107 additions and 8 deletions

View File

@@ -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];
}
}