/// <summary> /// Initializes the <see cref="AngleDifferenceCalculator"/> calculator. /// </summary> public override void Initialize() { base.Initialize(); // Validate input measurements List <MeasurementKey> validInputMeasurementKeys = new List <MeasurementKey>(); SignalType keyType; for (int i = 0; i < InputMeasurementKeys.Length; i++) { keyType = InputMeasurementKeyTypes[i]; // Make sure measurement key type is a phase angle if (keyType == SignalType.VPHA || keyType == SignalType.IPHA) { validInputMeasurementKeys.Add(InputMeasurementKeys[i]); } } // Make sure only phase angles are used as input if (validInputMeasurementKeys.Count == 0) { throw new InvalidOperationException("No valid phase angles were specified as inputs to the angle difference calculator."); } if (InputMeasurementKeyTypes.Count(s => s == SignalType.VPHA) > 0 && InputMeasurementKeyTypes.Count(s => s == SignalType.IPHA) > 0) { throw new InvalidOperationException("A mixture of voltage and current phase angles were specified as inputs to the angle difference calculator - you must specify one or the other: only voltage phase angles or only current phase angles."); } if (validInputMeasurementKeys.Count != 2) { throw new InvalidOperationException($"Expected exactly two phase angles as inputs to the angle difference calculator, got {validInputMeasurementKeys.Count}."); } InputMeasurementKeys = validInputMeasurementKeys.ToArray(); // Validate output measurements if (OutputMeasurements.Length < 1) { throw new InvalidOperationException("An output measurement was not specified for the angle difference calculator - one measurement is expected to represent the \"Calculated Angle Difference\" value."); } Dictionary <string, string> settings = Settings; string setting; if (settings.TryGetValue("AlwaysProduceResult", out setting)) { AlwaysProduceResult = setting.ParseBoolean(); } // Initialize member fields m_lastAngles = new double[2]; m_unwrapOffsets = new double[2]; m_latestCalculatedAngles = new List <double>(); // Set last angles as uninitialized m_lastAngles[0] = double.NaN; m_lastAngles[1] = double.NaN; }
/// <summary> /// Initializes the <see cref="ReferenceAngle"/> calculator. /// </summary> public override void Initialize() { base.Initialize(); // Validate input measurements List <MeasurementKey> validInputMeasurementKeys = new List <MeasurementKey>(); SignalType keyType; for (int i = 0; i < InputMeasurementKeys.Length; i++) { keyType = InputMeasurementKeyTypes[i]; // Make sure measurement key type is a phase angle if (keyType == SignalType.VPHA || keyType == SignalType.IPHA) { validInputMeasurementKeys.Add(InputMeasurementKeys[i]); } } if (validInputMeasurementKeys.Count == 0) { throw new InvalidOperationException("No valid phase angles were specified as inputs to the reference angle calculator."); } if (InputMeasurementKeyTypes.Count(s => s == SignalType.VPHA) > 0 && InputMeasurementKeyTypes.Count(s => s == SignalType.IPHA) > 0) { throw new InvalidOperationException("A mixture of voltage and current phase angles were specified as inputs to the reference angle calculator - you must specify one or the other: only voltage phase angles or only current phase angles."); } // Make sure only phase angles are used as input InputMeasurementKeys = validInputMeasurementKeys.ToArray(); // Validate output measurements if (OutputMeasurements.Length < 1) { throw new InvalidOperationException("An output measurement was not specified for the reference angle calculator - one measurement is expected to represent the \"Calculated Reference Angle\" value."); } // Initialize member fields m_lastAngles = new Dictionary <MeasurementKey, double>(); m_unwrapOffsets = new Dictionary <MeasurementKey, double>(); m_latestCalculatedAngles = new List <double>(); m_phaseResetAngle = MinimumMeasurementsToUse * 360.0D; }
/// <summary> /// Initializes the <see cref="ReferenceMagnitude"/> calculator. /// </summary> public override void Initialize() { base.Initialize(); // Validate input measurements List <MeasurementKey> validInputMeasurementKeys = new List <MeasurementKey>(); SignalType keyType; for (int i = 0; i < InputMeasurementKeys.Length; i++) { keyType = InputMeasurementKeyTypes[i]; // Make sure measurement key type is a phase magnitude if (keyType == SignalType.VPHM || keyType == SignalType.IPHM) { validInputMeasurementKeys.Add(InputMeasurementKeys[i]); } } if (validInputMeasurementKeys.Count == 0) { throw new InvalidOperationException("No valid phase magnitudes were specified as inputs to the reference magnitude calculator."); } if (InputMeasurementKeyTypes.Count(s => s == SignalType.VPHM) > 0 && InputMeasurementKeyTypes.Count(s => s == SignalType.IPHM) > 0) { throw new InvalidOperationException("A mixture of voltage and current phase magnitudes were specified as inputs to the reference magnitude calculator - you must specify one or the other: only voltage phase magnitudes or only current phase magnitudes."); } // Make sure only phase magnitudes are used as input InputMeasurementKeys = validInputMeasurementKeys.ToArray(); // Validate output measurements if (OutputMeasurements.Length < 1) { throw new InvalidOperationException("An output measurement was not specified for the reference magnitude calculator - one measurement is expected to represent the \"Calculated Reference Magnitude\" value."); } }
/// <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."); } }
/// <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 }); } } } }