Files

80 lines
3.1 KiB
C#
Raw Permalink Normal View History

2026-04-17 14:55:32 -04:00
using System;
using System.Collections.Generic;
using System.Linq;
using DTS.Common.DAS.Concepts;
namespace DTS.Serialization
{
/// <summary>
/// A collection of a channel and associated metadata that will all be needed together when
/// this file format starts laying down bytes.
/// </summary>
public class ChannelWithMeta
{
/// <summary>
/// Get/set the <see cref="DTS.Serialization.Test.Module.Channel"/> to be serialized.
/// </summary>
public Test.Module.Channel Channel { get; }
/// <summary>
/// Get/set the <see cref="DataScaler"/> associated with the
/// specified channel.
/// </summary>
public DataScaler Scaler { get; }
/// <summary>
/// Get/set the <see cref="double"/> sample rate associated with the specified channel.
/// </summary>
public double SampleRate { get; }
/// <summary>
/// Get/set the <see cref="double"/> start time associated with the specified channel.
/// </summary>
public double StartTime { get; }
/// <summary>
/// Initialize an instance of the ChannelWithMeta class.
/// </summary>
///
/// <param name="channel">
/// A <see cref="DTS.Serialization.Test.Module.Channel"/> to be serialized.
/// </param>
///
/// <param name="scaler">
/// The <see cref="DataScaler"/> containing scaling information for
/// the specified channel.
/// </param>
///
/// <param name="samplerate">
/// The <see cref="double"/> sample rate of the associated channel.
/// </param>
///
/// <param name="starttime">
/// The <see cref="double"/> start time of the associated channel.
/// </param>
///
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<ChannelWithMeta> 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<ChannelWithMeta> 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));
}
}
}