123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106 |
- namespace ProximaAnalizer.Helpers;
- internal class DisplayDataHelper(IDictionary<string, object> Left, IDictionary<string, object> Right)
- {
- public HashSet<DateTime> Time { get; } = [];
- public Dictionary<string, List<float>> DataLeft { get; } = [];
- public Dictionary<string, List<float>> DataRight { get; } = [];
- public void CreateData(List<dynamic> main, List<dynamic>? sub)
- {
- while (sub is not null && main.Count != sub.Count!)
- {
- switch (main.Count > sub.Count)
- {
- case true:
- main.RemoveAt(main.Count - 1);
- break;
- case false:
- sub.RemoveAt(sub.Count - 1);
- break;
- }
- }
- this.ClearData();
- foreach (var item in main)
- {
- if (item is not IDictionary<string, object> data)
- continue;
- long ticks = (long)data["time"];
- //ticks -= ticks % 10000000;
- DateTime time = new(ticks);
- Time.Add(time);
- foreach (string key in Left.Keys)
- {
- if (!data.TryGetValue(key, out object? value) || value is null)
- continue;
- if (!DataLeft.TryGetValue(key, out List<float>? collections) || collections is null)
- {
- collections = [];
- DataLeft[key] = collections;
- }
- collections.Add(Convert.ToSingle(value));
- }
- foreach (string key in Right.Keys)
- {
- if (!data.TryGetValue(key, out object? value) || value is null)
- continue;
- if (!DataRight.TryGetValue(key, out List<float>? collections) || collections is null)
- {
- collections = [];
- DataRight[key] = collections;
- }
- collections.Add(Convert.ToSingle(value));
- }
- }
- if (sub is null)
- return;
- foreach (var item in sub)
- {
- if (item is not IDictionary<string, object> data)
- continue;
- foreach (string key in Left.Keys)
- {
- if (!data.TryGetValue(key, out object? value) || value is null)
- continue;
- if (!DataLeft.TryGetValue(key, out List<float>? collections) || collections is null)
- {
- collections = [];
- DataLeft[key] = collections;
- }
- collections.Add(Convert.ToSingle(value));
- }
- foreach (string key in Right.Keys)
- {
- if (!data.TryGetValue(key, out object? value) || value is null)
- continue;
- if (!DataRight.TryGetValue(key, out List<float>? collections) || collections is null)
- {
- collections = [];
- DataRight[key] = collections;
- }
- collections.Add(Convert.ToSingle(value));
- }
- }
- }
- public void ClearData()
- {
- this.Time.Clear();
- this.DataLeft.Clear();
- this.DataRight.Clear();
- }
- }
|