protected override Task Context()
        {
            _calculationMethodRepository         = A.Fake <ICalculationMethodRepository>();
            _calculationMethodCategoryRepository = A.Fake <ICalculationMethodCategoryRepository>();
            _logger = A.Fake <ILogger>();

            sut             = new CalculationMethodCacheMapper(_calculationMethodRepository, _calculationMethodCategoryRepository, _logger);
            _singleCategory = new CalculationMethodCategory {
                Name = "Multiple"
            };
            _multipleCategory = new CalculationMethodCategory {
                Name = "Single"
            };


            _calculationMethodWithMultipleOptions = new CalculationMethod
            {
                Name        = "CM1",
                DisplayName = "CM1",
                Category    = _multipleCategory.Name
            };

            _calculationMethodWithSingleOption = new CalculationMethod
            {
                Name        = "CM2",
                DisplayName = "CM2",
                Category    = _singleCategory.Name
            };

            _anotherCalculationMethodInMultipleOptions = new CalculationMethod
            {
                Name     = "Another CM",
                Category = _multipleCategory.Name
            };

            A.CallTo(() => _calculationMethodRepository.All()).Returns(new [] { _calculationMethodWithMultipleOptions, _anotherCalculationMethodInMultipleOptions, _calculationMethodWithSingleOption, });

            _singleCategory.Add(_calculationMethodWithSingleOption);
            _multipleCategory.Add(_calculationMethodWithMultipleOptions);
            _multipleCategory.Add(_anotherCalculationMethodInMultipleOptions);

            _calculationMethodCache = new CalculationMethodCache();
            _calculationMethodCache.AddCalculationMethod(_calculationMethodWithMultipleOptions);
            _calculationMethodCache.AddCalculationMethod(_calculationMethodWithSingleOption);

            A.CallTo(() => _calculationMethodCategoryRepository.FindBy(_singleCategory.Name)).Returns(_singleCategory);
            A.CallTo(() => _calculationMethodCategoryRepository.FindBy(_multipleCategory.Name)).Returns(_multipleCategory);

            return(Task.FromResult(true));
        }
Beispiel #2
0
        private void addCalculationMethodToSnapshot(SnapshotCalculationMethodCache snapshot, CalculationMethod calculationMethod, string species)
        {
            var category = _calculationMethodCategoryRepository.FindBy(calculationMethod.Category);

            var allPossibleCalculationMethods = category.AllItems().ToList();

            //only one CM in this category. Nothing to do
            if (allPossibleCalculationMethods.Count <= 1)
            {
                return;
            }

            //all CM have the same name? they will never be displayed together
            if (allPossibleCalculationMethods.Select(x => x.DisplayName).Distinct().Count() == 1)
            {
                return;
            }

            //only one calculation method exists for the given species. Nothing to do
            if (!string.IsNullOrEmpty(species) && allPossibleCalculationMethods.Count(x => x.AllSpecies.Contains(species)) == 1)
            {
                return;
            }

            //at least one CM that can be used in two models or different names. We may have a choice here. save it
            snapshot.Add(calculationMethod.Name);
        }
        protected override void FillUpReport(IEnumerable <CalculationMethod> calculationMethods, ReportPart reportPart)
        {
            var calcMethodPart = new TablePart(keyName: PKSimConstants.UI.Category, valueName: PKSimConstants.UI.CalculationMethods)
            {
                Title = PKSimConstants.UI.CalculationMethods
            };

            foreach (var calculationMethod in calculationMethods)
            {
                var currentCalculationMethod = calculationMethod;
                var category = _calculationMethodCategoryRepository.FindBy(currentCalculationMethod.Category);
                var allCalculationMethods = category.AllItems().ToList();
                if (allCalculationMethods.Count == 1)
                {
                    continue;
                }

                //more than one cm in this category. Check that this is not only due to different models
                allCalculationMethods.Remove(calculationMethod);
                var allModelsUsedInCategory  = allCalculationMethods.SelectMany(x => x.AllModels).Distinct();
                var allSpeciesUsedInCategory = allCalculationMethods.SelectMany(x => x.AllSpecies).Distinct();

                //at least another category available in the model and species
                if (allModelsUsedInCategory.Any(x => currentCalculationMethod.AllModels.Contains(x)) &&
                    allSpeciesUsedInCategory.Any(x => currentCalculationMethod.AllSpecies.Contains(x)))
                {
                    calcMethodPart.AddIs(_representationInfoRepository.DisplayNameFor(category),
                                         _representationInfoRepository.DisplayNameFor(calculationMethod));
                }
            }

            reportPart.AddPart(calcMethodPart);
        }
Beispiel #4
0
 public IEnumerable <ICoreCalculationMethod> AllMoleculeCalculationMethodsUsedBy(IWithCalculationMethods withCalculationMethods)
 {
     return(withCalculationMethods.AllCalculationMethods()
            .Select(calculationMethod => new { calculationMethod, category = _calculationMethodCategoryRepository.FindBy(calculationMethod.Category) })
            .Where(cmc => cmc.category.CategoryType == CategoryType.Molecule)
            .Select(cmc => _coreCalculationMethodRepository.FindByName(cmc.calculationMethod.Name))
            .Where(coreCalculationMethod => coreCalculationMethod != null));
 }
Beispiel #5
0
        private CalculationMethodCategory mapCategoryFrom(IEnumerable <CalculationMethod> calculationMethods, string calcMethodCategoryName, string modelName)
        {
            var sortedCalculationMethods   = calculationMethods.OrderBy(cm => _flatModelCalculationMethodRepository.By(modelName, cm.Name).Sequence);
            var templateCalcMethodCategory = _calculationMethodCategoryRepository.FindBy(calcMethodCategoryName);
            var calcMethodCategory         = new CalculationMethodCategory {
                Name = calcMethodCategoryName, CategoryType = templateCalcMethodCategory.CategoryType
            };

            sortedCalculationMethods.Each(calcMethodCategory.Add);
            return(calcMethodCategory);
        }
Beispiel #6
0
        public override void Report(CalculationMethodCache calculationMethodCache, MarkdownTracker tracker, int indentationLevel = 0)
        {
            var calculationMethods = calculationMethodCache
                                     .Select(x => new
            {
                CalculationMethod = x,
                Category          = _calculationMethodCategoryRepository.FindBy(x.Category)
            })
                                     .Where(x => x.Category.AllItems().Count() > 1)
                                     .Select(x => new
            {
                Name  = _representationInfoRepository.DisplayNameFor(x.Category),
                Value = _representationInfoRepository.DisplayNameFor(x.CalculationMethod),
            }
                                             );


            tracker.Add(calculationMethods.ToMarkdownTable());
        }
Beispiel #7
0
 public IEnumerable <CalculationMethod> AllCalculationMethodsFor(string category)
 {
     return(_calculationMethodCategoryRepository.FindBy(category).AllForSpecies(_individualSettingsDTO.Species));
 }