private static void validateResults(SimulationResultsImport simulationResultsImport, IndividualResults individualResults)
        {
            var simulationResults = simulationResultsImport.SimulationResults;

            //No entry yet? Set this indiviudal results as base for the import
            if (!simulationResults.Any())
            {
                simulationResults.Time = individualResults.Time;
                individualResults.UpdateQuantityTimeReference();
                return;
            }

            validateTimeResults(simulationResultsImport, individualResults);
            var availableQuantityPaths = simulationResults.AllQuantityPaths();
            var currentQuantityPaths   = individualResults.Select(x => x.QuantityPath).ToList();

            if (availableQuantityPaths.Count != currentQuantityPaths.Count)
            {
                simulationResultsImport.AddError(PKSimConstants.Error.IndividualResultsDoesNotHaveTheExpectedQuantity(individualResults.IndividualId, availableQuantityPaths, currentQuantityPaths));
                return;
            }

            for (int i = 0; i < availableQuantityPaths.Count; i++)
            {
                if (!string.Equals(availableQuantityPaths[i], currentQuantityPaths[i]))
                {
                    simulationResultsImport.AddError(PKSimConstants.Error.IndividualResultsDoesNotHaveTheExpectedQuantity(individualResults.IndividualId, availableQuantityPaths, currentQuantityPaths));
                    return;
                }
            }
        }
示例#2
0
 private void updateFromImportedResults(SimulationResultsImport importResults)
 {
     _simulationResults = importResults.SimulationResults;
     _importSimulationResultsDTO.Clear();
     importResults.SimulationResultsFiles.Each(f => _importSimulationResultsDTO.AddFile(SimulationResultsFileSelectionDTO.From(f)));
     _importSimulationResultsDTO.Status   = importResults.Status;
     _importSimulationResultsDTO.Messages = importResults.Log;
     rebind();
 }
        protected override async Task Context()
        {
            await base.Context();

            _simulationResults = new SimulationResultsImport();
            _simulationResults.SimulationResults.Add(new IndividualResults());
            _simulationResults.SimulationResults.Add(new IndividualResults());
            A.CallTo(() => _coreSimulationResultsImportTask.ImportResults(_populationSimulation, _files, _cancellationToken, true)).Returns(_simulationResults);
            A.CallTo(() => _populationSimulation.NumberOfItems).Returns(3);
        }
        private void addImportedQuantityToLogForSuccessfulImport(SimulationResultsImport simulationResultsImport)
        {
            if (simulationResultsImport.Status.Is(NotificationType.Error))
            {
                return;
            }

            simulationResultsImport.AddInSeparator(PKSimConstants.Information.FollowingOutputsWereSuccessfulyImported(simulationResultsImport.SimulationResults.Count));
            foreach (var quantityPath in simulationResultsImport.SimulationResults.AllQuantityPaths())
            {
                simulationResultsImport.AddInfo(quantityPath);
            }
        }
        private void validateImportedQuantities(SimulationResultsImport simulationResultsImport)
        {
            foreach (var quantityPath in simulationResultsImport.SimulationResults.AllQuantityPaths())
            {
                var quantity = _allQuantities[quantityPath];
                if (quantity != null)
                {
                    continue;
                }

                simulationResultsImport.AddError(PKSimConstants.Error.CouldNotFindQuantityWithPath(quantityPath));
            }
        }
        private SimulationResultsImport createSimulationResultsFrom(IEnumerable <IndividualResultsImport> importedResults)
        {
            var simulationResultsImport = new SimulationResultsImport();

            //First add all available results
            importedResults.Each(import => addIndividualResultsFromSingleFile(simulationResultsImport, import));

            //now check that the defined outputs are actually available in the population simulation
            validateImportedQuantities(simulationResultsImport);


            return(simulationResultsImport);
        }
        private void addIndividualResultsFromSingleFile(SimulationResultsImport simulationResultsImport, IndividualResultsImport individualResultsImport)
        {
            var simulationResults = simulationResultsImport.SimulationResults;

            simulationResultsImport.SimulationResultsFiles.Add(individualResultsImport.SimulationResultsFile);

            foreach (var individualResult in individualResultsImport.IndividualResults)
            {
                validateResults(simulationResultsImport, individualResult);

                if (simulationResults.HasResultsFor(individualResult.IndividualId))
                {
                    simulationResultsImport.AddError(PKSimConstants.Error.DuplicatedIndividualResultsForId(individualResult.IndividualId));
                }
                else
                {
                    simulationResults.Add(individualResult);
                }
            }
        }
示例#8
0
        protected override void Context()
        {
            _dialogCreator = A.Fake <IDialogCreator>();
            _view          = A.Fake <IImportSimulationResultsView>();
            _simulationResultsImportTask = A.Fake <ISimulationResultsImportTask>();
            _populationSimulation        = A.Fake <PopulationSimulation>();
            _importedResults             = A.Fake <SimulationResultsImport>();
            _simulationResults           = new SimulationResults();

            sut = new ImportSimulationResultsPresenter(_view, _simulationResultsImportTask, _dialogCreator);

            A.CallTo(() => _view.BindTo(A <ImportSimulationResultsDTO> ._))
            .Invokes(x => _dto = x.GetArgument <ImportSimulationResultsDTO>(0));

            A.CallTo(() => _simulationResultsImportTask.ImportResults(_populationSimulation, A <IReadOnlyCollection <string> > ._, A <CancellationToken> ._))
            .Returns(_importedResults);

            A.CallTo(() => _importedResults.SimulationResults).Returns(_simulationResults);
            A.CallTo(() => _importedResults.SimulationResultsFiles).Returns(_simulationResultsFiles);


            sut.ImportResultsFor(_populationSimulation);
        }
        private static void validateTimeResults(SimulationResultsImport simulationResultsImport, IndividualResults individualResults)
        {
            var time           = simulationResultsImport.SimulationResults.Time;
            int expectedLength = time.Values.Length;
            int currentLength  = individualResults.Time.Values.Length;

            if (time.Values.Length != individualResults.Time.Values.Length)
            {
                simulationResultsImport.AddError(PKSimConstants.Error.TimeArrayLengthDoesNotMatchFirstIndividual(individualResults.IndividualId, expectedLength, currentLength));
                return;
            }

            for (int i = 0; i < currentLength; i++)
            {
                if (!ValueComparer.AreValuesEqual(time[i], individualResults.Time[i]))
                {
                    simulationResultsImport.AddError(PKSimConstants.Error.TimeArrayValuesDoesNotMatchFirstIndividual(individualResults.IndividualId, i, time[i], individualResults.Time[i]));
                }
            }

            //update reference time to ensure that all results are using the same time
            individualResults.Time = time;
            individualResults.UpdateQuantityTimeReference();
        }