Exemplo n.º 1
0
        public override void Prepare(DbAdapterContainer dbAdapterContainer)
        {
            m_dbAdapterContainer = dbAdapterContainer;

            m_phaseLookup           = new DataContextLookup <string, Phase>(dbAdapterContainer.GetAdapter <MeterInfoDataContext>(), phase => phase.Name);
            m_breakerOperationTable = new MeterData.BreakerOperationDataTable();
            m_breakerOperations     = new List <Tuple <EventKey, MeterData.BreakerOperationRow> >();

            LoadBreakerOperationTypes(dbAdapterContainer);
        }
Exemplo n.º 2
0
        private int GetPhaseID(GSF.PQDIF.Logical.Phase phase)
        {
            if ((object)m_phaseLookup == null)
            {
                m_phaseLookup = new DataContextLookup <string, Phase>(m_dbAdapterContainer.GetAdapter <MeterInfoDataContext>(), ph => ph.Name);
            }

            return(m_phaseLookup.GetOrAdd(phase.ToString(), name => new Phase()
            {
                Name = name, Description = name
            }).ID);
        }
Exemplo n.º 3
0
        private void UpdateConfigurationData(MeterDataSet meterDataSet)
        {
            using (TransactionScope transaction = new TransactionScope(TransactionScopeOption.Required, GetTransactionOptions()))
            {
                if (meterDataSet.Meter.MeterLines.Count != 1)
                {
                    return;
                }

                Line line = meterDataSet.Meter.MeterLines
                            .Select(meterLine => meterLine.Line)
                            .Single();

                if (meterDataSet.Configuration.LineLength.HasValue)
                {
                    line.Length = meterDataSet.Configuration.LineLength.GetValueOrDefault();
                    m_meterInfo.SubmitChanges();
                }

                if (meterDataSet.Configuration.R1.HasValue && meterDataSet.Configuration.X1.HasValue && meterDataSet.Configuration.R0.HasValue && meterDataSet.Configuration.X0.HasValue)
                {
                    DataContextLookup <int, LineImpedance> lookup = new DataContextLookup <int, LineImpedance>(m_faultLocationInfo, impedance => impedance.LineID);
                    LineImpedance lineImpedance = lookup.GetOrAdd(line.ID, id => new LineImpedance()
                    {
                        LineID = id
                    });

                    if (meterDataSet.Configuration.R1.HasValue)
                    {
                        lineImpedance.R1 = meterDataSet.Configuration.R1.GetValueOrDefault();
                    }

                    if (meterDataSet.Configuration.X1.HasValue)
                    {
                        lineImpedance.X1 = meterDataSet.Configuration.X1.GetValueOrDefault();
                    }

                    if (meterDataSet.Configuration.R0.HasValue)
                    {
                        lineImpedance.R0 = meterDataSet.Configuration.R0.GetValueOrDefault();
                    }

                    if (meterDataSet.Configuration.X0.HasValue)
                    {
                        lineImpedance.X0 = meterDataSet.Configuration.X0.GetValueOrDefault();
                    }

                    m_faultLocationInfo.SubmitChanges();
                }

                transaction.Complete();
            }
        }
Exemplo n.º 4
0
        // Static Methods
        private static Series GetSeriesInfo(MeterInfoDataContext meterInfo, Meter meter, DataGroup dataGroup, string measurementTypeName, string phaseName)
        {
            int    lineID;
            string measurementCharacteristicName;
            string seriesTypeName;

            char   typeDesignation;
            char   phaseDesignation;
            string channelName;

            DataContextLookup <ChannelKey, Channel>               channelLookup;
            DataContextLookup <SeriesKey, Series>                 seriesLookup;
            DataContextLookup <string, MeasurementType>           measurementTypeLookup;
            DataContextLookup <string, MeasurementCharacteristic> measurementCharacteristicLookup;
            DataContextLookup <string, Phase>      phaseLookup;
            DataContextLookup <string, SeriesType> seriesTypeLookup;

            ChannelKey channelKey;
            SeriesKey  seriesKey;

            lineID = dataGroup.Line.ID;
            measurementCharacteristicName = "Instantaneous";
            seriesTypeName = "Values";

            typeDesignation  = (measurementTypeName == "Current") ? 'I' : measurementTypeName[0];
            phaseDesignation = (phaseName == "RES") ? 'R' : phaseName[0];
            channelName      = string.Concat(typeDesignation, phaseDesignation);

            channelLookup = new DataContextLookup <ChannelKey, Channel>(meterInfo, channel => new ChannelKey(channel))
                            .WithFilterExpression(channel => channel.MeterID == meter.ID)
                            .WithFilterExpression(channel => channel.LineID == dataGroup.Line.ID)
                            .WithFilterExpression(channel => channel.MeasurementType.Name == measurementTypeName)
                            .WithFilterExpression(channel => channel.MeasurementCharacteristic.Name == measurementCharacteristicName)
                            .WithFilterExpression(channel => channel.Phase.Name == phaseName);

            seriesLookup = new DataContextLookup <SeriesKey, Series>(meterInfo, series => new SeriesKey(series))
                           .WithFilterExpression(series => series.Channel.Meter.ID == meter.ID)
                           .WithFilterExpression(series => series.Channel.Line.ID == dataGroup.Line.ID)
                           .WithFilterExpression(series => series.Channel.MeasurementType.Name == measurementTypeName)
                           .WithFilterExpression(series => series.Channel.MeasurementCharacteristic.Name == measurementCharacteristicName)
                           .WithFilterExpression(series => series.Channel.Phase.Name == phaseName)
                           .WithFilterExpression(series => series.SeriesType.Name == seriesTypeName);

            measurementTypeLookup           = new DataContextLookup <string, MeasurementType>(meterInfo, measurementType => measurementType.Name);
            measurementCharacteristicLookup = new DataContextLookup <string, MeasurementCharacteristic>(meterInfo, measurementCharacteristic => measurementCharacteristic.Name);
            phaseLookup      = new DataContextLookup <string, Phase>(meterInfo, phase => phase.Name);
            seriesTypeLookup = new DataContextLookup <string, SeriesType>(meterInfo, seriesType => seriesType.Name);

            channelKey = new ChannelKey(lineID, 0, channelName, measurementTypeName, measurementCharacteristicName, phaseName);
            seriesKey  = new SeriesKey(channelKey, seriesTypeName);

            return(seriesLookup.GetOrAdd(seriesKey, key =>
            {
                SeriesType seriesType = seriesTypeLookup.GetOrAdd(key.SeriesType, name => new SeriesType()
                {
                    Name = name, Description = name
                });

                Channel channel = channelLookup.GetOrAdd(channelKey, chKey =>
                {
                    MeasurementType measurementType = measurementTypeLookup.GetOrAdd(chKey.MeasurementType, name => new MeasurementType()
                    {
                        Name = name, Description = name
                    });
                    MeasurementCharacteristic measurementCharacteristic = measurementCharacteristicLookup.GetOrAdd(chKey.MeasurementCharacteristic, name => new MeasurementCharacteristic()
                    {
                        Name = name, Description = name
                    });
                    Phase phase = phaseLookup.GetOrAdd(chKey.Phase, name => new Phase()
                    {
                        Name = name, Description = name
                    });

                    return new Channel()
                    {
                        Meter = meter,
                        Line = dataGroup.Line,
                        MeasurementType = measurementType,
                        MeasurementCharacteristic = measurementCharacteristic,
                        Phase = phase,
                        Name = chKey.Name,
                        SamplesPerHour = dataGroup.SamplesPerHour,
                        PerUnitValue = 0,
                        HarmonicGroup = 0,
                        Description = string.Concat(measurementCharacteristic.Name, " ", measurementType.Name, " ", phase.Name),
                        Enabled = 1
                    };
                });

                return new Series()
                {
                    SeriesType = seriesType,
                    Channel = channel,
                    SourceIndexes = string.Empty
                };
            }));
        }
Exemplo n.º 5
0
        private void AddUndefinedChannels(MeterDataSet meterDataSet)
        {
            DataContextLookup <SeriesKey, Series>                 seriesLookup;
            DataContextLookup <ChannelKey, Channel>               channelLookup;
            DataContextLookup <string, MeasurementType>           measurementTypeLookup;
            DataContextLookup <string, MeasurementCharacteristic> measurementCharacteristicLookup;
            DataContextLookup <string, SeriesType>                seriesTypeLookup;
            DataContextLookup <string, Phase> phaseLookup;

            List <DataSeries> undefinedDataSeries;

            Line line;

            undefinedDataSeries = meterDataSet.DataSeries
                                  .Where(dataSeries => (object)dataSeries.SeriesInfo.Channel.Line == null)
                                  .ToList();

            if (undefinedDataSeries.Count <= 0)
            {
                return;
            }

            line = meterDataSet.Meter.MeterLines
                   .Select(meterLine => meterLine.Line)
                   .Single();

            foreach (DataSeries series in undefinedDataSeries)
            {
                series.SeriesInfo.Channel.LineID = line.ID;
            }

            seriesLookup = new DataContextLookup <SeriesKey, Series>(m_meterInfo, GetSeriesKey)
                           .WithFilterExpression(series => series.Channel.MeterID == meterDataSet.Meter.ID)
                           .WithFilterExpression(series => series.SourceIndexes == "");

            channelLookup = new DataContextLookup <ChannelKey, Channel>(m_meterInfo, GetChannelKey)
                            .WithFilterExpression(channel => channel.MeterID == meterDataSet.Meter.ID);

            measurementTypeLookup           = new DataContextLookup <string, MeasurementType>(m_meterInfo, type => type.Name);
            measurementCharacteristicLookup = new DataContextLookup <string, MeasurementCharacteristic>(m_meterInfo, characteristic => characteristic.Name);
            seriesTypeLookup = new DataContextLookup <string, SeriesType>(m_meterInfo, type => type.Name);
            phaseLookup      = new DataContextLookup <string, Phase>(m_meterInfo, phase => phase.Name);

            for (int i = 0; i < undefinedDataSeries.Count; i++)
            {
                DataSeries dataSeries = undefinedDataSeries[i];

                // Search for an existing series info object
                dataSeries.SeriesInfo = seriesLookup.GetOrAdd(GetSeriesKey(dataSeries.SeriesInfo), seriesKey =>
                {
                    Series clonedSeries = dataSeries.SeriesInfo.Clone();

                    // Search for an existing series type object to associate with the new series
                    SeriesType seriesType = seriesTypeLookup.GetOrAdd(dataSeries.SeriesInfo.SeriesType.Name, name => dataSeries.SeriesInfo.SeriesType.Clone());

                    // Search for an existing channel object to associate with the new series
                    Channel channel = channelLookup.GetOrAdd(GetChannelKey(dataSeries.SeriesInfo.Channel), channelKey =>
                    {
                        Channel clonedChannel = dataSeries.SeriesInfo.Channel.Clone();

                        // Search for an existing measurement type object to associate with the new channel
                        MeasurementType measurementType = measurementTypeLookup.GetOrAdd(dataSeries.SeriesInfo.Channel.MeasurementType.Name, name => dataSeries.SeriesInfo.Channel.MeasurementType.Clone());

                        // Search for an existing measurement characteristic object to associate with the new channel
                        MeasurementCharacteristic measurementCharacteristic = measurementCharacteristicLookup.GetOrAdd(dataSeries.SeriesInfo.Channel.MeasurementCharacteristic.Name, name => dataSeries.SeriesInfo.Channel.MeasurementCharacteristic.Clone());

                        // Search for an existing phase object to associate with the new channel
                        Phase phase = phaseLookup.GetOrAdd(dataSeries.SeriesInfo.Channel.Phase.Name, name => dataSeries.SeriesInfo.Channel.Phase.Clone());

                        // Assign the foreign keys of the channel
                        // to reference the objects from the lookup
                        clonedChannel.Meter                     = meterDataSet.Meter;
                        clonedChannel.Line                      = line;
                        clonedChannel.MeasurementType           = measurementType;
                        clonedChannel.MeasurementCharacteristic = measurementCharacteristic;
                        clonedChannel.Phase                     = phase;
                        clonedChannel.Enabled                   = 1;

                        // If the per-unit value was not specified in the input file,
                        // we can obtain the per-unit value from the line configuration
                        // if the channel happens to be an instantaneous or RMS voltage
                        if (!clonedChannel.PerUnitValue.HasValue)
                        {
                            if (IsVoltage(clonedChannel))
                            {
                                if (IsLineToNeutral(clonedChannel))
                                {
                                    clonedChannel.PerUnitValue = (line.VoltageKV * 1000.0D) / Sqrt3;
                                }
                                else if (IsLineToLine(clonedChannel))
                                {
                                    clonedChannel.PerUnitValue = line.VoltageKV * 1000.0D;
                                }
                            }
                        }

                        return(clonedChannel);
                    });

                    // Assign the foreign keys of the series
                    // to reference the objects from the lookup
                    clonedSeries.SeriesType = seriesType;
                    clonedSeries.Channel    = channel;

                    return(clonedSeries);
                });
            }
        }
Exemplo n.º 6
0
        // Static Methods
        private static Series GetSeriesInfo(MeterInfoDataContext meterInfo, Meter meter, DataGroup dataGroup, string measurementTypeName, string phaseName)
        {
            int lineID;
            string measurementCharacteristicName;
            string seriesTypeName;

            char typeDesignation;
            char phaseDesignation;
            string channelName;

            DataContextLookup<ChannelKey, Channel> channelLookup;
            DataContextLookup<SeriesKey, Series> seriesLookup;
            DataContextLookup<string, MeasurementType> measurementTypeLookup;
            DataContextLookup<string, MeasurementCharacteristic> measurementCharacteristicLookup;
            DataContextLookup<string, Phase> phaseLookup;
            DataContextLookup<string, SeriesType> seriesTypeLookup;

            ChannelKey channelKey;
            SeriesKey seriesKey;

            lineID = dataGroup.Line.ID;
            measurementCharacteristicName = "Instantaneous";
            seriesTypeName = "Values";

            typeDesignation = (measurementTypeName == "Current") ? 'I' : measurementTypeName[0];
            phaseDesignation = (phaseName == "RES") ? 'R' : phaseName[0];
            channelName = string.Concat(typeDesignation, phaseDesignation);

            channelLookup = new DataContextLookup<ChannelKey, Channel>(meterInfo, channel => new ChannelKey(channel))
                .WithFilterExpression(channel => channel.MeterID == meter.ID)
                .WithFilterExpression(channel => channel.LineID == dataGroup.Line.ID);

            seriesLookup = new DataContextLookup<SeriesKey, Series>(meterInfo, series => new SeriesKey(series))
                .WithFilterExpression(series => series.Channel.Meter.ID == meter.ID)
                .WithFilterExpression(series => series.Channel.Line.ID == dataGroup.Line.ID);

            measurementTypeLookup = new DataContextLookup<string, MeasurementType>(meterInfo, measurementType => measurementType.Name);
            measurementCharacteristicLookup = new DataContextLookup<string, MeasurementCharacteristic>(meterInfo, measurementCharacteristic => measurementCharacteristic.Name);
            phaseLookup = new DataContextLookup<string, Phase>(meterInfo, phase => phase.Name);
            seriesTypeLookup = new DataContextLookup<string, SeriesType>(meterInfo, seriesType => seriesType.Name);

            channelKey = new ChannelKey(lineID, 0, channelName, measurementTypeName, measurementCharacteristicName, phaseName);
            seriesKey = new SeriesKey(channelKey, seriesTypeName);

            return seriesLookup.GetOrAdd(seriesKey, key =>
            {
                SeriesType seriesType = seriesTypeLookup.GetOrAdd(key.SeriesType, name => new SeriesType() { Name = name, Description = name });

                Channel channel = channelLookup.GetOrAdd(channelKey, chKey =>
                {
                    MeasurementType measurementType = measurementTypeLookup.GetOrAdd(chKey.MeasurementType, name => new MeasurementType() { Name = name, Description = name });
                    MeasurementCharacteristic measurementCharacteristic = measurementCharacteristicLookup.GetOrAdd(chKey.MeasurementCharacteristic, name => new MeasurementCharacteristic() { Name = name, Description = name });
                    Phase phase = phaseLookup.GetOrAdd(chKey.Phase, name => new Phase() { Name = name, Description = name });

                    return new Channel()
                    {
                        Meter = meter,
                        Line = dataGroup.Line,
                        MeasurementType = measurementType,
                        MeasurementCharacteristic = measurementCharacteristic,
                        Phase = phase,
                        Name = chKey.Name,
                        SamplesPerHour = dataGroup.SamplesPerHour,
                        PerUnitValue = 0,
                        HarmonicGroup = 0,
                        Description = string.Concat(measurementCharacteristic.Name, " ", measurementType.Name, " ", phase.Name),
                        Enabled = 1
                    };
                });

                return new Series()
                {
                    SeriesType = seriesType,
                    Channel = channel,
                    SourceIndexes = string.Empty
                };
            });
        }
Exemplo n.º 7
0
        private static Series GetSeriesInfo(MeterInfoDataContext meterInfo, Meter meter, DataGroup dataGroup, int index)
        {
            Dictionary <int, string> measurementTypeNameLookup = new Dictionary <int, string>()
            {
                { VAIndex, "Voltage" },
                { VBIndex, "Voltage" },
                { VCIndex, "Voltage" },
                { IAIndex, "Current" },
                { IBIndex, "Current" },
                { ICIndex, "Current" },
                { IRIndex, "Current" }
            };

            Dictionary <int, string> phaseNameLookup = new Dictionary <int, string>()
            {
                { VAIndex, "AN" },
                { VBIndex, "BN" },
                { VCIndex, "CN" },
                { IAIndex, "AN" },
                { IBIndex, "BN" },
                { ICIndex, "CN" },
                { IRIndex, "RES" }
            };

            int    lineID;
            string measurementTypeName;
            string measurementCharacteristicName;
            string phaseName;
            string seriesTypeName;
            string channelName;

            DataContextLookup <ChannelKey, Channel>               channelLookup;
            DataContextLookup <SeriesKey, Series>                 seriesLookup;
            DataContextLookup <string, MeasurementType>           measurementTypeLookup;
            DataContextLookup <string, MeasurementCharacteristic> measurementCharacteristicLookup;
            DataContextLookup <string, Phase>      phaseLookup;
            DataContextLookup <string, SeriesType> seriesTypeLookup;

            SeriesKey  seriesKey;
            ChannelKey channelKey;

            lineID = dataGroup.Line.ID;
            measurementTypeName           = measurementTypeNameLookup[index];
            measurementCharacteristicName = "Instantaneous";
            phaseName      = phaseNameLookup[index];
            seriesTypeName = "Values";
            channelName    = string.Concat(measurementTypeName, " ", phaseName);

            channelLookup = new DataContextLookup <ChannelKey, Channel>(meterInfo, GetChannelKey)
                            .WithFilterExpression(channel => channel.MeterID == meter.ID)
                            .WithFilterExpression(channel => channel.LineID == dataGroup.Line.ID);

            seriesLookup = new DataContextLookup <SeriesKey, Series>(meterInfo, GetSeriesKey)
                           .WithFilterExpression(series => series.Channel.Meter.ID == meter.ID)
                           .WithFilterExpression(series => series.Channel.Line.ID == dataGroup.Line.ID);

            measurementTypeLookup           = new DataContextLookup <string, MeasurementType>(meterInfo, measurementType => measurementType.Name);
            measurementCharacteristicLookup = new DataContextLookup <string, MeasurementCharacteristic>(meterInfo, measurementCharacteristic => measurementCharacteristic.Name);
            phaseLookup      = new DataContextLookup <string, Phase>(meterInfo, phase => phase.Name);
            seriesTypeLookup = new DataContextLookup <string, SeriesType>(meterInfo, seriesType => seriesType.Name);

            seriesKey  = Tuple.Create(lineID, 0, channelName, measurementTypeName, measurementCharacteristicName, phaseName, seriesTypeName);
            channelKey = Tuple.Create(lineID, 0, channelName, measurementTypeName, measurementCharacteristicName, phaseName);

            return(seriesLookup.GetOrAdd(seriesKey, key =>
            {
                SeriesType seriesType = seriesTypeLookup.GetOrAdd(seriesTypeName, name => new SeriesType()
                {
                    Name = name, Description = name
                });

                Channel channel = channelLookup.GetOrAdd(channelKey, chKey =>
                {
                    MeasurementType measurementType = measurementTypeLookup.GetOrAdd(measurementTypeName, name => new MeasurementType()
                    {
                        Name = name, Description = name
                    });
                    MeasurementCharacteristic measurementCharacteristic = measurementCharacteristicLookup.GetOrAdd(measurementCharacteristicName, name => new MeasurementCharacteristic()
                    {
                        Name = name, Description = name
                    });
                    Phase phase = phaseLookup.GetOrAdd(phaseName, name => new Phase()
                    {
                        Name = name, Description = name
                    });

                    return new Channel()
                    {
                        Meter = meter,
                        Line = dataGroup.Line,
                        MeasurementType = measurementType,
                        MeasurementCharacteristic = measurementCharacteristic,
                        Phase = phase,
                        Name = string.Concat(measurementType.Name, " ", phase.Name),
                        SamplesPerHour = dataGroup.SamplesPerHour,
                        PerUnitValue = 0,
                        HarmonicGroup = 0,
                        Description = string.Concat(measurementCharacteristic.Name, " ", measurementType.Name, " ", phase.Name),
                        Enabled = 1
                    };
                });

                return new Series()
                {
                    SeriesType = seriesType,
                    Channel = channel,
                    SourceIndexes = string.Empty
                };
            }));
        }