init
This commit is contained in:
191
Common/DTS.Common.ISO/CalculatedValueClass.cs
Normal file
191
Common/DTS.Common.ISO/CalculatedValueClass.cs
Normal file
@@ -0,0 +1,191 @@
|
||||
/* Copyright 2017 Diversified Technical Systems
|
||||
*/
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using DTS.Common.Classes.TestSetups;
|
||||
using DTS.Common.Interface.Channels;
|
||||
using DTS.Common.Interface.TestSetups;
|
||||
|
||||
namespace DTS.Common.ISO
|
||||
{
|
||||
/// <summary>
|
||||
/// this class will probably become an abstract base class in the future but for now since we only have
|
||||
/// summed realtime channels, we can be a little less formal
|
||||
/// </summary>
|
||||
public class CalculatedValueClass : CalculatedChannelRecord
|
||||
{
|
||||
public CalculatedValueClass() { }
|
||||
public CalculatedValueClass(CalculatedValueClass copy)
|
||||
{
|
||||
Id = copy.Id;
|
||||
Operation = copy.Operation;
|
||||
TestSetupName = copy.TestSetupName;
|
||||
Name = copy.Name;
|
||||
foreach (var a in copy.Attributes)
|
||||
{
|
||||
_attributes.Add(a.Copy());
|
||||
}
|
||||
CalculatedValueCode = copy.CalculatedValueCode;
|
||||
CFCForInputChannels = copy.CFCForInputChannels;
|
||||
ChannelFilterClassForOutput = copy.ChannelFilterClassForOutput;
|
||||
var ids = new List<string>(copy.InputChannelIds);
|
||||
_inputChannelIds = ids.ToArray();
|
||||
ViewInRealtime = copy.ViewInRealtime;
|
||||
ClipLength = copy.ClipLength;
|
||||
}
|
||||
public CalculatedValueClass(ICalculatedChannelRecord record)
|
||||
: base(record)
|
||||
{
|
||||
|
||||
}
|
||||
/// <summary>
|
||||
/// returns true if the calculation channel supports realtime
|
||||
/// </summary>
|
||||
public bool SupportsRealtime
|
||||
{
|
||||
get
|
||||
{
|
||||
if (!ViewInRealtime) { return false; }
|
||||
return true;
|
||||
}
|
||||
}
|
||||
public bool IsValid(Dictionary<string, bool> channelIdLookup)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(Name)) { return false; }
|
||||
if (InputChannelIds.Length < 1) { return false; }
|
||||
foreach (var id in _inputChannelIds) { if (!channelIdLookup.ContainsKey(id)) { return false; } }
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public new Operations Operation
|
||||
{
|
||||
get => base.Operation;
|
||||
set
|
||||
{
|
||||
base.Operation = value;
|
||||
OnPropertyChanged("ViewInRealtime");
|
||||
OnPropertyChanged("CanChangeViewInRealtime");
|
||||
}
|
||||
}
|
||||
|
||||
public new bool ViewInRealtime
|
||||
{
|
||||
get
|
||||
{
|
||||
switch (Operation)
|
||||
{
|
||||
case Operations.IRTRACC3D:
|
||||
case Operations.IRTRACC3D_ABDOMEN:
|
||||
case Operations.IRTRACC3D_LOWERTHORAX:
|
||||
case Operations.HIC:
|
||||
return false;
|
||||
}
|
||||
return base.ViewInRealtime;
|
||||
}
|
||||
set => base.ViewInRealtime = value;
|
||||
}
|
||||
|
||||
public bool CanChangeViewInRealtime
|
||||
{
|
||||
get
|
||||
{
|
||||
switch (Operation)
|
||||
{
|
||||
case Operations.IRTRACC3D:
|
||||
case Operations.IRTRACC3D_ABDOMEN:
|
||||
case Operations.IRTRACC3D_LOWERTHORAX:
|
||||
case Operations.HIC:
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
public new string[] InputChannelIds
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_channels.Any())
|
||||
{
|
||||
var ids = new List<string>();
|
||||
foreach (var ch in _channels)
|
||||
{
|
||||
if (null == ch)
|
||||
{
|
||||
ids.Add("-1");
|
||||
}
|
||||
else
|
||||
{
|
||||
ids.Add(ch.Id.ToString());
|
||||
}
|
||||
}
|
||||
_inputChannelIds = ids.ToArray();
|
||||
}
|
||||
|
||||
return base.InputChannelIds;
|
||||
}
|
||||
set => base.InputChannelIds = value;
|
||||
}
|
||||
|
||||
private List<IGroupChannel> _channels = new List<IGroupChannel>();
|
||||
|
||||
public List<TestObjectChannel> TestObjectChannels { get; set; } = new List<TestObjectChannel>();
|
||||
|
||||
public void SetChannels(IGroupChannel[] groupChannels)
|
||||
{
|
||||
_channels = new List<IGroupChannel>(groupChannels);
|
||||
}
|
||||
|
||||
public void SetTestObjectChannels(TestObjectChannel[] testObjectChannels)
|
||||
{
|
||||
TestObjectChannels = new List<TestObjectChannel>(testObjectChannels);
|
||||
}
|
||||
public byte[] InputChannelIdsBlob
|
||||
{
|
||||
get
|
||||
{
|
||||
var text = string.Join(CultureInfo.InvariantCulture.TextInfo.ListSeparator, InputChannelIds);
|
||||
return Encoding.UTF8.GetBytes(text);
|
||||
}
|
||||
set
|
||||
{
|
||||
var text = Encoding.UTF8.GetString(value);
|
||||
var ids = new List<string>(text.Split(
|
||||
new[] { CultureInfo.InvariantCulture.TextInfo.ListSeparator },
|
||||
StringSplitOptions.None));
|
||||
_inputChannelIds = ids.ToArray();
|
||||
}
|
||||
}
|
||||
|
||||
private readonly List<CCAttributeBase> _attributes = new List<CCAttributeBase>();
|
||||
public CCAttributeBase[] Attributes
|
||||
{
|
||||
get => _attributes.ToArray();
|
||||
set { _attributes.Clear(); _attributes.AddRange(value); }
|
||||
}
|
||||
public void ReplaceInputChannelIdAtIndex(int index, string newId)
|
||||
{
|
||||
_inputChannelIds[index] = newId;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// the design here is so that we can attach attributes to calculated channels that need them (HIC, Head Contact Duration), but let them be a bit variable and dynamic
|
||||
/// </summary>
|
||||
public abstract class CCAttributeBase
|
||||
{
|
||||
protected int _attributeId;
|
||||
public int AttributeId => _attributeId;
|
||||
|
||||
protected object _attributeValue;
|
||||
public abstract string GetSerializedValue();
|
||||
|
||||
public abstract string GetDefaultValue();
|
||||
|
||||
public abstract string GetNameResourceId { get; }
|
||||
public abstract CCAttributeBase Copy();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user