StatsDataRecorder.cs 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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 StatsDataRecorder
  13. {
  14. public static List<StatsStatisticsData> QueryStatsStatistics(string sql)
  15. {
  16. List<StatsStatisticsData> result = new List<StatsStatisticsData>();
  17. try
  18. {
  19. DataSet ds = DB.ExecuteDataset(sql);
  20. if (ds == null)
  21. return result;
  22. for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
  23. {
  24. string name = ds.Tables[0].Rows[i]["name"].ToString();
  25. string description = ds.Tables[0].Rows[i]["description"].ToString();
  26. string value =ds.Tables[0].Rows[i]["value"].ToString();
  27. string[] nameSplit = name.Split('.');
  28. if (nameSplit != null && nameSplit.Length == 3)
  29. {
  30. var tempStats = result.Where(x => x.Date == nameSplit[2]).FirstOrDefault();
  31. if (tempStats != null)
  32. {
  33. switch (description)
  34. {
  35. case "Unknown":
  36. tempStats.Unknown = value;
  37. break;
  38. case "Setup":
  39. tempStats.Setup = value;
  40. break;
  41. case "Idle":
  42. tempStats.Idle = value;
  43. break;
  44. case "Ready":
  45. tempStats.Ready = value;
  46. break;
  47. case "Executing":
  48. tempStats.Executing = value;
  49. break;
  50. case "Pause":
  51. tempStats.Pause = value;
  52. break;
  53. default:
  54. break;
  55. }
  56. }
  57. else
  58. {
  59. StatsStatisticsData ev = new StatsStatisticsData();
  60. ev.Date = nameSplit[2];
  61. switch (description)
  62. {
  63. case "Unknown":
  64. ev.Unknown = value;
  65. break;
  66. case "Setup":
  67. ev.Setup = value;
  68. break;
  69. case "Idle":
  70. ev.Idle = value;
  71. break;
  72. case "Ready":
  73. ev.Ready = value;
  74. break;
  75. case "Executing":
  76. ev.Executing = value;
  77. break;
  78. case "Pause":
  79. ev.Pause = value;
  80. break;
  81. default:
  82. break;
  83. }
  84. result.Add(ev);
  85. }
  86. }
  87. }
  88. return result;
  89. }
  90. catch (Exception ex)
  91. {
  92. LOG.Write(ex);
  93. }
  94. return result;
  95. }
  96. }
  97. }