Make_ThruputLog.cs 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  1. using NPOI.SS.Formula.Eval;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.ComponentModel;
  5. using System.Data;
  6. using System.Drawing;
  7. using System.IO;
  8. using System.Linq;
  9. using System.Text;
  10. using System.Text.RegularExpressions;
  11. using System.Threading.Tasks;
  12. using System.Windows.Forms;
  13. using UAS_MES_NEW.DataOperate;
  14. using UAS_MES_NEW.Entity;
  15. using UAS_MES_NEW.PublicMethod;
  16. namespace UAS_MES_NEW.Make
  17. {
  18. public partial class Make_ThruputLog : Form
  19. {
  20. public Make_ThruputLog()
  21. {
  22. InitializeComponent();
  23. }
  24. StringBuilder SQL = new StringBuilder();
  25. DataTable dt;
  26. DataHelper dh;
  27. string sVal1, sVal2, rVal1, rVal2;
  28. private void Make_ThruputLog_Load(object sender, EventArgs e)
  29. {
  30. dh = SystemInf.dh;
  31. }
  32. private void Parse_Click(object sender, EventArgs e)
  33. {
  34. if (string.IsNullOrEmpty(ExePath.Text))
  35. {
  36. ShowMsg(0, $"请选择测试使用的iperf3.exe");
  37. return;
  38. }
  39. string passPath, failPath;
  40. string parentPath = Path.GetDirectoryName(ExePath.Text.Trim());
  41. string logsPath = Path.Combine(parentPath, "log");
  42. passPath = Path.Combine(logsPath, "pass");
  43. failPath = Path.Combine(logsPath, "fail");
  44. string[] passFiles = Directory.GetFiles(passPath, $"*up.log");
  45. foreach (string currLog in passFiles)
  46. {
  47. string upRes = ParseIperfBitrate(currLog);
  48. string sn = Path.GetFileName(currLog).Split('_')[0];
  49. SQL.Clear();
  50. SQL.Append($@"SELECT ms_sncode,ma_code,pr_code,pr_spec FROM makeserial,make,product WHERE ms_sncode = '{sn}' AND ms_makecode = ma_code AND ms_prodcode = pr_code");
  51. dt = (DataTable)dh.ExecuteSql(SQL.ToString(), "select");
  52. if (dt.Rows.Count == 0)
  53. {
  54. ShowMsg(0, $"序列号无归属工单");
  55. continue;
  56. }
  57. string wo = dt.Rows[0]["ma_code"].ToString();
  58. string logPath = Path.GetDirectoryName(currLog);
  59. string downLog = Path.Combine(logPath, $"{sn}_down.log");
  60. string downRes = ParseIperfBitrate(downLog);
  61. string tDetail = $"upRate/{upRes};downRate/{downRes}";
  62. CheckPassStation(wo, sn, "PASS", tDetail);
  63. }
  64. string[] failFiles = Directory.GetFiles(failPath, $"*up.log");
  65. foreach (string currLog in failFiles)
  66. {
  67. string upRes = ParseIperfBitrate(currLog);
  68. string sn = Path.GetFileName(currLog).Split('_')[0];
  69. SQL.Clear();
  70. SQL.Append($@"SELECT ms_sncode,ma_code,pr_code,pr_spec FROM makeserial,make,product WHERE ms_sncode = '{sn}' AND ms_makecode = ma_code AND ms_prodcode = pr_code");
  71. dt = (DataTable)dh.ExecuteSql(SQL.ToString(), "select");
  72. if (dt.Rows.Count == 0)
  73. {
  74. ShowMsg(0, $"序列号无归属工单");
  75. continue;
  76. }
  77. string wo = dt.Rows[0]["ma_code"].ToString();
  78. string logPath = Path.GetDirectoryName(currLog);
  79. string downLog = Path.Combine(logPath, $"{sn}_down.log");
  80. string downRes = ParseIperfBitrate(downLog);
  81. string tDetail = $"upRate/{upRes};downRate/{downRes}";
  82. CheckPassStation(wo, sn, "PASS", tDetail);
  83. }
  84. }
  85. private void CheckPassStation(string wo,string sn, string testRes, string testDetail)
  86. {
  87. List<string> param = new List<string>() { };
  88. string outMsg = "";
  89. param.Add(wo);
  90. param.Add(sn);
  91. param.Add(User.UserSourceCode);
  92. param.Add(testRes);
  93. param.Add("");
  94. param.Add("");
  95. param.Add("ThruputLog");
  96. param.Add(testDetail);
  97. param.Add(outMsg);
  98. string[] paramList = param.ToArray();
  99. dh.CallProcedure("cs_insert_testrejects", ref paramList);
  100. if (paramList[8].Substring(0, 2) == "OK")
  101. {
  102. ShowMsg(1, $"序列号{sn}采集成功:测试结果为{testRes}");
  103. LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, workOrder.Text, User.UserLineCode, User.UserSourceCode, "无线吞吐量", "无线吞吐量过站成功", sn, "");
  104. }
  105. dt = (DataTable)dh.ExecuteSql($"SELECT mp_id FROM makeprocess WHERE mp_sncode = '{sn}' AND instr(mp_stepname, '吞吐量') > 0", "select");
  106. if (dt.Rows.Count > 0)
  107. {
  108. ShowMsg(1, $"序列号:{sn}已经过站记录");
  109. return;
  110. }
  111. string oWO, oWOId, oErrMsg = "";
  112. if (LogicHandler.CheckStepSNAndMacode(workOrder.Text, User.UserSourceCode, sn, User.UserCode, out oWO, out oWOId, out oErrMsg))
  113. {
  114. if (LogicHandler.SetStepResult(oWO, User.UserSourceCode, sn, "无线吞吐量", "OK", User.UserCode, out oErrMsg))
  115. {
  116. ShowMsg(0, $"序列号{sn},过站记录成功");
  117. }
  118. else
  119. {
  120. ShowMsg(0, $"序列号{sn},处理过站NG:{oErrMsg}");
  121. }
  122. }
  123. else
  124. {
  125. ShowMsg(0, $"序列号{sn},过站核对NG:{oErrMsg}");
  126. }
  127. }
  128. public string ParseIperfBitrate(string logPath)
  129. {
  130. if (!File.Exists(logPath)) return "0.0";
  131. var lines = File.ReadAllLines(logPath);
  132. List<string> logItem = new List<string> { };
  133. foreach (var line in lines)
  134. {
  135. //if (line.Trim().StartsWith("[SUM]"))
  136. //{
  137. // logItem.Add(line);
  138. //}
  139. if(line.Contains("sender") || line.Contains("receiver"))
  140. {
  141. logItem.Add(line);
  142. }
  143. }
  144. if (logItem.Count > 0 && logItem[logItem.Count - 2].Contains("sender"))
  145. {
  146. var match = Regex.Match(logItem[logItem.Count - 2], @"(\d+\.\d+\s+MBytes).*?(\d+\.\d+\s+Mbits/sec)");
  147. if (match.Success)
  148. {
  149. sVal1 = match.Groups[1].Value;
  150. sVal2 = match.Groups[2].Value;
  151. }
  152. }
  153. if (logItem.Count > 0 && logItem[logItem.Count - 1].Contains("receiver"))
  154. {
  155. var match = Regex.Match(logItem[logItem.Count - 1], @"(\d+\.\d+\s+MBytes).*?(\d+\.\d+\s+Mbits/sec)");
  156. if (match.Success)
  157. {
  158. rVal1 = match.Groups[1].Value;
  159. rVal2 = match.Groups[2].Value;
  160. }
  161. }
  162. //double num1 = (double.Parse(sVal1.Split(' ')[0]) + double.Parse(rVal1.Split(' ')[0])) / 2;
  163. //double num2 = (double.Parse(sVal2.Split(' ')[0]) + double.Parse(rVal2.Split(' ')[0])) / 2;
  164. return rVal2;
  165. }
  166. private void ShowMsg(int type, string msg)
  167. {
  168. msg = msg.Replace("\r", "").Replace("\n", "");
  169. string msgTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  170. string showMsg = $"{msgTime}: {msg}\n";
  171. if (type == 0)
  172. {
  173. OperatResult.AppendText(showMsg, Color.Red);
  174. }
  175. else if (type == 1)
  176. {
  177. OperatResult.AppendText(showMsg, Color.Green);
  178. }
  179. }
  180. private void ExePath_Click(object sender, EventArgs e)
  181. {
  182. using (OpenFileDialog openFileDialog = new OpenFileDialog())
  183. {
  184. openFileDialog.Title = "选择iperf3启动文件";
  185. openFileDialog.Filter = "可执行文件 (*.exe)|*.exe|所有文件 (*.*)|*.*";
  186. openFileDialog.FilterIndex = 1;
  187. openFileDialog.RestoreDirectory = true;
  188. // 设置初始目录(可选)
  189. if (!string.IsNullOrEmpty(ExePath.Text) && System.IO.File.Exists(ExePath.Text))
  190. {
  191. openFileDialog.InitialDirectory = System.IO.Path.GetDirectoryName(ExePath.Text);
  192. }
  193. else
  194. {
  195. openFileDialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles);
  196. }
  197. if (openFileDialog.ShowDialog() == DialogResult.OK)
  198. {
  199. ExePath.Text = openFileDialog.FileName;
  200. ShowMsg(1, $"已成功选择iperf3启动文件");
  201. }
  202. }
  203. }
  204. private void UpdateSN(string type, string sn)
  205. {
  206. if (type == "C")
  207. {
  208. serialNumber.Text = "";
  209. workOrder.Text = "";
  210. productCode.Text = "";
  211. productName.Text = "";
  212. }
  213. else if (type == "L")
  214. {
  215. SQL.Clear();
  216. SQL.Append($@"SELECT ms_sncode,ma_code,pr_code,pr_spec FROM makeserial,make,product
  217. WHERE ms_sncode = '{sn}' AND ms_makecode = ma_code AND ms_prodcode = pr_code");
  218. dt = (DataTable)dh.ExecuteSql(SQL.ToString(), "select");
  219. if (dt.Rows.Count > 0)
  220. {
  221. serialNumber.Text = dt.Rows[0]["ms_sncode"].ToString();
  222. workOrder.Text = dt.Rows[0]["ma_code"].ToString();
  223. productCode.Text = dt.Rows[0]["pr_code"].ToString();
  224. productName.Text = dt.Rows[0]["pr_spec"].ToString();
  225. }
  226. else
  227. {
  228. UpdateSN("C", sn);
  229. }
  230. }
  231. }
  232. }
  233. }