/// <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> /// Queries the provided signals within a the provided time window [Inclusive] /// </summary> /// <param name="database"></param> /// <param name="startTime">the lower bound of the time</param> /// <param name="endTime">the upper bound of the time. [Inclusive]</param> /// <param name="signals">an IEnumerable of all of the signals to query as part of the results set.</param> /// <returns></returns> public static Dictionary <ulong, RawSignalTimeValue> GetRawSignals(this ClientDatabaseBase <HistorianKey, HistorianValue> database, DateTime startTime, DateTime endTime, IEnumerable <ulong> signals) { HistorianKey key = new HistorianKey(); HistorianValue value = new HistorianValue(); Dictionary <ulong, RawSignalTimeValue> results = signals.ToDictionary((x) => x, (x) => new RawSignalTimeValue()); TreeStream <HistorianKey, HistorianValue> stream = database.Read((ulong)startTime.Ticks, (ulong)endTime.Ticks, signals); while (stream.Read(key, value)) { results[key.PointID].Signals.Add(key.TimestampAsDate, value.ToStruct()); } return(results); }
/// <summary> /// Queries the provided signals within a the provided time window [Inclusive] /// </summary> /// <param name="database"></param> /// <param name="startTime">the lower bound of the time</param> /// <param name="endTime">the upper bound of the time. [Inclusive]</param> /// <param name="signals">an IEnumerable of all of the signals to query as part of the results set.</param> /// <returns></returns> public static Dictionary<ulong, RawSignalTimeValue> GetRawSignals(this ClientDatabaseBase<HistorianKey, HistorianValue> database, DateTime startTime, DateTime endTime, IEnumerable<ulong> signals) { HistorianKey key = new HistorianKey(); HistorianValue value = new HistorianValue(); Dictionary<ulong, RawSignalTimeValue> results = signals.ToDictionary((x) => x, (x) => new RawSignalTimeValue()); TreeStream<HistorianKey, HistorianValue> stream = database.Read((ulong)startTime.Ticks, (ulong)endTime.Ticks, signals); while (stream.Read(key, value)) { results[key.PointID].Signals.Add(key.TimestampAsDate, value.ToStruct()); } return results; }
/// <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); }