Пример #1
0
            /// <summary>
            /// Aligns data from the given signal buffer to the appropriate samples
            /// in the sample window and fills in with null where data is missing.
            /// </summary>
            /// <param name="signalBuffer">The signal buffer that contains the data to be aligned.</param>
            /// <param name="frameTime">The time of the frame that defines the current sample window.</param>
            /// <returns>Data from the signal buffer aligned to the appropriate samples in the sample window.</returns>
            public List <IMeasurement> AlignFill(SignalBuffer signalBuffer, Ticks frameTime)
            {
                List <IMeasurement> window = new List <IMeasurement>(m_windowSize);
                Ticks startTime            = ((DateTime)frameTime) - m_frameOffset;
                Ticks maxDiff = (m_startOffset.Ticks / m_windowSize) / 2;

                for (int i = 0; i < m_windowSize; i++)
                {
                    TimeSpan     startOffset        = TimeSpan.FromTicks(m_startOffset.Ticks * i / m_windowSize);
                    Ticks        targetTimestamp    = ((DateTime)startTime) + startOffset;
                    IMeasurement nearestMeasurement = signalBuffer.GetNearestMeasurement(targetTimestamp);
                    Ticks        diff = Math.Abs(nearestMeasurement.Timestamp - targetTimestamp);

                    if (diff <= maxDiff)
                    {
                        window.Add(nearestMeasurement);
                    }
                    else
                    {
                        window.Add(null);
                    }
                }

                return(window);
            }
Пример #2
0
 /// <summary>
 /// Aligns data from the given signal buffer to the nearest samples in the sample window.
 /// </summary>
 /// <param name="signalBuffer">The signal buffer that contains the data to be aligned.</param>
 /// <param name="frameTime">The time of the frame that defines the current sample window.</param>
 /// <returns>Data from the signal buffer aligned to the nearest samples in the sample window.</returns>
 public List <IMeasurement> AlignNearest(SignalBuffer signalBuffer, Ticks frameTime)
 {
     return(GetTimestamps(frameTime)
            .Select(Timestamp => new { Timestamp, Measurement = signalBuffer.GetNearestMeasurement(Timestamp) })
            .Where(obj => (object)obj.Measurement != null)
            .Select(obj => ChangeTimestamp(obj.Measurement, obj.Timestamp))
            .ToList());
 }
Пример #3
0
            /// <summary>
            /// Aligns data from the given signal buffer to the nearest samples in the sample window.
            /// </summary>
            /// <param name="signalBuffer">The signal buffer that contains the data to be aligned.</param>
            /// <param name="frameTime">The time of the frame that defines the current sample window.</param>
            /// <returns>Data from the signal buffer aligned to the nearest samples in the sample window.</returns>
            public List <IMeasurement> AlignNearest(SignalBuffer signalBuffer, Ticks frameTime)
            {
                List <IMeasurement> window = new List <IMeasurement>(m_windowSize);
                Ticks startTime            = ((DateTime)frameTime) - m_frameOffset;

                for (int i = 0; i < m_windowSize; i++)
                {
                    TimeSpan     startOffset        = TimeSpan.FromTicks(m_startOffset.Ticks * i / m_windowSize);
                    Ticks        targetTimestamp    = ((DateTime)startTime) + startOffset;
                    IMeasurement nearestMeasurement = signalBuffer.GetNearestMeasurement(targetTimestamp);

                    window.Add(nearestMeasurement);
                }

                return(window);
            }
Пример #4
0
            /// <summary>
            /// Aligns data from the given signal buffer to the appropriate samples
            /// in the sample window and fills in with null where data is missing.
            /// </summary>
            /// <param name="signalBuffer">The signal buffer that contains the data to be aligned.</param>
            /// <param name="frameTime">The time of the frame that defines the current sample window.</param>
            /// <returns>Data from the signal buffer aligned to the appropriate samples in the sample window.</returns>
            public List <IMeasurement> AlignFill(SignalBuffer signalBuffer, Ticks frameTime)
            {
                Ticks maxDiff = (m_startOffset.Ticks / m_windowSize) / 2;

                return(GetTimestamps(frameTime)
                       .Select(Timestamp => new { Timestamp, Measurement = signalBuffer.GetNearestMeasurement(Timestamp) })
                       .Where(obj => (object)obj.Measurement != null)
                       .Select(obj =>
                {
                    Ticks timestamp = obj.Timestamp;
                    IMeasurement nearestMeasurement = obj.Measurement;
                    Ticks diff = Math.Abs(nearestMeasurement.Timestamp - timestamp);

                    return (diff <= maxDiff) ? nearestMeasurement : new Measurement()
                    {
                        Metadata = signalBuffer.Key.Metadata,
                        Timestamp = timestamp,
                        Value = double.NaN,
                        StateFlags = MeasurementStateFlags.UpSampled
                    };
                })
                       .ToList());
            }