浏览代码

增加处理速度、开始和结束时间

Michael Wang 6 年之前
父节点
当前提交
9653bbd4e2
共有 3 个文件被更改,包括 86 次插入41 次删除
  1. 5 0
      package-lock.json
  2. 1 0
      package.json
  3. 80 41
      src/views/index.vue

+ 5 - 0
package-lock.json

@@ -10034,6 +10034,11 @@
         }
       }
     },
+    "moment": {
+      "version": "2.22.2",
+      "resolved": "https://registry.npmjs.org/moment/-/moment-2.22.2.tgz",
+      "integrity": "sha1-PCV/mDn8DpP/UxSWMiOeuQeD/2Y="
+    },
     "move-concurrently": {
       "version": "1.0.1",
       "resolved": "https://registry.npmjs.org/move-concurrently/-/move-concurrently-1.0.1.tgz",

+ 1 - 0
package.json

@@ -17,6 +17,7 @@
     "electron": "^2.0.8",
     "js-base64": "^2.4.6",
     "js-md5": "^0.7.3",
+    "moment": "^2.22.2",
     "mysql": "^2.16.0",
     "vue": "^2.5.16",
     "vue-resource": "^1.5.1",

+ 80 - 41
src/views/index.vue

@@ -13,20 +13,31 @@
           </button>
         </a>
         <div id='progressDiv'>
-          <span>
-            成功:
-            <span style="color:green;">{{successNum}}</span>/{{allNum}}
-          </span>
-          <span>
-            失败:
-            <span style="color:red;">{{errorNum}}</span>/{{allNum}}
-          </span>
-          <span>
-            并发请求:
-            <span style="color:black;">{{reqNum}}</span>
-          </span>
-          <span v-show="completeShow" style="color: green;font-weight: bold;">全部处理完成</span>
-          <span v-show="!completeShow&&(successNum>0||errorNum>0)" style="color: red;font-weight: bold;">处理中...</span>
+          <div>
+
+            <span>
+              成功:
+              <span style="color:green;">{{successNum}}</span>/{{allNum}}
+            </span>
+            <span>
+              失败:
+              <span style="color:red;">{{errorNum}}</span>/{{allNum}}
+            </span>
+            <span>
+              并发请求:
+              <span style="color:black;">{{reqNum}}</span>
+            </span>
+          </div>
+          <div>
+            <span>开始时间:{{startProcessTimeFormat}} </span>
+            <span>结束时间:{{endProcessTimeFormat}} </span>
+            <span>处理速度:{{(1000*processSpeed).toFixed(2)}}个/秒</span>
+          </div>
+          <div>
+            <span v-show="completeShow" style="color: green;font-weight: bold;">全部处理完成</span>
+            <span v-show="!completeShow&&(successNum>0||errorNum>0)" style="color: red;font-weight: bold;">处理中...</span>
+
+          </div>
         </div>
       </div>
       <div id='progress-div'>
@@ -57,6 +68,7 @@ const Base64 = require("js-base64").Base64;
 const fs = window.nodeRequire("fs");
 const path = window.nodeRequire("path");
 const async = require("async");
+const moment = require("moment");
 
 function isImageFile(fileName) {
   const lowercaseName = fileName.toLowerCase();
@@ -89,7 +101,10 @@ export default {
       errorNum: 0, //失败数量
       allNum: 0, //总数
       completeShow: false,
-      reqNum: 0
+      reqNum: 0,
+      startProcessTime: null,
+      endProcessTime: null,
+      processSpeed: 0
     };
   },
   methods: {
@@ -100,6 +115,10 @@ export default {
       this.errorNum = 0;
       this.allNum = 0;
       this.completeShow = false;
+      this.reqNum = 0;
+      this.startProcessTime = null;
+      this.endProcessTime = null;
+      this.processSpeed = 0;
     },
     importPhotos() {
       this.init();
@@ -114,6 +133,7 @@ export default {
           if (folderPaths) {
             this.photoList = readImageFiles(folderPaths[0]);
             this.allNum = this.photoList.length;
+            this.startProcessTime = Date.now();
             this.processQueue();
           }
         }
@@ -124,27 +144,28 @@ export default {
       let total = 0;
       for (
         let i = this.successNum + this.errorNum;
-        i < this.photoList.length && total < 500;
+        i < this.photoList.length && total < 1000;
         i++, total++
       ) {
         taskQueue.push(this.processStudentPhoto.bind(this, this.photoList[i]));
       }
       this.processQueueSingle(taskQueue);
     },
-    processQueueSingle(taskQueue500) {
+    processQueueSingle(taskQueue1000) {
       // 并发处理请求,可在控制台查看请求峰值
-      CONCURRENCY = new Date().getHours() < 6 ? 8 : 4;
-      async.parallelLimit(taskQueue500, CONCURRENCY, (err, results) => {
+      CONCURRENCY = new Date().getHours() < 6 ? 8 : 5;
+      async.parallelLimit(taskQueue1000, CONCURRENCY, (err, results) => {
         if (err) {
           alert(err);
           console.log(err);
         } else {
           console.log(results);
           if (this.successNum + this.errorNum < this.allNum) {
-            console.log("处理完500张图片了,3秒后继续...");
+            console.log("处理完1000张图片了,3秒后继续...");
             setTimeout(this.processQueue, 3000);
           } else {
             console.log("photoList处理完毕");
+            this.endProcessTime = Date.now();
             this.completeShow = true;
           }
         }
@@ -160,6 +181,10 @@ export default {
       const rootOrgId = localStorage.getItem("rootOrgId");
       this.reqNum = window.requestInProcessingTotal;
 
+      this.processSpeed =
+        (this.successNum + this.errorNum) /
+        (Date.now() - this.startProcessTime);
+
       //生成新名称
       const upyunPhotoPath = (() => {
         const md5Hash = CryptoJS.MD5(
@@ -262,7 +287,7 @@ export default {
             //     res.data.face_added
             //   }, res.data.face_count: ${res.data.face_count}`
             // );
-            if (res.data.face_count > 4000) {
+            if (res.data.face_count > 8000) {
               window.DB.updateFaceSet(faceset_token, res.data.face_count).then(
                 () => {
                   this.faceSetToken = undefined;
@@ -330,28 +355,32 @@ export default {
     },
     //成功或失败处理
     finishOnePhotoFail(msg, studentPhotoPath) {
-      const fileName = path.basename(studentPhotoPath);
-      this.returnMsgList.push({
-        success: false,
-        fileName,
-        msg
-      });
-      this.errorNum++;
+      try {
+        const fileName = path.basename(studentPhotoPath);
+        this.returnMsgList.push({
+          success: false,
+          fileName,
+          msg
+        });
+        this.errorNum++;
 
-      //移动照片到errorfiles文件夹
-      const errorfilePath = path.join(
-        path.dirname(studentPhotoPath),
-        "errorfiles"
-      );
-      if (!fs.existsSync(errorfilePath)) {
-        fs.mkdirSync(errorfilePath);
-      }
-      fs.copyFileSync(studentPhotoPath, path.join(errorfilePath, fileName));
+        //移动照片到errorfiles文件夹
+        const errorfilePath = path.join(
+          path.dirname(studentPhotoPath),
+          "errorfiles"
+        );
+        if (!fs.existsSync(errorfilePath)) {
+          fs.mkdirSync(errorfilePath);
+        }
+        fs.copyFileSync(studentPhotoPath, path.join(errorfilePath, fileName));
 
-      fs.appendFile(
-        path.join(errorfilePath, "errorPhotos.txt"),
-        fileName + ":" + msg + "\n"
-      );
+        fs.appendFileSync(
+          path.join(errorfilePath, "errorPhotos.txt"),
+          fileName + ":" + msg + "\n"
+        );
+      } catch (error) {
+        console.log(error);
+      }
     },
     //成功处理一张照片
     finishOnePhotoSuccess(msg, studentPhotoPath) {
@@ -374,6 +403,16 @@ export default {
   computed: {
     returnMsgList200() {
       return this.returnMsgList.slice(this.returnMsgList.length - 200);
+    },
+    startProcessTimeFormat() {
+      return this.startProcessTime
+        ? moment(this.startProcessTime).format("YYYY-MM-DD HH:mm:ss")
+        : "-";
+    },
+    endProcessTimeFormat() {
+      return this.endProcessTime
+        ? moment(this.endProcessTime).format("YYYY-MM-DD HH:mm:ss")
+        : "-";
     }
   }
 };