コード例 #1
0
ファイル: PQDiff.cs プロジェクト: epri-dev/PQDs
        private Boolean RemoveEmptyEvents(PQds.Model.Event evt)
        {
            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.Event>      evtTable        = new GSF.Data.Model.TableOperations <PQds.Model.Event>(connection);

                int nEvents = dataSeriesTable.QueryRecordCountWhere("EventID = {0} ", evt.ID);

                if (nEvents == 0)
                {
                    evtTable.DeleteRecord(evt);
                    return(false);
                }
                else
                {
                    return(true);
                }
            }
        }
コード例 #2
0
ファイル: PQDiff.cs プロジェクト: epri-dev/PQDs
        private void Parse(string filename)
        {
            List <ObservationRecord> observationRecords;
            List <DataSourceRecord>  dataSourceRecords;

            using (LogicalParser logicalParser = new LogicalParser(filename))
            {
                observationRecords = new List <ObservationRecord>();
                logicalParser.Open();

                while (logicalParser.HasNextObservationRecord())
                {
                    observationRecords.Add(logicalParser.NextObservationRecord());
                }

                dataSourceRecords = logicalParser.DataSourceRecords;
            }

            this.m_previousProgress = this.m_previousProgress + 50;
            this.mProgress.Report(this.m_previousProgress);

            if (observationRecords.Count == 0)
            {
                return;
            }
            if (dataSourceRecords.Count != 1)
            {
                return;
            }

            //create Meter Definition
            //For now assume a single meter
            PQds.Model.Meter meter = new Meter();

            meter.DeviceName     = dataSourceRecords[0].DataSourceName;
            meter.Owner          = dataSourceRecords[0].DataSourceOwner;
            meter.DeviceAlias    = GSF.PQDIF.Logical.Equipment.ToString(dataSourceRecords[0].EquipmentID);
            meter.DeviceLocation = dataSourceRecords[0].DataSourceLocation;
            if (dataSourceRecords[0].Latitude < uint.MaxValue)
            {
                meter.Latitude = dataSourceRecords[0].Latitude;
            }
            if (dataSourceRecords[0].Longitude < uint.MaxValue)
            {
                meter.Longitude = dataSourceRecords[0].Longitude;
            }

            meter.AccountName = GSF.PQDIF.Logical.Vendor.ToString(dataSourceRecords[0].VendorID);

            using (AdoDataConnection connection = new AdoDataConnection("systemSettings"))
            {
                GSF.Data.Model.TableOperations <PQds.Model.Meter> meterTable = new GSF.Data.Model.TableOperations <PQds.Model.Meter>(connection);

                meterTable.AddNewRecord(meter);
                meter.ID = PQds.Model.ModelID.GetID <Meter>(connection);
            }

            //create Channel Definitions
            List <PQds.Model.Channel> channels = dataSourceRecords[0].ChannelDefinitions.Select(channel => ParseChannel(meter, channel)).ToList();
            List <PQds.Model.Event>   events   = new List <Event>();

            //create Event Definitions
            foreach (ObservationRecord record in observationRecords)
            {
                //Create Event
                PQds.Model.Event evt = ParseObservationRecord(record);

                //create DataSeries objects
                foreach (ChannelInstance channelInstance in record.ChannelInstances)
                {
                    ParseSeries(channelInstance, channels[(int)channelInstance.ChannelDefinitionIndex], evt);
                }
                events.Add(evt);
            }

            // Remove Channels whithout data
            channels = channels.FindAll(RemoveEmptyChannel).ToList();
            events   = events.FindAll(RemoveEmptyEvents).ToList();

            // Remove Channels whithout data
            channels = channels.FindAll(RemoveEmptyChannel).ToList();

            // If only one set of data it's easy to keep only single line
            int nVa = channels.Count(channel => channel.MeasurementType.ToLower() == PQds.Model.MeasurementType.VoltageA);
            int nVb = channels.Count(channel => channel.MeasurementType.ToLower() == PQds.Model.MeasurementType.VoltageB);
            int nVc = channels.Count(channel => channel.MeasurementType.ToLower() == PQds.Model.MeasurementType.VoltageC);
            int nIa = channels.Count(channel => channel.MeasurementType.ToLower() == PQds.Model.MeasurementType.CurrentA);
            int nIb = channels.Count(channel => channel.MeasurementType.ToLower() == PQds.Model.MeasurementType.CurrentB);
            int nIc = channels.Count(channel => channel.MeasurementType.ToLower() == PQds.Model.MeasurementType.CurrentC);

            if (nVa == 1 && nVb == 1 && nVc == 1)
            {
                //Create new asset
                PQds.Model.Asset asset = new Asset()
                {
                    AssetKey = String.Format("Asset 1 ({0})", meter.AccountName)
                };
                using (AdoDataConnection connection = new AdoDataConnection("systemSettings"))
                {
                    GSF.Data.Model.TableOperations <PQds.Model.Asset> assetTable = new GSF.Data.Model.TableOperations <PQds.Model.Asset>(connection);
                    assetTable.AddNewRecord(asset);
                    asset.ID = PQds.Model.ModelID.GetID <Asset>(connection);

                    GSF.Data.Model.TableOperations <PQds.Model.Channel> channelTable = new GSF.Data.Model.TableOperations <PQds.Model.Channel>(connection);

                    Channel Va = channels.Find(item => item.MeasurementType.ToLower() == PQds.Model.MeasurementType.VoltageA);
                    Channel Vb = channels.Find(item => item.MeasurementType.ToLower() == PQds.Model.MeasurementType.VoltageB);
                    Channel Vc = channels.Find(item => item.MeasurementType.ToLower() == PQds.Model.MeasurementType.VoltageC);

                    Va.AssetID = asset.ID;
                    Vb.AssetID = asset.ID;
                    Vc.AssetID = asset.ID;

                    channelTable.UpdateRecord(Va);
                    channelTable.UpdateRecord(Vb);
                    channelTable.UpdateRecord(Vc);

                    if (nIa == 1 && nIb == 1 && nIc == 1)
                    {
                        Channel Ia = channels.Find(item => item.MeasurementType.ToLower() == PQds.Model.MeasurementType.CurrentA);
                        Channel Ib = channels.Find(item => item.MeasurementType.ToLower() == PQds.Model.MeasurementType.CurrentB);
                        Channel Ic = channels.Find(item => item.MeasurementType.ToLower() == PQds.Model.MeasurementType.CurrentC);

                        Ia.AssetID = asset.ID;
                        Ib.AssetID = asset.ID;
                        Ic.AssetID = asset.ID;

                        channelTable.UpdateRecord(Ia);
                        channelTable.UpdateRecord(Ib);
                        channelTable.UpdateRecord(Ic);
                    }
                }
            }
            this.m_previousProgress = this.m_previousProgress + 50;
            this.mProgress.Report(this.m_previousProgress);
        }
コード例 #3
0
ファイル: PQDiff.cs プロジェクト: epri-dev/PQDs
        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);
            }
        }