Exemplo n.º 1
0
        public TBuildingBlock FindByName <TBuildingBlock>(string name) where TBuildingBlock : class, IPKSimBuildingBlock
        {
            var bb = _project.All <TBuildingBlock>().FindByName(name);

            Load(bb);
            return(bb);
        }
        protected override void Context()
        {
            var workspace = A.Fake <ICoreWorkspace>();

            _project          = A.Fake <PKSimProject>();
            workspace.Project = _project;
            A.CallTo(() => _project.All(PKSimBuildingBlockType.Template)).Returns(_allBuildingBlocks);
            A.CallTo(() => _project.All <Simulation>()).Returns(new[] { _simulation });
            sut = IoC.Resolve <SimulationsReporter>();
        }
Exemplo n.º 3
0
 public void should_return_a_project_with_the_expected_building_blocks()
 {
     _newProject.All <Compound>().ShouldContain(_compound);
     _newProject.All <PKSimEvent>().ShouldContain(_event);
     _newProject.All <Formulation>().ShouldContain(_formulation);
     _newProject.All <Protocol>().ShouldContain(_protocol);
     _newProject.All <Population>().ShouldContain(_population);
     _newProject.All <ObserverSet>().ShouldContain(_observerSet);
     _newProject.All <ExpressionProfile>().ShouldContain(_expressionProfile);
     _newProject.All <Individual>().ShouldContain(_individual);
 }
Exemplo n.º 4
0
        private void mapQualificationStepPropertiesToModel(IQualificationStep qualificationStep, SnapshotQualificationStep snapshot, PKSimProject project)
        {
            switch (qualificationStep)
            {
            case RunParameterIdentificationQualificationStep runParameterIdentification:
                var parameterIdentification = project.AllParameterIdentifications.FindByName(snapshot.Subject);
                if (parameterIdentification == null)
                {
                    throw new SnapshotOutdatedException(PKSimConstants.Error.CouldNotFindParameterIdentification(snapshot.Subject));
                }

                runParameterIdentification.ParameterIdentification = parameterIdentification;
                break;

            case RunSimulationQualificationStep runSimulationQualificationStep:
                var simulation = project.All <Model.Simulation>().FindByName(snapshot.Subject);
                if (simulation == null)
                {
                    throw new SnapshotOutdatedException(PKSimConstants.Error.CouldNotFindSimulation(snapshot.Subject));
                }

                runSimulationQualificationStep.Simulation = simulation;
                break;

            default:
                throw new ArgumentException(PKSimConstants.Error.NotMappingDefinedForQualificationStep(qualificationStep.GetType().Name));
            }
        }
Exemplo n.º 5
0
        public async Task <SimulationExport[]> ExportSimulationsIn(PKSimProject project, ExportRunOptions exportRunOptions)
        {
            var nameOfSimulationsToExport = (exportRunOptions.Simulations ?? Enumerable.Empty <string>()).ToList();

            if (!nameOfSimulationsToExport.Any())
            {
                nameOfSimulationsToExport.AddRange(project.All <Simulation>().AllNames());
            }

            var simulationExports = new List <SimulationExport>();

            //sequential for now
            foreach (var simulationName in nameOfSimulationsToExport)
            {
                var simulation = project.BuildingBlockByName <Simulation>(simulationName);
                if (simulation == null)
                {
                    _logger.AddWarning($"Simulation '{simulationName}' was not found in project '{project.Name}'", project.Name);
                    continue;
                }

                simulationExports.Add((await ExportSimulation(simulation, exportRunOptions, project)));
            }

            return(simulationExports.ToArray());
        }
Exemplo n.º 6
0
        private SimulationQuantitySelection outputSelectionFrom(string outputFullPath, PKSimProject project)
        {
            var outputPath = new ObjectPath(outputFullPath.ToPathArray());

            if (outputPath.Count == 0)
            {
                return(null);
            }

            var simulationName = outputPath[0];
            var simulation     = project.All <Model.Simulation>().FindByName(simulationName);

            if (simulation == null)
            {
                _logger.AddWarning(PKSimConstants.Error.CouldNotFindSimulation(simulationName));
                return(null);
            }

            outputPath.RemoveAt(0);
            var output = simulation.Model.Root.EntityAt <IQuantity>(outputPath.ToArray());

            if (output == null)
            {
                _logger.AddWarning(PKSimConstants.Error.CouldNotFindOutputInSimulation(outputPath, simulationName));
                return(null);
            }


            return(new SimulationQuantitySelection(simulation, new QuantitySelection(outputPath, output.QuantityType)));
        }
Exemplo n.º 7
0
 public void UpdateProjectAfterSave(PKSimProject project)
 {
     foreach (var simulation in project.All <Simulation>())
     {
         simulation.ResultsHaveChanged = false;
     }
 }
Exemplo n.º 8
0
 protected override void Context()
 {
     _projectRetriever = A.Fake <IProjectRetriever>();
     _project          = A.Fake <PKSimProject>();
     _individual1      = new Individual();
     _individual2      = new Individual();
     A.CallTo(() => _projectRetriever.CurrentProject).Returns(_project);
     A.CallTo(() => _project.All <Individual>()).Returns(new[] { _individual1, _individual2 });
     sut = new BuildingBlockRepository(_projectRetriever);
 }
Exemplo n.º 9
0
        private void addSimulation(string simulationName, ModelParameterIdentification parameterIdentification, PKSimProject project)
        {
            var simulation = project.All <Model.Simulation>().FindByName(simulationName);

            if (simulation == null)
            {
                _logger.AddWarning(PKSimConstants.Error.CouldNotFindSimulation(simulationName));
                return;
            }

            parameterIdentification.AddSimulation(simulation);
        }
        public ProjectMetaData MapFrom(PKSimProject project)
        {
            var projectMetaData = new ProjectMetaData();

            project.All <IPKSimBuildingBlock>().Each(x => projectMetaData.AddBuildingBlock(mapFrom(x)));
            project.AllSimulationComparisons.Each(x => projectMetaData.AddSimulationComparison(mapFrom(x)));
            project.AllParameterIdentifications.Each(x => projectMetaData.AddParameterIdentification(mapFrom(x)));
            project.AllSensitivityAnalyses.Each(x => projectMetaData.AddSensitivityAnalysis(mapFrom(x)));
            project.AllObservedData.Each(x => projectMetaData.AddObservedData(mapFrom(x)));

            projectMetaData.Name         = project.Name;
            projectMetaData.Description  = project.Description;
            projectMetaData.Content.Data = _serializationManager.Serialize(project);
            _metaData = null;
            return(projectMetaData);
        }
Exemplo n.º 11
0
        private ParameterSelection parameterSelectionFrom(string parameterFullPath, PKSimProject project)
        {
            var parameterPath = new ObjectPath(parameterFullPath.ToPathArray());

            if (parameterPath.Count == 0)
            {
                return(null);
            }

            var simulationName = parameterPath[0];
            var simulation     = project.All <Model.Simulation>().FindByName(simulationName);

            if (simulation == null)
            {
                _logger.AddWarning(PKSimConstants.Error.CouldNotFindSimulation(simulationName));
                return(null);
            }

            parameterPath.RemoveAt(0);
            return(new ParameterSelection(simulation, parameterPath));
        }
Exemplo n.º 12
0
        private async Task exportSimulations(PKSimProject project, ExportRunOptions exportRunOptions)
        {
            var nameOfSimulationsToExport = (exportRunOptions.Simulations ?? Enumerable.Empty <string>()).ToList();

            if (!nameOfSimulationsToExport.Any())
            {
                nameOfSimulationsToExport.AddRange(project.All <Simulation>().AllNames());
            }

            //sequential for now
            foreach (var simulationName in nameOfSimulationsToExport)
            {
                var simulation = project.BuildingBlockByName <Simulation>(simulationName);
                if (simulation == null)
                {
                    _logger.AddWarning($"Simulation '{simulationName}' was not found in project '{project.Name}'");
                    continue;
                }

                await exportSimulation(simulation, exportRunOptions);
            }
        }
        public IPKSimProject MapFrom(ProjectMetaData projectMetaData)
        {
            var project = new PKSimProject
            {
                Name        = projectMetaData.Name,
                Description = projectMetaData.Description
            };

            //Observed data needs to be loaded first into project
            projectMetaData.AllObservedData.Each(x => project.AddObservedData(mapFrom(x)));

            projectMetaData.BuildingBlocks.Each(x => project.AddBuildingBlock(mapFrom(x)));

            //we need a shared context for all object referencing observed data and simulations
            using (var context = _serializationContextFactory.Create(project.AllObservedData, project.All <ISimulation>()))
            {
                var localContext = context;
                projectMetaData.ParameterIdentifications.Each(x => project.AddParameterIdentification(mapFrom(x, localContext)));
                projectMetaData.SensitivityAnalyses.Each(x => project.AddSensitivityAnalysis(mapFrom(x, localContext)));
            }

            projectMetaData.SimulationComparisons.Each(x => project.AddSimulationComparison(mapFrom(x)));

            //Once reference to dynamic meta data was added, deserialize the project itself
            _serializationManager.Deserialize(project, projectMetaData.Content.Data);

            //if the project DB Version is the same as the current project, the project did not change
            if (projectMetaData.Version == ProjectVersions.Current)
            {
                project.HasChanged = false;
            }

            return(project);
        }