Example #1
0
        internal OutputsViewModel(
            IAppState appState,
            IAppService appService,
            IAppSettings appSettings,
            ModuleState moduleState,
            SamplingDesigns samplingDesigns
            )
        {
            _appState    = appState;
            _appSettings = appSettings;
            _moduleState = moduleState;
            _simulation  = appState.Target.AssertSome();

            _outputsSelectedSampleViewModel  = new OutputsSelectedSampleViewModel(appState, appService, moduleState);
            _outputsFilteredSamplesViewModel = new OutputsFilteredSamplesViewModel(appState, appService, moduleState, samplingDesigns);
            _outputsEvidenceViewModel        = new OutputsEvidenceViewModel(appState, appService, moduleState);

            var output = _simulation.SimConfig.SimOutput;

            _outputNames = output.DependentVariables
                           .Map(e => e.Name)
                           .OrderBy(n => n.ToUpperInvariant())
                           .ToArr();

            _moduleState.OutputsState.SelectedOutputName ??= _outputNames.Head();

            _selectedOutputName = _outputNames.IndexOf(
                _moduleState.OutputsState.SelectedOutputName
                );

            PlotController = new();
            PlotController.Bind(
                new OxyMouseDownGesture(OxyMouseButton.Left),
                new DelegatePlotCommand <OxyMouseDownEventArgs>(HandleOutputsMouseDown)
                );
            PlotController.Bind(
                new OxyMouseDownGesture(OxyMouseButton.Left, OxyModifierKeys.Control),
                new DelegatePlotCommand <OxyMouseDownEventArgs>(HandleOutputsMouseDown)
                );

            Outputs = new();

            var horizontalAxis = new LinearAxis
            {
                Position = AxisPosition.Bottom,
                Title    = output.IndependentVariable.Name,
                Unit     = output.IndependentVariable.Unit
            };

            Outputs.Axes.Add(horizontalAxis);

            var verticalAxis = new LinearAxis
            {
                Position = AxisPosition.Left
            };

            Outputs.Axes.Add(verticalAxis);

            Outputs.ApplyThemeToPlotModelAndAxes();

            PopulateAll();

            ToggleSeriesType = ReactiveCommand.Create(HandleToggleSeriesType);
            ResetAxes        = ReactiveCommand.Create(HandleResetAxes);

            _reactiveSafeInvoke = appService.GetReactiveSafeInvoke();

            _subscriptions = new CompositeDisposable(

                appSettings
                .GetWhenPropertyChanged()
                .Subscribe(
                    _reactiveSafeInvoke.SuspendAndInvoke <string?>(
                        ObserveAppSettingsPropertyChange
                        )
                    ),

                moduleState.OutputsState
                .ObservableForProperty(os => os.SelectedOutputName)
                .Subscribe(
                    _reactiveSafeInvoke.SuspendAndInvoke <object>(
                        ObserveOutputsStateSelectedOutputName
                        )
                    ),

                moduleState.OutputsState
                .ObservableForProperty(os => os.ObservationsReferences)
                .Subscribe(
                    _reactiveSafeInvoke.SuspendAndInvoke <object>(
                        ObserveOutputsStateObservationsReferences
                        )
                    ),

                moduleState
                .ObservableForProperty(ms => ms.FilterConfig)
                .Subscribe(
                    _reactiveSafeInvoke.SuspendAndInvoke <object>(
                        ObserveModuleStateFilterConfig
                        )
                    ),

                moduleState
                .ObservableForProperty(ms => ms.Outputs)
                .Subscribe(
                    _reactiveSafeInvoke.SuspendAndInvoke <object>(
                        ObserveModuleStateOutputs
                        )
                    ),

                moduleState
                .ObservableForProperty(ms => ms.OutputFilters)
                .Subscribe(
                    _reactiveSafeInvoke.SuspendAndInvoke <object>(
                        ObserveModuleStateOutputFilters
                        )
                    ),

                this
                .ObservableForProperty(vm => vm.SelectedOutputName)
                .Subscribe(
                    _reactiveSafeInvoke.SuspendAndInvoke <object>(
                        ObserveSelectedOutputName
                        )
                    )

                );
        }
Example #2
0
        internal DesignViewModel(
            IAppState appState,
            IAppService appService,
            IAppSettings appSettings,
            ModuleState moduleState,
            SamplingDesigns samplingDesigns
            )
        {
            _appService      = appService;
            _appSettings     = appSettings;
            _moduleState     = moduleState;
            _samplingDesigns = samplingDesigns;

            _simulation = appState.Target.AssertSome();
            _simData    = appState.SimData;

            CreateDesign = ReactiveCommand.Create(
                HandleCreateDesign,
                this.WhenAny(vm => vm.CanCreateDesign, _ => CanCreateDesign)
                );

            UnloadDesign = ReactiveCommand.Create(
                HandleUnloadDesign,
                this.WhenAny(vm => vm.CanUnloadDesign, _ => CanUnloadDesign)
                );

            AcquireOutputs = ReactiveCommand.Create(
                HandleAcquireOutputs,
                this.WhenAny(vm => vm.CanAcquireOutputs, _ => CanAcquireOutputs)
                );

            CancelAcquireOutputs = ReactiveCommand.Create(
                HandleCancelAcquireOutputs,
                this.WhenAny(vm => vm.CanCancelAcquireOutputs, _ => CanCancelAcquireOutputs)
                );

            _reactiveSafeInvoke = appService.GetReactiveSafeInvoke();

            _subscriptions = new CompositeDisposable(

                moduleState
                .ObservableForProperty(vm => vm.Samples)
                .Subscribe(
                    _reactiveSafeInvoke.SuspendAndInvoke <object>(
                        ObserveModuleStateSamples
                        )
                    ),

                moduleState
                .ObservableForProperty(vm => vm.SamplingDesign)
                .Subscribe(
                    _reactiveSafeInvoke.SuspendAndInvoke <object>(
                        ObserveModuleStateSamplingDesign
                        )
                    )

                );

            using (_reactiveSafeInvoke.SuspendedReactivity)
            {
                Populate();

                if (_moduleState.SamplingDesign != default)
                {
                    ConfigureOutputsAcquisition();
                }

                UpdateEnable();
            }
        }
        internal OutputsFilteredSamplesViewModel(
            IAppState appState,
            IAppService appService,
            ModuleState moduleState,
            SamplingDesigns samplingDesigns
            )
        {
            _moduleState     = moduleState;
            _samplingDesigns = samplingDesigns;

            _simulation = appState.Target.AssertSome();

            _toggleEnable = ReactiveCommand.Create <OutputsFilterViewModel>(HandleToggleEnable);
            _delete       = ReactiveCommand.Create <OutputsFilterViewModel>(HandleDelete);

            var independentVariable = _simulation.SimConfig.SimOutput.IndependentVariable;

            IndependentVariableName = independentVariable.Name;
            IndependentVariableUnit = independentVariable.Unit;

            _outputName = moduleState.OutputsState.SelectedOutputName;

            AddNewFilter = ReactiveCommand.Create(
                HandleAddNewFilter,
                this.WhenAny(
                    vm => vm.FromN,
                    vm => vm.ToN,
                    (_, _) => FromN.HasValue && ToN.HasValue
                    )
                );

            IsUnion = moduleState.SamplingDesign is null
        ? moduleState.FilteredSamplesState.IsUnion
        : _moduleState.FilterConfig.IsUnion;
            IsEnabled = moduleState.SamplingDesign is null
        ? moduleState.FilteredSamplesState.IsEnabled
        : moduleState.FilterConfig.IsEnabled;

            PopulateOutputFilters();

            _reactiveSafeInvoke = appService.GetReactiveSafeInvoke();

            _subscriptions = new CompositeDisposable(

                moduleState
                .ObservableForProperty(ms => ms.Outputs)
                .Subscribe(
                    _reactiveSafeInvoke.SuspendAndInvoke <object>(
                        ObserveModuleStateOutputs
                        )
                    ),

                moduleState
                .ObservableForProperty(ms => ms.FilterConfig)
                .Subscribe(
                    _reactiveSafeInvoke.SuspendAndInvoke <object>(
                        ObserveModuleStateFilterConfig
                        )
                    ),

                moduleState
                .ObservableForProperty(ms => ms.OutputFilters)
                .Subscribe(
                    _reactiveSafeInvoke.SuspendAndInvoke <object>(
                        ObserveModuleStateOutputFilters
                        )
                    ),

                moduleState.OutputsState
                .ObservableForProperty(os => os.SelectedOutputName)
                .Subscribe(
                    _reactiveSafeInvoke.SuspendAndInvoke <object>(
                        ObserveOutputsStateSelectedOutputName
                        )
                    ),

                this
                .ObservableForProperty(vm => vm.FromT)
                .Subscribe(
                    _reactiveSafeInvoke.SuspendAndInvoke <object>(
                        ObserveFromT
                        )
                    ),

                this
                .ObservableForProperty(vm => vm.ToT)
                .Subscribe(
                    _reactiveSafeInvoke.SuspendAndInvoke <object>(
                        ObserveToT
                        )
                    ),

                this
                .ObservableForProperty(vm => vm.IsEnabled)
                .Subscribe(
                    _reactiveSafeInvoke.SuspendAndInvoke <object>(
                        ObserveIsEnabled
                        )
                    ),

                this
                .ObservableForProperty(vm => vm.IsUnion)
                .Subscribe(
                    _reactiveSafeInvoke.SuspendAndInvoke <object>(
                        ObserveIsUnion
                        )
                    )

                );
        }
Example #4
0
        internal SamplesViewModel(
            IAppState appState,
            IAppService appService,
            IAppSettings appSettings,
            ModuleState moduleState
            )
        {
            _appState    = appState;
            _appService  = appService;
            _appSettings = appSettings;
            _moduleState = moduleState;

            _simulation = appState.Target.AssertSome();

            ShareParameters = ReactiveCommand.Create(
                HandleShareParameters,
                this.WhenAny(
                    vm => vm.Distributions,
                    _ => _moduleState.FilterConfig.IsEnabled &&
                    !_moduleState.FilterConfig.Filters.IsEmpty &&
                    !_moduleState.Outputs.IsEmpty &&
                    Distributions.Count > 0)
                );

            ConfigureLHS = ReactiveCommand.Create(
                HandleConfigureLHS,
                this.WhenAny(vm => vm.CanConfigureLHS, _ => CanConfigureLHS)
                );

            ConfigureRC = ReactiveCommand.Create(
                HandleConfigureRC,
                this.WhenAny(vm => vm.CanConfigureRC, _ => CanConfigureRC)
                );

            GenerateSamples = ReactiveCommand.Create(
                HandleGenerateSamplesAsync,
                this.WhenAny(vm => vm.CanGenerateSamples, _ => CanGenerateSamples)
                );

            ViewCorrelation = ReactiveCommand.Create(
                HandleViewCorrelation,
                this.WhenAny(vm => vm.CanViewCorrelation, _ => CanViewCorrelation)
                );

            _reactiveSafeInvoke = appService.GetReactiveSafeInvoke();

            _subscriptions = new CompositeDisposable(

                _moduleState.ParameterStateChanges.Subscribe(
                    _reactiveSafeInvoke.SuspendAndInvoke <(Arr <ParameterState>, ObservableQualifier)>(
                        ObserveParameterStateChange
                        )
                    ),

                _moduleState.SamplesState
                .ObservableForProperty(ms => ms.LatinHypercubeDesign)
                .Subscribe(
                    _reactiveSafeInvoke.SuspendAndInvoke <object>(
                        ObserveSamplesStateLatinHypercubeDesign
                        )
                    ),

                _moduleState
                .ObservableForProperty(ms => ms.FilterConfig)
                .Subscribe(
                    _reactiveSafeInvoke.SuspendAndInvoke <object>(
                        ObserveModuleStateFilterConfig
                        )
                    ),

                _moduleState
                .ObservableForProperty(ms => ms.OutputFilters)
                .Subscribe(
                    _reactiveSafeInvoke.SuspendAndInvoke <object>(
                        ObserveModuleStateOutputFilters
                        )
                    ),

                _moduleState
                .ObservableForProperty(ms => ms.SamplesState.RankCorrelationDesign)
                .Subscribe(
                    _reactiveSafeInvoke.SuspendAndInvoke <object>(
                        ObserveSamplesStateRankCorrelationDesign
                        )
                    ),

                _moduleState
                .ObservableForProperty(vm => vm.SamplingDesign)
                .Subscribe(
                    _reactiveSafeInvoke.SuspendAndInvoke <object>(
                        ObserveModuleStateSamplingDesign
                        )
                    ),

                _appSettings
                .GetWhenPropertyChanged()
                .Subscribe(
                    _reactiveSafeInvoke.SuspendAndInvoke <string?>(
                        ObserveAppSettingsPropertyChange
                        )
                    ),

                Observable
                .Merge(
                    this.ObservableForProperty(vm => vm.NSamples),
                    this.ObservableForProperty(vm => vm.Seed)
                    )
                .Subscribe(
                    _reactiveSafeInvoke.SuspendAndInvoke <object>(
                        ObserveInputs
                        )
                    ),

                this
                .ObservableForProperty(vm => vm.IsReadOnly)
                .Subscribe(
                    _reactiveSafeInvoke.SuspendAndInvoke <object>(
                        ObserveIsReadOnly
                        )
                    )

                );

            using (_reactiveSafeInvoke.SuspendedReactivity)
            {
                if (_moduleState.SamplingDesign == default)
                {
                    Populate(_moduleState.SamplesState, _moduleState.ParameterStates);
                }
                else
                {
                    Populate(_moduleState.SamplingDesign);
                }

                UpdateEnable();
            }
        }
Example #5
0
        internal DesignDigestsViewModel(
            IAppService appService,
            ModuleState moduleState,
            SamplingDesigns samplingDesigns
            )
        {
            _moduleState     = moduleState;
            _samplingDesigns = samplingDesigns;

            LoadSamplingDesign = ReactiveCommand.Create(
                HandleLoadSamplingDesign,
                this.WhenAny(
                    vm => vm.SelectedDesignDigestViewModel,
                    _ => SelectedDesignDigestViewModel != default
                    )
                );

            DeleteSamplingDesign = ReactiveCommand.Create(
                HandleDeleteSamplingDesign,
                this.WhenAny(
                    vm => vm.SelectedDesignDigestViewModel,
                    _ => SelectedDesignDigestViewModel != default
                    )
                );

            FollowKeyboardInDesignDigests = ReactiveCommand.Create <(Key Key, bool Control, bool Shift)>(
                HandleFollowKeyboardInDesignDigests
                );

            DesignDigestViewModels = new ObservableCollection <IDesignDigestViewModel>(
                samplingDesigns.DesignDigests.Map(
                    dd => new DesignDigestViewModel(dd.CreatedOn, dd.Description)
                    ));

            if (_moduleState.SamplingDesign != default)
            {
                TargetSamplingDesign = Some((_moduleState.SamplingDesign.CreatedOn, DateTime.Now));

                SelectedDesignDigestViewModel = DesignDigestViewModels
                                                .Find(vm => vm.CreatedOn == _moduleState.SamplingDesign.CreatedOn)
                                                .Match <IDesignDigestViewModel?>(vm => vm, () => default);
            }

            _reactiveSafeInvoke = appService.GetReactiveSafeInvoke();

            _subscriptions = new CompositeDisposable(

                moduleState
                .ObservableForProperty(ms => ms.SamplingDesign)
                .Subscribe(
                    _reactiveSafeInvoke.SuspendAndInvoke <object>(
                        ObserveModuleStateSamplingDesign
                        )
                    ),

                samplingDesigns.SamplingDesignChanges.Subscribe(
                    _reactiveSafeInvoke.SuspendAndInvoke <(DesignDigest, ObservableQualifier)>(
                        ObserveSamplingDesignChange
                        )
                    )

                );
        }