Beispiel #1
0
        protected int GetUDTArrayTypeMappingCount(ArrayMapping arrayMapping)
        {
            // UDT[] where each array element is the same mapping, but represent different times
            if (arrayMapping.WindowSize != 0.0M)
            {
                MeasurementKey[] keys;
                AlignmentCoordinator.SampleWindow sampleWindow = GetSampleWindow(arrayMapping, out keys);

                m_lastKeyIndex  = m_keyIndex;
                m_cachedMapping = GetTypeMapping(arrayMapping);
                m_cachedFrames  = AlignmentCoordinator.GetFrames(keys, CurrentFrameTime, sampleWindow);

                return(m_cachedFrames.Count);
            }

            // UDT[] where each array element is the same time (relative to now), but represent different mappings
            if (arrayMapping.RelativeTime != 0.0M)
            {
                MeasurementKey[] keys;
                AlignmentCoordinator.SampleWindow sampleWindow = GetSampleWindow(arrayMapping, out keys);

                CurrentFrame     = AlignmentCoordinator.GetFrame(keys, CurrentFrameTime, sampleWindow);
                m_cachedMappings = MappingCompiler.EnumerateTypeMappings(arrayMapping.Expression).ToArray();

                return(m_cachedMappings.Length);
            }

            // UDT[] where each array element is the same time, but represent different mappings
            m_cachedMappings = MappingCompiler.EnumerateTypeMappings(arrayMapping.Expression).ToArray();

            return(m_cachedMappings.Length);
        }
Beispiel #2
0
        protected AlignmentCoordinator.SampleWindow CreateSampleWindow(ArrayMapping arrayMapping)
        {
            decimal  relativeTime = arrayMapping.RelativeTime;
            TimeSpan relativeUnit = arrayMapping.RelativeUnit;
            decimal  sampleRate   = arrayMapping.SampleRate;
            TimeSpan sampleUnit   = arrayMapping.SampleUnit;
            decimal  windowSize   = arrayMapping.WindowSize;
            TimeSpan windowUnit   = arrayMapping.WindowUnit;

            // Collection with no time window
            if (windowSize == 0.0M)
            {
                return(CreateSampleWindow((FieldMapping)arrayMapping));
            }

            // No relative time indicates that the relative
            // time is actually equal to the window size
            //  Ex: last 5 seconds
            if (relativeTime == 0.0M)
            {
                relativeTime = windowSize;
                relativeUnit = windowUnit;
            }

            return(AlignmentCoordinator.CreateSampleWindow(relativeTime, relativeUnit, sampleRate, sampleUnit, windowSize, windowUnit));
        }
Beispiel #3
0
        protected List <MetaValues> CreateMetaValues(ArrayMapping arrayMapping)
        {
            MeasurementKey[] keys = m_keys[m_keyIndex++];

            if (arrayMapping.WindowSize != 0.0M)
            {
                AlignmentCoordinator.SampleWindow sampleWindow = CreateSampleWindow(arrayMapping);
                MeasurementKey key = keys.Single();
                return(AlignmentCoordinator.CreateMetaValues(key, m_currentFrameTime, sampleWindow));
            }

            if (arrayMapping.RelativeTime != 0.0M)
            {
                AlignmentCoordinator.SampleWindow sampleWindow = CreateSampleWindow(arrayMapping);

                return(keys
                       .Select(key => AlignmentCoordinator.CreateMetaValue(key, m_currentFrameTime, sampleWindow))
                       .ToList());
            }

            return(keys
                   .Select(key => new MetaValues()
            {
                ID = key.SignalID,
                Timestamp = m_currentFrameTime,
                Flags = MeasurementFlags.CalculatedValue
            })
                   .ToList());
        }
Beispiel #4
0
        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);
        }
Beispiel #5
0
        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));
        }
Beispiel #6
0
        /// <summary>
        /// Creates a sample window defined by the given field mapping.
        /// </summary>
        /// <param name="fieldMapping">The mapping that defines the parameters for the sample window.</param>
        /// <returns>The sample window defined by the given field mapping.</returns>
        protected AlignmentCoordinator.SampleWindow CreateSampleWindow(FieldMapping fieldMapping)
        {
            decimal  relativeTime = fieldMapping.RelativeTime;
            TimeSpan relativeUnit = fieldMapping.RelativeUnit;
            decimal  sampleRate   = fieldMapping.SampleRate;
            TimeSpan sampleUnit   = fieldMapping.SampleUnit;

            return(AlignmentCoordinator.CreateSampleWindow(relativeTime, relativeUnit, sampleRate, sampleUnit));
        }
Beispiel #7
0
        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()));
        }
Beispiel #8
0
        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);
        }
Beispiel #9
0
        protected MetaValues CreateMetaValues(FieldMapping fieldMapping)
        {
            if (fieldMapping.RelativeTime != 0.0M)
            {
                AlignmentCoordinator.SampleWindow sampleWindow = CreateSampleWindow(fieldMapping);
                MeasurementKey key = m_keys[m_keyIndex++].Single();
                return(AlignmentCoordinator.CreateMetaValue(key, CurrentFrameTime, sampleWindow));
            }

            return(new MetaValues()
            {
                ID = m_keys[m_keyIndex++].Single().SignalID,
                Timestamp = m_currentFrameTime,
                Flags = MeasurementFlags.CalculatedValue
            });
        }
Beispiel #10
0
        /// <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;
        }
Beispiel #11
0
        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);
        }
Beispiel #12
0
 protected IDictionary <MeasurementKey, IMeasurement> GetRelativeFrame(FieldMapping fieldMapping)
 {
     MeasurementKey[] keys = m_timeWindowKeys[m_timeWindowKeyIndex++];
     AlignmentCoordinator.SampleWindow sampleWindow = CreateSampleWindow(fieldMapping);
     return(AlignmentCoordinator.GetFrame(keys, CurrentFrameTime, sampleWindow));
 }
Beispiel #13
0
 protected List <IDictionary <MeasurementKey, IMeasurement> > GetWindowFrames(ArrayMapping arrayMapping)
 {
     MeasurementKey[] keys = m_timeWindowKeys[m_timeWindowKeyIndex++];
     AlignmentCoordinator.SampleWindow sampleWindow = CreateSampleWindow(arrayMapping);
     return(AlignmentCoordinator.GetFrames(keys, CurrentFrameTime, sampleWindow));
 }