11 KiB
source_files, generated_at, model, schema_version, sha256
| source_files | generated_at | model | schema_version | sha256 | |
|---|---|---|---|---|---|
|
2026-04-16T13:58:53.491336+00:00 | zai-org/GLM-5-FP8 | 1 | 5cfd5d272102b3bf |
Documentation: AddCalculatedChannelViewModel
1. Purpose
The AddCalculatedChannelViewModel class provides the presentation logic for creating and adding calculated channels to test data within the DTS Viewer application. It supports multiple calculation types including mathematical operations (Integral, Double Integral, Derivative, Sin, Cos), aggregate functions (SUM, Average, Resultant), and specialized biomechanical calculations (3D IR-Tracc variants, HIC - Head Injury Criterion). The ViewModel manages channel selection UI state, validates user inputs, persists calculated channels to .dts test files, and coordinates with the event aggregation system for cross-component communication.
2. Public Interface
Class Declaration
public class AddCalculatedChannelViewModel : BaseViewModel<IAddCalculatedChannelViewModel>, IAddCalculatedChannelViewModel
Constructor
public AddCalculatedChannelViewModel(IAddCalculatedChannelView view, IRegionManager regionManager, IEventAggregator eventAggregator, IUnityContainer unityContainer)
Initializes the ViewModel with its associated view, region manager for UI composition, event aggregator for pub/sub messaging, and Unity dependency injection container.
Public Properties
| Property | Type | Description |
|---|---|---|
View |
IBaseView |
The associated view instance; DataContext is set to this in constructor. |
Parent |
IBaseViewModel |
Parent ViewModel passed during initialization. |
ContextSearchRegion |
object |
Context region placeholder. |
NotificationRequest |
InteractionRequest<Notification> |
Raises notification dialogs. |
ConfirmationRequest |
InteractionRequest<Confirmation> |
Raises confirmation dialogs (hides base member). |
HeaderInfo |
string |
Returns "AddCalculatedChannelRegion". |
IsBusy |
bool |
Throws NotImplementedException on get/set. |
IsDirty |
bool |
Throws NotImplementedException on get. |
IsAddCalculatedChannelIncluded |
bool |
Feature inclusion flag. |
IncludeGroupNameInISOExport |
bool |
Controls ISO export format. |
DefaultDTSEncoding |
int |
Encoding codepage 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 identifier; defaults to "NONE". |
SingleChannelSelectorVisibility |
bool |
Controls visibility for single-channel selection UI. |
MultipleChannelSelectorVisibility |
bool |
Controls visibility for multi-channel selection UI. |
HICChannelSelectorVisibility |
bool |
Controls visibility for HIC-specific channel selection. |
ThreeDIRTRACCVisibility |
bool |
Controls visibility for 3D IR-Tracc channel selection. |
CalculationList |
CalculationHelper[] |
Lazy-initialized list of available calculations. |
SelectedCalculation |
CalculationHelper |
Currently selected calculation type; setter updates UI visibility states. |
ChannelList |
ObservableCollection<ITestChannel> |
All available input channels. |
ChannelListObjects |
ObservableCollection<ChannelHelper> |
Wrapped channel objects with inclusion tracking. |
SourceChannel |
ITestChannel |
Selected source channel for single-channel calculations. |
AvailableHICChannels |
ChannelHelper[] |
Channels with acceleration units valid for HIC calculation. |
HICAccelerationX |
ChannelHelper |
X-axis acceleration channel for HIC. |
HICAccelerationY |
ChannelHelper |
Y-axis acceleration channel for HIC. |
HICAccelerationZ |
ChannelHelper |
Z-axis acceleration channel for HIC. |
HICLength |
int |
HIC calculation length parameter; defaults to 16. |
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 Methods
public void PublishChanges()
Empty implementation (commented NotImplementedException).
public override void Initialize()
public override void Initialize(object parameter)
Sets Parent from parameter and subscribes to events.
public override void Activated()
Resets UI state: sets default SourceChannel, IsoCode to "NONE", ChannelName to "New Channel", clears HIC selections, sets HICLength to 16.
public override void Cleanup()
Empty implementation.
public bool Validate(ref List<string> errors, ref List<string> warnings, bool displayWindow)
Validates channel name and calculation-specific requirements (HIC requires 3 channels; Resultant requires matching units and sample rates).
public bool ValidateChannelName()
Returns true if ChannelName is non-empty.
Commands
public ICommand AddCalculatedChannelCommand { get; private set; }
Executes AddCalculatedChannel(object obj) which validates input, creates calculated channels via CalculatedChannelCreator.CreateChannels(), adds them to the test structure, and persists changes to .dts files.
Public Enum
public enum Calculation
{
[Description("Integral")] Integral = 0,
[Description("Double Integral")] DoubleIntegral = 1,
[Description("Derivative")] Derivative = 2,
[Description("Sin")] Sin = 3,
[Description("Cos")] Cos = 4,
[Description("3D IR-Tracc")] ThreeDIRTracc = 5,
[Description("SUM")] SUM = 6,
[Description("Average")] AVE = 7,
[Description("3D IR-TRACC Abdomen")] ThreeDIRTraccAbdomen = 8,
[Description("3D IR-TRACC Lower Thorax")] ThreeDIRTraccLowerThorax = 9,
[Description("Resultant")] Resultant = 10,
[Description("HIC")] HIC = 11
}
Nested Public Classes
public class ChannelHelper : BasePropertyChanged
Wraps ITestChannel with DisplayName, ChannelName, and IsIncluded properties for UI binding.
public class CalculationHelper
Wraps Calculation enum with localized ToString() via resource manager.
3. Invariants
- Channel Name Validation:
ChannelNamemust be non-null and non-empty for validation to pass. - HIC Channel Requirement: HIC calculation requires all three acceleration channels (
HICAccelerationX,HICAccelerationY,HICAccelerationZ) to be non-null. - Resultant Channel Consistency: All channels included in a Resultant calculation must have identical
SensitivityUnitsandSampleRateHz. - Display Order Preservation: Channels are sorted by
AbsoluteDisplayOrderwhen determining insertion position for new calculated channels. - File Backup Behavior: Backup files (
.dtsbak) are created only if one does not already exist; original file is preserved. - IR-Tracc Channel Eligibility: IR-Tracc channels must be
AnalogInputChanneltype with validLinearizationFormula,ZeroMethodofNone, non-zeroZeroPoint, and non-zeroFactoryExcitationVoltage. - Potentiometer Channel Eligibility: Pot channels must be
AnalogInputChanneltype with units"deg"or"deg-ang",ZeroMethodofNone, and non-zeroFactoryExcitationVoltage. - HIC Channel Filtering: Only channels with units in
Constants.ACCELERATION_UNITSare available for HIC selection.
4. Dependencies
External Dependencies (from imports)
Prism.Events-IEventAggregatorfor event pub/subPrism.Regions-IRegionManagerfor UI region managementUnity-IUnityContainerfor dependency injectionDTS.Serialization.Test- Test data structuresDTS.Serialization.SliceRaw.File- File I/O for.dtsfiles
Internal Dependencies
DTS.Common/DTS.Common.Base- Base classes, constantsDTS.Common.Classes.Viewer.Commands-RelayCommandDTS.Common.DAS.Concepts-ITestChannelinterfaceDTS.Common.Enums.Sensors-ZeroMethodTypeDTS.Common.Events- Event types (RaiseNotification,TestSummaryChangeNotification,PageErrorEvent,SetSaveButton,RefreshTestRequestEvent)DTS.Common.Interactivity-InteractionRequest<T>,Notification,ConfirmationDTS.Common.Interface-IAddCalculatedChannelView,IAddCalculatedChannelViewModelDTS.Common.Utilities.Logging-APILoggerDTS.Common.Utils-Utilsstatic helpersDTS.Slice.Control- Slice control functionalityDTS.Viewer.AddCalculatedChannel.Model-CalculatedChannelCreator,LinearizationFormula
Events Consumed
RaiseNotification- Displays notification dialogsTestSummaryChangeNotification- Triggers channel list population
Events Published
PageErrorEvent- Publishes validation errors/warningsSetSaveButton- Controls save button enabled stateRefreshTestRequestEvent- Triggers test data refresh after saveRaiseNotification- Displays error messages
5. Gotchas
-
NotImplementedException on IsBusy/IsDirty: Both properties throw on access. These appear to be placeholder implementations that were never completed.
-
HIC Save Button Logic Appears Inverted: In
UpdateSaveButtonVisibility(), the HIC case setsIsUsable = truewhen channels are null andIsUsable = falsewhen all three are set—the opposite of expected behavior:if (null == HICAccelerationX || null == HICAccelerationY || null == HICAccelerationZ) { _eventAggregator.GetEvent<SetSaveButton>().Publish(new SaveButtonUsability() { IsUsable = true }); } else { _eventAggregator.GetEvent<SetSaveButton>().Publish(new SaveButtonUsability() { IsUsable = false }); } -
Member Hiding with
newKeyword: Several members (PropertyChanged,OnPropertyChanged,IsBusy,IsDirty,ConfirmationRequest) hide base class members usingnew, which may cause confusion when casting to base types. -
Empty PublishChanges() Method: The
PublishChanges()method has a commented-outNotImplementedExceptionwith no implementation, suggesting incomplete feature work. -
Hardcoded Thread.Sleep: A 10ms
Thread.Sleep()is used after file write operations inAddCalculatedChannel()—this is a potential code smell for file I/O timing issues. -
Test ID Extraction Fragility:
GetTestIdFromBinaryFileName()parses the test ID from binary filenames by looking for"Ch"substring; if not found, it uses the entire prefix which may produce incorrect results. -
Duplicate Channel Handling: When adding a calculated channel, existing channels with the same
ChannelIdare silently removed without user confirmation (logged only).