DBDisplayHelper.cs 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. namespace ProximaAnalizer.Helpers;
  2. internal class DBDisplayHelper(IDictionary<string, object> Left, IDictionary<string, object> Right)
  3. {
  4. public readonly HashSet<DateTime> Time = [];
  5. public readonly Dictionary<string, List<float>> DataLeft = [];
  6. public readonly Dictionary<string, List<float>> DataRight = [];
  7. public void CreateData(List<dynamic> main, List<dynamic> sub)
  8. {
  9. while (main.Count != sub.Count!)
  10. {
  11. switch (main.Count > sub.Count)
  12. {
  13. case true:
  14. main.RemoveAt(main.Count - 1);
  15. break;
  16. case false:
  17. sub.RemoveAt(sub.Count - 1);
  18. break;
  19. }
  20. }
  21. foreach (var item in main)
  22. {
  23. if (item is not IDictionary<string, object> data)
  24. continue;
  25. long ticks = (long)data["time"];
  26. //ticks -= ticks % 10000000;
  27. DateTime time = new(ticks);
  28. Time.Add(time);
  29. foreach (string key in Left.Keys)
  30. {
  31. if (!data.TryGetValue(key, out object? value) || value is null)
  32. continue;
  33. if (!DataLeft.TryGetValue(key, out List<float>? collections) || collections is null)
  34. {
  35. collections = [];
  36. DataLeft[key] = collections;
  37. }
  38. collections.Add(Convert.ToSingle(value));
  39. }
  40. foreach (string key in Right.Keys)
  41. {
  42. if (!data.TryGetValue(key, out object? value) || value is null)
  43. continue;
  44. if (!DataRight.TryGetValue(key, out List<float>? collections) || collections is null)
  45. {
  46. collections = [];
  47. DataRight[key] = collections;
  48. }
  49. collections.Add(Convert.ToSingle(value));
  50. }
  51. }
  52. foreach (var item in sub)
  53. {
  54. if (item is not IDictionary<string, object> data)
  55. continue;
  56. foreach (string key in Left.Keys)
  57. {
  58. if (!data.TryGetValue(key, out object? value) || value is null)
  59. continue;
  60. if (!DataLeft.TryGetValue(key, out List<float>? collections) || collections is null)
  61. {
  62. collections = [];
  63. DataLeft[key] = collections;
  64. }
  65. collections.Add(Convert.ToSingle(value));
  66. }
  67. foreach (string key in Right.Keys)
  68. {
  69. if (!data.TryGetValue(key, out object? value) || value is null)
  70. continue;
  71. if (!DataRight.TryGetValue(key, out List<float>? collections) || collections is null)
  72. {
  73. collections = [];
  74. DataRight[key] = collections;
  75. }
  76. collections.Add(Convert.ToSingle(value));
  77. }
  78. }
  79. }
  80. public void ClearData()
  81. {
  82. this.Time.Clear();
  83. this.DataLeft.Clear();
  84. this.DataRight.Clear();
  85. }
  86. }