This commit is contained in:
2026-04-17 14:55:32 -04:00
commit bc3ac1d4c9
18017 changed files with 4371742 additions and 0 deletions

View File

@@ -0,0 +1,115 @@
---
source_files:
- DTS Viewer/DTS.Viewer.Modules/DTS.Viewer.AddCalculatedChannel/Model/CalculatedChannelCreator.cs
generated_at: "2026-04-16T11:21:42.260506+00:00"
model: "zai-org/GLM-5-FP8"
schema_version: 1
sha256: "d05bf6b72e9c97be"
---
# Documentation: CalculatedChannelCreator
## 1. Purpose
The `CalculatedChannelCreator` class is a static factory that creates derived data channels from existing test data channels. It supports multiple calculation types including aggregate operations (SUM, AVE, Resultant, HIC), binary operations (Integral, DoubleIntegral, Derivative, Sin, Cos), and specialized 3D IR-Tracc sensor calculations. The module handles sample rate alignment via super-sampling, creates persistent memory-mapped file storage for calculated data, and integrates the results back into the test data hierarchy.
## 2. Public Interface
### `CreateChannels`
```csharp
public static Test.Module.CalculatedChannel[] CreateChannels(
string testId,
string folder,
Calculation calculation,
List<Test.Module.Channel> inputChannels,
string channelName,
int startingNumber,
List<Test.Module.Channel> allChannels,
int clipLength,
out List<string> errorList,
int defaultEncoding)
```
**Behavior:** Main entry point for creating calculated channels. Routes to appropriate internal creation method based on `Calculation` type:
- `ThreeDIRTracc`, `ThreeDIRTraccLowerThorax`, `ThreeDIRTraccAbdomen``Create3DIRTraccChannels`
- `SUM`, `AVE`, `Resultant`, `HIC``CreateChannelsAggregateOperation`
- All others → `CreateChannelsBinaryOperation`
Returns `null` if channel name validation fails or calculation produces no results. Sets `AbsoluteDisplayOrder` on each returned channel starting from `startingNumber`.
### `ValidateChannelName`
```csharp
public static bool ValidateChannelName(
string channelName,
List<Test.Module.Channel> inputChannels,
List<Test.Module.Channel> allChannels,
out List<string> errorList)
```
**Behavior:** Validates that the channel name is non-empty and unique across both `inputChannels` and `allChannels`. Returns `true` if valid (empty error list). If `allChannels` is `null`, returns `true` immediately with no validation performed.
### `ThreeDIRTraccType` (nested enum)
```csharp
public enum ThreeDIRTraccType
{
Thorax,
Abdomen,
LowerThorax
}
```
**Behavior:** Specifies the anatomical mounting position for 3D IR-Tracc sensors, which affects calculation constants (`δ` and `D0`).
---
## 3. Invariants
1. **Channel Number Offset:** All calculated channels use `ChannelNumberCalculationChannelIndicator` (100000) as a base offset added to the provided starting number.
2. **3D IR-Tracc Input Count:** `Create3DIRTraccChannels` asserts that exactly 3 input channels are provided. Failure triggers `System.Diagnostics.Trace.Assert`.
3. **Aggregate Operation Input Count:** `CreateChannelsAggregateOperation` asserts at least 1 input channel is provided.
4. **Sample Rate Compatibility:** For aggregate and 3D IR-Tracc operations, the maximum sample rate must be an integer multiple of all input channel sample rates. If not, `NotSupportedException` is thrown.
5. **Binary Operations:** Only the first channel in `inputChannels` is used for binary operations (Integral, Derivative, Sin, Cos, etc.).
6. **HIC Unit Requirement:** HIC calculations require acceleration in g's. If input engineering units are not "g", data is converted from m/s² using factor `9.80665`.
7. **Super-Sampling Warning:** When input channels have different sample rates, a `PageErrorEvent` is published with `SuperSamplingWarning` resource string.
---
## 4. Dependencies
### This module depends on:
- `DTS.Common.Enums.Sensors` - `SensorConstants` for IR-Tracc physical constants
- `DTS.Common.Utilities.Logging` - `APILogger` for file operation logging
- `DTS.Common.Utils` - `FileUtils` for file deletion
- `DTS.Serialization` - `SliceRaw.File` format handling
- `DTS.Slice.Control` - Test/Event module channel types
- `DTS.Common` - `Constants.ADC_MIDPOINT`, `ZeroMethodType`
- `DTS.Common.Events` - `PageErrorEvent`, `PageErrorArg`
- `DTS.Common.Calculations` - `HeadInjuryCriterion` for HIC calculation
- `DTS.Common.Utilities.Math.Nhtsa` - `Integration`, `Differentiation` classes
- `Prism.Ioc` - `ContainerLocator` for service resolution
- `Prism.Events` - `IEventAggregator` for event publishing
### What depends on this module:
- **Inferred:** `AddCalculatedChannelViewModel` (referenced via `using static` for `ThreeDIRTraccType` context)
- **Inferred:** Any module calling `CreateChannels` to generate derived data channels
---
## 5. Gotchas
1. **Explicit GC.Collect():** `CreatePersistentInformationObject` calls `GC.Collect()` before attempting file deletion to release file handles. This is a heavy operation that may cause performance issues.
2. **Unused Variable:** In `PerformCalculationsAggregate`, the variable `timeAtIndex` is declared and assigned (`var timeAtIndex =`) but the value is never used—the assignment result is discarded.
3. **Debug File Replacement:** `PerformCalculation` (3D IR-Tracc) calls `DiskUtility.ReplaceDataIfNeeded` with hardcoded filenames (`"DISPLEU.txt"`, `"YPOTEU.txt"`, `"ZPOTEU.txt"`). This appears to be debug/test instrumentation left in production code.
4. **ScaleEuData Scaling Logic:** The scaling factor calculation handles bipolar signals by doubling the max value (`max *= 2`), but the scaleFactor calculation differs based on whether max exceeds `short.MaxValue`—one path divides, the other multiplies, which may produce unexpected scaling behavior.
5. **Null Return on Validation Failure:** `CreateChannels` returns `null` if `ValidateChannelName` fails, but the error list is populated via `out` parameter. Callers must check both the return value and error list.
6. **Binary Operations Ignore Additional Channels:** `CreateChannelsBinaryOperation` and `PerformCalculationBinary` only use `inputChannels[0]`. Additional channels in the list are silently ignored.
7. **HIC-Specific Handling:** HIC calculation is performed inside `CreateChannelsAggregateOperation` after channel creation, setting `T1`, `T2`, and `HIC` properties on the calculated channel. This is not visible from the public method signature.