private IndividualValuesCache withUpdatedGenderAndRace(IndividualValuesCache individualValuesCache) { var parameterValues = individualValuesCache.ParameterValuesCache; var covariateValuesCache = new CovariateValuesCache(); individualValuesCache.CovariateValuesCache.AllCovariateValues.Each(x => { if (!x.CovariateName.IsOneOf(Constants.Population.RACE_INDEX, Constants.Population.GENDER)) { covariateValuesCache.Add(x); } else if (string.Equals(x.CovariateName, Constants.Population.RACE_INDEX)) { covariateValuesCache.Add(populationCovariateFrom(x)); } else { covariateValuesCache.Add(genderCovariateFrom(x)); } }); return(new IndividualValuesCache(parameterValues, covariateValuesCache, individualValuesCache.IndividualIds)); }
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(); sut.Add("Gender", new List <string> { "Male", "Female" }); sut.Add("Race", new List <string> { "Japanese", "European" }); _cacheToMerge = new CovariateValuesCache(); _cacheToMerge.Add("Gender", new List <string> { "Female", "Female" }); _cacheToMerge.Add("Head", new List <string> { "Big", "Small" }); }
private XElement createCovariateValuesCacheElement(IEnumerable <XElement> allCovariatesElement) { var covariateValuesCache = new CovariateValuesCache(); var individualCovariatesReader = _container.Resolve <IXmlReader <IndividualCovariates> >(); var covariateValuesCacheWriter = _container.Resolve <IXmlWriter <CovariateValuesCache> >(); var context = SerializationTransaction.Create(_container); // List of old covariates as defined in PKSim 8.x and below var allIndividualCovariates = new List <IndividualCovariates>(); foreach (var individualCovariatesElement in allCovariatesElement.Descendants("IndividualCovariates")) { var individualCovariates = individualCovariatesReader.ReadFrom(individualCovariatesElement, context); allIndividualCovariates.Add(individualCovariates); } var allCovariateNames = allIndividualCovariates.FirstOrDefault()?.Attributes.Keys.ToList() ?? new List <string>(); allCovariateNames.Add(Constants.Population.GENDER); allCovariateNames.Add(Constants.Population.POPULATION); // Transform the old covariates in the new structure foreach (var covariateName in allCovariateNames) { var covariateValues = new CovariateValues(covariateName); if (string.Equals(covariateName, Constants.Population.GENDER)) { covariateValues.Values = allIndividualCovariates.Select(x => x.Gender.Name).ToList(); } else if (string.Equals(covariateName, Constants.Population.POPULATION)) { covariateValues.Values = allIndividualCovariates.Select(x => x.Race.Name).ToList(); } else { covariateValues.Values = allIndividualCovariates.Select(x => x.Covariate(covariateName)).ToList(); } covariateValuesCache.Add(covariateValues); } return(covariateValuesCacheWriter.WriteFor(covariateValuesCache, context)); }