Exemplo n.º 1
0
        internal static ModuleState LoadOrCreate(Simulation simulation, SensitivityDesigns sensitivityDesigns)
        {
            var maybeDTO = simulation.LoadPrivateData <_ModuleStateDTO>(
                nameof(Sensitivity),
                nameof(ViewModel),
                nameof(ModuleState)
                );

            return(maybeDTO.Match(
                       dto => new ModuleState(dto, sensitivityDesigns),
                       () => new ModuleState(sensitivityDesigns)
                       ));
        }
Exemplo n.º 2
0
        internal DesignDigestsViewModel(
            IAppService appService,
            ModuleState moduleState,
            SensitivityDesigns sensitivityDesigns
            )
        {
            _moduleState        = moduleState;
            _sensitivityDesigns = sensitivityDesigns;

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

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

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

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

            if (_moduleState.SensitivityDesign != default)
            {
                TargetSensitivityDesign = Some((_moduleState.SensitivityDesign.CreatedOn, DateTime.Now));

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

            _reactiveSafeInvoke = appService.GetReactiveSafeInvoke();

            _subscriptions = new CompositeDisposable(

                moduleState
                .ObservableForProperty(ms => ms.SensitivityDesign)
                .Subscribe(
                    _reactiveSafeInvoke.SuspendAndInvoke <object>(
                        ObserveModuleStateSensitivityDesign
                        )
                    ),

                sensitivityDesigns.SensitivityDesignChanges.Subscribe(
                    _reactiveSafeInvoke.SuspendAndInvoke <(DesignDigest, ObservableQualifier)>(
                        ObserveSensitivityDesignChange
                        )
                    )

                );
        }
Exemplo n.º 3
0
        internal Fast99MeasuresViewModel(
            IAppState appState,
            IAppService appService,
            IAppSettings appSettings,
            ModuleState moduleState,
            SensitivityDesigns sensitivityDesigns
            )
        {
            _appState           = appState;
            _appService         = appService;
            _appSettings        = appSettings;
            _moduleState        = moduleState;
            _sensitivityDesigns = sensitivityDesigns;

            _simulation = appState.Target.AssertSome();
            var independentVariable = _simulation.SimConfig.SimOutput.IndependentVariable;

            XUnits = independentVariable.Unit;

            RankParameters = ReactiveCommand.Create(
                HandleRankParameters,
                this.ObservableForProperty(vm => vm.IsReady, _ => IsReady)
                );

            UseRankedParameters = ReactiveCommand.Create(
                HandleUseRankedParameters,
                this.ObservableForProperty(vm => vm.RankedParameterViewModels, _ => RankedParameterViewModels.Count > 0)
                );

            ShareRankedParameters = ReactiveCommand.Create(
                HandleShareRankedParameters,
                this.ObservableForProperty(vm => vm.RankedParameterViewModels, _ => RankedParameterViewModels.Count > 0)
                );

            PlotModel = new PlotModel()
            {
                LegendPosition  = LegendPosition.RightMiddle,
                LegendPlacement = LegendPlacement.Outside
            };

            PlotModel.Axes.Add(new LinearAxis
            {
                Position = AxisPosition.Bottom,
                Title    = independentVariable.GetFQName()
            });

            PlotModel.Axes.Add(new LinearAxis
            {
                Position = AxisPosition.Left,
            });

            _annotation = new RectangleAnnotation
            {
                Fill     = OxyColor.FromAColor(120, OxyColors.SkyBlue),
                MinimumX = 0,
                MaximumX = 0
            };
            PlotModel.Annotations.Add(_annotation);

            PlotModel.MouseDown += HandlePlotModelMouseDown;
            PlotModel.MouseMove += HandlePlotModelMouseMove;
            PlotModel.MouseUp   += HandlePlotModelMouseUp;

            PlotModel.ApplyThemeToPlotModelAndAxes();

            _reactiveSafeInvoke = appService.GetReactiveSafeInvoke();

            _subscriptions = new CompositeDisposable(

                moduleState
                .ObservableForProperty(ms => ms.SensitivityDesign)
                .Subscribe(ObserveModuleStateSensitivityDesign),

                moduleState.MeasuresState
                .ObservableForProperty(ms => ms.Fast99OutputMeasures)
                .Subscribe(ObserveMeasuresStateFast99OutputMeasures),

                moduleState.MeasuresState
                .ObservableForProperty(ms => ms.SelectedOutputName)
                .Subscribe(ObserveMeasuresStateSelectedOutputName),

                moduleState
                .ObservableForProperty(ms => ms.Ranking)
                .Subscribe(ObserveModuleStateRanking),

                this
                .ObservableForProperty(vm => vm.IsVisible)
                .Subscribe(ObserveIsVisible),

                this
                .ObservableForProperty(vm => vm.SelectedOutputName)
                .Subscribe(ObserveSelectedOutputName),

                this
                .ObservableForProperty(vm => vm.Fast99MeasureType)
                .Subscribe(ObserveFast99MeasureType),

                this
                .ObservableForProperty(vm => vm.XBeginText)
                .Subscribe(
                    _reactiveSafeInvoke.SuspendAndInvoke <object>(
                        ObserveXBeginText
                        )
                    ),

                this
                .ObservableForProperty(vm => vm.XEndText)
                .Subscribe(
                    _reactiveSafeInvoke.SuspendAndInvoke <object>(
                        ObserveXEndText
                        )
                    ),

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

                );

            using (_reactiveSafeInvoke.SuspendedReactivity)
            {
                Populate();
                PlotModel.InvalidatePlot(updateData: true);
            }
        }
Exemplo n.º 4
0
        internal DesignViewModel(
            IAppState appState,
            IAppService appService,
            IAppSettings appSettings,
            ModuleState moduleState,
            SensitivityDesigns sensitivityDesigns
            )
        {
            _appState           = appState;
            _appService         = appService;
            _appSettings        = appSettings;
            _moduleState        = moduleState;
            _sensitivityDesigns = sensitivityDesigns;
            _simData            = appState.SimData;
            _simulation         = _appState.Target.AssertSome();

            CreateDesign = ReactiveCommand.Create(
                HandleCreateDesign,
                this.WhenAny(
                    vm => vm.SensitivityMethod,
                    vm => vm.NoOfRuns,
                    vm => vm.NoOfSamples,
                    (_, __, ___) =>
                    (SensitivityMethod == SensitivityMethod.Morris && NoOfRuns > 0) ||
                    (SensitivityMethod == SensitivityMethod.Fast99 && NoOfSamples > 0))
                );

            UnloadDesign = ReactiveCommand.Create(HandleUnloadDesign);

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

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

            ShareParameters = ReactiveCommand.Create(
                HandleShareParameters,
                this.WhenAny(vm => vm.CanShareParameters, _ => CanShareParameters)
                );

            ViewError = ReactiveCommand.Create(
                HandleViewError,
                this.WhenAny(vm => vm.CanViewError, _ => CanViewError)
                );

            _reactiveSafeInvoke = appService.GetReactiveSafeInvoke();

            using (_reactiveSafeInvoke.SuspendedReactivity)
            {
                _subscriptions = new CompositeDisposable(

                    moduleState
                    .ObservableForProperty(ms => ms.ParameterStates)
                    .Subscribe(
                        _reactiveSafeInvoke.SuspendAndInvoke <object>(
                            ObserveParameterStateChange
                            )
                        ),

                    moduleState
                    .ObservableForProperty(ms => ms.SensitivityDesign)
                    .Subscribe(
                        _reactiveSafeInvoke.SuspendAndInvoke <object>(
                            ObserveModuleStateSensitivityDesign
                            )
                        ),

                    moduleState.MeasuresState
                    .ObservableForProperty(ms => ms.SelectedOutputName)
                    .Subscribe(
                        _reactiveSafeInvoke.SuspendAndInvoke <object>(
                            ObserveMeasuresStateSelectedOutputName
                            )
                        ),

                    this
                    .WhenAnyValue(
                        vm => vm.SensitivityMethod,
                        vm => vm.NoOfRuns,
                        vm => vm.NoOfSamples
                        )
                    .Subscribe(
                        _reactiveSafeInvoke.SuspendAndInvoke <(SensitivityMethod, int?, int?)>(
                            ObserveInputs
                            )
                        ),

                    this
                    .ObservableForProperty(vm => vm.SelectedInputIndex)
                    .Subscribe(
                        _reactiveSafeInvoke.SuspendAndInvoke <object>(
                            ObserveSelectedInputIndex
                            )
                        ),

                    this
                    .ObservableForProperty(vm => vm.ShowIssues)
                    .Subscribe(
                        _reactiveSafeInvoke.SuspendAndInvoke <object>(
                            ObserveShowBadRows
                            )
                        )

                    );

                if (_moduleState.SensitivityDesign == default)
                {
                    Populate(
                        _moduleState.DesignState,
                        _moduleState.ParameterStates
                        );
                }
                else
                {
                    Populate();
                }

                UpdateDesignEnable();
                UpdateSamplesEnable();
            }
        }
Exemplo n.º 5
0
 private ModuleState(SensitivityDesigns sensitivityDesigns) : this(new _ModuleStateDTO(), sensitivityDesigns)
 {
 }
Exemplo n.º 6
0
        private ModuleState(_ModuleStateDTO dto, SensitivityDesigns sensitivityDesigns)
        {
            ParametersState.SelectedParameter = dto.ParametersState?.SelectedParameter;

            DesignState.SensitivityMethod =
                Enum.TryParse(dto.DesignState?.SensitivityMethod, out SensitivityMethod sensitivityMethod)
        ? sensitivityMethod
        : default(SensitivityMethod?);

            DesignState.NoOfRuns    = dto.DesignState?.NoOfRuns;
            DesignState.NoOfSamples = dto.DesignState?.NoOfSamples;

            DesignState.SelectedElementName = dto.DesignState?.SelectedElementName;

            if (dto.TraceState == default)
            {
                TraceState.VerticalAxisMinimum         = 0d;
                TraceState.VerticalAxisAbsoluteMinimum = 0d;
            }
            else
            {
                TraceState.ViewHeight = dto.TraceState.ViewHeight;
                TraceState.ChartTitle = dto.TraceState.ChartTitle;
                TraceState.XAxisTitle = dto.TraceState.XAxisTitle;
                TraceState.YAxisTitle = dto.TraceState.YAxisTitle;
                if (dto.TraceState?.MarkerFill.IsAString() == true)
                {
                    TraceState.MarkerFill = OxyColor.Parse(dto.TraceState.MarkerFill);
                }
                if (dto.TraceState?.SeriesColor.IsAString() == true)
                {
                    TraceState.SeriesColor = OxyColor.Parse(dto.TraceState.SeriesColor);
                }
                TraceState.HorizontalAxisMinimum         = dto.TraceState?.HorizontalAxisMinimum ?? TraceState.HorizontalAxisMinimum;
                TraceState.HorizontalAxisMaximum         = dto.TraceState?.HorizontalAxisMaximum ?? TraceState.HorizontalAxisMaximum;
                TraceState.HorizontalAxisAbsoluteMinimum = dto.TraceState?.HorizontalAxisAbsoluteMinimum ?? TraceState.HorizontalAxisAbsoluteMinimum;
                TraceState.HorizontalAxisAbsoluteMaximum = dto.TraceState?.HorizontalAxisAbsoluteMaximum ?? TraceState.HorizontalAxisAbsoluteMaximum;
                TraceState.VerticalAxisMinimum           = dto.TraceState?.VerticalAxisMinimum ?? TraceState.VerticalAxisMinimum;
                TraceState.VerticalAxisMaximum           = dto.TraceState?.VerticalAxisMaximum ?? TraceState.VerticalAxisMaximum;
                TraceState.VerticalAxisAbsoluteMinimum   = dto.TraceState?.VerticalAxisAbsoluteMinimum ?? TraceState.VerticalAxisAbsoluteMinimum;
                TraceState.VerticalAxisAbsoluteMaximum   = dto.TraceState?.VerticalAxisAbsoluteMaximum ?? TraceState.VerticalAxisAbsoluteMaximum;
            }

            if (dto.LowryState == default)
            {
                LowryState.YAxisTitle = "Total (= Main Effect + Interaction)";
            }
            else
            {
                LowryState.ChartTitle = dto.LowryState.ChartTitle;
                LowryState.XAxisTitle = dto.LowryState.XAxisTitle;
                LowryState.YAxisTitle = dto.LowryState.YAxisTitle;
                if (dto.LowryState.InteractionsFillColor?.IsAString() == true)
                {
                    LowryState.InteractionsFillColor = OxyColor.Parse(dto.LowryState.InteractionsFillColor);
                }
                if (dto.LowryState.MainEffectsFillColor?.IsAString() == true)
                {
                    LowryState.MainEffectsFillColor = OxyColor.Parse(dto.LowryState.MainEffectsFillColor);
                }
                if (dto.LowryState.SmokeFill?.IsAString() == true)
                {
                    LowryState.SmokeFill = OxyColor.Parse(dto.LowryState.SmokeFill);
                }
            }

            MeasuresState.SelectedOutputName = dto.MeasuresState?.SelectedOutputName;

            if (!dto.ParameterStates.IsNullOrEmpty())
            {
                _parameterStates = dto.ParameterStates
                                   .Select(ps =>
                {
                    var name               = ps.Name.AssertNotNull();
                    var distributionType   = Enum.TryParse(ps.DistributionType, out DistributionType dt) ? dt : DistributionType.None;
                    var distributionStates = Distribution.DeserializeDistributions(ps.DistributionStates.AssertNotNull());
                    var isSelected         = ps.IsSelected;
                    return(new ParameterState(name, distributionType, distributionStates, isSelected));
                })
                                   .ToArr();
            }

            if (dto.SensitivityDesign.IsAString())
            {
                try
                {
                    var createdOn = dto.SensitivityDesign.FromDirectoryName();
                    SensitivityDesign = sensitivityDesigns.Load(createdOn);
                    Trace             = sensitivityDesigns.LoadTrace(SensitivityDesign);
                    Ranking           = sensitivityDesigns.LoadRanking(SensitivityDesign);
                }
                catch (Exception) { /* logged elsewhere */ }
            }

            RootExportDirectory = dto.RootExportDirectory;
            OpenAfterExport     = dto.OpenAfterExport;

            _autoApplyParameterSharedState    = dto.AutoApplyParameterSharedState;
            _autoShareParameterSharedState    = dto.AutoShareParameterSharedState;
            _autoApplyElementSharedState      = dto.AutoApplyElementSharedState;
            _autoShareElementSharedState      = dto.AutoShareElementSharedState;
            _autoApplyObservationsSharedState = dto.AutoApplyObservationsSharedState;
            _autoShareObservationsSharedState = dto.AutoShareObservationsSharedState;
        }
Exemplo n.º 7
0
        internal ViewModel(IAppState appState, IAppService appService, IAppSettings appSettings)
        {
            _appState   = appState;
            _appService = appService;
            _simulation = appState.Target.AssertSome();

            var pathToSensitivityDesignsDirectory = _simulation.GetPrivateDirectory(
                nameof(Sensitivity),
                nameof(SensitivityDesigns)
                );

            _sensitivityDesigns = new SensitivityDesigns(pathToSensitivityDesignsDirectory);

            _moduleState = ModuleState.LoadOrCreate(_simulation, _sensitivityDesigns);

            _parametersViewModel     = new ParametersViewModel(appState, appService, appSettings, _moduleState);
            _designViewModel         = new DesignViewModel(appState, appService, appSettings, _moduleState, _sensitivityDesigns);
            _morrisMeasuresViewModel = new MorrisMeasuresViewModel(appState, appService, appSettings, _moduleState, _sensitivityDesigns);
            _morrisEffectsViewModel  = new MorrisEffectsViewModel(appState, appService, appSettings, _moduleState);
            _fast99MeasuresViewModel = new Fast99MeasuresViewModel(appState, appService, appSettings, _moduleState, _sensitivityDesigns);
            _fast99EffectsViewModel  = new Fast99EffectsViewModel(appState, appService, appSettings, _moduleState);
            _designDigestsViewModel  = new DesignDigestsViewModel(appService, _moduleState, _sensitivityDesigns);

            _reactiveSafeInvoke = appService.GetReactiveSafeInvoke();

            _subscriptions = new CompositeDisposable(

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

                _appState.SimSharedState.ParameterSharedStateChanges.Subscribe(
                    _reactiveSafeInvoke.SuspendAndInvoke <(Arr <SimParameterSharedState>, ObservableQualifier)>(
                        ObserveParameterSharedStateChange
                        )
                    ),

                _designDigestsViewModel
                .ObservableForProperty(vm => vm.TargetSensitivityDesign).Subscribe(
                    _reactiveSafeInvoke.SuspendAndInvoke <object>(
                        ObserveTargetSensitivityDesign
                        )
                    ),

                _moduleState
                .ObservableForProperty(ms => ms.SensitivityDesign)
                .Subscribe(
                    _reactiveSafeInvoke.SuspendAndInvoke <object>(
                        ObserveModuleStateSensitivityDesign
                        )
                    ),

                _sensitivityDesigns.SensitivityDesignChanges.Subscribe(
                    _reactiveSafeInvoke.SuspendAndInvoke <(DesignDigest, ObservableQualifier)>(
                        ObserveSensitivityDesignChange
                        )
                    )

                );

            SetActivities();

            if (_moduleState.SensitivityDesign != default)
            {
                _designViewModel.IsSelected = true;
            }
        }