using System; using System.Collections.Generic; using System.Linq; using DTS.Common.Interface.DASFactory.Diagnostics; using DTS.Common.SerializationPlus; using DTS.Common.Utilities; namespace DTS.Slice.Control { // *** see DTS.Slice.Control.Event.cs *** public partial class Event { // *** see DTS.Slice.Control.Event.Module.cs *** public partial class Module { public partial class Channel { public abstract class CalculatedChannel : Channel, Common.DAS.Concepts.DAS.Channel.IEngineeringUnitAware { public enum Operation { Integral, //DefiniteIntegral, Derivative, HeadInjuryCriteria, FFT, ImportedCSV, Resultant, TSR, Scale, Offset, Sine, Cosine, } private readonly Operation _operation; public Operation CalculationType => _operation; private readonly List _x = new List(); public double[] X => _x.ToArray(); private readonly List _y = new List(); public double[] Y => _y.ToArray(); private readonly XUnits _xAxis; public XUnits XAxis => _xAxis; public string XUnitsString { get { switch (_xAxis) { case XUnits.Hz: return "Hz"; case XUnits.msec: return "ms"; case XUnits.samples: return "samples"; case XUnits.sec: return "s"; default: return "N/A"; } } } private string _yAxis; public string EngineeringUnits { get => _yAxis; set => _yAxis = value; } public override bool SupportsADC => false; public override bool SupportsEU => true; public override bool SupportsmV => false; public override double ActualMaxRangeEu => _y.Max(); public override double ActualMaxRangeMv => throw new NotSupportedException(); public override double ActualMinRangeEu => _y.Min(); public override double ActualMinRangeMv => throw new NotImplementedException(); public override double DataHalfRangeValueEu => .5D * (_y.Min() + _y.Max()); public override double DataMaxEu => _y.Max(); public override double DataMinEu => _y.Min(); public override double DataRangeEu => (Math.Max(Math.Abs(_y.Min()), Math.Abs(_y.Max()))); public override short DataZeroLevelAdc => 0; public override bool IsConfigured { get => true; set => throw new NotSupportedException(); } public override void FromDtsSerializationTestModuleChannel(Serialization.Test.Module.Channel that) { throw new NotSupportedException(); } public override List GetUnfilteredDataEu() { return new List(_y); } /* protected override void InitializeReviewableAttributes(List reviewableAttributes) { switch (CalculationType) { case Operation.HeadInjuryCriteria: break; case Operation.ImportedCSV: break; case Operation.TSR: break; } } */ public override void SetPropertyValuesFrom(DASLib.Service.DASChannel dasChannel) { throw new NotSupportedException(); } public override void SetPropertyValuesFrom(IDiagnosticResult diagResults) { throw new NotSupportedException(); } public override Serialization.Test.Module.Channel ToDtsSerializationTestModuleChannel(Serialization.Test.Module parentModule) { throw new NotSupportedException(); } public override double SensorCapacityEU => throw new NotImplementedException(); public override List GetUnfilteredDataMV() { throw new NotImplementedException(); } public override double DesiredRangeEU => throw new NotImplementedException(); public enum XUnits { msec, sec, Hz, samples } public CalculatedChannel(string name, XUnits xAxis, string yAxis, double[] xValues, double[] yValues, Operation calcType, int number, Module parentModule ) { _x = new List(xValues); _y = new List(yValues); _xAxis = xAxis; _yAxis = yAxis; ChannelDescriptionString = name; _operation = calcType; Number = number; CurrentFilter = new DefaultSaeJ211Filter(ChannelFilter.Unfiltered); ParentModule = parentModule; _UnfilteredDataEu = new List(yValues); DataCount = yValues.Length; } /// /// Generate a representation for this object. /// /// /// /// The representation of this object. /// /// public override string ToString() { try { return !string.IsNullOrEmpty(ChannelDescriptionString) ? ChannelDescriptionString : "N/A"; } catch (System.Exception ex) { throw new Exception("encountered problem getting string representation", ex); } } } public class FFTCalculatedChannel : CalculatedChannel { private readonly double _peakFrequency; public double PeakFrequency => _peakFrequency; public FFTCalculatedChannel(string name, XUnits xAxis, string yAxis, double[] xValues, double[] yValues, Operation calcType, int number, Module parentModule, double peakFrequency) : base(name, xAxis, yAxis, xValues, yValues, calcType, number, parentModule) { _peakFrequency = peakFrequency; } /* protected override void InitializeReviewableAttributes(List reviewableAttributes) { base.InitializeReviewableAttributes(reviewableAttributes); //try { reviewableAttributes.Add(new ReviewablePeakFrequencyAttribute(this)); } //catch { } } public class ReviewablePeakFrequencyAttribute : Slice.Control.Event.Module.Channel.ReviewableAttribute { public ReviewablePeakFrequencyAttribute(Event.Module.Channel channel) : base("Peak (Hz)", delegate { return (channel as FFTCalculatedChannel).PeakFrequency.ToString("N"); }) { } }*/ } public class IntegralCalculatedChannel : CalculatedChannel { public IntegralCalculatedChannel(string name, XUnits xAxis, string yAxis, double[] xValues, double[] yValues, Operation calcType, int number, Module parentModule ) : base(name, xAxis, yAxis, xValues, yValues, calcType, number, parentModule) { } } public class DerivativeCalculatedChannel : CalculatedChannel { public DerivativeCalculatedChannel(string name, XUnits xAxis, string yAxis, double[] xValues, double[] yValues, Operation calcType, int number, Module parentModule ) : base(name, xAxis, yAxis, xValues, yValues, calcType, number, parentModule) { } } public class ScaleCalculatedChannel : CalculatedChannel { public ScaleCalculatedChannel(string name, XUnits xAxis, string yAxis, double[] xValues, double[] yValues, Operation calcType, int number, Module parentModule) : base(name, xAxis, yAxis, xValues, yValues, calcType, number, parentModule) { } } public class OffsetCalculatedChannel : CalculatedChannel { public OffsetCalculatedChannel(string name, XUnits xAxis, string yAxis, double[] xValues, double[] yVAlues, Operation calcType, int number, Module parentModule) : base(name, xAxis, yAxis, xValues, yVAlues, calcType, number, parentModule) { } } public class ResultantCalculatedChannel : CalculatedChannel { public ResultantCalculatedChannel(string name, XUnits xAxis, string yAxis, double[] xValues, double[] yValues, Operation calcType, int number, Module parentModule) : base(name, xAxis, yAxis, xValues, yValues, calcType, number, parentModule) { } } public class AdditiveVectorCalculatedChannel : CalculatedChannel { public AdditiveVectorCalculatedChannel(string name, XUnits xAxis, string yAxis, double[] xValues, double[] yValues, Operation calcType, int number, Module parentModule) : base(name, xAxis, yAxis, xValues, yValues, calcType, number, parentModule) { } } public class SineCalculatedChannel : CalculatedChannel { public SineCalculatedChannel(string name, XUnits xAxis, string yAxis, double[] xValues, double[] yValues, Operation calcType, int number, Module parentModule ) : base(name, xAxis, yAxis, xValues, yValues, calcType, number, parentModule) { } } public class CosineCalculatedChannel : CalculatedChannel { public CosineCalculatedChannel(string name, XUnits xAxis, string yAxis, double[] xValues, double[] yValues, Operation calcType, int number, Module parentModule ) : base(name, xAxis, yAxis, xValues, yValues, calcType, number, parentModule) { } } /* public class HICCalculatedChannel : CalculatedChannel { public double GetT1(bool ms) { double start = (double)HIC.StartSample - (double)ParentModule.TriggerSampleNumbers[0] + (double)ParentModule.StartRecordSampleNumber; start /= (double)ParentModule.SampleRateHz; if (ms) { start *= 1000; } return start; } public double GetT2(bool ms) { double end = (double)HIC.EndSample - (double)ParentModule.TriggerSampleNumbers[0] + (double)ParentModule.StartRecordSampleNumber; end /= (double)ParentModule.SampleRateHz; if (ms) { end *= 1000; } return end; } public HICCalculatedChannel(string name, XUnits xAxis, string yAxis, double[] xValues, double[] yValues, Operation calcType, int number, Module parentModule, DTS.Calculations.HeadInjuryCriterion.HICResult hic ) : base(name, xAxis, yAxis, xValues, yValues, calcType, number, parentModule) { _hic = hic; } private DTS.Calculations.HeadInjuryCriterion.HICResult _hic; public DTS.Calculations.HeadInjuryCriterion.HICResult HIC { get { return _hic; } } protected override void InitializeReviewableAttributes(List reviewableAttributes) { base.InitializeReviewableAttributes(reviewableAttributes); try { reviewableAttributes.Add(new ReviewableHICAttribute(this)); } catch {} try { reviewableAttributes.Add(new ReviewableHICLengthAttribute(this)); } catch { } try { reviewableAttributes.Add(new ReviewableHICT1T2Attribute(this)); } catch { } } public class ReviewableHICLengthAttribute : Slice.Control.Event.Module.Channel.ReviewableAttribute { public ReviewableHICLengthAttribute(Event.Module.Channel channel) : base("Clip Length", delegate { return (channel as HICCalculatedChannel).HIC.HicLengthMS.ToString(); }) { } } public class ReviewableHICAttribute : Slice.Control.Event.Module.Channel.ReviewableAttribute { /// /// Initialize an instance of this class. /// /// /// /// The to which this attribute is attached. /// /// public ReviewableHICAttribute(Event.Module.Channel channel) : base("HIC", delegate { return (channel as HICCalculatedChannel).HIC.HIC.ToString("N1"); }) { } } public class ReviewableHICT1T2Attribute : Slice.Control.Event.Module.Channel.ReviewableAttribute { public ReviewableHICT1T2Attribute(Event.Module.Channel channel) : base("T1/T2", delegate { HICCalculatedChannel hic = channel as HICCalculatedChannel; if (null == hic) { return ""; } else { return string.Format("{0}s/{1}s", hic.GetT1(false), hic.GetT2(false)); } }) { } } } * */ } } } }