Esempio n. 1
0
        /// <summary>
        /// Initializes the <see cref="LossOfField"/> detector.
        /// </summary>
        public override void Initialize()
        {
            base.Initialize();

            Dictionary <string, string> settings = Settings;
            string setting;

            // Load parameters
            if (settings.TryGetValue("pSet", out setting))
            {
                m_pSet = double.Parse(setting);
            }
            else
            {
                m_pSet = -600;
            }

            if (settings.TryGetValue("qSet", out setting))
            {
                m_qSet = double.Parse(setting);
            }
            else
            {
                m_qSet = 200;
            }

            if (settings.TryGetValue("qAreaSet", out setting))
            {
                m_qAreaSet = double.Parse(setting);
            }
            else
            {
                m_qAreaSet = 500;
            }

            if (settings.TryGetValue("voltageThreshold", out setting))
            {
                m_voltageThreshold = double.Parse(setting);
            }
            else
            {
                m_voltageThreshold = 475000;
            }

            if (settings.TryGetValue("analysisInterval", out setting))
            {
                m_analysisInterval = int.Parse(setting);
            }
            else
            {
                m_analysisInterval = FramesPerSecond;
            }

            m_count  = 0;
            m_count1 = 0;
            m_count2 = 0;

            // Load needed measurement keys from defined InputMeasurementKeys
            int index;

            // Get expected voltage magnitude
            index = InputMeasurementKeyTypes.IndexOf(signalType => signalType == SignalType.VPHM);
            if (index < 0)
            {
                throw new InvalidOperationException("No voltage magnitude input measurement key was not found - this is a required input measurement for the loss of field detector.");
            }

            m_voltageMagnitude = InputMeasurementKeys[index];

            // Get expected voltage angle
            index = InputMeasurementKeyTypes.IndexOf(signalType => signalType == SignalType.VPHA);
            if (index < 0)
            {
                throw new InvalidOperationException("No voltage angle input measurement key was not found - this is a required input measurement for the loss of field detector.");
            }

            m_voltageAngle = InputMeasurementKeys[index];

            // Get expected current magnitude
            index = InputMeasurementKeyTypes.IndexOf(signalType => signalType == SignalType.IPHM);
            if (index < 0)
            {
                throw new InvalidOperationException("No current magnitude input measurement key was not found - this is a required input measurement for the loss of field detector.");
            }

            m_currentMagnitude = InputMeasurementKeys[index];

            // Get expected current angle
            index = InputMeasurementKeyTypes.IndexOf(signalType => signalType == SignalType.IPHA);
            if (index < 0)
            {
                throw new InvalidOperationException("No current angle input measurement key was not found - this is a required input measurement for the loss of field detector.");
            }

            m_currentAngle = InputMeasurementKeys[index];

            // Make sure only these phasor measurements are used as input
            InputMeasurementKeys = new[] { m_voltageMagnitude, m_voltageAngle, m_currentMagnitude, m_currentAngle };

            // Validate output measurements
            if (OutputMeasurements.Length < Enum.GetValues(typeof(Output)).Length)
            {
                throw new InvalidOperationException("Not enough output measurements were specified for the loss of field detector, expecting measurements for \"Warning Signal Status (0 = Not Signaled, 1 = Signaled)\", \"Real Power\", \"Reactive Power\" and \"Q-Area Value\" - in this order.");
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Initializes <see cref="SNRComputation"/>.
        /// </summary>
        public override void Initialize()
        {
            new ConnectionStringParser <CalculatedMesaurementAttribute>().ParseConnectionString(ConnectionString, this);

            base.Initialize();

            // Figure Output Measurement Keys
            m_dataWindow        = new Dictionary <Guid, List <double> >();
            m_refWindow         = new List <double>();
            m_outputMapping     = new Dictionary <Guid, MeasurementKey>();
            m_statisticsMapping = new Dictionary <Guid, StatisticsCollection>();
            m_saveStats         = SaveAggregates;

            if (ReportingInterval % (double)WindowLength != 0.0D)
            {
                ReportingInterval = WindowLength * (ReportingInterval / WindowLength);
                OnStatusMessage(MessageLevel.Warning, $"Adjusting Reporting Interval to every {ReportingInterval} frames.");
            }

            CategorizedSettingsElementCollection reportSettings = ConfigurationFile.Current.Settings["reportSettings"];

            reportSettings.Add("DefaultSNRThreshold", "4.0", "Default SNR Alert threshold.");
            m_threshold = reportSettings["DefaultSNRThreshold"].ValueAs(m_threshold);

            using (AdoDataConnection connection = new AdoDataConnection("systemSettings"))
            {
                TableOperations <MeasurementRecord> measurementTable = new TableOperations <MeasurementRecord>(connection);
                TableOperations <Device>            deviceTable      = new TableOperations <Device>(connection);
                TableOperations <SignalTypeRecord>  signalTable      = new TableOperations <SignalTypeRecord>(connection);

                Device device      = deviceTable.QueryRecordWhere("Acronym = {0}", ResultDeviceName);
                int    historianID = Convert.ToInt32(connection.ExecuteScalar("SELECT ID FROM Historian WHERE Acronym = {0}", new object[] { HistorianInstance }));

                if (!InputMeasurementKeys.Any())
                {
                    return;
                }

                m_nodeID = deviceTable.QueryRecordWhere("Id={0}", measurementTable.QueryRecordWhere("SignalID = {0}", InputMeasurementKeys[0].SignalID).DeviceID).NodeID;

                if (device == null)
                {
                    device = CreateDefaultDevice(deviceTable);
                    OnStatusMessage(MessageLevel.Warning, $"Default Device for Output Measurments not found. Created Device {device.Acronym}");
                }

                foreach (MeasurementKey key in InputMeasurementKeys)
                {
                    m_dataWindow.Add(key.SignalID, new List <double>());

                    string outputReference = measurementTable.QueryRecordWhere("SignalID = {0}", key.SignalID).SignalReference + "-SNR";

                    if (measurementTable.QueryRecordCountWhere("SignalReference = {0}", outputReference) > 0)
                    {
                        // Measurement Exists
                        m_outputMapping.Add(key.SignalID, MeasurementKey.LookUpBySignalID(measurementTable.QueryRecordWhere("SignalReference = {0}", outputReference).SignalID));
                    }
                    else
                    {
                        // Add Measurment to Database and make a statement
                        MeasurementRecord inMeasurement = measurementTable.QueryRecordWhere("SignalID = {0}", key.SignalID);

                        MeasurementRecord outMeasurement = new MeasurementRecord
                        {
                            HistorianID     = historianID,
                            DeviceID        = device.ID,
                            PointTag        = inMeasurement.PointTag + "-SNR",
                            AlternateTag    = inMeasurement.AlternateTag + "-SNR",
                            SignalTypeID    = signalTable.QueryRecordWhere("Acronym = {0}", "CALC").ID,
                            SignalReference = outputReference,
                            Description     = inMeasurement.Description + " SNR",
                            Enabled         = true,
                            CreatedOn       = DateTime.UtcNow,
                            UpdatedOn       = DateTime.UtcNow,
                            CreatedBy       = UserInfo.CurrentUserID,
                            UpdatedBy       = UserInfo.CurrentUserID,
                            SignalID        = Guid.NewGuid(),
                            Adder           = 0.0D,
                            Multiplier      = 1.0D
                        };

                        measurementTable.AddNewRecord(outMeasurement);

                        m_outputMapping.Add(key.SignalID, MeasurementKey.LookUpBySignalID(
                                                measurementTable.QueryRecordWhere("SignalReference = {0}", outputReference).SignalID));

                        OnStatusMessage(MessageLevel.Warning, $"Output measurment {outputReference} not found. Creating measurement");
                    }

                    if (m_saveStats)
                    {
                        m_statisticsMapping.Add(key.SignalID, CreateStatistics(measurementTable, key, device, historianID));
                    }
                }

                if (Reference == null)
                {
                    OnStatusMessage(MessageLevel.Warning, "No Reference Angle Specified");

                    int refIndex = InputMeasurementKeyTypes.IndexOf(item => item == SignalType.IPHA || item == SignalType.VPHA);

                    if (refIndex > -1)
                    {
                        Reference = InputMeasurementKeys[refIndex];
                    }
                }

                if (Reference != null)
                {
                    if (!InputMeasurementKeys.Contains(Reference))
                    {
                        InputMeasurementKeys.AddRange(new[] { Reference });
                    }
                }
            }
        }