protected AlignmentCoordinator.SampleWindow GetSampleWindow(ArrayMapping arrayMapping, out MeasurementKey[] keys) { IEnumerable <FieldMapping> signalMappings = MappingCompiler.TraverseSignalMappings(arrayMapping); keys = signalMappings.SelectMany(mapping => SignalLookup.GetMeasurementKeys(mapping.Expression)).ToArray(); return(CreateSampleWindow(arrayMapping)); }
protected IMeasurement GetMeasurement(FieldMapping fieldMapping) { IMeasurement measurement; if (fieldMapping.RelativeTime != 0.0M) { AlignmentCoordinator.SampleWindow sampleWindow = CreateSampleWindow(fieldMapping); MeasurementKey key = m_keys[m_keyIndex++].Single(); measurement = AlignmentCoordinator.GetMeasurement(key, CurrentFrameTime, sampleWindow); } else { measurement = SignalLookup.GetMeasurement(m_keys[m_keyIndex++].Single()); } // Set OverRangeError flag if the value of the measurement is NaN and the // destination field's type does not support NaN; this will set the UnreasonableValue // flag in the ECA MeasurementFlags of the MetaValues structure if (IsNaNOrInfinity(measurement.Value) && s_nonNanTypes.Contains($"{fieldMapping.Field.Type.Category}.{fieldMapping.Field.Type.Identifier}")) { measurement = new Measurement() { Metadata = measurement.Metadata, Timestamp = measurement.Timestamp, Value = 0.0D, StateFlags = measurement.StateFlags | MeasurementStateFlags.OverRangeError }; } return(measurement); }
void IMapper.CrunchMetadata(DataSet metadata) { m_metadataCache = metadata; SignalLookup.CrunchMetadata(metadata); TypeMapping inputMapping = m_mappingCompiler.GetTypeMapping(m_inputMapping); BuildMeasurementKeys(inputMapping); BuildTimeWindowKeys(inputMapping); BuildMappingCollections(inputMapping); m_unmapper.CrunchMetadata(metadata); m_mappingRetentionTimes = BuildRetentionTimes(inputMapping); UpdateRetentionTimes(); FixSignalBuffers(); IEnumerable <Guid> filterIDs = m_keys .SelectMany(keys => keys) .Concat(m_retentionTimes.Keys) .Select(key => key.SignalID) .Distinct(); m_filterExpression = string.Join(";", filterIDs); }
private void BuildMeasurementKeys(TypeMapping inputMapping) { foreach (FieldMapping fieldMapping in inputMapping.FieldMappings) { DataType fieldType = fieldMapping.Field.Type; DataType underlyingType = (fieldType as ArrayType)?.UnderlyingType; // ReSharper disable once PossibleNullReferenceException if (fieldType.IsArray && underlyingType.IsUserDefined) { m_mappingCompiler.EnumerateTypeMappings(fieldMapping.Expression).ToList().ForEach(BuildMeasurementKeys); } else if (fieldType.IsUserDefined) { BuildMeasurementKeys(m_mappingCompiler.GetTypeMapping(fieldMapping.Expression)); } else if (fieldType.IsArray) { m_keys.Add(SignalLookup.GetMeasurementKeys(fieldMapping.Expression)); } else { m_keys.Add(new[] { SignalLookup.GetMeasurementKey(fieldMapping.Expression) }); } } }
protected Ticks GetRelativeFrameTime(FieldMapping fieldMapping) { IEnumerable <FieldMapping> signalMappings = m_mappingCompiler.TraverseSignalMappings(fieldMapping); MeasurementKey[] keys = signalMappings.SelectMany(mapping => SignalLookup.GetMeasurementKeys(mapping.Expression)).ToArray(); AlignmentCoordinator.SampleWindow sampleWindow = CreateSampleWindow(fieldMapping); return(sampleWindow.GetTimestamps(CurrentFrameTime).FirstOrDefault()); }
protected IDictionary <MeasurementKey, IMeasurement> GetRelativeFrame(FieldMapping fieldMapping) { IEnumerable <FieldMapping> signalMappings = MappingCompiler.TraverseSignalMappings(fieldMapping); MeasurementKey[] keys = signalMappings.SelectMany(mapping => SignalLookup.GetMeasurementKeys(mapping.Expression)).ToArray(); AlignmentCoordinator.SampleWindow sampleWindow = CreateSampleWindow(fieldMapping); return(AlignmentCoordinator.GetFrame(keys, CurrentFrameTime, sampleWindow)); }
public override void Map(IDictionary <MeasurementKey, IMeasurement> measurements) { m_index = 0; SignalLookup.UpdateMeasurementLookup(measurements); TypeMapping inputMapping = MappingCompiler.GetTypeMapping(InputMapping); Real_Time_Calculator.Model.VT.VI_pair input = CreateVTVI_pair(inputMapping); Real_Time_Calculator.Model.VT.Line_parameters output = Algorithm.Execute(input); // TODO: Later versions will publish output to the openECA server }
public override void Map(IDictionary <MeasurementKey, IMeasurement> measurements) { SignalLookup.UpdateMeasurementLookup(measurements); TypeMapping inputMapping = MappingCompiler.GetTypeMapping(InputMapping); TVA_LSETestHarness.Model.ECA.PhasorCollection inputData = CreateECAPhasorCollection(inputMapping); KeyIndex = 0; TVA_LSETestHarness.Model.ECA._PhasorCollectionMeta inputMeta = CreateECA_PhasorCollectionMeta(inputMapping); Algorithm.Output algorithmOutput = Algorithm.Execute(inputData, inputMeta); Subscriber.SendMeasurements(m_unmapper.Unmap(algorithmOutput.OutputData, algorithmOutput.OutputMeta)); }
protected IMeasurement GetMeasurement(FieldMapping fieldMapping) { if (fieldMapping.RelativeTime != 0.0M) { AlignmentCoordinator.SampleWindow sampleWindow = CreateSampleWindow(fieldMapping); MeasurementKey key = Keys[m_keyIndex++].Single(); return(AlignmentCoordinator.GetMeasurement(key, CurrentFrameTime, sampleWindow)); } return(SignalLookup.GetMeasurement(Keys[m_keyIndex++].Single())); }
public override void Map(IDictionary <MeasurementKey, IMeasurement> measurements) { SignalLookup.UpdateMeasurementLookup(measurements); TypeMapping inputMapping = MappingCompiler.GetTypeMapping(InputMapping); LVC.Model.test.Input inputData = CreatetestInput(inputMapping); KeyIndex = 0; LVC.Model.test._InputMeta inputMeta = Createtest_InputMeta(inputMapping); Algorithm.Output algorithmOutput = Algorithm.Execute(inputData, inputMeta); // TODO: Later versions will publish output to the openECA server }
public override void Map(IDictionary <MeasurementKey, IMeasurement> measurements) { SignalLookup.UpdateMeasurementLookup(measurements); TypeMapping inputMapping = MappingCompiler.GetTypeMapping(InputMapping); Reset(); Beta_Application_CTPT_LineZ.Model.GPA.Measurement_set inputData = CreateGPAMeasurement_set(inputMapping); Reset(); Beta_Application_CTPT_LineZ.Model.GPA._Measurement_setMeta inputMeta = CreateGPA_Measurement_setMeta(inputMapping); Algorithm.Output algorithmOutput = Algorithm.Execute(inputData, inputMeta); Subscriber.SendMeasurements(m_unmapper.Unmap(algorithmOutput.OutputData, algorithmOutput.OutputMeta)); }
public override void Map(IDictionary <MeasurementKey, IMeasurement> measurements) { SignalLookup.UpdateMeasurementLookup(measurements); TypeMapping inputMapping = MappingCompiler.GetTypeMapping(InputMapping); Reset(); LVC118.Model.LVC118Data.Inputs inputData = CreateLVC118DataInputs(inputMapping); Reset(); LVC118.Model.LVC118Data._InputsMeta inputMeta = CreateLVC118Data_InputsMeta(inputMapping); Algorithm.Output algorithmOutput = Algorithm.Execute(inputData, inputMeta); Subscriber.SendMeasurements(m_unmapper.Unmap(algorithmOutput.OutputData, algorithmOutput.OutputMeta)); }
public override void Map(IDictionary <MeasurementKey, IMeasurement> measurements) { SignalLookup.UpdateMeasurementLookup(measurements); TypeMapping inputMapping = MappingCompiler.GetTypeMapping(InputMapping); LseTestHarness.Model.ECA.PhasorCollection inputData = CreateECAPhasorCollection(inputMapping); KeyIndex = 0; LseTestHarness.Model.ECA._PhasorCollectionMeta inputMeta = CreateECA_PhasorCollectionMeta(inputMapping); MainWindow.WriteMessage("Executing.."); Algorithm.Output algorithmOutput = Algorithm.Execute(inputData, inputMeta); // TODO: Later versions will publish output to the openECA server }
static void Main() { SignalLookup lookup = new SignalLookup(); IMapper mapper = new Mapper(lookup); Algorithm.UpdateSystemSettings(); Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); MainWindow mainWindow = new MainWindow(mapper); mainWindow.Text = "C# Real_Time_Calculator Test Harness"; Application.Run(mainWindow); }
protected int GetArrayMeasurementCount(ArrayMapping arrayMapping) { Lazy <bool> isNanType = new Lazy <bool>(() => { DataType underlyingType = (arrayMapping.Field.Type as ArrayType)?.UnderlyingType; return(!s_nonNanTypes.Contains($"{underlyingType?.Category}.{underlyingType?.Identifier}")); }); // Set OverRangeError flag if the value of the measurement is NaN and the // destination field's type does not support NaN; this will set the UnreasonableValue // flag in the ECA MeasurementFlags of the MetaValues structure Func <IMeasurement, IMeasurement> toNotNan = measurement => new Measurement() { Metadata = measurement.Metadata, Timestamp = measurement.Timestamp, Value = 0.0D, StateFlags = measurement.StateFlags | MeasurementStateFlags.OverRangeError }; if (arrayMapping.WindowSize != 0.0M) { // native[] where each array element is the same mapping, but represent different times AlignmentCoordinator.SampleWindow sampleWindow = CreateSampleWindow(arrayMapping); m_cachedMeasurements = AlignmentCoordinator .GetMeasurements(m_keys[m_keyIndex++].Single(), CurrentFrameTime, sampleWindow) .Select(measurement => (!IsNaNOrInfinity(measurement.Value) || isNanType.Value) ? measurement : toNotNan(measurement)) .ToArray(); } else if (arrayMapping.RelativeTime != 0.0M) { // native[] where each array element is the same time (relative to now), but represent different mappings AlignmentCoordinator.SampleWindow sampleWindow = CreateSampleWindow(arrayMapping); m_cachedMeasurements = m_keys[m_keyIndex++] .Select(key => AlignmentCoordinator.GetMeasurement(key, CurrentFrameTime, sampleWindow)) .Select(measurement => (!IsNaNOrInfinity(measurement.Value) || isNanType.Value) ? measurement : toNotNan(measurement)) .ToArray(); } else { // native[] where each array element is the same time, but represent different mappings m_cachedMeasurements = SignalLookup.GetMeasurements(m_keys[m_keyIndex++]) .Select(measurement => (!IsNaNOrInfinity(measurement.Value) || isNanType.Value) ? measurement : toNotNan(measurement)) .ToArray(); } return(m_cachedMeasurements.Length); }
/// <summary> /// Creates a new <see cref="MapperBase"/>. /// </summary> /// <param name="framework">Container object for framework elements.</param> /// <param name="inputMapping">Input mapping name.</param> protected MapperBase(Framework framework, string inputMapping) { m_signalLookup = framework.SignalLookup; m_alignmentCoordinator = framework.AlignmentCoordinator; m_signalBuffers = framework.SignalBuffers; UDTCompiler udtCompiler = new UDTCompiler(); m_mappingCompiler = new MappingCompiler(udtCompiler); udtCompiler.Compile(Path.Combine("Model", "UserDefinedTypes.ecaidl")); m_mappingCompiler.Compile(Path.Combine("Model", "UserDefinedMappings.ecamap")); m_keys = new List <MeasurementKey[]>(); m_readonlyKeys = m_keys.AsReadOnly(); m_inputMapping = inputMapping; }
//public override void Map(IDictionary<MeasurementKey, IMeasurement> measurements) //{ // SignalLookup.UpdateMeasurementLookup(measurements); // TypeMapping inputMapping = MappingCompiler.GetTypeMapping(InputMapping); // Phasor inputData = CreateECAPhasor(inputMapping); // KeyIndex = 0; // _PhasorMeta inputMeta = CreateECA_PhasorMeta(inputMapping); // Analytic.InputData = inputData; // Analytic.InputMeta = inputMeta; // Analytic.TakeSample(); // (Analytic.Host as IAlgorithmHost).SpecialStatus = $"Processing {inputData.Magnitude}"; // Algorithm.Output algorithmOutput = Algorithm.Execute(inputData, inputMeta); // Subscriber.SendMeasurements(m_unmapper.Unmap(algorithmOutput.OutputData, algorithmOutput.OutputMeta)); //} #region [ Methods ] public override void Map(IDictionary <MeasurementKey, IMeasurement> measurements) { SignalLookup.UpdateMeasurementLookup(measurements); TypeMapping inputMapping = MappingCompiler.GetTypeMapping(InputMapping); Reset(); Input inputData = CreateLSEInput(inputMapping); Reset(); _InputMeta inputMeta = CreateLSE_InputMeta(inputMapping); Analytic.InputData = inputData; Analytic.InputMeta = inputMeta; Analytic.Execute(); Algorithm.Output algorithmOutput = Algorithm.Execute(inputData, inputMeta); Subscriber.SendMeasurements(m_unmapper.Unmap(algorithmOutput.OutputData, algorithmOutput.OutputMeta)); }
private void BuildRetentionTimes(IDictionary <MeasurementKey, TimeSpan> retentionTimes, TypeMapping typeMapping, TimeSpan parentRetention) { foreach (FieldMapping fieldMapping in typeMapping.FieldMappings) { TimeSpan retentionTime = TimeSpan.Zero; if (fieldMapping.RelativeTime != 0) { retentionTime = GetRetentionTime(fieldMapping); } else if (fieldMapping.Field.Type.IsArray && ((ArrayMapping)fieldMapping).WindowSize != 0) { retentionTime = GetRetentionTime((ArrayMapping)fieldMapping); } if (retentionTime != TimeSpan.Zero && parentRetention != TimeSpan.Zero) { throw new NotSupportedException($"Detected nested buffering while processing mapping with identifier '{typeMapping.Identifier}'."); } else if (retentionTime == TimeSpan.Zero) { retentionTime = parentRetention; } DataType fieldType = fieldMapping.Field.Type; DataType underlyingType = (fieldType as ArrayType)?.UnderlyingType; if ((underlyingType ?? fieldType).IsUserDefined) { foreach (TypeMapping nestedMapping in m_mappingCompiler.EnumerateTypeMappings(fieldMapping.Expression)) { BuildRetentionTimes(retentionTimes, nestedMapping, retentionTime); } } else if (retentionTime != TimeSpan.Zero) { foreach (MeasurementKey key in SignalLookup.GetMeasurementKeys(fieldMapping.Expression)) { retentionTimes.AddOrUpdate(key, k => retentionTime, (k, time) => (time > retentionTime) ? time : retentionTime); } } } }
protected int GetArrayMeasurementCount(ArrayMapping arrayMapping) { if (arrayMapping.WindowSize != 0.0M) { // native[] where each array element is the same mapping, but represent different times AlignmentCoordinator.SampleWindow sampleWindow = CreateSampleWindow(arrayMapping); m_cachedMeasurements = AlignmentCoordinator.GetMeasurements(Keys[m_keyIndex++].Single(), CurrentFrameTime, sampleWindow).ToArray(); } else if (arrayMapping.RelativeTime != 0.0M) { // native[] where each array element is the same time (relative to now), but represent different mappings AlignmentCoordinator.SampleWindow sampleWindow = CreateSampleWindow(arrayMapping); m_cachedMeasurements = Keys[m_keyIndex++].Select(key => AlignmentCoordinator.GetMeasurement(key, CurrentFrameTime, sampleWindow)).ToArray(); } else { // native[] where each array element is the same time, but represent different mappings m_cachedMeasurements = SignalLookup.GetMeasurements(Keys[m_keyIndex++]); } return(m_cachedMeasurements.Length); }
private Real_Time_Calculator.Model.VT.VI_pair CreateVTVI_pair(TypeMapping typeMapping) { Dictionary <string, FieldMapping> fieldLookup = typeMapping.FieldMappings.ToDictionary(fieldMapping => fieldMapping.Field.Identifier); Real_Time_Calculator.Model.VT.VI_pair obj = new Real_Time_Calculator.Model.VT.VI_pair(); obj.From_bus_Voltage_Mag = (double)SignalLookup.GetMeasurement(Keys[m_index++][0]).Value; obj.From_bus_Voltage_Ang = (double)SignalLookup.GetMeasurement(Keys[m_index++][0]).Value; obj.From_bus_Current_Mag = (double)SignalLookup.GetMeasurement(Keys[m_index++][0]).Value; obj.From_bus_Current_Ang = (double)SignalLookup.GetMeasurement(Keys[m_index++][0]).Value; obj.To_bus_Voltage_Mag = (double)SignalLookup.GetMeasurement(Keys[m_index++][0]).Value; obj.To_bus_Voltage_Ang = (double)SignalLookup.GetMeasurement(Keys[m_index++][0]).Value; obj.To_bus_Current_Mag = (double)SignalLookup.GetMeasurement(Keys[m_index++][0]).Value; obj.To_bus_Current_Ang = (double)SignalLookup.GetMeasurement(Keys[m_index++][0]).Value; return(obj); }
private void BuildTimeWindowKeys(TypeMapping inputMapping) { foreach (FieldMapping fieldMapping in inputMapping.FieldMappings) { ArrayMapping arrayMapping = fieldMapping as ArrayMapping; DataType fieldType = fieldMapping.Field.Type; DataType underlyingType = (fieldType as ArrayType)?.UnderlyingType; Action addTimeWindowKeys = () => { IEnumerable <FieldMapping> signalMappings = MappingCompiler.TraverseSignalMappings(arrayMapping); MeasurementKey[] keys = signalMappings.SelectMany(mapping => SignalLookup.GetMeasurementKeys(mapping.Expression)).ToArray(); m_timeWindowKeys.Add(keys); }; // ReSharper disable once PossibleNullReferenceException if (fieldType.IsArray && underlyingType.IsUserDefined && (arrayMapping.WindowSize != 0.0M || arrayMapping.RelativeTime != 0.0M)) { addTimeWindowKeys(); } else if (fieldType.IsArray && underlyingType.IsUserDefined) { m_mappingCompiler.EnumerateTypeMappings(fieldMapping.Expression).ToList().ForEach(BuildTimeWindowKeys); } else if (fieldType.IsUserDefined) { BuildTimeWindowKeys(m_mappingCompiler.GetTypeMapping(fieldMapping.Expression)); } } }
public Mapper(SignalLookup lookup) { m_lookup = lookup; }
public Mapper(SignalLookup lookup) : base(lookup, "VI_data") { }