init
This commit is contained in:
1
Common/DTS.Common.Calculations/.svn/entries
Normal file
1
Common/DTS.Common.Calculations/.svn/entries
Normal file
@@ -0,0 +1 @@
|
||||
12
|
||||
1
Common/DTS.Common.Calculations/.svn/format
Normal file
1
Common/DTS.Common.Calculations/.svn/format
Normal file
@@ -0,0 +1 @@
|
||||
12
|
||||
@@ -0,0 +1,35 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace DTS.Common.Calculations
|
||||
{
|
||||
/// <summary>
|
||||
/// Filtered Channel Data
|
||||
/// simple class for holding generic data for calculations
|
||||
/// in the future I'd like to be able to accept channels with different units and convert them
|
||||
/// to a common unit, so I add support for that now
|
||||
/// </summary>
|
||||
public class ChannelData
|
||||
{
|
||||
/// <summary>
|
||||
/// Engineering units of Data
|
||||
/// </summary>
|
||||
public string Units { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Pre-Filtered EU data
|
||||
/// </summary>
|
||||
public double[] FilteredEU { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Constructs a ChannelData object
|
||||
/// </summary>
|
||||
/// <param name="units">Engineering units of data</param>
|
||||
public ChannelData(string units)
|
||||
{
|
||||
Units = units;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
using System;
|
||||
|
||||
namespace DTS.Common.Calculations
|
||||
{
|
||||
public class HeadInjuryCriterion
|
||||
{
|
||||
/// <summary>
|
||||
/// Calculates the head injury criterion given a resultant channel, and a desired clip length
|
||||
/// </summary>
|
||||
/// <param name="resultant">Acceleration vector (x,y,z resultant)</param>
|
||||
/// <param name="SPS">Actual sample rate</param>
|
||||
/// <param name="clipLengthMS">Length in ms </param>
|
||||
/// <returns>MAX Head Injury Criterion over the data input for the clip requested</returns>
|
||||
public static HICResult GetHeadInjuryCriterion(ChannelData resultant, double SPS, int clipLengthMS)
|
||||
{
|
||||
System.Diagnostics.Trace.Assert(SPS > 0, "Actual sample rate must be positive");
|
||||
System.Diagnostics.Trace.Assert(clipLengthMS > 0, "Clip length must be positive");
|
||||
|
||||
int maxHICPoint = int.MinValue;
|
||||
double maxHIC = int.MinValue;
|
||||
int maxHICEndPoint = int.MinValue;
|
||||
|
||||
int maxclip = Convert.ToInt32(Math.Ceiling(clipLengthMS * SPS / 1000D));
|
||||
|
||||
for (int clip = 1; clip <= maxclip; clip++)
|
||||
{
|
||||
System.Diagnostics.Trace.Assert(clip < resultant.FilteredEU.Length, string.Format("data must be atleast {0} ms", clipLengthMS));
|
||||
double clipInSeconds = clip / SPS;
|
||||
for (int i = 0; i < resultant.FilteredEU.Length - clip; i++)
|
||||
{
|
||||
//note we are exhaustively recalculating sums, we can do this much better without a doubt, but lets get the
|
||||
//first method done (brute force)
|
||||
//also note, definite integral doesn't include last point, so we have to add one point back in
|
||||
double integral = Integral.DefiniteIntegral(resultant.FilteredEU, i, i + clip, SPS);
|
||||
double hic = clipInSeconds * Math.Pow(integral / clipInSeconds, 2.5D);
|
||||
if (hic > maxHIC) { maxHIC = hic; maxHICPoint = i; maxHICEndPoint = i + clip; }
|
||||
}
|
||||
}
|
||||
return new HICResult(maxHIC, clipLengthMS, maxHICPoint, maxHICEndPoint);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// helper class for storing/handling hic results
|
||||
/// </summary>
|
||||
public class HICResult
|
||||
{
|
||||
public int StartSample { get; }
|
||||
public int EndSample { get; }
|
||||
public int HicLengthMS { get; }
|
||||
public double HIC { get; }
|
||||
/// <summary>
|
||||
/// constructs a new HIC result
|
||||
/// </summary>
|
||||
/// <param name="hic">HIC value</param>
|
||||
/// <param name="hicLength">length of HIC in ms</param>
|
||||
/// <param name="endSample">start sample of HIC</param>
|
||||
/// <param name="startSample">end sample of HIC</param>
|
||||
public HICResult(double hic, int hicLength, int startSample, int endSample)
|
||||
{
|
||||
StartSample = startSample;
|
||||
EndSample = endSample;
|
||||
HicLengthMS = hicLength;
|
||||
HIC = hic;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace DTS.Common.Calculations
|
||||
{
|
||||
public static class Resultant
|
||||
{
|
||||
/// <summary>
|
||||
/// generates a resultant channel given input vectors
|
||||
/// Will throw an assertion if lengths of data don't match, or if
|
||||
/// units don't match
|
||||
/// </summary>
|
||||
/// <param name="channels">List of channels to combine via
|
||||
/// sum of squares
|
||||
/// </param>
|
||||
/// <returns>
|
||||
/// resultant vector from sum of squares of inputs
|
||||
/// </returns>
|
||||
public static ChannelData GenerateResultantChannel(List<ChannelData> channels)
|
||||
{
|
||||
int length = (from ch in channels select ch.FilteredEU.Length).Max();
|
||||
foreach (var ch in channels) { System.Diagnostics.Trace.Assert(ch.FilteredEU.Length == length); }
|
||||
//make sure the channels are all the same units and lengths,
|
||||
//we assert here since the higher level should be expected to provide clean inputs
|
||||
var units = (from ch in channels select ch.Units).Distinct();
|
||||
System.Diagnostics.Trace.Assert(units.Count() == 1);
|
||||
|
||||
var values = new List<double>();
|
||||
|
||||
//in a future version we can parallize this for efficiency
|
||||
//values.Add will need to be replaced by an indexer when we do
|
||||
for (int i = 0; i < length; i++)
|
||||
{
|
||||
double d = 0D;
|
||||
foreach (var ch in channels)
|
||||
{
|
||||
d += ch.FilteredEU[i] * ch.FilteredEU[i];
|
||||
}
|
||||
values.Add(System.Math.Sqrt(d));
|
||||
}
|
||||
|
||||
var cd = new ChannelData(units.First());
|
||||
cd.FilteredEU = values.ToArray();
|
||||
return cd;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
namespace DTS.Common.Calculations
|
||||
{
|
||||
public static class Integral
|
||||
{
|
||||
/// <summary>
|
||||
/// integrates a channel over an interval
|
||||
/// </summary>
|
||||
/// <param name="input">data to integrate</param>
|
||||
/// <param name="start">index to start integration at (inclusive)</param>
|
||||
/// <param name="end">index to end integration at (inclusive)</param>
|
||||
/// <returns></returns>
|
||||
public static double DefiniteIntegral(double[] input, int start, int end, double SPS)
|
||||
{
|
||||
//we use trapezoidal summation to get integral, there is an assumption that the input data is
|
||||
//tightly time aligned (otherwise we'd have to divide each interval by the actual distance, and not 1/2)
|
||||
//=(SUMPRODUCT(H25:H56,A26:A57)-SUMPRODUCT(A25:A56,H26:H57)+A57*H57-A25*H25)/2
|
||||
double d = 0;
|
||||
for (int i = start + 1; i < end; i++)
|
||||
{
|
||||
d += 2D * input[i];
|
||||
}
|
||||
d += input[start];
|
||||
d += input[end];
|
||||
|
||||
return .5D * d / SPS;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="15.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProductVersion>9.0.21022</ProductVersion>
|
||||
<SchemaVersion>2.0</SchemaVersion>
|
||||
<ProjectGuid>{5CE6F27B-1C5B-4101-88DE-58A30B1E5F37}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>DTS.Common.Calculations</RootNamespace>
|
||||
<AssemblyName>Calculations</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<FileUpgradeFlags>
|
||||
</FileUpgradeFlags>
|
||||
<UpgradeBackupLocation>
|
||||
</UpgradeBackupLocation>
|
||||
<OldToolsVersion>3.5</OldToolsVersion>
|
||||
<TargetFrameworkProfile />
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<OutputPath>bin\x86\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<DebugType>full</DebugType>
|
||||
<PlatformTarget>x86</PlatformTarget>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<Prefer32Bit>false</Prefer32Bit>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
|
||||
<OutputPath>bin\x86\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<Optimize>true</Optimize>
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<PlatformTarget>x86</PlatformTarget>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<Prefer32Bit>false</Prefer32Bit>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<OutputPath>bin\x64\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<DebugType>full</DebugType>
|
||||
<PlatformTarget>x64</PlatformTarget>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
|
||||
<Prefer32Bit>false</Prefer32Bit>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
|
||||
<OutputPath>bin\x64\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<Optimize>true</Optimize>
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<PlatformTarget>x64</PlatformTarget>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
|
||||
<Prefer32Bit>false</Prefer32Bit>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core">
|
||||
<RequiredTargetFramework>3.5</RequiredTargetFramework>
|
||||
</Reference>
|
||||
<Reference Include="System.Xml.Linq">
|
||||
<RequiredTargetFramework>3.5</RequiredTargetFramework>
|
||||
</Reference>
|
||||
<Reference Include="System.Data.DataSetExtensions">
|
||||
<RequiredTargetFramework>3.5</RequiredTargetFramework>
|
||||
</Reference>
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="ChannelData.cs" />
|
||||
<Compile Include="HeadInjuryCriterion.cs" />
|
||||
<Compile Include="Integral.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="Resultant.cs" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
<Target Name="BeforeBuild">
|
||||
</Target>
|
||||
<Target Name="AfterBuild">
|
||||
</Target>
|
||||
-->
|
||||
</Project>
|
||||
@@ -0,0 +1,36 @@
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// General Information about an assembly is controlled through the following
|
||||
// set of attributes. Change these attribute values to modify the information
|
||||
// associated with an assembly.
|
||||
[assembly: AssemblyTitle("HeadInjuryCriterion")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("HeadInjuryCriterion")]
|
||||
[assembly: AssemblyCopyright("Copyright © 2013")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
// Setting ComVisible to false makes the types in this assembly not visible
|
||||
// to COM components. If you need to access a type in this assembly from
|
||||
// COM, set the ComVisible attribute to true on that type.
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
// The following GUID is for the ID of the typelib if this project is exposed to COM
|
||||
[assembly: Guid("a83e3800-290f-4513-9756-d37168152099")]
|
||||
|
||||
// Version information for an assembly consists of the following four values:
|
||||
//
|
||||
// Major Version
|
||||
// Minor Version
|
||||
// Build Number
|
||||
// Revision
|
||||
//
|
||||
// You can specify all the values or you can default the Build and Revision Numbers
|
||||
// by using the '*' as shown below:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.0.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
||||
BIN
Common/DTS.Common.Calculations/.svn/wc.db
Normal file
BIN
Common/DTS.Common.Calculations/.svn/wc.db
Normal file
Binary file not shown.
0
Common/DTS.Common.Calculations/.svn/wc.db-journal
Normal file
0
Common/DTS.Common.Calculations/.svn/wc.db-journal
Normal file
Reference in New Issue
Block a user