private void btnPlot_Click(object sender, EventArgs e) { List <ulong> keys = new List <ulong>(chkAllPoints.CheckedItems.OfType <ulong>()); plot.Clear(); plot.AddInteraction(new PlotSurface2D.Interactions.HorizontalDrag()); plot.AddInteraction(new PlotSurface2D.Interactions.VerticalDrag()); plot.AddInteraction(new PlotSurface2D.Interactions.AxisDrag(false)); if (keys.Count == 0) { return; } SnapClient client = SnapClient.Connect(m_archiveFile.Host); ClientDatabaseBase <HistorianKey, HistorianValue> db = client.GetDatabase <HistorianKey, HistorianValue>(""); Dictionary <ulong, SignalDataBase> results = db.GetSignals(0, ulong.MaxValue, keys, TypeSingle.Instance); foreach (ulong point in keys) { List <double> y = new List <double>(); List <double> x = new List <double>(); SignalDataBase data = results[point]; for (int i = 0; i < data.Count; i++) { data.GetData(i, out ulong time, out double value); x.Add(time); y.Add(value); } LinePlot lines = new LinePlot(y, x); plot.Add(lines); } plot.Refresh(); db.Dispose(); client.Dispose(); }
public static IDictionary <Guid, SignalDataBase> GetSignalsWithCalculations(this ClientDatabaseBase <HistorianKey, HistorianValue> database, SeekFilterBase <HistorianKey> timestamps, IEnumerable <ISignalCalculation> signals, SortedTreeEngineReaderOptions readerOptions) { Dictionary <ulong, SignalDataBase> queryResults = database.GetSignals(timestamps, signals, readerOptions); Dictionary <Guid, SignalDataBase> calculatedResults = new Dictionary <Guid, SignalDataBase>(); foreach (ISignalCalculation signal in signals) { if (signal.HistorianId.HasValue) { calculatedResults.Add(signal.SignalId, queryResults[signal.HistorianId.Value]); } else { calculatedResults.Add(signal.SignalId, new SignalData(signal.Functions)); } } foreach (ISignalCalculation signal in signals) { signal.Calculate(calculatedResults); } return(calculatedResults); }
public static DataTable GetTable(this ClientDatabaseBase <HistorianKey, HistorianValue> database, ulong start, ulong stop, IList <ISignalWithName> columns) { if (columns.Any((x) => !x.HistorianId.HasValue)) { throw new Exception("All columns must be contained in the historian for this function to work."); } Dictionary <ulong, SignalDataBase> results = database.GetSignals(start, stop, columns); int[] columnPosition = new int[columns.Count]; object[] rowValues = new object[columns.Count + 1]; SignalDataBase[] signals = new SignalDataBase[columns.Count]; DataTable table = new DataTable(); table.Columns.Add("Time", typeof(DateTime)); foreach (ISignalWithName signal in columns) { table.Columns.Add(signal.TagName, typeof(double)); } for (int x = 0; x < columns.Count; x++) { signals[x] = results[columns[x].HistorianId.Value]; } while (true) { ulong minDate = ulong.MaxValue; for (int x = 0; x < columns.Count; x++) { SignalDataBase signal = signals[x]; if (signal.Count < columnPosition[x]) { minDate = Math.Min(minDate, signals[x].GetDate(columnPosition[x])); } } rowValues[0] = null; for (int x = 0; x < columns.Count; x++) { SignalDataBase signal = signals[x]; if (signal.Count < columnPosition[x] && minDate == signals[x].GetDate(columnPosition[x])) { ulong date; double value; signals[x].GetData(columnPosition[x], out date, out value); rowValues[x + 1] = value; columnPosition[x]++; } else { rowValues[x + 1] = null; } } if (minDate == ulong.MaxValue && rowValues.All((x) => x == null)) { return(table); } rowValues[0] = minDate; table.Rows.Add(rowValues); } }