public void Convert(IMoleculeStartValue moleculeStartValue, IFormulaCache formulaCache)
        {
            if (!conversionRequired(moleculeStartValue))
            {
                return;
            }

            moleculeStartValue.Dimension   = _concentrationDimension;
            moleculeStartValue.DisplayUnit = _displayUnitRetriever.PreferredUnitFor(moleculeStartValue);

            if (moleculeStartValue.Formula.IsExplicit())
            {
                convertExplicitFormula(moleculeStartValue.Formula, _concentrationDimension);
                return;
            }

            var startValue = moleculeStartValue.StartValue.GetValueOrDefault(0);

            if (startValue == 0)
            {
                return;
            }

            moleculeStartValue.Formula = createConcentrationFormulaFromConstantValue(startValue, moleculeStartValue.Path.ToPathString(), formulaCache);
        }
Пример #2
0
        public IParameter CreateConcentrationParameterIn(IFormulaCache formulaCache)
        {
            var parameter = CreateFor(CoreConstants.Parameters.CONCENTRATION, PKSimBuildingBlockType.Simulation);

            parameter.BuildMode    = ParameterBuildMode.Local;
            parameter.Info.Visible = false;
            parameter.Formula      = _formulaFactory.ConcentrationFormulaFor(formulaCache);
            parameter.Dimension    = _dimensionRepository.MolarConcentration;
            parameter.DisplayUnit  = _displayUnitRetriever.PreferredUnitFor(parameter);
            return(parameter);
        }
Пример #3
0
        private void updateChart()
        {
            var xUnit = _displayUnitRetriever.PreferredUnitFor(_dimensionRepository.AgeInYears);
            var yUnit = _displayUnitRetriever.PreferredUnitFor(_dimensionRepository.Fraction);
            var chart = _simpleChartPresenter.Plot(dataForSelectedOntogeny(xUnit, yUnit), Scalings.Linear);

            chart.Axes[AxisTypes.X].Caption   = PKSimConstants.UI.PostMenstrualAge;
            chart.Axes[AxisTypes.X].GridLines = true;
            chart.Axes[AxisTypes.Y].Caption   = PKSimConstants.UI.OntogenyFor(_dto.SelectedOntogeny.Name);
            chart.Axes[AxisTypes.Y].GridLines = true;
        }
        private IParameter createPKParameter(string name, double value, string dimension)
        {
            var parameter = _parameterFactory.CreateFor(name, value, dimension, PKSimBuildingBlockType.Simulation);

            parameter.Dimension   = _dimensionRepository.MergedDimensionFor(parameter);
            parameter.DisplayUnit = _displayUnitRetriever.PreferredUnitFor(parameter);
            parameter.Rules.Clear();
            return(parameter);
        }
Пример #5
0
 public override void Compare(IComparison <ConstantFormula> comparison)
 {
     if (!comparison.Settings.CompareHiddenEntities)
     {
         return;
     }
     CompareDoubleValues(x => x.Value, x => x.Value, comparison, x => _displayUnitRetriever.PreferredUnitFor(x));
     CompareValues(x => x.Dimension, x => x.Dimension, comparison);
 }
Пример #6
0
 protected void UpdateParameterDisplayUnit(IEnumerable <IQuantity> quantities, IPresentationSettings presentationSettings)
 {
     quantities.Each(p =>
     {
         var preferredUnit = _displayUnitRetriever.PreferredUnitFor(p);
         var unitName      = presentationSettings.GetSetting(p.Name, preferredUnit.Name);
         p.DisplayUnit     = p.Dimension.UnitOrDefault(unitName);
     });
 }
Пример #7
0
        private AdvancedProtocol createAdvancedProtocol(ApplicationType applicationType)
        {
            var protocol = _objectBaseFactory.Create <AdvancedProtocol>();

            protocol.Root     = _objectBaseFactory.Create <IRootContainer>();
            protocol.TimeUnit = _displayUnitRetriever.PreferredUnitFor(_dimensionRepository.Time);

            var schema = _schemaFactory.CreateWithDefaultItem(applicationType, protocol);

            protocol.AddSchema(schema);
            return(protocol);
        }
Пример #8
0
        protected override void Context()
        {
            _dimensionRepository  = A.Fake <IDimensionRepository>();
            _displayUnitRetriever = A.Fake <IDisplayUnitRetriever>();
            sut = new PopulationAnalysisFactory(_dimensionRepository, _displayUnitRetriever);

            var timeDimension = A.Fake <IDimension>();

            _defaultUnit = A.Fake <Unit>();
            A.CallTo(() => _displayUnitRetriever.PreferredUnitFor(timeDimension)).Returns(_defaultUnit);
            A.CallTo(() => _dimensionRepository.Time).Returns(timeDimension);
        }
Пример #9
0
        public IParameter CreateParameter(string name, double?value = null, IDimension dimension = null, string groupName = null, IFormula formula = null, Unit displayUnit = null)
        {
            var dimensionToUse   = dimension ?? _dimensionFactory.NoDimension;
            var displayUnitToUse = displayUnit ?? _displayUnitRetriever.PreferredUnitFor(dimensionToUse);
            var formulaToUse     = formula ?? _formulaFactory.ConstantFormula(value.GetValueOrDefault(double.NaN), dimensionToUse);

            return(_objectBaseFactory.Create <IParameter>()
                   .WithName(name)
                   .WithDimension(dimensionToUse)
                   .WithFormula(formulaToUse)
                   .WithDisplayUnit(displayUnitToUse)
                   .WithGroup(groupName ?? Constants.Groups.MOBI));
        }
Пример #10
0
        protected override void Context()
        {
            _presentationSettingsTask = A.Fake <IPresentationSettingsTask>();
            _displayUnitRetriever     = A.Fake <IDisplayUnitRetriever>();
            sut = new PresentableTeXBuilderForSpecs(_presentationSettingsTask, _displayUnitRetriever);

            _parameter1           = DomainHelperForSpecs.ConstantParameterWithValue(1).WithName("P1");
            _parameter1.Dimension = DomainHelperForSpecs.LengthDimensionForSpecs();

            _parameter2           = DomainHelperForSpecs.ConstantParameterWithValue(2).WithName("P2");
            _parameter2.Dimension = DomainHelperForSpecs.TimeDimensionForSpecs();

            _parameter3           = DomainHelperForSpecs.ConstantParameterWithValue(3).WithName("P3");
            _parameter3.Dimension = DomainHelperForSpecs.LengthDimensionForSpecs();


            _container = new Container
            {
                _parameter1,
                _parameter2,
                _parameter3,
            }.WithId("Id");

            _presentationSettings = new DefaultPresentationSettings();

            //existing unit
            _presentationSettings.SetSetting(_parameter1.Name, "cm");

            //wrong unit for dimension
            _presentationSettings.SetSetting(_parameter2.Name, "cm");

            A.CallTo(() => _displayUnitRetriever.PreferredUnitFor(_parameter1)).Returns(_parameter1.Dimension.BaseUnit);
            A.CallTo(() => _displayUnitRetriever.PreferredUnitFor(_parameter2)).Returns(_parameter2.Dimension.BaseUnit);

            //wrong preferred unit.
            A.CallTo(() => _displayUnitRetriever.PreferredUnitFor(_parameter3)).Returns(_parameter2.Dimension.DefaultUnit);

            A.CallTo(_presentationSettingsTask).WithReturnType <DefaultPresentationSettings>().Returns(_presentationSettings);
        }
Пример #11
0
        private void setParameterProperties(IParameter parameter, ParameterMetaData parameterMetaData)
        {
            parameter.Name      = parameterMetaData.ParameterName;
            parameter.BuildMode = parameterMetaData.BuildMode;
            parameter.Info      = parameterMetaData.Clone();
            parameter.Dimension = _dimensionRepository.DimensionByName(parameterMetaData.Dimension);

            if (!string.IsNullOrEmpty(parameterMetaData.DefaultUnit))
            {
                parameter.DisplayUnit = parameter.Dimension.Unit(parameterMetaData.DefaultUnit);
            }

            parameter.DisplayUnit = _displayUnitRetriever.PreferredUnitFor(parameter);
        }
Пример #12
0
        protected override void Context()
        {
            _schemaFactory                = A.Fake <ISchemaFactory>();
            _objectBaseFactory            = A.Fake <IObjectBaseFactory>();
            _parameterFactory             = A.Fake <IParameterFactory>();
            _dimensionRepository          = A.Fake <IDimensionRepository>();
            _schemaItemParameterRetriever = A.Fake <ISchemaItemParameterRetriever>();
            _displayUnitRetriever         = A.Fake <IDisplayUnitRetriever>();
            sut = new ProtocolFactory(_objectBaseFactory, _schemaFactory, _parameterFactory, _dimensionRepository, _schemaItemParameterRetriever, _displayUnitRetriever);

            _timeDimension   = A.Fake <IDimension>();
            _doseDimension   = A.Fake <IDimension>();
            _defaultTimeUnit = A.Fake <Unit>();
            A.CallTo(() => _dimensionRepository.Mass).Returns(_doseDimension);
            A.CallTo(() => _dimensionRepository.Time).Returns(_timeDimension);
            A.CallTo(() => _displayUnitRetriever.PreferredUnitFor(_timeDimension)).Returns(_defaultTimeUnit);
        }
Пример #13
0
        public PopulationStatisticalAnalysis CreateStatisticalAnalysis()
        {
            var statisticalAnalysis = new PopulationStatisticalAnalysis {
                TimeUnit = _displayUnitRetriever.PreferredUnitFor(_dimensionRepository.Time)
            };

            //add predefined single curve selection
            EnumHelper.AllValuesFor <StatisticalAggregationType>()
            .Each(x => statisticalAnalysis.AddStatistic(new PredefinedStatisticalAggregation {
                Method = x
            }));

            CoreConstants.DEFAULT_STATISTIC_PERCENTILES.Each(p => statisticalAnalysis.AddStatistic(new PercentileStatisticalAggregation {
                Percentile = p
            }));

            return(statisticalAnalysis);
        }
Пример #14
0
        private DataColumn createColumn(BaseGrid xValues, IQuantity quantity, IValues yValues, IEnumerable <string> quantityPath, IModelCoreSimulation simulation)
        {
            var column = new DataColumn(_dataNamingService.GetEntityName(yValues.EntityId), quantity.Dimension, xValues)
            {
                DataInfo =
                {
                    Origin              = ColumnOrigins.Calculation,
                    ComparisonThreshold = (float)yValues.ComparisonThreshold
                },
                Values       = new List <float>(yValues.Values.ToFloatArray()),
                QuantityInfo = new QuantityInfo(yValues.Name, quantityPath, quantity.QuantityType),
                DisplayUnit  = _displayUnitRetriever.PreferredUnitFor(quantity)
            };

            _dataRepositoryTask.UpdateMolWeight(column, quantity, simulation.Model);

            return(column);
        }
Пример #15
0
        private void plotContinousData <TObject>(IPopulationDataCollector populationDataCollector, TObject objectToPlot, INumericValueField numericValueField,
                                                 Func <IPopulationDistributionPresenter, Action <IPopulationDataCollector, TObject, DistributionSettings, IDimension, Unit> > plotFunc)
            where TObject : class, IWithDimension

        {
            if (objectToPlot == null)
            {
                return;
            }

            var displayUnit = _displayUnitRetriever.PreferredUnitFor(objectToPlot);
            var dimension   = objectToPlot.Dimension;
            var settings    = new DistributionSettings();

            if (numericValueField != null)
            {
                displayUnit          = numericValueField.DisplayUnit;
                settings.PlotCaption = numericValueField.Name;
                dimension            = _dimensionRepository.MergedDimensionFor(new NumericFieldContext(numericValueField, populationDataCollector));
            }
            plotFunc(_populationDistributionPresenter)(populationDataCollector, objectToPlot, settings, dimension, displayUnit);
        }
        private DataTable createPKAnalysesDataToExport(PopulationSimulation populationSimulation)
        {
            var dataTable = new DataTable(populationSimulation.Name);

            if (!populationSimulation.HasPKAnalyses)
            {
                return(dataTable);
            }

            var pkAnalyses = populationSimulation.PKAnalyses;

            dataTable.AddColumn <int>(CoreConstants.SimulationResults.INDIVIDUAL_ID);
            dataTable.AddColumn <string>(CoreConstants.SimulationResults.QUANTITY_PATH);
            dataTable.AddColumn <string>(CoreConstants.SimulationResults.PARAMETER);
            dataTable.AddColumn <string>(CoreConstants.SimulationResults.VALUE);
            dataTable.AddColumn <string>(CoreConstants.SimulationResults.UNIT);

            dataTable.BeginLoadData();
            foreach (var pkParameter in pkAnalyses.All())
            {
                var parameter = pkParameter;
                var unit      = _displayUnitRetriever.PreferredUnitFor(parameter);
                parameter.Values.Each((value, index) =>
                {
                    var row = dataTable.NewRow();
                    row[CoreConstants.SimulationResults.INDIVIDUAL_ID] = index;
                    row[CoreConstants.SimulationResults.QUANTITY_PATH] = parameter.QuantityPath;
                    row[CoreConstants.SimulationResults.PARAMETER]     = parameter.Name;
                    row[CoreConstants.SimulationResults.VALUE]         = parameter.ConvertToUnit(value, unit).ConvertedTo <string>();
                    row[CoreConstants.SimulationResults.UNIT]          = unit.Name;
                    dataTable.Rows.Add(row);
                });
            }
            dataTable.EndLoadData();
            return(dataTable);
        }
Пример #17
0
        public void UpdateDimension(ParameterStartValueDTO startValueObject, IDimension newDimension)
        {
            var macroCommand = new MoBiMacroCommand();
            var startValue   = StartValueFrom(startValueObject);

            macroCommand.CommandType = AppConstants.Commands.EditCommand;
            macroCommand.Description = AppConstants.Commands.UpdateDimensionsAndUnits;
            macroCommand.ObjectType  = new ObjectTypeResolver().TypeFor <ParameterStartValue>();

            var value = startValue.ConvertToDisplayUnit(startValue.StartValue);

            macroCommand.AddCommand(_parameterStartValuesTask.UpdateStartValueDimension(_buildingBlock, startValue, newDimension));
            macroCommand.AddCommand(_parameterStartValuesTask.SetStartDisplayValueWithUnit(startValue, value, _displayUnitRetriever.PreferredUnitFor(startValue), _buildingBlock));

            AddCommand(macroCommand);
        }
Пример #18
0
 public Unit GetDisplayUnitFor(IDimension dimension)
 {
     return(_displayUnitRetriever.PreferredUnitFor(dimension) ?? dimension.DefaultUnit);
 }
Пример #19
0
        public void Plot(IVectorialParametersContainer vectorialParametersContainer, IParameter parameter, DistributionSettings settings = null, IDimension dimension = null, Unit displayUnit = null)
        {
            var displayUnitToUse = displayUnit ?? _displayUnitRetriever.PreferredUnitFor(parameter);

            plot(vectorialParametersContainer, parameter, _distributionDataCreator.CreateFor, updatePlotOptionsDefaultsFor, settings, dimension, displayUnitToUse);
        }
Пример #20
0
 private void adjustAxes(DataColumn calculatedColumn)
 {
     Chart.AxisBy(AxisTypes.Y).UnitName = _displayUnitRetriever.PreferredUnitFor(calculatedColumn).Name;
 }
 private void adjustAxes(DataColumn calculationColumn, ParameterIdentificationPredictedVsObservedChart chart)
 {
     chart.AxisBy(AxisTypes.Y).UnitName = _displayUnitRetriever.PreferredUnitFor(calculationColumn).Name;
 }
Пример #22
0
 public OutputSchema Create()
 {
     return(create(CoreConstants.DEFAULT_PROTOCOL_END_TIME_IN_MIN, _displayUnitRetriever.PreferredUnitFor(_dimensionRepository.Time)));
 }
Пример #23
0
 private void updateDisplayUnit(IWithDisplayUnit withDisplayUnit)
 {
     withDisplayUnit.DisplayUnit = _displayUnitRetriever.PreferredUnitFor(withDisplayUnit);
 }