internal MorrisEffectsViewModel( IAppState appState, IAppService appService, IAppSettings appSettings, ModuleState moduleState ) { _appState = appState; _simulation = appState.Target.AssertSome(); _moduleState = moduleState; var independentVariable = _simulation.SimConfig.SimOutput.IndependentVariable; XUnits = independentVariable.Unit; _muStarSigmaViewModel = new MuStarSigmaViewModel(appService, appSettings); _traceViewModel = new TraceViewModel(appService, appSettings, moduleState.TraceState); _playTicker = new DispatcherTimer(DispatcherPriority.Normal); _playTicker.Tick += HandlePlayTick; PlaySpeed = _playSpeeds[_playSpeedIndex]; PlaySimulation = ReactiveCommand.Create( HandlePlaySimulation, this.ObservableForProperty(vm => vm.CanPlaySimulation, _ => CanPlaySimulation) ); StopSimulation = ReactiveCommand.Create( HandleStopSimulation, this.ObservableForProperty(vm => vm.CanStopSimulation, _ => CanStopSimulation) ); PlaySlower = ReactiveCommand.Create( HandlePlaySlower, this.ObservableForProperty(vm => vm.CanPlaySlower, _ => CanPlaySlower) ); PlayFaster = ReactiveCommand.Create( HandlePlayFaster, this.ObservableForProperty(vm => vm.CanPlayFaster, _ => CanPlayFaster) ); UseRankedParameters = ReactiveCommand.Create( HandleUseRankedParameters, this.ObservableForProperty(vm => vm.RankedParameterViewModels, _ => RankedParameterViewModels.Count > 0) ); ShareRankedParameters = ReactiveCommand.Create( HandleShareRankedParameters, this.ObservableForProperty(vm => vm.RankedParameterViewModels, _ => RankedParameterViewModels.Count > 0) ); _reactiveSafeInvoke = appService.GetReactiveSafeInvoke(); _subscriptions = new CompositeDisposable( moduleState .ObservableForProperty(ms => ms.SensitivityDesign) .Subscribe(ObserveModuleStateSensitivityDesign), moduleState.MeasuresState .ObservableForProperty(ms => ms.MorrisOutputMeasures) .Subscribe(ObserveMeasuresStateMorrisOutputMeasures), 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), _traceViewModel .ObservableForProperty(vm => vm.SelectedX) .Subscribe(ObserveTraceSelectedX) ); using (_reactiveSafeInvoke.SuspendedReactivity) { Populate(); PopulateRanking(); UpdateEnable(); } }
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 ) ) ); }
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); } }
internal ParametersViewModel( IAppState appState, IAppService appService, IAppSettings appSettings, ModuleState moduleState ) { _simulation = appState.Target.AssertSome("No simulation"); _moduleState = moduleState; _toggleSelectParameter = ReactiveCommand.Create <IParameterViewModel>( HandleToggleSelectParameter ); var parameters = _simulation.SimConfig.SimInput.SimParameters; AllParameterViewModels = parameters .Map(p => new ParameterViewModel(p.Name, _toggleSelectParameter)) .OrderBy(vm => vm.SortKey) .ToArr <IParameterViewModel>(); moduleState.ParameterStates.Iter(ps => { var parameterViewModel = AllParameterViewModels .Find(vm => vm.Name == ps.Name) .AssertSome($"Unknown parameter in module state: {ps.Name}"); parameterViewModel.IsSelected = ps.IsSelected; parameterViewModel.Distribution = ps.GetDistribution().ToString(ps.Name); }); SelectedParameterViewModels = new ObservableCollection <IParameterViewModel>( AllParameterViewModels.Where(vm => vm.IsSelected) ); SelectedParameterViewModel = SelectedParameterViewModels.FindIndex( vm => vm.Name == moduleState.ParametersState.SelectedParameter ); _parameterDistributionViewModel = new ParameterDistributionViewModel( appState, appService, appSettings, SupportedDistTypes, allowTruncation: true ); _reactiveSafeInvoke = appService.GetReactiveSafeInvoke(); _subscriptions = new CompositeDisposable( this .WhenAny(vm => vm.SelectedParameterViewModel, _ => default(object)) .Subscribe( _reactiveSafeInvoke.SuspendAndInvoke <object?>( ObserveSelectedParameterViewModel ) ), _parameterDistributionViewModel .ObservableForProperty(vm => vm.ParameterState) .Subscribe( _reactiveSafeInvoke.SuspendAndInvoke <object>( ObserveParameterDistributionViewModelParameterState ) ), moduleState.ParameterStateChanges.Subscribe( _reactiveSafeInvoke.SuspendAndInvoke <(Arr <ParameterState>, ObservableQualifier)>( ObserveModuleStateParameterStateChange ) ) ); }
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(); } }
internal static void Save(ModuleState instance, Simulation simulation) { simulation.SavePrivateData( new _ModuleStateDTO { ParametersState = new _ParametersStateDTO { SelectedParameter = instance.ParametersState.SelectedParameter }, DesignState = new _DesignStateDTO { SensitivityMethod = instance.DesignState.SensitivityMethod?.ToString(), NoOfRuns = instance.DesignState.NoOfRuns, NoOfSamples = instance.DesignState.NoOfSamples, SelectedElementName = instance.DesignState.SelectedElementName }, TraceState = new _TraceStateDTO { ViewHeight = instance.TraceState.ViewHeight, MarkerFill = instance.TraceState.MarkerFill?.ToByteString(), SeriesColor = instance.TraceState.SeriesColor?.ToByteString(), HorizontalAxisMinimum = ToDTOAxisValue(instance.TraceState.HorizontalAxisMinimum), HorizontalAxisMaximum = ToDTOAxisValue(instance.TraceState.HorizontalAxisMaximum), HorizontalAxisAbsoluteMinimum = ToDTOAxisValue(instance.TraceState.HorizontalAxisAbsoluteMinimum), HorizontalAxisAbsoluteMaximum = ToDTOAxisValue(instance.TraceState.HorizontalAxisAbsoluteMaximum), VerticalAxisMinimum = ToDTOAxisValue(instance.TraceState.VerticalAxisMinimum), VerticalAxisMaximum = ToDTOAxisValue(instance.TraceState.VerticalAxisMaximum), VerticalAxisAbsoluteMinimum = ToDTOAxisValue(instance.TraceState.VerticalAxisAbsoluteMinimum), VerticalAxisAbsoluteMaximum = ToDTOAxisValue(instance.TraceState.VerticalAxisAbsoluteMaximum) }, LowryState = new _LowryStateDTO { ChartTitle = instance.LowryState.ChartTitle, XAxisTitle = instance.LowryState.XAxisTitle, YAxisTitle = instance.LowryState.YAxisTitle, InteractionsFillColor = instance.LowryState.InteractionsFillColor?.ToByteString(), MainEffectsFillColor = instance.LowryState.MainEffectsFillColor?.ToByteString(), SmokeFill = instance.LowryState.SmokeFill?.ToByteString() }, MeasuresState = new _MeasuresStateDTO { SelectedOutputName = instance.MeasuresState.SelectedOutputName }, ParameterStates = instance.ParameterStates .Map(ps => new _ParameterStateDTO { Name = ps.Name, DistributionType = ps.DistributionType.ToString(), DistributionStates = Distribution.SerializeDistributions(ps.Distributions), IsSelected = ps.IsSelected }) .ToArray(), SensitivityDesign = instance.SensitivityDesign?.CreatedOn.ToDirectoryName(), RootExportDirectory = instance.RootExportDirectory, OpenAfterExport = instance.OpenAfterExport, AutoApplyParameterSharedState = instance.AutoApplyParameterSharedState, AutoShareParameterSharedState = instance.AutoShareParameterSharedState, AutoApplyElementSharedState = instance.AutoApplyElementSharedState, AutoShareElementSharedState = instance.AutoShareElementSharedState, AutoApplyObservationsSharedState = instance.AutoApplyObservationsSharedState, AutoShareObservationsSharedState = instance.AutoShareObservationsSharedState }, nameof(Sensitivity), nameof(ViewModel), nameof(ModuleState) ); }
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; } }