using System;
using System.Collections.Generic;
using System.Linq;
using DTS.Common.DAS.Concepts;
namespace DTS.Serialization
{
///
/// A collection of a channel and associated metadata that will all be needed together when
/// this file format starts laying down bytes.
///
public class ChannelWithMeta
{
///
/// Get/set the to be serialized.
///
public Test.Module.Channel Channel { get; }
///
/// Get/set the associated with the
/// specified channel.
///
public DataScaler Scaler { get; }
///
/// Get/set the sample rate associated with the specified channel.
///
public double SampleRate { get; }
///
/// Get/set the start time associated with the specified channel.
///
public double StartTime { get; }
///
/// Initialize an instance of the ChannelWithMeta class.
///
///
///
/// A to be serialized.
///
///
///
/// The containing scaling information for
/// the specified channel.
///
///
///
/// The sample rate of the associated channel.
///
///
///
/// The start time of the associated channel.
///
///
public ChannelWithMeta(DTS.Serialization.Test.Module.Channel channel, DataScaler scaler, double samplerate, double starttime)
{
Channel = channel;
Scaler = scaler;
SampleRate = samplerate;
StartTime = starttime;
}
public static double GetMinStartTime(double start, IList channelsWithMeta)
{
// Start is a generally a negative value, so to get the value for the start time of the minimum common data set, run Max()
return Math.Max(start, channelsWithMeta.Min(cwm => cwm.StartTime));
}
public static double GetMinStopTime(double stop, IList channelsWithMeta)
{
// To get the value for the stop time of the minimum common data set, run Min()
// LINQ statement will sometimes hand back float-rounding error numbers (4.999999999999995 v 5.0), so cast to decimals.
return (double)Math.Min((decimal)stop,
channelsWithMeta.Min(cwm =>
(decimal)cwm.StartTime + (cwm.Channel.PersistentChannelInfo.Length - 1) * 1m / (decimal)cwm.SampleRate));
}
}
}