From 2f92f84f6af2f9a65e7c6e04ccb3792433233a1e Mon Sep 17 00:00:00 2001 From: Administrator <Administrator@DESKTOP-1VKMM8S> Date: 星期五, 19 三月 2021 14:33:09 +0800 Subject: [PATCH] 1.修复脏污、划伤有时无法写入报表中。 --- P066.Data/Form1.Designer.cs | 22 +-- P066.Data/Form1.cs | 117 +++++++++++------------ P066.Data/P066RunParam.cs | 105 +++++++++++++++++++++ 3 files changed, 169 insertions(+), 75 deletions(-) diff --git a/P066.Data/Form1.Designer.cs b/P066.Data/Form1.Designer.cs index f399a82..39ff21d 100644 --- a/P066.Data/Form1.Designer.cs +++ b/P066.Data/Form1.Designer.cs @@ -36,10 +36,9 @@ // // btnLoadData1 // - this.btnLoadData1.Location = new System.Drawing.Point(16, 15); - this.btnLoadData1.Margin = new System.Windows.Forms.Padding(4); + this.btnLoadData1.Location = new System.Drawing.Point(12, 12); this.btnLoadData1.Name = "btnLoadData1"; - this.btnLoadData1.Size = new System.Drawing.Size(176, 29); + this.btnLoadData1.Size = new System.Drawing.Size(132, 23); this.btnLoadData1.TabIndex = 0; this.btnLoadData1.Text = "鍔犺浇鏂囦欢澶�1"; this.btnLoadData1.UseVisualStyleBackColor = true; @@ -47,10 +46,9 @@ // // btnAnalyze // - this.btnAnalyze.Location = new System.Drawing.Point(16, 88); - this.btnAnalyze.Margin = new System.Windows.Forms.Padding(4); + this.btnAnalyze.Location = new System.Drawing.Point(12, 70); this.btnAnalyze.Name = "btnAnalyze"; - this.btnAnalyze.Size = new System.Drawing.Size(176, 29); + this.btnAnalyze.Size = new System.Drawing.Size(132, 23); this.btnAnalyze.TabIndex = 1; this.btnAnalyze.Text = "寮�濮嬪垎鏋�"; this.btnAnalyze.UseVisualStyleBackColor = true; @@ -58,24 +56,22 @@ // // btnLoadData2 // - this.btnLoadData2.Location = new System.Drawing.Point(16, 51); - this.btnLoadData2.Margin = new System.Windows.Forms.Padding(4); + this.btnLoadData2.Location = new System.Drawing.Point(12, 41); this.btnLoadData2.Name = "btnLoadData2"; - this.btnLoadData2.Size = new System.Drawing.Size(176, 29); + this.btnLoadData2.Size = new System.Drawing.Size(149, 23); this.btnLoadData2.TabIndex = 1; - this.btnLoadData2.Text = "鍔犺浇鏂囦欢澶�2"; + this.btnLoadData2.Text = "鍒激銆侀晙鑶滅牬鎹熸枃浠跺す"; this.btnLoadData2.UseVisualStyleBackColor = true; this.btnLoadData2.Click += new System.EventHandler(this.btnLoadData2_Click); // // Form1 // - this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 15F); + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(1067, 562); + this.ClientSize = new System.Drawing.Size(800, 450); this.Controls.Add(this.btnAnalyze); this.Controls.Add(this.btnLoadData2); this.Controls.Add(this.btnLoadData1); - this.Margin = new System.Windows.Forms.Padding(4); this.Name = "Form1"; this.Text = "Form1"; this.ResumeLayout(false); diff --git a/P066.Data/Form1.cs b/P066.Data/Form1.cs index d7e3a78..d36c9f1 100644 --- a/P066.Data/Form1.cs +++ b/P066.Data/Form1.cs @@ -49,11 +49,13 @@ private void btnAnalyze_Click(object sender, EventArgs e) { - var fileinfos11 = directoryInfo1.GetFiles(); - var fileinfos22 = directoryInfo2.GetFiles(); + var fileinfos11 = directoryInfo1.GetFiles().ToList().FindAll(a => a.Extension == ".csv"); + + + ; List<FileInfo> fileInfo1 = new List<FileInfo>(); List<FileInfo> fileInfo2 = new List<FileInfo>(); - for (int i = 0; i < fileinfos11.Length; i++) + for (int i = 0; i < fileinfos11.Count; i++) { if (fileinfos11[i].Name.Contains("1_1") || fileinfos11[i].Name.Contains("2_1") || fileinfos11[i].Name.Contains("3_1") || fileinfos11[i].Name.Contains("4_1") ) { @@ -94,25 +96,15 @@ dataListSum22.Sort(); #endregion - //濡傛灉闇�瑕佸悎骞惰〃鏍煎氨鎵ц - - for (int i = 0; i < fileinfos22.Length; i++) + if (directoryInfo2 != null) { + var fileinfos22 = directoryInfo2.GetFiles().ToList().FindAll(a=>a.Extension==".csv"); + for (int i = 0; i < fileinfos22.Count; i++) + { var allLines = File.ReadAllLines(fileinfos22[i].FullName, Encoding.Default); var list = GetData(allLines, GetDefactType(fileinfos22[i])).FindAll(a=>!a.Result); /*CompareFile(fileInfo1[i], fileInfo2[i],dataListSum22)*/ - for (int ii = 0; ii < list.Count; ii++) - { - if (list[ii].Width > list[ii].Height) - { - list[ii].ex = list[ii].Width * 0.0043; - } - else - { - list[ii].ex = list[ii].Height * 0.0043; - } - - } + GetMaxSize(list); if (fileinfos22[i].Name.Contains("鍒掍激")) { ScratchI++; @@ -125,12 +117,12 @@ ZoomI++; list.ForEach(a => a.Lensnumber = ZoomI); listSum.AddRange(list); - } } - + directoryInfo2 = null; + } @@ -231,19 +223,6 @@ } - //涓嶉渶瑕佸悎骞惰〃鏍� - //else if(fileInfo1.Count>0&& fileInfo2.Count==0) - //{ - // for (int i = 0; i < fileInfo1.Count; i++) - // { - // var allLines = File.ReadAllLines(fileInfo1[i].FullName, Encoding.Default); - // var list = GetData(allLines,GetDefactType(fileInfo1[i])); /*CompareFile(fileInfo1[i], fileInfo2[i],dataListSum22)*/ - - // } - //} - - - #region//灏嗚澶囧垽鏂粨鏋滆緭鍑哄埌CSV鎶ヨ〃涓� var title12 = $"鏃堕棿鎴�,鐩告満搴忓彿,璁惧鍒ゆ柇缁撴灉,缂洪櫡绫诲瀷,璁惧鍚庡鐞嗙粨鏋�,鏈�澶у昂瀵�,浣嶇疆,X,Y,R,瑙掑害"; var file12 = $"{directoryInfo1.Parent.FullName}\\{filenameDir + "璁惧鍒ゆ柇缁撴灉"}.csv"; @@ -329,33 +308,13 @@ var list1 = dataList1.FindAll(a => a.TimeTip == item && !a.Result); var list2 = dataList2.FindAll(a => a.TimeTip == item && !a.Result); var itemToRemove = new List<ResultData>(); - #region//璁$畻琛ㄦ牸2鏈�澶у昂瀵� - for (int ii = 0; ii < list2.Count; ii++) - { - if (list2[ii].Width > list2[ii].Height) - { - list2[ii].ex = list2[ii].Width * 0.0043; - } - else - { - list2[ii].ex = list2[ii].Height * 0.0043; - } - - } - #endregion + //璁$畻琛ㄦ牸1鏈�澶у昂瀵� + GetMaxSize(list1); + //璁$畻琛ㄦ牸2鏈�澶у昂瀵� + GetMaxSize(list2); for (int i = 0; i < list1.Count; i++) { - #region//璁$畻琛ㄦ牸1鏈�澶у昂瀵� - if (list1[i].Width > list1[i].Height) - { - list1[i].ex = list1[i].Width * 0.0043; - } - else - { - list1[i].ex = list1[i].Height * 0.0043; - } - #endregion for (int j = 0; j < list2.Count; j++) { if (list1[i].JudgmentResult != list2[j].JudgmentResult) @@ -782,14 +741,14 @@ } } - else if (Lens[0].DefectType == "鍒掍激") + else if (Lens[0].DefectType == "鍒掍激"|| Lens[0].DefectType == "鑴忔薄") { var content11 = $"{item},{LensNumb},{Lens[0].JudgmentResult},{Lens[0].DefectType}"; File.AppendAllText(file12, content11, Encoding.UTF8); File.AppendAllText(file12, "\r\n"); for (int i = 0; i < Lens.Count; i++) { - if (Lens[i].DefectType == "鍒掍激") + if (Lens[i].DefectType == "鍒掍激"|| Lens[i].DefectType == "鑴忔薄") { var content111 = $"{""},{""},{""},{""},{""},{Lens[i].ex},{Lens[i].location},{Lens[i].X},{Lens[i].Y},{(int)(Lens[i].R)},{(int)(Lens[i].angle)}"; File.AppendAllText(file12, content111, Encoding.UTF8); @@ -853,6 +812,23 @@ { return Math.Atan2((y1 - size), (x1 - size)) * (180 / Math.PI); } + //璁$畻鏈�澶у昂瀵� + private List<ResultData> GetMaxSize(List<ResultData> list) + { + for (int i = 0; i < list.Count; i++) + { + if (list[i].Width > list[i].Height) + { + list[i].ex = list[i].Width * 0.0043; + } + else + { + list[i].ex = list[i].Height * 0.0043; + } + + } + return list; + } //鑾峰彇鏂囦欢鍚嶇О骞剁‘瀹氱己闄风被鍨� @@ -888,6 +864,7 @@ var nametemp = allLines[1].Split(',')[0]; var resulttemp = allLines[1].Split(',')[1]; string Ptr = ""; + string deTy = ""; for (int i = 1; i < allLines.Length; i++) { @@ -901,6 +878,7 @@ if (defectType == "鐧界偣") { data[10] = Ptr; + deTy = "鐧界偣"; } @@ -908,14 +886,28 @@ if (defectType == "鍒櫧") { Ptr = "鍒櫧"; + deTy = "鍒櫧"; } + else if (defectType == "鍒掍激") { - Ptr = "鍒掍激"; + Ptr = ""; + if (data[3]!="OK") + { + deTy = data[3]; + } + else + { + deTy = ""; + } + + } + else if (defectType == "鐧界偣") { Ptr = data[10]; + deTy = "鐧界偣"; } if (defectType== "闀�鑶滅牬鎹�") @@ -993,7 +985,7 @@ { TimeTip = data[0].Split('-')[0], ImageFileName = data[0], - JudgmentResult = data[1]=="OK" ? "OK" :"NG", + JudgmentResult = data[1]== "OK" ? "OK" :"NG", Result = data[3] == "OK", Probability = Convert.ToDouble(data[4]), Uncertainty = Convert.ToDouble(data[5]), @@ -1003,13 +995,14 @@ Width = Convert.ToDouble(data[7]), X = Convert.ToDouble(data[8].Replace("#", "").Replace("-", "")), Y = Convert.ToDouble(data[9].Replace("#", "").Replace("-", "")), - DefectType = defectType, + DefectType = deTy, PostTreatmentResults = Ptr, }); ; ; nametemp = data[0]; resulttemp = data[1]; + //Ptr = data[10]; } diff --git a/P066.Data/P066RunParam.cs b/P066.Data/P066RunParam.cs index 5cb4ab1..5ad24ce 100644 --- a/P066.Data/P066RunParam.cs +++ b/P066.Data/P066RunParam.cs @@ -26,4 +26,109 @@ public double BkLens4R1; //public double BkLens4R2; } + public class P066ReadFile + { + public List<ResultData1> GetWhiteFile(string[] allLines) + { + var dataList = new List<ResultData1>(); + var nametemp = allLines[1].Split(',')[0]; + var resulttemp = allLines[1].Split(',')[1]; + string Ptr = ""; + string deTy = ""; + for (int i = 1; i < allLines.Length; i++) + { + var data = allLines[i].Split(','); + if (data[0] == "") + { + data[0] = nametemp; + data[1] = resulttemp; + } + if (data[6] == "-") + { + + dataList.Add(new ResultData1() + { + TimeTip = data[0].Split('-')[0], + ImageFileName = data[0], + JudgmentResult = data[1] == "OK" ? "OK" : "NG", + Result = data[3] == "OK", + + }); ; ; + + continue; + + } + //灏嗗湴7銆�8鍒椾腑閫夋渶澶у儚绱犵偣 + data[6] = SelectMaxPiont(data[6]); + data[7] = SelectMaxPiont(data[7]); + + dataList.Add(new ResultData1() + { + TimeTip = data[0].Split('-')[0], + ImageFileName = data[0], + JudgmentResult = data[1] == "OK" ? "OK" : "NG", + Result = data[3] == "OK", + Probability = Convert.ToDouble(data[4]), + Uncertainty = Convert.ToDouble(data[5]), + //Height = Convert.ToDouble(data[6].Replace("#", "").Replace("-", "")), + //Width = Convert.ToDouble(data[7].Replace("#", "").Replace("-", "")), + Height = Convert.ToDouble(data[6]), + Width = Convert.ToDouble(data[7]), + X = Convert.ToDouble(data[8].Replace("#", "").Replace("-", "")), + Y = Convert.ToDouble(data[9].Replace("#", "").Replace("-", "")), + DefectType = deTy, + PostTreatmentResults = Ptr, + + }); ; ; + + nametemp = data[0]; + resulttemp = data[1]; + + } + + return dataList; + } + + + private string SelectMaxPiont(string Data) + { + var data = Data.Split('#').ToList(); + data.Remove(""); + var temp = Convert.ToInt32(data[0]); + for (int i = 0; i < data.Count; i++) + { + if (Convert.ToInt32(data[i]) > temp) + { + temp = Convert.ToInt32(data[i]); + } + } + return Convert.ToString(temp); + } + + + } + + public class ResultData1 + { + public string TimeTip = ""; + public string JudgmentResult = ""; + public string ImageFileName = ""; + public bool Result = true; + public int Lensnumber = 0; + public double Probability = 0; + public double Uncertainty = 0; + public double Height = 0; + public double Width = 0; + public double X = 0; + public double Y = 0; + public double ex = 0; + public string location = ""; + public double angle = 0; + public double R = 0; + public string DefectType = ""; + public string PostTreatmentResults = ""; + + + } } + -- Gitblit v1.8.0