Ejemplo n.º 1
0
        protected override void Context()
        {
            var pathParameterIndividual = "individual";

            _pathParameterAdvanced = "advanced";
            var anotherPath = "another";

            sut = new RandomPopulation();
            sut.SetAdvancedParameters(new AdvancedParameterCollection());
            _baseIndividual = A.Fake <Individual>();
            sut.Settings    = new RandomPopulationSettings {
                BaseIndividual = _baseIndividual
            };
            _entityPathResolver = A.Fake <IEntityPathResolver>();

            _indvidualProperties = new IndividualProperties();
            _indvidualProperties.AddParameterValue(new ParameterValue(pathParameterIndividual, 10, 0.1));
            _indvidualProperties.AddParameterValue(new ParameterValue(_pathParameterAdvanced, 20, 0.2));
            _oneAdvancedParameter = A.Fake <IParameter>().WithName("Advanced");
            A.CallTo(() => _oneAdvancedParameter.IsChangedByCreateIndividual).Returns(false);
            _oneAdvancedParameter.Visible = true;
            _individualParameter          = A.Fake <IParameter>().WithName("Individual");
            A.CallTo(() => _individualParameter.IsChangedByCreateIndividual).Returns(true);
            _individualParameter.Visible = true;
            _anotherParameter            = A.Fake <IParameter>().WithName("Another");
            A.CallTo(() => _anotherParameter.IsChangedByCreateIndividual).Returns(true);
            _anotherParameter.Visible = true;
            A.CallTo(() => _entityPathResolver.PathFor(_oneAdvancedParameter)).Returns(_pathParameterAdvanced);
            A.CallTo(() => _entityPathResolver.PathFor(_individualParameter)).Returns(pathParameterIndividual);
            A.CallTo(() => _entityPathResolver.PathFor(_anotherParameter)).Returns(anotherPath);
            A.CallTo(() => _baseIndividual.GetAllChildren <IParameter>()).Returns(new[] { _individualParameter, _oneAdvancedParameter, _anotherParameter });
            sut.AddIndividualProperties(_indvidualProperties);
        }
Ejemplo n.º 2
0
        private void updateMoleculeOntogeny(IndividualMolecule molecule, Ontogeny ontogeny, Population population, IReadOnlyList <double> allAges, IReadOnlyList <double> allGAs)
        {
            var ontogenyFactorPath   = _entityPathResolver.PathFor(molecule.OntogenyFactorParameter);
            var ontogenyFactorGIPath = _entityPathResolver.PathFor(molecule.OntogenyFactorGIParameter);

            molecule.Ontogeny = ontogeny;

            clearOntogenyFor(ontogenyFactorPath, ontogenyFactorGIPath, population);

            if (ontogeny.IsUndefined())
            {
                return;
            }

            var ontogenyFactors   = new ParameterValues(ontogenyFactorPath);
            var ontogenyFactorsGI = new ParameterValues(ontogenyFactorGIPath);

            for (int i = 0; i < population.NumberOfItems; i++)
            {
                var age = allAges[i];
                var ga  = allGAs[i];
                ontogenyFactors.Add(_ontogenyRepository.OntogenyFactorFor(ontogeny, CoreConstants.Groups.ONTOGENY_LIVER, age, ga, population.RandomGenerator));
                ontogenyFactorsGI.Add(_ontogenyRepository.OntogenyFactorFor(ontogeny, CoreConstants.Groups.ONTOGENY_DUODENUM, age, ga, population.RandomGenerator));
            }

            population.IndividualPropertiesCache.Add(ontogenyFactors);
            population.IndividualPropertiesCache.Add(ontogenyFactorsGI);
        }
Ejemplo n.º 3
0
 public override void Compare(IComparison <ITransport> comparison)
 {
     _containerDiffBuilder.Compare(comparison);
     CompareValues(x => _entityPathResolver.PathFor(x.TargetAmount), Captions.Diff.TargetAmount, comparison);
     CompareValues(x => _entityPathResolver.PathFor(x.SourceAmount), Captions.Diff.SourceAmount, comparison);
     _objectComparer.Compare(comparison.FormulaComparison());
 }
Ejemplo n.º 4
0
        public IEnumerable <ParameterRateMetaData> ParameterRatesFor(IContainer parameterContainer, IEnumerable <string> calculationMethods, Func <ParameterMetaData, bool> predicate)
        {
            var containerPath = _entityPathResolver.PathFor(parameterContainer);

            return(from parameterRateDefinition in _parameterRateRepository.AllFor(containerPath)
                   where predicate(parameterRateDefinition)
                   where calculationMethods.Contains(parameterRateDefinition.CalculationMethod)
                   select parameterRateDefinition);
        }
Ejemplo n.º 5
0
        protected override void Context()
        {
            _populationSimulationSettingsPresenter = A.Fake <IPopulationSimulationSettingsPresenter>();
            _applicationController        = A.Fake <IApplicationController>();
            _projectRetriever             = A.Fake <IPKSimProjectRetriever>();
            _simulationPersistableUpdater = A.Fake <ISimulationPersistableUpdater>();
            _project    = A.Fake <PKSimProject>();
            _compound1  = A.Fake <Compound>();
            _individual = A.Fake <Individual>();
            _human      = new Species().WithName(CoreConstants.Species.HUMAN);
            _rat        = new Species().WithName(CoreConstants.Species.RAT);
            _mouse      = new Species().WithName(CoreConstants.Species.MOUSE);
            A.CallTo(() => _individual.Species).Returns(_human);
            _populationSimulation = A.Fake <PopulationSimulation>();
            A.CallTo(() => _populationSimulation.Compounds).Returns(new[] { _compound1 });
            A.CallTo(() => _populationSimulation.Individual).Returns(_individual);
            _keyPathMapper      = A.Fake <IKeyPathMapper>();
            _entityPathResolver = A.Fake <IEntityPathResolver>();
            _userSettings       = A.Fake <ICoreUserSettings>();
            _originalSettings   = new OutputSelections();
            A.CallTo(() => _populationSimulation.OutputSelections).Returns(_originalSettings);

            _populationSimulation.Model      = new Model();
            _populationSimulation.Model.Root = new Container();
            _compound1.Name = "DRUG";
            var organism = new Organism();
            var peripheralVenousBlood         = new Container().WithName(CoreConstants.Organ.PeripheralVenousBlood);
            var venousBlood                   = new Container().WithName(CoreConstants.Organ.VenousBlood);
            var venousBloodPlasma             = new Container().WithName(CoreConstants.Compartment.Plasma).WithParentContainer(venousBlood);
            var drugPeripheralBlood           = new Container().WithName(_compound1.Name);
            var drugVenousBlood               = new Container().WithName(_compound1.Name);
            var periperhalVenousBloodObserver = new Observer {
                Name = CoreConstants.Observer.PLASMA_PERIPHERAL_VENOUS_BLOOD
            };

            drugPeripheralBlood.Add(periperhalVenousBloodObserver);
            var venousBloodObserver = new Observer {
                Name = CoreConstants.Observer.CONCENTRATION
            };

            drugVenousBlood.Add(venousBloodObserver);
            peripheralVenousBlood.Add(drugPeripheralBlood);
            venousBloodPlasma.Add(drugVenousBlood);
            organism.Add(peripheralVenousBlood);
            organism.Add(venousBlood);

            _populationSimulation.Model.Root.Add(organism);


            A.CallTo(() => _projectRetriever.Current).Returns(_project);
            A.CallTo(() => _applicationController.Start <ISimulationOutputSelectionPresenter <PopulationSimulation> >()).Returns(_populationSimulationSettingsPresenter);
            sut = new SimulationSettingsRetriever(_applicationController, _projectRetriever, _entityPathResolver, _keyPathMapper, _userSettings, _simulationPersistableUpdater);

            A.CallTo(() => _entityPathResolver.PathFor(periperhalVenousBloodObserver)).Returns("PERIPHERAL_OBSERVER");
            A.CallTo(() => _entityPathResolver.PathFor(venousBloodObserver)).Returns("VENOUS_BLOOD_OBSERVER");
        }
        public PopulationAnalysisParameterField CreateFor(IParameter parameter)
        {
            var field = new PopulationAnalysisParameterField
            {
                ParameterPath = _entityPathResolver.PathFor(parameter),
                Name          = _fullPathDisplayResolver.FullPathFor(parameter),
            };

            updateDimension(parameter, field);
            return(field);
        }
 protected override void Context()
 {
     _view = A.Fake <IAdvancedParametersView>();
     _allConstantParameterGroupsPresenter = A.Fake <IPopulationParameterGroupsPresenter>();
     _advancedParameterGroupsPresenter    = A.Fake <IPopulationParameterGroupsPresenter>();
     _advancedParameterPresenter          = A.Fake <IAdvancedParameterPresenter>();
     _entityPathResolver     = A.Fake <IEntityPathResolver>();
     _advancedParametersTask = A.Fake <IAdvancedParametersTask>();
     _eventPublisher         = A.Fake <IEventPublisher>();
     A.CallTo(() => _allConstantParameterGroupsPresenter.View).Returns(A.Fake <IPopulationParameterGroupsView>());
     A.CallTo(() => _advancedParameterGroupsPresenter.View).Returns(A.Fake <IPopulationParameterGroupsView>());
     A.CallTo(() => _advancedParameterPresenter.View).Returns(A.Fake <IAdvancedParameterView>());
     _population            = A.Fake <RandomPopulation>();
     _commandRegister       = A.Fake <ICommandCollector>();
     _allConstantParameters = new List <IParameter>();
     _allAdvancedParameters = new List <IParameter>();
     _allParameters         = new List <IParameter>();
     A.CallTo(() => _population.AllIndividualParameters()).Returns(_allParameters);
     A.CallTo(() => _population.AllConstantParameters(_entityPathResolver)).Returns(_allConstantParameters);
     A.CallTo(() => _population.AllAdvancedParameters(_entityPathResolver)).Returns(_allAdvancedParameters);
     _para1                                 = A.Fake <IParameter>().WithName("_para1");
     _para1.Visible                         = true;
     _para1.CanBeVaried                     = true;
     _para1.CanBeVariedInPopulation         = true;
     _para1.Editable                        = true;
     _para2                                 = A.Fake <IParameter>().WithName("_para2");
     _para2.Editable                        = true;
     _para2.Visible                         = true;
     _para2.CanBeVaried                     = true;
     _para2.CanBeVariedInPopulation         = true;
     _advancedPara1                         = A.Fake <IParameter>().WithName("_advancedPara1");
     _advancedPara1.Visible                 = true;
     _advancedPara1.Editable                = true;
     _advancedPara1.CanBeVaried             = true;
     _advancedPara1.CanBeVariedInPopulation = true;
     _pathPara1                             = "_pathPara1";
     _pathPara2                             = "_pathPara2";
     _pathAdvancedPara1                     = "_pathAdvancedPara1";
     _allParameters.AddRange(new[] { _para1, _para2, _advancedPara1 });
     _allConstantParameters.AddRange(new[] { _para1, _para2 });
     _allAdvancedParameters.AddRange(new[] { _advancedPara1 });
     A.CallTo(() => _entityPathResolver.PathFor(_para1)).Returns(_pathPara1);
     A.CallTo(() => _entityPathResolver.PathFor(_para2)).Returns(_pathPara2);
     A.CallTo(() => _entityPathResolver.PathFor(_advancedPara1)).Returns(_pathAdvancedPara1);
     _representationInfoRepository = A.Fake <IRepresentationInfoRepository>();
     sut = new PopulationAdvancedParametersPresenter(_view, _entityPathResolver, _allConstantParameterGroupsPresenter, _advancedParameterGroupsPresenter, _advancedParameterPresenter,
                                                     _advancedParametersTask, _eventPublisher);
     sut.InitializeWith(_commandRegister);
 }
Ejemplo n.º 8
0
        public void should_have_addded_the_bsa_values_to_the_population()
        {
            var population       = First <Population>();
            var bsaParameterPath = _entityPathResolver.PathFor(population.Organism.Parameter(CoreConstants.Parameter.BSA));

            population.IndividualPropertiesCache.Has(bsaParameterPath).ShouldBeTrue();
        }
Ejemplo n.º 9
0
        public IReadOnlyList <IContainer> SubContainersFor(SpeciesPopulation speciesPopulation, IContainer parentContainer)
        {
            var pathToParentContainer = _entityPathResolver.PathFor(parentContainer);
            var flatParentContainer   = _flatContainerRepository.ContainerFrom(pathToParentContainer);

            return(_populationContainerRepository.AllSubContainerFor(speciesPopulation.Name, flatParentContainer.Id).MapAllUsing(_containerMapper));
        }
Ejemplo n.º 10
0
        public void ShowParametersFor(Simulation simulation)
        {
            var allParameters = simulation.All <IParameter>().Where(parameterShouldBeDisplayed);

            _view.Caption = $"All Parameters for Simulation with Id {simulation.Id}";

            var parameterIdTable = new DataTable("Parameter Id");

            parameterIdTable.AddColumn("Parameter Path");
            parameterIdTable.AddColumn("Building block Type");
            parameterIdTable.AddColumn("Building block Id");
            parameterIdTable.AddColumn("Parameter Id");
            parameterIdTable.AddColumn("Simulation Id");

            foreach (var parameter in allParameters)
            {
                var row = parameterIdTable.NewRow();
                row[0] = _entityPathResolver.PathFor(parameter);
                row[1] = parameter.BuildingBlockType.ToString();
                row[2] = parameter.Origin.BuilingBlockId;
                row[3] = parameter.Origin.ParameterId;
                row[4] = parameter.Origin.SimulationId;
                parameterIdTable.Rows.Add(row);
            }

            _view.BindTo(parameterIdTable);
            _view.Display();
        }
Ejemplo n.º 11
0
        private void addBSAParameterValues(Population population)
        {
            if (!population.IsHuman)
            {
                return;
            }

            var defaultHuman = _cloner.Clone(_defaultIndividualRetriever.DefaultHuman());

            var heightParameter = defaultHuman.Organism.Parameter(CoreConstants.Parameter.HEIGHT);
            var weightParameter = defaultHuman.Organism.Parameter(CoreConstants.Parameter.WEIGHT);
            var bsaParameter    = defaultHuman.Organism.Parameter(CoreConstants.Parameter.BSA);

            var allWeights = population.AllOrganismValuesFor(weightParameter.Name, _entityPathResolver);
            var allHeights = population.AllOrganismValuesFor(heightParameter.Name, _entityPathResolver);

            if (allHeights.Count != allWeights.Count)
            {
                return;
            }

            var parameterValues = new ParameterValues(_entityPathResolver.PathFor(bsaParameter));

            for (int i = 0; i < allWeights.Count; i++)
            {
                weightParameter.Value = allWeights[i];
                heightParameter.Value = allHeights[i];
                parameterValues.Add(bsaParameter.Value);
            }

            population.IndividualPropertiesCache.Add(parameterValues);
        }
 private List <ParameterValue> parameterValuesFor(IModel simulationModel)
 {
     return(simulationModel.Root.GetAllChildren <IParameter>().Select(p => new ParameterValue
     {
         Path = _entityPathResolver.PathFor(p),
         Value = p.Value
     }).ToList());
 }
Ejemplo n.º 13
0
 private void convertIndividualSimulationSettings(IndividualSimulation simulation)
 {
     _simulationPersistableUpdater.ResetPersistable(simulation);
     foreach (var observer in simulation.All <IObserver>().Where(x => x.Persistable))
     {
         simulation.OutputSelections.AddOutput(new QuantitySelection(_entityPathResolver.PathFor(observer), observer.QuantityType));
     }
 }
        protected override void Context()
        {
            _lazyLoadTask                = A.Fake <ILazyLoadTask>();
            _pkValuesCalculator          = A.Fake <IPKValuesCalculator>();
            _pkParameterRepository       = A.Fake <IPKParameterRepository>();
            _pkCalculationOptionsFactory = A.Fake <IPKCalculationOptionsFactory>();
            _entityPathResolver          = A.Fake <IEntityPathResolver>();
            _pkMapper            = A.Fake <IPKValuesToPKAnalysisMapper>();
            _dimensionRepository = A.Fake <IDimensionRepository>();
            sut = new PKAnalysesTask(_lazyLoadTask, _pkValuesCalculator, _pkParameterRepository, _pkCalculationOptionsFactory, _entityPathResolver, _pkMapper, _dimensionRepository);

            _populationSimulation = A.Fake <PopulationSimulation>();
            _outputSelections     = new OutputSelections();
            A.CallTo(() => _populationSimulation.OutputSelections).Returns(_outputSelections);
            _allBodyWeights = new List <double>();
            _bodyWeight     = A.Fake <IParameter>();
            var bodyWeightPath = "PATH";

            A.CallTo(() => _populationSimulation.BodyWeight).Returns(_bodyWeight);
            A.CallTo(() => _entityPathResolver.PathFor(_bodyWeight)).Returns(bodyWeightPath);
            A.CallTo(() => _populationSimulation.AllValuesFor(bodyWeightPath)).Returns(_allBodyWeights);
            A.CallTo(() => _populationSimulation.NumberOfItems).Returns(2);
            _individualResult0 = new IndividualResults {
                IndividualId = 0, Time = new QuantityValues {
                    Values = new[] { 1f, 2f }
                }
            };
            _individualResult0.Add(new QuantityValues {
                QuantityPath = _quantityPath1, Values = new[] { 10f, 20f }
            });
            _individualResult0.Add(new QuantityValues {
                QuantityPath = _quantityPath2, Values = new[] { 11f, 21f }
            });
            _individualResult1 = new IndividualResults {
                IndividualId = 1, Time = new QuantityValues {
                    Values = new[] { 3f, 4f }
                }
            };
            _individualResult1.Add(new QuantityValues {
                QuantityPath = _quantityPath1, Values = new[] { 30f, 40f }
            });
            _individualResult1.Add(new QuantityValues {
                QuantityPath = _quantityPath2, Values = new[] { 31f, 41f }
            });
            _simulationResults = new SimulationResults {
                _individualResult0, _individualResult1
            };
            _populationSimulation.Results = _simulationResults;

            _pkParameter1 = new PKParameter {
                Mode = PKParameterMode.Always, Name = "Cmax"
            };
            _pkParameter2 = new PKParameter {
                Mode = PKParameterMode.Always, Name = "tMax"
            };

            A.CallTo(() => _pkParameterRepository.All()).Returns(new[] { _pkParameter1, _pkParameter2 });
        }
Ejemplo n.º 15
0
        public IEnumerable <IContainer> SubContainersFor(Species species, IContainer parentContainer)
        {
            var pathToParentContainer = _entityPathResolver.PathFor(parentContainer);

            var flatParentContainer = _flatContainerRepository.ContainerFrom(pathToParentContainer);

            return(_speciesContainerRepository.AllSubContainer(species.Name, flatParentContainer.Id)
                   .Select(speciesContainer => _containerMapper.MapFrom(speciesContainer)));
        }
Ejemplo n.º 16
0
        private string parameterPathFor(IParameter parameter)
        {
            if (parameter == null)
            {
                return(string.Empty);
            }

            return(_entityPathResolver.PathFor(parameter));
        }
Ejemplo n.º 17
0
        private void addParameterToTable(IVectorialParametersContainer parameterContainer, DataTable dataTable, IParameter parameter)
        {
            //some path have changed and the parameter is not found anymore
            if (parameter == null)
            {
                return;
            }

            addColumnForParameterToTable(parameterContainer, dataTable, _entityPathResolver.PathFor(parameter));
        }
Ejemplo n.º 18
0
        private ICommand synchronizeInParameters <TBuilder>(IEnumerable <TBuilder> builders) where TBuilder : IContainer
        {
            var buildingBlockParameters = new PathCache <IParameter>(_entityPathResolver);

            buildingBlockParameters.AddRange(builders.SelectMany(x => x.GetAllChildren <IParameter>()));
            var parameterPath          = _entityPathResolver.PathFor(_parameter);
            var buildingBlockParameter = buildingBlockParameters[parameterPath];

            return(setSynchronizeCommand(buildingBlockParameter));
        }
Ejemplo n.º 19
0
 protected override void Context()
 {
     base.Context();
     _entityPathResolver = A.Fake <IEntityPathResolver>();
     _parameter          = new PKSimParameter();
     _parameterPath      = "TOTO";
     sut = new ParameterTask(_entityPathResolver, _executionContext, _favoriteTask);
     A.CallTo(() => _entityPathResolver.PathFor(_parameter)).Returns(_parameterPath);
     A.CallTo(() => _executionContext.PublishEvent(A <AddParameterToFavoritesEvent> ._))
     .Invokes(x => _event = x.GetArgument <AddParameterToFavoritesEvent>(0));
 }
Ejemplo n.º 20
0
        public ICache <IParameter, IParameter> GroupExpressionParameters(IEnumerable <IParameter> allExpressionsParameters)
        {
            var allExpressionsParametersList      = allExpressionsParameters.ToList();
            var normRelativeExpressionsParameters = allExpressionsParametersList.Where(x => x.Name.Contains(CoreConstants.Parameter.NormSuffix)).ToList();
            var relativeExpressionsParameters     = allExpressionsParametersList.Where(x => !normRelativeExpressionsParameters.Contains(x))
                                                    .Where(x => x.Name.StartsWith(CoreConstants.Parameter.RelExp));

            var results        = new Cache <IParameter, IParameter>();
            var containerPaths = normRelativeExpressionsParameters.Select(x => _entityPathResolver.PathFor(x.ParentContainer)).ToList();

            foreach (var parameter in relativeExpressionsParameters)
            {
                var normParameter = findNormParameterFor(parameter, normRelativeExpressionsParameters, containerPaths);
                if (normParameter != null)
                {
                    results.Add(parameter, normParameter);
                }
            }
            return(results);
        }
Ejemplo n.º 21
0
        /// <summary>
        ///    Returns all values defined for the organism parameter names <paramref name="parameterName" />
        /// </summary>
        public virtual IReadOnlyList <double> AllOrganismValuesFor(string parameterName, IEntityPathResolver entityPathResolver)
        {
            if (FirstIndividual == null)
            {
                return(defaultValuesWith(double.NaN));
            }

            var parameterPath = entityPathResolver.PathFor(FirstIndividual.Organism.Parameter(parameterName));

            return(AllValuesFor(parameterPath));
        }
        private void compareNeighbors(IComparison <INeighborhoodBase> comparison)
        {
            var firstNeigbor1Path  = _entityPathResolver.PathFor(comparison.Object1.FirstNeighbor);
            var secondNeigbor1Path = _entityPathResolver.PathFor(comparison.Object1.SecondNeighbor);
            var firstNeigbor2Path  = _entityPathResolver.PathFor(comparison.Object2.FirstNeighbor);
            var secondNeigbor2Path = _entityPathResolver.PathFor(comparison.Object2.SecondNeighbor);

            if (firstNeigbor1Path.Equals(firstNeigbor2Path) && secondNeigbor1Path.Equals(secondNeigbor2Path) ||
                firstNeigbor1Path.Equals(secondNeigbor2Path) && secondNeigbor1Path.Equals(firstNeigbor2Path))
            {
                return;
            }

            comparison.Add(new PropertyValueDiffItem
            {
                CommonAncestor  = comparison.Object1,
                FormattedValue1 = Captions.Diff.ConnectionBetween(firstNeigbor1Path, secondNeigbor1Path),
                FormattedValue2 = Captions.Diff.ConnectionBetween(firstNeigbor2Path, secondNeigbor2Path),
                PropertyName    = Captions.Diff.Connection,
                Description     = Captions.Diff.PropertyDiffers(Captions.Diff.Connection, Captions.Diff.ConnectionBetween(firstNeigbor1Path, secondNeigbor1Path), Captions.Diff.ConnectionBetween(firstNeigbor2Path, secondNeigbor2Path))
            });
        }
Ejemplo n.º 23
0
        private IParameter templateParameterFor(IParameter parameter, PathCache <IParameter> templateParameters)
        {
            var buildingBlockParameter = _executionContext.Get <IParameter>(parameter.Origin.ParameterId);

            if (buildingBlockParameter == null)
            {
                return(null);
            }

            var buildingBlockParameterPath = _entityPathResolver.PathFor(buildingBlockParameter);

            return(templateParameters[buildingBlockParameterPath]);
        }
Ejemplo n.º 24
0
        private void addAgeDependentPercentileValues(ParameterValues parameterValues, RandomPopulation randomPopulation, IDistributedParameter parameter, Individual individual)
        {
            var originData     = individual.OriginData.Clone();
            var allAges        = randomPopulation.AllValuesFor(_entityPathResolver.PathFor(individual.Organism.Parameter(CoreConstants.Parameter.AGE))).ToList();
            var allGender      = randomPopulation.AllGenders.ToList();
            var allValues      = randomPopulation.AllValuesFor(_entityPathResolver.PathFor(parameter)).ToList();
            var allPercentiles = new double[allValues.Count].InitializeWith(0);

            originData.GestationalAge = CoreConstants.NOT_PRETERM_GESTATIONAL_AGE_IN_WEEKS;

            //cache female and male distributions
            originData.Gender = _genderRepository.Female;
            var allFemalesDistributions = _parameterQuery.ParameterDistributionsFor(parameter.ParentContainer, originData, p => string.Equals(p.ParameterName, parameter.Name)).ToList();

            originData.Gender = _genderRepository.Male;
            var allMaleDistributions = _parameterQuery.ParameterDistributionsFor(parameter.ParentContainer, originData, p => string.Equals(p.ParameterName, parameter.Name)).ToList();

            for (int individualIndex = 0; individualIndex < randomPopulation.NumberOfItems; individualIndex++)
            {
                //create orgin data for individual i
                originData.Age = allAges[individualIndex];
                var distributions = allFemalesDistributions;
                if (_genderRepository.Male == allGender[individualIndex])
                {
                    distributions = allMaleDistributions;
                }

                if (distributions.Count == 0)
                {
                    allPercentiles[individualIndex] = CoreConstants.DEFAULT_PERCENTILE;
                }
                else
                {
                    allPercentiles[individualIndex] = percentileFrom(distributions, originData, allValues[individualIndex]);
                }
            }
            addPercentileValues(parameterValues, allPercentiles);
        }
Ejemplo n.º 25
0
        protected override void Context()
        {
            _affectedBuildingBlockRetriever = A.Fake <IAffectedBuildingBlockRetriever>();
            _entityPathResolver             = A.Fake <IEntityPathResolver>();
            _context = A.Fake <IMoBiContext>();
            sut      = new QuantitySynchronizer(_affectedBuildingBlockRetriever, _entityPathResolver, _context);

            _simulation        = A.Fake <IMoBiSimulation>();
            _buildingBlockInfo = A.Fake <IBuildingBlockInfo>();
            _objectPath        = new ObjectPath("P");
            A.CallTo(() => _entityPathResolver.ObjectPathFor(_parameter, false)).Returns(_objectPath);
            A.CallTo(() => _entityPathResolver.PathFor(_parameter)).Returns("P");
            A.CallTo(() => _affectedBuildingBlockRetriever.RetrieveFor(_quantity, _simulation)).Returns(_buildingBlockInfo);
        }
Ejemplo n.º 26
0
        private IEnumerable <FlatContainer> flatSubContainersFor(IContainer container, Func <string, bool> containerTypeCondition)
        {
            var pathToParentContainer = _entityPathResolver.PathFor(container);

            //find parent container in repo
            var flatParentContainer = _flatContainerRepo.ContainerFrom(pathToParentContainer);

            return(from flatContainer in _flatContainerRepo.All()
                   let parentContainer = _flatContainerRepo.ParentContainerFrom(flatContainer.Id)
                                         where parentContainer != null
                                         where parentContainer.Id == flatParentContainer.Id
                                         where containerTypeCondition(flatContainer.Type)
                                         select flatContainer);
        }
Ejemplo n.º 27
0
        private void updateParameterValue(Population population, int individualId, IParameter parameter, PathCache <IParameter> exctractedIndividualParameterCache)
        {
            var parameterPath        = _entityPathResolver.PathFor(parameter);
            var parameterValues      = population.AllValuesFor(parameterPath);
            var exactractedParameter = exctractedIndividualParameterCache[parameterPath];
            var value = parameterValues[individualId];

            if (!shouldUpdateParameter(exactractedParameter, value))
            {
                return;
            }

            exactractedParameter.Value = value;
        }
Ejemplo n.º 28
0
        private void addParameterToTable(IVectorialParametersContainer parameterContainer, DataTable dataTable, IParameter parameter, bool includeUnitsInHeader)
        {
            //some path have changed and the parameter is not found anymore
            if (parameter == null)
            {
                return;
            }

            var parameterPath = _entityPathResolver.PathFor(parameter);

            var columnName = includeUnitsInHeader ? Constants.NameWithUnitFor(parameterPath, parameter.Dimension.BaseUnit.Name) : parameterPath;

            addColumnForParameterToTable(parameterContainer, dataTable, parameterPath, columnName);
        }
Ejemplo n.º 29
0
        private TestSimulation createSimulation()
        {
            var buildConfiguration = _modelHelper.CreateBuildConfiguration();
            var result             = _modelConstructor.CreateModelFrom(buildConfiguration, "Test");
            var simulation         = new TestSimulation
            {
                BuildConfiguration = buildConfiguration,
                Model = result.Model,
                Name  = "Test"
            };

            var allPersistable = simulation.All <IQuantity>().Where(x => x.Persistable).ToList();
            var firstAmount    = allPersistable.First(x => x.Dimension.Name == Constants.Dimension.AMOUNT);

            simulation.OutputSelections.AddOutput(new QuantitySelection(_entityPathResolver.PathFor(firstAmount), QuantityType.Molecule));

            var firstFraction = allPersistable.First(x => x.Dimension.Name == Constants.Dimension.FRACTION);

            simulation.OutputSelections.AddOutput(new QuantitySelection(_entityPathResolver.PathFor(firstFraction), QuantityType.Molecule));

            _projectRetriever.CurrentProject.AddObservedData(observedDataFor(firstAmount));
            _projectRetriever.CurrentProject.AddObservedData(observedDataFor(firstFraction));
            return(simulation);
        }
Ejemplo n.º 30
0
        public void SetParameterFavorite(IParameter parameter, bool isFavorite)
        {
            var parameterPath = _entityPathResolver.PathFor(parameter);

            if (isFavorite)
            {
                _favoriteRepository.AddFavorite(parameterPath);
                _eventPublisher.PublishEvent(new AddParameterToFavoritesEvent(parameterPath));
            }
            else
            {
                _favoriteRepository.RemoveFavorite(parameterPath);
                _eventPublisher.PublishEvent(new RemoveParameterFromFavoritesEvent(parameterPath));
            }
        }