OCRDataRecorder.cs.cs 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. using Aitex.Core.RT.DBCore;
  2. using Aitex.Core.RT.Log;
  3. using Aitex.Sorter.Common;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Data;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. namespace MECF.Framework.Common.DBCore
  11. {
  12. public class OCRDataRecorder
  13. {
  14. public static void OcrReadComplete(string guid, string waferid, string sourcelp, string sourcecarrier, string sourceslot,
  15. string ocrno, string ocrjob, bool readresult, string lasermark, string ocrscore, string readperiod)
  16. {
  17. string sql = string.Format(
  18. "INSERT INTO \"ocr_data\"(\"guid\", \"wafer_id\", \"read_time\" , \"source_lp\", \"source_carrier\", \"source_slot\", " +
  19. "\"ocr_no\", \"ocr_job\", \"read_result\" , \"lasermark\", \"ocr_score\", \"read_period\")VALUES ('{0}', '{1}', '{2}','{3}','" +
  20. "{4}', '{5}', '{6}','{7}', '{8}', '{9}','{10}','{11}');",
  21. guid, waferid,
  22. DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss.fff"),
  23. sourcelp, sourcecarrier, sourceslot, ocrno, ocrjob, readresult ? "1" : "0", lasermark, ocrscore, readperiod);
  24. DB.Insert(sql);
  25. }
  26. public static List<HistoryStatisticsOCRData> QueryDBOCRStatistics(string sql)
  27. {
  28. List<HistoryStatisticsOCRData> result = new List<HistoryStatisticsOCRData>();
  29. try
  30. {
  31. DataSet ds = DB.ExecuteDataset(sql);
  32. if (ds == null)
  33. return result;
  34. var TempValue = new List<Tuple<DateTime,bool>>();
  35. for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
  36. {
  37. TempValue.Add(new Tuple<DateTime, bool>(DateTime.Parse(ds.Tables[0].Rows[i]["read_time"].ToString()),
  38. Convert.ToBoolean(ds.Tables[0].Rows[i]["read_result"].ToString()))); ;
  39. }
  40. result = TempValue.GroupBy(time => time.Item1.Date)
  41. .Select(x => new HistoryStatisticsOCRData
  42. {
  43. Date = x.Key.Date.ToString("yyyy-MM-dd"),
  44. Totaltimes=x.Count().ToString(),
  45. Successfueltimes=x.Where(data=> data.Item2==true).Count().ToString(),
  46. Failuretimes = x.Where(data => data.Item2 == false).Count().ToString(),
  47. }).ToList();
  48. return result;
  49. }
  50. catch (Exception ex)
  51. {
  52. LOG.Write(ex);
  53. }
  54. return result;
  55. }
  56. public static List<HistoryOCRData> QueryDBOCRHistory(string sql)
  57. {
  58. List<HistoryOCRData> result = new List<HistoryOCRData>();
  59. try
  60. {
  61. DataSet ds = DB.ExecuteDataset(sql);
  62. if (ds == null)
  63. return result;
  64. var TempValue = new List<Tuple<DateTime, bool>>();
  65. for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
  66. {
  67. HistoryOCRData ev = new HistoryOCRData();
  68. ev.Guid = ds.Tables[0].Rows[i]["guid"].ToString();
  69. ev.wafer_id = ds.Tables[0].Rows[i]["wafer_id"].ToString();
  70. if (!ds.Tables[0].Rows[i]["read_time"].Equals(DBNull.Value))
  71. ev.read_time = ((DateTime)ds.Tables[0].Rows[i]["read_time"]).ToString("yyyy/MM/dd HH:mm:ss.fff");
  72. ev.source_lp = ds.Tables[0].Rows[i]["source_lp"].ToString();
  73. ev.source_carrier = ds.Tables[0].Rows[i]["source_carrier"].ToString();
  74. ev.source_slot = ds.Tables[0].Rows[i]["source_slot"].ToString();
  75. ev.ocr_no = ds.Tables[0].Rows[i]["ocr_no"].ToString();
  76. ev.ocr_job = ds.Tables[0].Rows[i]["ocr_job"].ToString();
  77. ev.read_result = ds.Tables[0].Rows[i]["read_result"].ToString();
  78. ev.lasermark = ds.Tables[0].Rows[i]["lasermark"].ToString();
  79. ev.ocr_score = ds.Tables[0].Rows[i]["ocr_score"].ToString();
  80. ev.read_period = ds.Tables[0].Rows[i]["read_period"].ToString();
  81. result.Add(ev);
  82. }
  83. return result;
  84. }
  85. catch (Exception ex)
  86. {
  87. LOG.Write(ex);
  88. }
  89. return result;
  90. }
  91. }
  92. }