DisplayDataHelper.cs 3.2 KB

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