예제 #1
0
        internal PriorsViewModel(IAppState appState, IAppService appService, IAppSettings appSettings, ModuleState moduleState)
        {
            _simulation  = appState.Target.AssertSome("No simulation");
            _moduleState = moduleState;

            _toggleSelectPrior = ReactiveCommand.Create <IPriorViewModel>(HandleToggleSelectPrior);

            var parameters = _simulation.SimConfig.SimInput.SimParameters;

            AllPriorViewModels = parameters
                                 .Map(p => new PriorViewModel(p.Name, _toggleSelectPrior))
                                 .OrderBy(vm => vm.SortKey)
                                 .ToArr <IPriorViewModel>();

            moduleState.PriorStates.Iter(ps =>
            {
                var priorViewModel = AllPriorViewModels
                                     .Find(vm => vm.Name == ps.Name)
                                     .AssertSome($"Unknown prior in module state: {ps.Name}");

                priorViewModel.IsSelected   = ps.IsSelected;
                priorViewModel.Distribution = ps.GetDistribution().ToString(ps.Name);
            });

            SelectedPriorViewModels = new ObservableCollection <IPriorViewModel>(
                AllPriorViewModels.Where(vm => vm.IsSelected)
                );

            SelectedPriorViewModel = SelectedPriorViewModels.FindIndex(
                vm => vm.Name == moduleState.PriorsState.SelectedPrior
                );

            var distributionTypes =
                DistributionType.Beta |
                DistributionType.Gamma |
                DistributionType.Invariant |
                DistributionType.LogNormal |
                DistributionType.Normal |
                DistributionType.Uniform
            ;

            _parameterDistributionViewModel = new ParameterDistributionViewModel(
                appState,
                appService,
                appSettings,
                distributionTypes,
                allowTruncation: true
                );

            _reactiveSafeInvoke = appService.GetReactiveSafeInvoke();

            _subscriptions = new CompositeDisposable(

                this
                .WhenAny(vm => vm.SelectedPriorViewModel, _ => default(object))
                .Subscribe(
                    _reactiveSafeInvoke.SuspendAndInvoke <object?>(
                        ObserveSelectedPriorViewModel
                        )
                    ),

                _parameterDistributionViewModel
                .ObservableForProperty(vm => vm.ParameterState)
                .Subscribe(
                    _reactiveSafeInvoke.SuspendAndInvoke <object>(
                        ObserveParameterDistributionViewModelParameterState
                        )
                    ),

                moduleState.PriorStateChanges.Subscribe(
                    _reactiveSafeInvoke.SuspendAndInvoke <(Arr <ParameterState>, ObservableQualifier)>(
                        ObserveModuleStatePriorStateChange
                        )
                    )

                );
        }
예제 #2
0
        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;
            });

            SelectedParameterViewModels = new ObservableCollection <IParameterViewModel>(
                AllParameterViewModels.Where(vm => vm.IsSelected)
                );

            SelectedParameterViewModel = SelectedParameterViewModels.FindIndex(
                vm => vm.Name == moduleState.ParametersState.SelectedParameter
                );

            _parameterDistributionViewModel = new ParameterDistributionViewModel(appState, appService, appSettings, true);

            _reactiveSafeInvoke = appService.GetReactiveSafeInvoke();

            using (_reactiveSafeInvoke.SuspendedReactivity)
            {
                _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
                            )
                        )

                    );

                UpdateParameterViewModelDistributions(moduleState.ParameterStates);
                UpdateSelectedParameter();
            }
        }