Преглед на файлове

优化 - 转档 + 快照&对比双线任务优化;

zhudongyong преди 2 години
родител
ревизия
e58c5cdaf5
променени са 1 файла, в които са добавени 36 реда и са изтрити 17 реда
  1. 36 17
      KdanAutoTest/KdanAuto/Class/AutoTestCase/AutoTest.swift

+ 36 - 17
KdanAutoTest/KdanAuto/Class/AutoTestCase/AutoTest.swift

@@ -173,20 +173,14 @@ class AutoTest : NSObject, AutoTestProtocal {
                 var tDegree = Double(0);
                 var tCount = Int(0)
                 var fileIndex = 0
+                var compareIndex = 0;
+                var convertFinished = false;
                 
                 // 用 Block 递归调用形式,确保转档单任务执行
                 var convertFileBlock = { (files:[String]) in }
                 convertFileBlock = { (files:[String]) in
                     if (fileIndex >= files.count) {
-                        //所有任务已经执行完成
-                        TestDegreeManager.shared().set(((tCount != 0) ? tDegree/Double(tCount) : 0.0),
-                                                       fileType: self.fileType(),
-                                                       type: self.type())
-                        
-                        self._status = .Finished
-                        DispatchQueue.main.async {
-                            complention(self, self.reportString);
-                        }
+                        convertFinished = true;
                         return
                     }
                     
@@ -203,18 +197,40 @@ class AutoTest : NSObject, AutoTestProtocal {
                         //                let checkPath = NSString(string: checkDirectory).appendingPathComponent(fName+"."+_extention)
                         
                         
-                        self.reportString?.append(NSMutableAttributedString.init(string: "【\(String(self.fileType())) - \(self.name())】开始转换文件 \"\(fName)\"\n",
-                                                                            attributes:[.foregroundColor : NSColor.blue]))
+//                        self.reportString?.append(NSMutableAttributedString.init(string: "【\(String(self.fileType())) - \(self.name())】开始转换文件 \"\(fName)\"\n",
+//                                                                            attributes:[.foregroundColor : NSColor.blue]))
                         // ...
                         // 执行异步转换过程
                         self.process(originPath, resultPath: resultPath) { status in
-                            self.compareResult(fileName, resultPath: resultPath, status: status, needCompare: needCompare) { degree in
-                                autoreleasepool {
-                                    fileIndex += 1;
-                                    convertFileBlock(files)
-                                }
-                            };
+                            DispatchQueue.global().async {
+                                Thread.sleep(forTimeInterval: 0.3)
+                                fileIndex += 1;
+                                convertFileBlock(files)
+                                
+                                self.compareResult(fileName, resultPath: resultPath, status: status, needCompare: needCompare) { degree in
+                                    autoreleasepool {
+                                        if (degree >= 0.0) {
+                                            tDegree += degree;
+                                            tCount += 1;
+                                        }
+                                        
+                                        compareIndex += 1;
+                                        if (convertFinished && compareIndex >= files.count) {
+                                            //所有任务已经执行完成
+                                            TestDegreeManager.shared().set(((tCount != 0) ? tDegree/Double(tCount) : 0.0),
+                                                                           fileType: self.fileType(),
+                                                                           type: self.type())
+                                            
+                                            self._status = .Finished
+                                            DispatchQueue.main.async {
+                                                complention(self, self.reportString);
+                                            }
+                                        }
+                                    }
+                                };
+                            }
                         }
+                        
                     }
                 }
                 // 启动第0号任务
@@ -255,6 +271,7 @@ class AutoTest : NSObject, AutoTestProtocal {
     }
     
     func compareResult(_ fileName:String, resultPath:String, status:Int, needCompare:Bool, complention:@escaping (_ degree:Double) -> ()) {
+        NSLog("开始识别:\(fileName)");
         let checkDirectory = self.checkFileDirectory()
 //        let originDirectory = self.originFileDirectory()
         let resultDirectory = self.resultFileDirectory()
@@ -302,6 +319,7 @@ class AutoTest : NSObject, AutoTestProtocal {
                                 autoreleasepool {
                                     // 执行下一个文件转档
                                     complention(subDegree)
+                                    NSLog("结束识别:\(fileName)");
                                 }
                             }
 //                        }
@@ -449,6 +467,7 @@ class AutoTest : NSObject, AutoTestProtocal {
         DispatchQueue.global().async {
             autoreleasepool {
                 // 执行下一个文件转档
+                NSLog("结束识别:\(fileName)");
                 complention(0)
             }
         }