/// <summary> /// Gets concentrated frames from the provided stream /// </summary> /// <param name="stream">the database to use</param> /// <returns></returns> public static SortedList <DateTime, FrameData> GetFrames(this TreeStream <HistorianKey, HistorianValue> stream) { SortedList <DateTime, FrameDataConstructor> results = new SortedList <DateTime, FrameDataConstructor>(); ulong lastTime = ulong.MinValue; FrameDataConstructor lastFrame = null; HistorianKey key = new HistorianKey(); HistorianValue value = new HistorianValue(); while (stream.Read(key, value)) { if (lastFrame == null || key.Timestamp != lastTime) { lastTime = key.Timestamp; DateTime timestamp = new DateTime((long)lastTime); if (!results.TryGetValue(timestamp, out lastFrame)) { lastFrame = new FrameDataConstructor(); results.Add(timestamp, lastFrame); } } lastFrame.PointId.Add(key.PointID); lastFrame.Values.Add(value.ToStruct()); } List <FrameData> data = new List <FrameData>(results.Count); data.AddRange(results.Values.Select(x => x.ToFrameData())); return(SortedListConstructor.Create(results.Keys, data)); }
/// <summary> /// Gets concentrated frames from the provided stream /// </summary> /// <param name="stream">the database to use</param> /// <returns></returns> public static SortedList<DateTime, FrameData> GetFrames(this TreeStream<HistorianKey, HistorianValue> stream) { SortedList<DateTime, FrameDataConstructor> results = new SortedList<DateTime, FrameDataConstructor>(); ulong lastTime = ulong.MinValue; FrameDataConstructor lastFrame = null; HistorianKey key = new HistorianKey(); HistorianValue value = new HistorianValue(); while (stream.Read(key, value)) { if (lastFrame == null || key.Timestamp != lastTime) { lastTime = key.Timestamp; DateTime timestamp = new DateTime((long)lastTime); if (!results.TryGetValue(timestamp, out lastFrame)) { lastFrame = new FrameDataConstructor(); results.Add(timestamp, lastFrame); } } lastFrame.PointId.Add(key.PointID); lastFrame.Values.Add(value.ToStruct()); } List<FrameData> data = new List<FrameData>(results.Count); data.AddRange(results.Values.Select(x => x.ToFrameData())); return SortedListConstructor.Create(results.Keys, data); }