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,124 @@
---
source_files:
- DTS Viewer/DTS.Viewer.Modules/DTS.Viewer.AddCalculatedChannel/Model/CalculatedChannelCreator.cs
generated_at: "2026-04-17T15:59:43.455218+00:00"
model: "zai-org/GLM-5-FP8"
schema_version: 1
sha256: "0bdba55cc7806845"
---
# CalculatedChannelCreator Documentation
## 1. Purpose
The `CalculatedChannelCreator` class is a factory responsible for creating derived data channels from existing sensor input channels. It performs mathematical transformations—including 3D IR-TRACC displacement calculations, aggregate operations (SUM, AVE, Resultant, HIC), and binary operations (integration, differentiation, trigonometric functions)—on channel data and persists the results to memory-mapped files. This module exists to support post-processing of crash test data, enabling engineers to synthesize new measurement channels from raw sensor inputs.
---
## 2. Public Interface
### `CreateChannels` (static method)
```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. Dispatches to appropriate private methods based on the `Calculation` enum value. Returns an array of `Test.Module.CalculatedChannel` objects on success, or `null` if validation fails. Populates `errorList` with validation errors.
### `ValidateChannelName` (static method)
```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 input channels and all channels. Returns `true` if valid; `false` otherwise. If `allChannels` is `null`, validation is bypassed and returns `true`.
### `ThreeDIRTraccType` (public enum)
```csharp
public enum ThreeDIRTraccType
{
Thorax,
Abdomen,
LowerThorax
}
```
**Behavior:** Specifies the anatomical location for 3D IR-TRACC calculations, which affects the constants (`δ` and `D0`) used in the displacement formulas.
---
## 3. Invariants
1. **Channel Number Offset:** All calculated channels use `ChannelNumberCalculationChannelIndicator` (constant value `100000`) as a base offset for their channel numbers.
2. **Sample Rate Compatibility:** For aggregate and 3D IR-TRACC operations, the maximum sample rate among input channels must be an integer multiple of each individual channel's sample rate. Otherwise, `NotSupportedException` is thrown.
3. **3D IR-TRACC Input Count:** `Create3DIRTraccChannels` asserts that exactly 3 input channels are provided.
4. **Aggregate Operation Input Count:** `CreateChannelsAggregateOperation` asserts that at least 2 input channels are provided (assertion message says "at least 1" but checks `1 < inputChannels.Count`).
5. **File Overwrite Safety:** `CreatePersistentInformationObject` deletes any existing file at the target filepath before creating a new persistent channel, using `GC.Collect()` followed by `FileUtils.DeleteFileOrMove`.
6. **Engineering Units Padding:** When persisting engineering units, the string is padded to even length for word-alignment if its length is odd.
---
## 4. Dependencies
### This Module Depends On:
- `DTS.Common.Enums.Sensors` - For `SensorConstants` (δ and D0 values)
- `DTS.Common.Utilities.Logging` - For `APILogger.Log`
- `DTS.Common.Utils` - For `FileUtils`
- `DTS.Serialization` - For `SliceRaw.File` format handling
- `DTS.Slice.Control` - Unclear specific usage (imported but no direct reference visible)
- `DTS.Common` - For `Constants.ADC_MIDPOINT`, `ZeroMethodType`
- `DTS.Common.Events` - For `PageErrorEvent`, `PageErrorArg`
- `DTS.Common.Calculations` - For `HeadInjuryCriterion`
- `DTS.Common.Utilities.Math.Nhtsa` - For `Integration`, `Differentiation`
- `Prism.Ioc` - For `ContainerLocator`
- `Prism.Events` - For `IEventAggregator`
- `Test.Module` namespace - For `Channel`, `CalculatedChannel`, `AnalogInputChannel`
- `Event.Module` namespace - For `Channel`, `AnalogInputChannel`
### What Depends On This Module:
- **Unclear from source alone** - No consumers are shown in this file.
---
## 5. Gotchas
### Critical Bugs Identified:
1. **Copy-Paste Error in `PerformCalculation` (line ~378):**
```csharp
var stepRPot1 = Convert.ToInt32(Math.Ceiling(indexAtCurrentTimeIRTracc) - actualIndexAtCurrentTimeIRTracc);
```
Uses `indexAtCurrentTimeIRTracc` instead of `indexAtCurrentTimeRPot1`. This causes incorrect interpolation for the R-Pot1 channel.
2. **Assignment Instead of Subtraction in `PerformCalculation` (line ~403):**
```csharp
incrementRPot2 = (valueRPot2AtPoint = rPot2EUData[actualIndexAtCurrentTimeRPot2 - 1]) / rateRPot2;
```
This is an assignment (`=`) inside parentheses, overwriting `valueRPot2AtPoint`, when it should be a subtraction (`-`).
3. **Unused Variable in `PerformCalculationsAggregate` (line ~151):**
```csharp
var timeAtIndex =
```
Variable is declared but never assigned or used. This is a syntax error or incomplete implementation.
### Non-Obvious Behaviors:
4. **Debug/Test Data Injection:** The method calls `DiskUtility.ReplaceDataIfNeeded(ref irTraccEUData, "DISPLEU.txt")` and similar for other channels. This appears to be a debug feature that can override channel data from disk files. Production behavior is unclear.
5. **Explicit `GC.Collect()` Call:** In `CreatePersistentInformationObject`, `GC.Collect()` is called before file deletion to handle file locks. This is a heavy operation that may cause performance issues.
6. **ScaleEuData Logic Appears Inverted:** When `max > short.MaxValue`, the scale factor calculation `scaleFactor = max / short.MaxValue` produces a value ≥ 1, which would amplify data that's already too large, potentially causing overflow when casting to `short`.
7. **HIC Unit Conversion:** For HIC calculations, if engineering units are not "g", the code multiplies by `9.80665` to convert from m/s² to g's. This assumes the input is in m/s², which may not always be true.
8. **Commented-Out Code:** There is a commented-out `DeleteChannelFile` method and associated logic for deferred file deletion, suggesting historical changes to file handling behavior.

View File

@@ -0,0 +1,41 @@
---
source_files:
- DTS Viewer/DTS.Viewer.Modules/DTS.Viewer.AddCalculatedChannel/Properties/AssemblyInfo.cs
generated_at: "2026-04-17T16:29:26.442754+00:00"
model: "zai-org/GLM-5-FP8"
schema_version: 1
sha256: "a42ffb66848e031f"
---
# Properties
### Purpose
This module contains assembly metadata for the `DTS.Viewer.AddCalculatedChannel` component. It is a standard .NET assembly information file that defines versioning, copyright, and COM visibility settings for the compiled output. It exists solely to provide identity and configuration information for the assembly at build time.
### Public Interface
No public types or functions are defined. This file only declares assembly-level attributes:
- `AssemblyTitle`: "DTS.Viewer.AddCalculatedChannel"
- `AssemblyDescription`: Empty
- `AssemblyProduct`: "DTS.Viewer.AddCalculatedChannel"
- `AssemblyCopyright`: "Copyright © 2017"
- `AssemblyVersion`: "1.0.0.0"
- `AssemblyFileVersion`: "1.0.0.0"
- `ComVisible`: false
- `Guid`: "6451f3ed-934e-47e3-a1ca-33c223a6507a"
### Invariants
- Assembly version is fixed at 1.0.0.0 (no auto-increment wildcard).
- COM visibility is disabled for all types in this assembly.
### Dependencies
**Depends on:**
- `System.Reflection`
- `System.Runtime.CompilerServices`
- `System.Runtime.InteropServices`
**Depended on by:** Unclear from source alone (consumed by the build system).
### Gotchas
None identified from source alone. This is boilerplate assembly metadata.
---

View File

@@ -0,0 +1,29 @@
---
source_files:
- DTS Viewer/DTS.Viewer.Modules/DTS.Viewer.AddCalculatedChannel/Resources/TranslateExtension.cs
- DTS Viewer/DTS.Viewer.Modules/DTS.Viewer.AddCalculatedChannel/Resources/StringResources.Designer.cs
generated_at: "2026-04-17T15:56:15.275064+00:00"
model: "zai-org/GLM-5-FP8"
schema_version: 1
sha256: "485d316f89383148"
---
# Documentation: DTS.Viewer.AddCalculatedChannel.Resources
## 1. Purpose
This module provides localization/internationalization infrastructure for the "Add Calculated Channel" feature within the DTS Viewer application. It consists of a WPF markup extension (`TranslateExtension`) that enables XAML-based string localization, backed by an auto-generated strongly-typed resource class (`StringResources`) that exposes localized strings for UI labels, calculation types, error messages, and sensor-related terminology (IR-TRACC, HIC calculations, etc.).
---
## 2. Public Interface
### `TranslateExtension` (Markup Extension)
**Namespace:** `DTS.Viewer.AddCalculatedChannel`
A WPF markup extension for retrieving localized strings in XAML bindings.
| Member | Signature | Description |
|--------|-----------|-------------|
| Constructor | `TranslateExtension(string key)` | Initializes the extension with the resource key to look up. Stores the key in

View File

@@ -0,0 +1,34 @@
---
source_files:
- DTS Viewer/DTS.Viewer.Modules/DTS.Viewer.AddCalculatedChannel/View/AddCalculatedChannelView.xaml.cs
generated_at: "2026-04-17T16:13:40.916446+00:00"
model: "zai-org/GLM-5-FP8"
schema_version: 1
sha256: "9d3bcf84fac09edf"
---
# View
### Purpose
This module provides the code-behind for the `AddCalculatedChannelView` XAML view, serving as the UI component for adding calculated channels within the DTS Viewer application. It implements the `IAddCalculatedChannelView` interface to integrate with the application's view abstraction layer, enabling loose coupling between the view and its consuming components.
### Public Interface
- **`AddCalculatedChannelView()`** (Constructor)
- Initializes the component by calling `InitializeComponent()`. No additional parameters or logic.
- **`IAddCalculatedChannelView`** (Implemented Interface)
- The class implements this interface from `DTS.Common.Interface`, making it usable wherever the interface type is required.
### Invariants
- The view must be a partial class to support WPF's code-generation model for XAML.
- `InitializeComponent()` must be called exactly once during construction to load the associated XAML.
### Dependencies
- **Depends on:** `DTS.Common.Interface` (for `IAddCalculatedChannelView` interface)
- **Depended on by:** Cannot be determined from source alone (likely consumed by a presenter/viewmodel or region navigation in the broader application)
### Gotchas
- The file includes a ReSharper directive `// ReSharper disable CheckNamespace`, suggesting the namespace `DTS.Viewer.AddCalculatedChannel` may not match the project's default namespace structure. This could cause confusion during refactoring or when locating the view.
---

View File

@@ -0,0 +1,207 @@
---
source_files:
- DTS Viewer/DTS.Viewer.Modules/DTS.Viewer.AddCalculatedChannel/ViewModel/AddCalculatedChannelViewModel.cs
generated_at: "2026-04-17T16:00:17.185622+00:00"
model: "zai-org/GLM-5-FP8"
schema_version: 1
sha256: "71a9c8acbea4fb64"
---
# Documentation: AddCalculatedChannelViewModel
## 1. Purpose
This module provides the ViewModel for the "Add Calculated Channel" feature in the DTS Viewer application. It manages the UI logic and business rules for creating derived data channels from existing test data, supporting multiple calculation types including mathematical operations (Integral, Derivative, Sin, Cos), aggregations (SUM, Average, Resultant), and specialized biomechanical calculations (HIC, 3D IR-Tracc variants). The ViewModel handles channel selection, validation, file I/O operations, and coordinates with the event aggregation system to notify other application components of changes.
## 2. Public Interface
### Class: `AddCalculatedChannelViewModel`
**Inherits:** `BaseViewModel<IAddCalculatedChannelViewModel>`
**Implements:** `IAddCalculatedChannelViewModel`
### Constructor
```csharp
public AddCalculatedChannelViewModel(
IAddCalculatedChannelView view,
IRegionManager regionManager,
IEventAggregator eventAggregator,
IUnityContainer unityContainer)
```
Initializes the ViewModel, sets up the View's DataContext, creates interaction requests, and registers the `AddCalculatedChannelCommand`.
### Public Properties
| Property | Type | Description |
|----------|------|-------------|
| `View` | `IBaseView` | The associated view instance. |
| `Parent` | `IBaseViewModel` | The parent ViewModel passed during initialization. |
| `ContextSearchRegion` | `object` | Context for search region (usage unclear from source). |
| `NotificationRequest` | `InteractionRequest<Notification>` | Raises notification dialogs. |
| `ConfirmationRequest` | `InteractionRequest<Confirmation>` | Raises confirmation dialogs. |
| `HeaderInfo` | `string` | Returns `"AddCalculatedChannelRegion"`. |
| `IsBusy` | `bool` | **Throws `NotImplementedException`** on get/set. |
| `IsDirty` | `bool` | **Throws `NotImplementedException`** on get. |
| `IsAddCalculatedChannelIncluded` | `bool` | Gets/sets inclusion flag. |
| `IncludeGroupNameInISOExport` | `bool` | Controls whether group names are included in ISO export. |
| `DefaultDTSEncoding` | `int` | Encoding code page for DTS file operations. |
| `ChannelName` | `string` | Name for the new calculated channel. |
| `ChannelDescription` | `string` | Auto-generated description based on selected calculation and channels. |
| `IsoCode` | `string` | ISO code for the channel (defaults to `"NONE"`). |
| `SingleChannelSelectorVisibility` | `bool` | Controls visibility for single-channel selection UI. |
| `HICChannelSelectorVisibility` | `bool` | Controls visibility for HIC channel selection UI. |
| `MultipleChannelSelectorVisibility` | `bool` | Controls visibility for multi-channel selection UI. |
| `ThreeDIRTRACCVisibility` | `bool` | Controls visibility for 3D IR-Tracc channel selection UI. |
| `CalculationList` | `CalculationHelper[]` | Lazy-initialized list of available calculations. |
| `SelectedCalculation` | `CalculationHelper` | Currently selected calculation type. |
| `ChannelList` | `ObservableCollection<ITestChannel>` | All available input channels. |
| `ChannelListObjects` | `ObservableCollection<ChannelHelper>` | Wrapped channel objects with `IsIncluded` tracking. |
| `AvailableHICChannels` | `ChannelHelper[]` | Channels with acceleration units valid for HIC calculation. |
| `HICAccelerationX` | `ChannelHelper` | Selected X-axis acceleration channel for HIC. |
| `HICAccelerationY` | `ChannelHelper` | Selected Y-axis acceleration channel for HIC. |
| `HICAccelerationZ` | `ChannelHelper` | Selected Z-axis acceleration channel for HIC. |
| `HICLength` | `int` | HIC calculation length parameter (default: 16). |
| `SourceChannel` | `ITestChannel` | Selected source channel for single-channel calculations. |
| `IRTraccChannelList` | `ObservableCollection<ChannelHelper>` | Valid IR-Tracc channels. |
| `IRTraccChannel` | `ChannelHelper` | Selected IR-Tracc channel. |
| `Pot1ChannelList` | `ObservableCollection<ChannelHelper>` | Valid potentiometer 1 channels. |
| `Pot1Channel` | `ChannelHelper` | Selected potentiometer 1 channel. |
| `Pot2ChannelList` | `ObservableCollection<ChannelHelper>` | Valid potentiometer 2 channels. |
| `Pot2Channel` | `ChannelHelper` | Selected potentiometer 2 channel. |
### Public Commands
| Command | Handler | Description |
|---------|---------|-------------|
| `AddCalculatedChannelCommand` | `AddCalculatedChannel(object obj)` | Validates input, creates calculated channel(s), writes to DTS file, and publishes refresh event. |
### Public Methods
```csharp
public void PublishChanges() // Throws NotImplementedException
public override void Initialize()
public override void Initialize(object parameter)
public override void Activated()
public override void Cleanup()
public bool Validate(ref List<string> errors, ref List<string> warnings, bool displayWindow)
```
### Public Enum: `Calculation`
| Value | Name | Description Attribute |
|-------|------|------------------------|
| 0 | `Integral` | "Integral" |
| 1 | `DoubleIntegral` | "Double Integral" |
| 2 | `Derivative` | "Derivative" |
| 3 | `Sin` | "Sin" |
| 4 | `Cos` | "Cos" |
| 5 | `ThreeDIRTracc` | "3D IR-Tracc" |
| 6 | `SUM` | "SUM" |
| 7 | `AVE` | "Average" |
| 8 | `ThreeDIRTraccAbdomen` | "3D IR-TRACC Abdomen" |
| 9 | `ThreeDIRTraccLowerThorax` | "3D IR-TRACC Lower Thorax" |
| 10 | `Resultant` | "Resultant" |
| 11 | `HIC` | "HIC" |
### Public Nested Classes
#### `ChannelHelper`
Wraps `ITestChannel` with display formatting and inclusion tracking.
| Member | Type | Description |
|--------|------|-------------|
| `MyChannel` | `ITestChannel` | The wrapped channel. |
| `DisplayName` | `string` | Formatted display name based on `IsoViewMode`. |
| `ChannelName` | `string` | Returns `ToString()` of the channel. |
| `IsIncluded` | `bool` | Tracks whether channel is included in multi-select calculations. |
#### `CalculationHelper`
Wraps `Calculation` enum with localized string representation.
| Member | Type | Description |
|--------|------|-------------|
| `MyCalculation` | `Calculation` | The wrapped calculation type. |
| `ToString()` | `string` | Returns localized name from resources or enum name. |
## 3. Invariants
1. **Channel List Ordering**: `ChannelList` is always sorted by `AbsoluteDisplayOrder` via `CompareDisplayOrders` comparison.
2. **IR-Tracc Channel Eligibility**: Channels in `IRTraccChannelList` must satisfy all of:
- `ChannelType` equals `Test.Module.AnalogInputChannel` type string
- `LinearizationFormula` is valid (via `LinearizationFormula.IsValid()`)
- `ZeroMethod` equals `ZeroMethodType.None`
- `ZeroPoint` is not zero
- `FactoryExcitationVoltage` is not zero
3. **Potentiometer Channel Eligibility**: Channels in `Pot1ChannelList` and `Pot2ChannelList` must satisfy:
- `ChannelType` equals `Test.Module.AnalogInputChannel` type string
- `Eu` (engineering units) is `"deg"` or `"deg-ang"` (case-insensitive)
- `ZeroMethod` equals `ZeroMethodType.None`
- `FactoryExcitationVoltage` is not zero
4. **HIC Channel Eligibility**: Channels in `AvailableHICChannels` must have engineering units contained in `Constants.ACCELERATION_UNITS`.
5. **Resultant Validation**: All included channels for Resultant calculation must have matching `SensitivityUnits` and `SampleRateHz`.
6. **HIC Validation**: HIC calculation requires all three acceleration channels (X, Y, Z) to be non-null.
7. **File Backup**: DTS file backup is only created if a backup file does not already exist.
## 4. Dependencies
### Direct Dependencies (Imports)
- `DTS.Common` / `DTS.Common.Base` / `DTS.Common.Utils` / `DTS.Common.Utilities.Logging`
- `DTS.Common.Classes.Viewer.Commands` (for `RelayCommand`)
- `DTS.Common.DAS.Concepts`
- `DTS.Common.Enums.Sensors` (for `ZeroMethodType`)
- `DTS.Common.Events` (for event types)
- `DTS.Common.Interactivity` (for `InteractionRequest`, `Notification`, `Confirmation`)
- `DTS.Common.Interface`
- `DTS.Slice.Control`
- `DTS.Viewer.AddCalculatedChannel.Model`
- `DTS.Serialization.Test` (aliased as `Test`)
- `Prism.Events` (for `IEventAggregator`)
- `Prism.Regions` (for `IRegionManager`)
- `Unity` (for `IUnityContainer`)
### Events Subscribed
- `RaiseNotification``OnRaiseNotification`
- `TestSummaryChangeNotification``OnTestSummaryChanged`
### Events Published
- `SetSaveButton` (via `SaveButtonUsability` payload)
- `PageErrorEvent` (via `PageErrorArg` payload)
- `RefreshTestRequestEvent` (with DTS file path)
- `RaiseNotification` (via `NotificationContentEventArgs`)
### Consumers
Unknown from source alone. The module is instantiated via Unity dependency injection and navigated to via Prism regions.
## 5. Gotchas
1. **Unimplemented Members**: `IsBusy`, `IsDirty`, and `PublishChanges()` throw `NotImplementedException`. These appear to be interface requirements that were never implemented.
2. **HIC Save Button Logic Appears Inverted**: In `UpdateSaveButtonVisibility()`, the HIC case sets `IsUsable = true` when acceleration channels are null and `IsUsable = false` when they are set. This appears to be a bug—the logic should likely be inverted.
```csharp
case Calculation.HIC:
if (null == HICAccelerationX || null == HICAccelerationY || null == HICAccelerationZ)
{
_eventAggregator.GetEvent<SetSaveButton>().Publish(new SaveButtonUsability() { IsUsable = true }); // Suspect
}
else
{
_eventAggregator.GetEvent<SetSaveButton>().Publish(new SaveButtonUsability() { IsUsable = false }); // Suspect
}
break;
```
3. **Member Hiding with `new` Keyword**: The class uses `new` to hide inherited members (`PropertyChanged`, `OnPropertyChanged`, `IsBusy`, `IsDirty`, `ConfirmationRequest`). This can lead to unexpected behavior when the ViewModel is accessed via base class references.
4. **Thread.Sleep in File Write**: A `Thread.Sleep(10)` follows the file write operation in `AddCalculatedChannel()`. This suggests a timing-related workaround for file system operations.
5. **Backup File Deletion**: After successful save, the backup file is deleted only if it was created during that save operation (`!backupExisted`). Original backups are preserved.
6. **Channel Loading Side Effect**: `OnTestSummaryChanged` triggers lazy loading of channel data via `Utils.SetChannelInfo()` when `ts.Channels.FirstOrDefault() == null`, modifying the test metadata in place.
7. **Default Encoding Fallback**: If `Encoding.GetEncoding(DefaultDTSEncoding)` fails, the code falls back to `Encoding.Default` without re-throwing, potentially causing encoding mismatches.