Pārlūkot izejas kodu

Demo - 图片对照窗口对照信息完善

zhudongyong 2 gadi atpakaļ
vecāks
revīzija
b28be91523

+ 4 - 0
KdanAutoTest/KdanAuto.xcodeproj/project.pbxproj

@@ -28,6 +28,7 @@
 		24CA2338298FD6BE00038E10 /* ImageCompareCellView.xib in Resources */ = {isa = PBXBuildFile; fileRef = 24CA2336298FD6BE00038E10 /* ImageCompareCellView.xib */; };
 		24CA233A298FEED300038E10 /* FileInfo.swift in Sources */ = {isa = PBXBuildFile; fileRef = 24CA2339298FEED300038E10 /* FileInfo.swift */; };
 		24CA233C298FF0F800038E10 /* CompareViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 24CA233B298FF0F800038E10 /* CompareViewController.xib */; };
+		24CB61CA2994FA0800C5085F /* TestDegreeManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 24CB61C92994FA0800C5085F /* TestDegreeManager.swift */; };
 		24D70000292B6FD100DAB5EE /* SettingViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 24D7FFFF292B6FD100DAB5EE /* SettingViewController.xib */; };
 		24D70009292D14DA00DAB5EE /* AutoTestProtocal.swift in Sources */ = {isa = PBXBuildFile; fileRef = 24D70008292D14DA00DAB5EE /* AutoTestProtocal.swift */; };
 		24D7000B292D16BB00DAB5EE /* StringAutoTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 24D7000A292D16BB00DAB5EE /* StringAutoTest.swift */; };
@@ -125,6 +126,7 @@
 		24CA2336298FD6BE00038E10 /* ImageCompareCellView.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = ImageCompareCellView.xib; sourceTree = "<group>"; };
 		24CA2339298FEED300038E10 /* FileInfo.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FileInfo.swift; sourceTree = "<group>"; };
 		24CA233B298FF0F800038E10 /* CompareViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = CompareViewController.xib; sourceTree = "<group>"; };
+		24CB61C92994FA0800C5085F /* TestDegreeManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TestDegreeManager.swift; sourceTree = "<group>"; };
 		24D70001292B71FB00DAB5EE /* KdanAutoDebug.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = KdanAutoDebug.entitlements; sourceTree = "<group>"; };
 		24D70008292D14DA00DAB5EE /* AutoTestProtocal.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AutoTestProtocal.swift; sourceTree = "<group>"; };
 		24D7000A292D16BB00DAB5EE /* StringAutoTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StringAutoTest.swift; sourceTree = "<group>"; };
@@ -432,6 +434,7 @@
 			isa = PBXGroup;
 			children = (
 				24D7FFFD292B509000DAB5EE /* DataModel.swift */,
+				24CB61C92994FA0800C5085F /* TestDegreeManager.swift */,
 			);
 			path = DataModel;
 			sourceTree = "<group>";
@@ -709,6 +712,7 @@
 				24DCE8A429504430004EBA35 /* AutoTestTypes.swift in Sources */,
 				24DCE8B32950543C004EBA35 /* AutoTestCellInfo.swift in Sources */,
 				240934B72992737200839CC8 /* ImageProcess.swift in Sources */,
+				24CB61CA2994FA0800C5085F /* TestDegreeManager.swift in Sources */,
 				24DCE8B1295047D8004EBA35 /* TestFileCellView.swift in Sources */,
 				24A6FF4B2930939D00B34F2E /* TextColorAutoTest.swift in Sources */,
 			);

BIN
KdanAutoTest/KdanAuto.xcodeproj/project.xcworkspace/xcuserdata/zhudongyong.xcuserdatad/UserInterfaceState.xcuserstate


+ 4 - 4
KdanAutoTest/KdanAuto.xcodeproj/xcuserdata/zhudongyong.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist

@@ -14,8 +14,8 @@
             filePath = "KdanAuto/Class/AutoTestCase/AutoTest.swift"
             startingColumnNumber = "9223372036854775807"
             endingColumnNumber = "9223372036854775807"
-            startingLineNumber = "575"
-            endingLineNumber = "575"
+            startingLineNumber = "589"
+            endingLineNumber = "589"
             landmarkName = "stringToImage(_:)"
             landmarkType = "7">
          </BreakpointContent>
@@ -46,8 +46,8 @@
             filePath = "KdanAuto/Class/AutoTestCase/AutoTest.swift"
             startingColumnNumber = "9223372036854775807"
             endingColumnNumber = "9223372036854775807"
-            startingLineNumber = "50"
-            endingLineNumber = "50"
+            startingLineNumber = "47"
+            endingLineNumber = "47"
             landmarkName = "autoTestFor(_:type:)"
             landmarkType = "7">
          </BreakpointContent>

+ 34 - 20
KdanAutoTest/KdanAuto/Class/AutoTestCase/AutoTest.swift

@@ -19,9 +19,6 @@ class AutoTest : NSObject, AutoTestProtocal {
     var _type : String = "Others"
     var _extention : String = "rtf"
     
-    var _degree : Double = 0.0
-    var _fileDegreeInfo : [String:Double] = [:]
-    
     class func autoTestFor(_ fileType:NSString ,type:NSString) -> AutoTest? {
         let key = String(fileType) + "." + String(type)
         
@@ -207,6 +204,14 @@ class AutoTest : NSObject, AutoTestProtocal {
                                     
                                     let degree = ImageProcess.compareJPEG(rComparePath, checkPath: cComparePath)
                                     
+                                    if isDirectory.boolValue {
+                                        TestDegreeManager.shared().set(degree,
+                                                                       fileType: self.fileType(),
+                                                                       type: self.type(),
+                                                                       fileName: fileName,
+                                                                       refFilePath: subFileName)
+                                    }
+                                    
                                     if degree == -1 {
                                         self.reportString?.append(NSMutableAttributedString.init(string: "【\(String(self.fileType())) - \(self.name())】文件 \"\(subResultPath)\"快照对比失败,生成快照失败或无比对文件\n",
                                                                                             attributes:[.foregroundColor : NSColor.red]))
@@ -238,7 +243,10 @@ class AutoTest : NSObject, AutoTestProtocal {
                             subDegree = 0.0
                         }
                         
-                        _fileDegreeInfo[fileName] = subDegree
+                        TestDegreeManager.shared().set(subDegree,
+                                                       fileType: self.fileType(),
+                                                       type: self.type(),
+                                                       fileName: fileName)
                         tDegree += subDegree;
                         tCount += 1
                     }
@@ -248,12 +256,10 @@ class AutoTest : NSObject, AutoTestProtocal {
                 }
             }
             
-            if tCount != 0 {
-                _degree = tDegree/Double(tCount)
-            }else {
-                _degree = 0.0
-            }
-            
+            TestDegreeManager.shared().set(((tCount != 0) ? tDegree/Double(tCount) : 0.0),
+                                           fileType: _fileType,
+                                           type: _type)
+    
             _status = .Finished
         }else {
             _status = .Normal
@@ -266,7 +272,7 @@ class AutoTest : NSObject, AutoTestProtocal {
     }
     
     func degree() -> Double {
-        return _degree
+        return TestDegreeManager.shared().degreeFor(self.fileType(), type: self.type())
     }
     
 //    func testReportOfFile(_ fileName:String) -> NSAttributedString? {
@@ -274,10 +280,14 @@ class AutoTest : NSObject, AutoTestProtocal {
 //    }
     
     func degreeOfFile(_ fileName:String) -> Double {
-        if _fileDegreeInfo[fileName] != nil {
-            return _fileDegreeInfo[fileName]!
+        return TestDegreeManager.shared().degreeFor(self.fileType(), type: self.type(), fileName: fileName)
+    }
+
+    func degreeOfFile(_ fileName:String, refFilePath:String?) -> Double {
+        if refFilePath != nil {
+            return TestDegreeManager.shared().degreeFor(self.fileType(), type: self.type(), fileName: fileName, refFilePath: refFilePath)
         }else {
-            return 0
+            return degreeOfFile(fileName)
         }
     }
     
@@ -483,12 +493,20 @@ class AutoTest : NSObject, AutoTestProtocal {
                 items.add(fName)
             }
             
-            for item in items {
+            let nitems = items.sortedArray { str1, str2 in
+                let s1 = str1 as! String
+                let s2 = str2 as! String
+                
+                return NSString(string: s1).compare(s2)
+            }
+            
+            for item in nitems {
                 let subFileName = item as! String
                 let rComparePath = NSString(string: resultDirectory).appendingPathComponent(subFileName+".jpg")
                 let cComparePath = NSString(string: checkDirectory).appendingPathComponent(subFileName+".jpg")
                 
-                let fileInfo = NSMutableDictionary.fileInfoWith(subFileName,
+                let fileInfo = NSMutableDictionary.fileInfoWith(fileName,
+                                                                refFilePath: (isDirectory.boolValue ? subFileName : nil),
                                                                 resultPath: rComparePath,
                                                                 comparePath: cComparePath,
                                                                 objc: self)
@@ -549,10 +567,6 @@ class AutoTest : NSObject, AutoTestProtocal {
                 }
             }
         }
-        
-        
-        _degree = 0.0;
-        _fileDegreeInfo.removeAll()
     }
 }
 

+ 3 - 3
KdanAutoTest/KdanAuto/Class/AutoTestCase/AutoTestProtocal.swift

@@ -35,13 +35,13 @@ protocol AutoTestProtocal : NSObjectProtocol {
     func autoTest()
     
     func testReport() -> NSAttributedString?
-    /** Default is 0.0, The range of value is [0, 1]
-     */
-    func degree() -> Double
 //    func testReportOfFile(_ fileName:String) -> NSAttributedString?
+    
     /** Default is 0.0, The range of value is [0, 1]
      */
+    func degree() -> Double
     func degreeOfFile(_ fileName:String) -> Double
+    func degreeOfFile(_ fileName:String, refFilePath:String?) -> Double
     
     func compareFiles() -> NSArray?
     func compareFiles(_ fileName: String) -> NSArray?

+ 13 - 1
KdanAutoTest/KdanAuto/Class/AutoTestCase/FileInfo.swift

@@ -9,12 +9,15 @@ import Foundation
 
 extension NSMutableDictionary {
     
-    class func fileInfoWith(_ fileName:String, resultPath:String, comparePath:String, objc:AutoTest) -> NSMutableDictionary {
+    class func fileInfoWith(_ fileName:String, refFilePath:String?, resultPath:String, comparePath:String, objc:AutoTest) -> NSMutableDictionary {
         let dic = NSMutableDictionary.init()
         
         dic.setValue(fileName, forKey: "fileName");
         dic.setValue(resultPath, forKey: "resultPath");
         dic.setValue(comparePath, forKey: "comparePath");
+        if nil != refFilePath {
+            dic.setValue(refFilePath, forKey: "refFilePath")
+        }
         dic.setValue(objc, forKey: "objc");
         
         return dic
@@ -32,7 +35,16 @@ extension NSMutableDictionary {
         return self.value(forKey: "comparePath") as! String
     }
     
+    func refFilePath() -> String? {
+        if nil == self.value(forKey: "refFilePath") {
+            return nil
+        }
+        
+        return self.value(forKey: "refFilePath") as? String
+    }
+    
     func objc() -> AutoTest {
         return self.value(forKey: "objc") as! AutoTest
     }
 }
+

+ 8 - 6
KdanAutoTest/KdanAuto/Class/AutoTestCase/StringAutoTest.swift

@@ -252,7 +252,11 @@ class CharacterAutoTest : AutoTest {
                                     color = NSColor.red
                                 }
                                 
-                                self._fileDegreeInfo[fileName] = degree
+                                TestDegreeManager.shared().set(degree,
+                                                               fileType: self.fileType(),
+                                                               type: self.type(),
+                                                               fileName: fileName)
+                                
                                 tDegree += degree
                                 tCount += 1
                                 
@@ -274,11 +278,9 @@ class CharacterAutoTest : AutoTest {
             
         }
         
-        if tCount != 0 {
-            _degree = tDegree / Double(tCount)
-        }else {
-            _degree = 0
-        }
+        TestDegreeManager.shared().set(((tCount != 0) ? tDegree/Double(tCount) : 0.0),
+                                       fileType: _fileType,
+                                       type: _type)
         
         NSLog("\(reportString)")
         

+ 8 - 6
KdanAutoTest/KdanAuto/Class/AutoTestCase/TextColorAutoTest.swift

@@ -291,7 +291,11 @@ class TextColorAutoTest : AutoTest {
                                     color = NSColor.red
                                 }
                                 
-                                self._fileDegreeInfo[fileName] = degree
+                                TestDegreeManager.shared().set(degree,
+                                                               fileType: self.fileType(),
+                                                               type: self.type(),
+                                                               fileName: fileName)
+                                
                                 tDegree += degree
                                 tCount += 1
                                 
@@ -314,11 +318,9 @@ class TextColorAutoTest : AutoTest {
             }
         }
         
-        if tCount != 0 {
-            _degree = tDegree / Double(tCount)
-        }else {
-            _degree = 0
-        }
+        TestDegreeManager.shared().set(((tCount != 0) ? tDegree/Double(tCount) : 0.0),
+                                       fileType: _fileType,
+                                       type: _type)
         
         _status = .Finished
     }

+ 1 - 1
KdanAutoTest/KdanAuto/Class/CompareViewController/CompareViewController.xib

@@ -85,7 +85,7 @@
                         </subviews>
                     </clipView>
                     <scroller key="horizontalScroller" hidden="YES" wantsLayer="YES" verticalHuggingPriority="750" horizontal="YES" id="tEb-3h-nsO">
-                        <rect key="frame" x="1" y="848" width="988" height="16"/>
+                        <rect key="frame" x="1" y="899" width="988" height="15"/>
                         <autoresizingMask key="autoresizingMask"/>
                     </scroller>
                     <scroller key="verticalScroller" hidden="YES" wantsLayer="YES" verticalHuggingPriority="750" horizontal="NO" id="Cgv-FT-VuQ">

+ 21 - 2
KdanAutoTest/KdanAuto/Class/CompareViewController/ImageCompareCellView.swift

@@ -10,6 +10,9 @@ import AppKit
 
 class ImageCompareCellView : NSTableCellView {
     @IBOutlet var _titleLbl : NSTextField!
+    @IBOutlet var _degreeInfoLbl : NSTextField!
+    
+    
     @IBOutlet var _contentView : NSView!
     @IBOutlet var _imageView01 : NSImageView!
     @IBOutlet var _imageView02 : NSImageView!
@@ -59,8 +62,6 @@ class ImageCompareCellView : NSTableCellView {
     public func setFileInfo(_ fileInfo:NSMutableDictionary) {
         _fileInfo = fileInfo;
         
-        setTitle(_fileInfo.fileName())
-        
         if nil != _fileInfo {
             let comparePath = _fileInfo.comparePath()
             let resultPath = _fileInfo.resultPath()
@@ -70,6 +71,24 @@ class ImageCompareCellView : NSTableCellView {
             
             let image2 = NSImage.init(contentsOfFile: resultPath)
             _imageView02.image = image2;
+            
+            setTitle(String("[\(_fileInfo.objc().fileType()):\(_fileInfo.objc().name())]:\(_fileInfo.fileName())"))
+
+            let degree = _fileInfo.degree()
+            if degree == -1 {
+                _degreeInfoLbl.stringValue = "文件不存在"
+                _degreeInfoLbl.textColor = NSColor.red
+            } else {
+                if abs(degree - 100) > 0 {
+                    _degreeInfoLbl.textColor = NSColor.red
+                }else {
+                    _degreeInfoLbl.textColor = NSColor.blue
+                }
+                _degreeInfoLbl.stringValue = NSString(format: "相似度:%.2f%%", degree) as String
+            }
+        }else {
+            setTitle("")
+            _degreeInfoLbl.stringValue = ""
         }
     }
     

+ 10 - 0
KdanAutoTest/KdanAuto/Class/CompareViewController/ImageCompareCellView.xib

@@ -77,9 +77,19 @@
                         <action selector="showCoverAction:" target="Ob6-j8-aNh" id="GkE-an-DD8"/>
                     </connections>
                 </button>
+                <textField horizontalHuggingPriority="251" verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="Ooh-60-kZ8">
+                    <rect key="frame" x="412" y="779" width="173" height="16"/>
+                    <autoresizingMask key="autoresizingMask" flexibleMinX="YES" flexibleMaxX="YES" flexibleMinY="YES"/>
+                    <textFieldCell key="cell" lineBreakMode="clipping" alignment="center" title="相似度:" id="7cX-su-WGo">
+                        <font key="font" metaFont="system"/>
+                        <color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
+                        <color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
+                    </textFieldCell>
+                </textField>
             </subviews>
             <connections>
                 <outlet property="_contentView" destination="l0O-8O-W8F" id="xFJ-xl-ppI"/>
+                <outlet property="_degreeInfoLbl" destination="Ooh-60-kZ8" id="tRz-ZD-Ynf"/>
                 <outlet property="_imageView01" destination="vKi-Ja-iHX" id="BOc-W2-6Zi"/>
                 <outlet property="_imageView02" destination="psc-pQ-nZq" id="CFk-4f-Vxf"/>
                 <outlet property="_imageView03" destination="Bnx-Mq-PDW" id="ilQ-Zi-a0X"/>

+ 79 - 0
KdanAutoTest/KdanAuto/Class/DataModel/TestDegreeManager.swift

@@ -0,0 +1,79 @@
+//
+//  TestDegreeManager.swift
+//  KdanAuto
+//
+//  Created by 朱东勇 on 2023/2/9.
+//
+
+import Foundation
+
+class TestDegreeManager : NSObject {
+    var degreeInfo = NSMutableDictionary()
+    
+    static var tdManager = TestDegreeManager()
+    class func shared() -> TestDegreeManager {
+        return tdManager
+    }
+    
+    // Clear
+    func clearAllHistory() {
+        degreeInfo.removeAllObjects()
+    }
+    
+    // Set
+    func set(_ degree:Double, fileType:String?) {
+        set(degree, fileType: fileType, type: nil)
+    }
+    
+    func set(_ degree:Double, fileType:String?, type:String?) {
+        set(degree, fileType: fileType, type: type, fileName: nil)
+    }
+    
+    func set(_ degree:Double, fileType:String?, type:String?, fileName:String?) {
+        set(degree, fileType: fileType, type: type, fileName: fileName, refFilePath: nil)
+    }
+    
+    func set(_ degree:Double, fileType:String?, type:String?, fileName:String?, refFilePath:String?) {
+        let key = String((fileType ?? "") + (type ?? "") + (fileName ?? "") + (refFilePath ?? ""))
+        
+        let number = NSNumber(floatLiteral: degree)
+        degreeInfo.setValue(number, forKey: key)
+    }
+    
+    //Get
+    
+    func degreeFor(_ fileType:String?) -> Double {
+        return degreeFor(fileType, type: nil)
+    }
+    
+    func degreeFor(_ fileType:String?, type:String?) -> Double {
+        return degreeFor(fileType, type: type, fileName: nil)
+    }
+    
+    func degreeFor(_ fileType:String?, type:String?, fileName:String?) -> Double {
+        return degreeFor(fileType, type: type, fileName: fileName, refFilePath: nil)
+    }
+    
+    func degreeFor(_ fileType:String?, type:String?, fileName:String?, refFilePath:String?) -> Double {
+        let key = String((fileType ?? "") + (type ?? "") + (fileName ?? "") + (refFilePath ?? ""))
+        
+        if nil != degreeInfo.value(forKey: key) {
+            let number = degreeInfo.value(forKey: key) as! NSNumber
+            return number.doubleValue
+        }
+        
+        return 0.0
+    }
+    
+    
+}
+
+// File Info
+extension NSMutableDictionary {
+    func degree() -> Double {
+        return TestDegreeManager.shared().degreeFor(self.objc().fileType(),
+                                                    type: self.objc().type(),
+                                                    fileName: self.fileName(),
+                                                    refFilePath: self.refFilePath())
+    }
+}

+ 1 - 0
KdanAutoTest/KdanAuto/ViewController.swift

@@ -127,6 +127,7 @@ class ViewController : NSViewController, SettingViewControllerDelegate, AutoTest
         DispatchQueue.global().async {
             var report = NSMutableAttributedString.init()
             DataModel.shared.generaNewReportID()
+            TestDegreeManager.shared().clearAllHistory()
             
             let testSemaphore = DispatchSemaphore(value: 0)