public void Convert(XElement element) { foreach (var parameterCacheElement in element.Descendants("ParameterValuesCache").ToList()) { var parameterValuesCache = new ParameterValuesCache(); foreach (var dataColumnNode in parameterCacheElement.Descendants(ConverterConstants.Serialization.DATA_TABLE_COLUMN)) { var parameterValues = new ParameterValues(dataColumnNode.GetAttribute(CoreConstants.Serialization.Attribute.Name)); parameterValuesCache.Add(parameterValues); } var documentElement = parameterCacheElement.Descendants("DocumentElement").First(); foreach (var parameterValuesElement in documentElement.Descendants("ParameterValues")) { int index = 0; foreach (var parameterValue in parameterValuesElement.Descendants()) { var parameterValues = parameterValuesCache.ParameterValuesAt(index); parameterValues.Add(parameterValue.Value.ConvertedTo <double>()); index++; } } var writer = _container.Resolve <IXmlWriter <ParameterValuesCache> >(); var newElement = writer.WriteFor(parameterValuesCache, SerializationTransaction.Create()); var parent = parameterCacheElement.Parent; parameterCacheElement.Remove(); parent.Add(newElement); } }
protected override void Context() { base.Context(); _individualPropertiesCache = A.Fake <IndividualValuesCache>(); _patchCache = new PathCacheForSpecs <IParameter>(); var individualParameter = A.Fake <IParameter>(); A.CallTo(() => individualParameter.IsChangedByCreateIndividual).Returns(true); _patchCache.Add("Path1", individualParameter); var advancedParameter = A.Fake <IParameter>(); A.CallTo(() => advancedParameter.IsChangedByCreateIndividual).Returns(false); advancedParameter.CanBeVariedInPopulation = true; _patchCache.Add("PathAdvanced", advancedParameter); A.CallTo(() => _individualPropertiesCache.AllParameterPaths()).Returns(new[] { "Path1", "Path2", "PathAdvanced" }); A.CallTo(() => _individualPropertiesCache.ParameterValuesFor("Path1")).Returns(_value1); A.CallTo(() => _individualPropertiesCache.ParameterValuesFor("Path2")).Returns(_value2); A.CallTo(() => _individualPropertiesCache.ParameterValuesFor("PathAdvanced")).Returns(_value3); _populationSimulation = A.Fake <PopulationSimulation>(); _parameterValueCache = A.Fake <ParameterValuesCache>(); A.CallTo(() => _populationSimulation.ParameterValuesCache).Returns(_parameterValueCache); _mobiPopulation = A.Fake <MoBiPopulation>(); A.CallTo(_simulationFactory).WithReturnType <PopulationSimulation>().Returns(_populationSimulation); A.CallTo(() => _objectBaseFactory.Create <MoBiPopulation>()).Returns(_mobiPopulation); A.CallTo(() => _parameterRetriever.ParametersFrom(_populationSimulation)).Returns(_patchCache); A.CallTo(() => _individualPropertiesCacheImporter.ImportFrom(_populationFile, _patchCache, A <IImportLogger> ._)).Returns(_individualPropertiesCache); _advancedParameterContainer = new AdvancedParameter(); A.CallTo(() => _advancedParameterFactory.Create(advancedParameter, DistributionTypes.Unknown)).Returns(_advancedParameterContainer); }
private string updatePath(string parameterPath, ParameterValuesCache parameterCache) { if (string.IsNullOrEmpty(parameterPath)) { return(parameterPath); } if (!parameterPath.Contains(CoreConstants.Parameter.ONTOGENY_FACTOR)) { return(parameterPath); } if (parameterPath.Contains("Lumen-Duodenum")) { parameterCache.Remove(parameterPath); return(parameterPath); } if (parameterPath.Contains("Liver")) { var newPath = parameterPath.Replace("Liver|", ""); parameterCache.RenamePath(parameterPath, newPath); return(newPath); } if (parameterPath.Contains("Duodenum")) { var newPath = parameterPath.Replace("Duodenum|", ""); newPath = newPath.Replace(CoreConstants.Parameter.ONTOGENY_FACTOR, CoreConstants.Parameter.ONTOGENY_FACTOR_GI); parameterCache.RenamePath(parameterPath, newPath); return(newPath); } return(parameterPath); }
protected override void Context() { base.Context(); _populationSimulation = A.Fake <PopulationSimulation>(); _parameterValueCache = new ParameterValuesCache(); _parameterValueCache.Add(new[] { new ParameterValue("PATH1", 1, 0.1), new ParameterValue("PATH2", 2, 0.2) }); _parameterValueCache.Add(new[] { new ParameterValue("PATH1", 11, 0.11), new ParameterValue("PATH2", 11, 0.22) }); _population = CreateRandomPopulation(); A.CallTo(() => _populationSimulation.BuildingBlock <RandomPopulation>()).Returns(_population); A.CallTo(() => _populationSimulation.ParameterValuesCache).Returns(_parameterValueCache); }
protected override void Context() { base.Context(); _originalValueCache = new ParameterValuesCache(); //3 individuals to in original pop _originalIndividualIds = new List <int> { 1, 2, 3 }; var parameterValues1 = new ParameterValues("Path1"); parameterValues1.Add(new double[] { 2, 3, 4 }); var parameterValues2 = new ParameterValues("Path2"); parameterValues2.Add(new double[] { 4, 5, 6 }); _originalValueCache.Add(parameterValues1); _originalValueCache.Add(parameterValues2); _originalCovariates = new CovariateValuesCache(); _originalCovariates.Add("Gender", new[] { "Male", "Female", "Female" }); _parameterCache = new PathCacheForSpecs <IParameter>(); _cacheToMerge = new ParameterValuesCache(); var parameterValuesToMerge1 = new ParameterValues("Path1"); parameterValuesToMerge1.Add(new double[] { 10, 20 }); _cacheToMerge.Add(parameterValuesToMerge1); var parameterValuesToMerge2 = new ParameterValues("Path3"); parameterValuesToMerge2.Add(new double[] { 30, 40 }); _cacheToMerge.Add(parameterValuesToMerge2); _covariatesToMerge = new CovariateValuesCache(); _covariatesToMerge.Add("Gender", new[] { "Female", "Female" }); _covariatesToMerge.Add("Population", new[] { "European", "American" }); _individualIdsToMerge = new List <int> { 10, 20 }; sut = new IndividualValuesCache(_originalValueCache, _originalCovariates, _originalIndividualIds); _individualPropertiesCacheToMerge = new IndividualValuesCache(_cacheToMerge, _covariatesToMerge, _individualIdsToMerge); }
protected override void Context() { base.Context(); _parameter = A.Fake <IDistributedParameter>(); _distributedParameters = new PathCacheForSpecs <IParameter> { { "P1", _parameter } }; _populationSimulation = A.Fake <PopulationSimulation>(); _mobiPopulation = A.Fake <MoBiPopulation>(); _advancedParameter = new AdvancedParameter(); _parameterValueCache = A.Fake <ParameterValuesCache>(); A.CallTo(() => _populationSimulation.ParameterValuesCache).Returns(_parameterValueCache); A.CallTo(_simulationFactory).WithReturnType <PopulationSimulation>().Returns(_populationSimulation); A.CallTo(() => _objectBaseFactory.Create <MoBiPopulation>()).Returns(_mobiPopulation); A.CallTo(() => _objectBaseFactory.Create <AdvancedParameter>()).Returns(_advancedParameter); A.CallTo(_parameterRetriever).WithReturnType <PathCache <IParameter> >().Returns(_distributedParameters); }
protected override void Context() { base.Context(); _parameter1 = DomainHelperForSpecs.ConstantParameterWithValue(1); _parameter2 = DomainHelperForSpecs.ConstantParameterWithValue(2); _parameter3 = DomainHelperForSpecs.ConstantParameterWithValue(3); _parameterCache = A.Fake <PathCache <IParameter> >(); A.CallTo(() => _parameterCache["PATH1"]).Returns(_parameter1); A.CallTo(() => _parameterCache["PATH2"]).Returns(_parameter2); A.CallTo(() => _parameterCache["PATH3"]).Returns(_parameter3); sut.SetValues("PATH1", new double[] { 1, 2, 3 }); sut.SetValues("PATH2", new double[] { 4, 5, 6 }); _cacheToMerge = new ParameterValuesCache(); _cacheToMerge.SetValues("PATH1", new double[] { 7, 8 }); _cacheToMerge.SetValues("PATH3", new double[] { 9, 10 }); }
protected override void Context() { base.Context(); _originalValueCache = A.Fake <ParameterValuesCache>(); _parameterCache = A.Fake <PathCache <IParameter> >(); _cov1 = new IndividualCovariates(); _cov2 = new IndividualCovariates(); _cov3 = new IndividualCovariates(); _cov4 = new IndividualCovariates(); _cacheToMerge = A.Fake <ParameterValuesCache>(); _originalCovariates = new List <IndividualCovariates> { _cov1, _cov2 }; _covariatesToMerge = new List <IndividualCovariates> { _cov3, _cov4 }; sut = new IndividualPropertiesCache(_originalValueCache, _originalCovariates); _individualPropertiesCacheToMerge = new IndividualPropertiesCache(_cacheToMerge, _covariatesToMerge); }
protected override void Because() { _result = sut.Clone(); }