private void ParseSeries(GSF.PQDIF.Logical.ChannelInstance channelInstance, PQds.Model.Channel channel, PQds.Model.Event evt) { PQds.Model.DataSeries dataSeries = new DataSeries(); dataSeries.EventID = evt.ID; dataSeries.ChannelID = channel.ID; Guid quantityType = channelInstance.Definition.QuantityTypeID; SeriesInstance timeSeries = null; SeriesInstance valuesSeries = null; if (isPOW(quantityType)) { timeSeries = channelInstance.SeriesInstances.Single(series => series.Definition.ValueTypeID == SeriesValueType.Time); valuesSeries = channelInstance.SeriesInstances.Single(series => series.Definition.ValueTypeID == SeriesValueType.Val); } else { return; } List <double> values = valuesSeries.OriginalValues.Select(val => Convert.ToDouble(val)).ToList(); List <DateTime> timeStamps = new List <DateTime>(); if (timeSeries.Definition.QuantityUnits == QuantityUnits.Seconds) { // If time series is in seconds from start time of the observation record, // TimeValues must be calculated by adding values to start time timeStamps = timeSeries.OriginalValues .Select(Convert.ToDouble) .Select(seconds => (long)(seconds * TimeSpan.TicksPerSecond)) .Select(TimeSpan.FromTicks) .Select(timeSpan => channelInstance.ObservationRecord.StartTime + timeSpan) .ToList(); } else if (timeSeries.Definition.QuantityUnits == QuantityUnits.Timestamp) { // If time series is a collection of absolute time, seconds from start time // must be calculated by subtracting the start time of the observation record timeStamps = timeSeries.OriginalValues.Cast <DateTime>().ToList(); } dataSeries.Series = timeStamps.Select((item, index) => new PQds.Model.DataPoint() { Time = item, Value = values[index] }).ToList(); using (AdoDataConnection connection = new AdoDataConnection("systemSettings")) { GSF.Data.Model.TableOperations <PQds.Model.DataSeries> dataSeriesTable = new GSF.Data.Model.TableOperations <PQds.Model.DataSeries>(connection); dataSeriesTable.AddNewRecord(dataSeries); } }
private Boolean RemoveEmptyChannel(PQds.Model.Channel channel) { using (AdoDataConnection connection = new AdoDataConnection("systemSettings")) { GSF.Data.Model.TableOperations <PQds.Model.DataSeries> dataSeriesTable = new GSF.Data.Model.TableOperations <PQds.Model.DataSeries>(connection); GSF.Data.Model.TableOperations <PQds.Model.Channel> channelTable = new GSF.Data.Model.TableOperations <PQds.Model.Channel>(connection); int nEvents = dataSeriesTable.QueryRecordCountWhere("ChannelID = {0} ", channel.ID); if (nEvents == 0) { //remove corresponsing MeasurmentID channelTable.DeleteRecord(channel); return(false); } else { return(true); } } }