Exemple #1
0
        /// <summary>
        ///    Gets a dimension unit string in a data row. Indicate which row contains the unit
        /// </summary>
        /// <param name="rowIndex">The index of the row being converted</param>
        /// <param name="unitColumn">The index of the column containing the unit</param>
        /// <param name="dimensionColumn">The index of the column containing the dimension</param>
        /// <param name="table">The table containing the row</param>
        /// <returns>A dimension corresponding to the unit given</returns>
        protected IDimension GetDimension(DataTable table, int rowIndex, int unitColumn, int dimensionColumn)
        {
            var row       = table.Rows[rowIndex];
            var unitName  = row[unitColumn].ToString();
            var dimension = _dimensionFactory.DimensionForUnit(unitName);

            if (dimension == null)
            {
                throw new ImportQuantityDTOsFromDataTablesMapperException(row, rowIndex,
                                                                          AppConstants.Exceptions.CouldNotFindDimensionFromUnits(unitName));
            }

            if (table.Columns.Count <= dimensionColumn)
            {
                return(dimension);
            }

            //now we may have a dimension specified
            var dimensionName = row[dimensionColumn].ToString();

            if (string.IsNullOrEmpty(dimensionName))
            {
                return(dimension);
            }

            if (!_dimensionFactory.Has(dimensionName))
            {
                throw new ImportQuantityDTOsFromDataTablesMapperException(row, rowIndex,
                                                                          AppConstants.Exceptions.CouldNotFindDimension(dimensionName));
            }

            return(_dimensionFactory.Dimension(dimensionName));
        }
Exemple #2
0
        protected void CreateDimensionFactory()
        {
            _concentrationDimension = new Dimension();
            _concentrationDimension.AddUnit("mol", 1.0, 0);

            _volumeDimension = new Dimension();
            _volumeDimension.AddUnit("ml", 0.001, 0);

            _timeDimension = new Dimension();
            _timeDimension.AddUnit("s", 1 / 60.0, 0);
            _dimensionFactory = A.Fake <IMoBiDimensionFactory>();

            A.CallTo(() => _dimensionFactory.DimensionForUnit("mol")).Returns(_concentrationDimension);
            A.CallTo(() => _dimensionFactory.DimensionForUnit("ml")).Returns(_volumeDimension);
            A.CallTo(() => _dimensionFactory.DimensionForUnit("s")).Returns(_timeDimension);
            A.CallTo(() => _dimensionFactory.DimensionForUnit("r/h")).Returns(null);
            A.CallTo(() => _dimensionFactory.DimensionForUnit("")).Throws <Exception>();
        }
        /// <summary>
        ///     Converts a SBML UnitDefinition into a MoBi Unit.
        /// </summary>
        public IDimension ConvertUnit(UnitDefinition unitDefinition)
        {
            var sbmlUnit  = unitDefinition.getId();
            var dimension = _moBiDimensionFactory.TryGetDimensionCaseInsensitive(sbmlUnit);

            if (dimension != Constants.Dimension.NO_DIMENSION)
            {
                _sbmlInformation.MobiDimension[sbmlUnit] = dimension;
                return(dimension);
            }

            var newFactor = 1.0;
            var unitsList = new List <Unit>();
            var brList    = new List <BaseDimensionRepresentation>();

            for (long i = 0; i < unitDefinition.getNumUnits(); i++)
            {
                var mobiUnit = SBMLBaseUnitToMoBi(unitDefinition.getUnit(i));
                if (mobiUnit == null)
                {
                    continue;
                }
                var unitDimension = _moBiDimensionFactory.DimensionForUnit(mobiUnit.Name);
                var unitBr        = unitDimension.BaseRepresentation;
                unitBr = SetExponents(unitDefinition, unitBr, i);
                brList.Add(unitBr);

                if (Math.Abs(newFactor) < 0.0001)
                {
                    newFactor = unitDefinition.getUnit(i).getMultiplier() * Math.Pow(10, unitDefinition.getUnit(i).getScale()) * Math.Pow(mobiUnit.Factor, unitDefinition.getUnit(i).getExponent());
                }
                else
                {
                    newFactor = newFactor * unitDefinition.getUnit(i).getMultiplier() * Math.Pow(10, unitDefinition.getUnit(i).getScale()) * Math.Pow(mobiUnit.Factor, unitDefinition.getUnit(i).getExponent());
                }
                unitsList.Add(mobiUnit);
            }

            var baseDimensionRepresentation = CreateBaseDimRepresentationExponents(brList);

            IDimension newDim = new Dimension(baseDimensionRepresentation, String.Format("SBML_{0}", unitDefinition.getId()), String.Format("SBML_{0}_BaseUnit", unitDefinition.getId()));

            var newBaseUnit = newDim.BaseUnit;

            newBaseUnit.Visible = false;
            var newUnit = new Unit(unitDefinition.getId(), newFactor, 0);

            newDim.AddUnit(newUnit);
            newDim.DefaultUnit = newUnit;

            _sbmlInformation.MobiDimension[sbmlUnit] = newDim;
            if (_moBiDimensionFactory.Dimensions.All(dim => dim.Name != newDim.Name))
            {
                _moBiDimensionFactory.AddDimension(newDim);
            }
            return(newDim);
        }
Exemple #4
0
        /// <summary>
        ///    Gets a dimension unit string in a data row. Indicate which row contains the unit
        /// </summary>
        /// <param name="rowIndex">The index of the row being converted</param>
        /// <param name="columnIndex">The index of the column containing the unit</param>
        /// <param name="table">The table containing the row</param>
        /// <returns>A dimension corresponding to the unit given</returns>
        protected IDimension GetDimension(DataTable table, int rowIndex, int columnIndex)
        {
            var row       = table.Rows[rowIndex];
            var dimension = _dimensionFactory.DimensionForUnit(row[columnIndex].ToString());

            if (dimension == null)
            {
                throw new ImportQuantityDTOsFromDataTablesMapperException(row, rowIndex, AppConstants.Exceptions.CouldNotFindDimensionFromUnits(row[columnIndex].ToString()));
            }
            return(dimension);
        }
        protected void CreateDimensionFactory()
        {
            BaseDimensionRepresentation baseRepresentation = new BaseDimensionRepresentation();

            _concentrationDimension = new Dimension(baseRepresentation, "Concentration", "mol");
            _volumeDimension        = new Dimension(baseRepresentation, "Volume", "l");
            _volumeDimension.AddUnit("ml", 0.001, 0);
            _timeDimension = new Dimension(baseRepresentation, "Time", "min");
            _timeDimension.AddUnit("s", 1 / 60.0, 0);
            _inversedTime = new Dimension(baseRepresentation, "Inversed time", "1/min");
            _becquerel    = new Dimension(baseRepresentation, "Becquerel", "1/min");

            _dimensionFactory = A.Fake <IMoBiDimensionFactory>();

            A.CallTo(() => _dimensionFactory.DimensionForUnit("mol")).Returns(_concentrationDimension);
            A.CallTo(() => _dimensionFactory.DimensionForUnit("ml")).Returns(_volumeDimension);
            A.CallTo(() => _dimensionFactory.DimensionForUnit("s")).Returns(_timeDimension);
            A.CallTo(() => _dimensionFactory.DimensionForUnit("1/min")).Returns(_inversedTime);
            A.CallTo(() => _dimensionFactory.Has(_inversedTime.Name)).Returns(true);
            A.CallTo(() => _dimensionFactory.Has(_becquerel.Name)).Returns(true);
            A.CallTo(() => _dimensionFactory.DimensionForUnit("r/h")).Returns(null);
            A.CallTo(() => _dimensionFactory.DimensionForUnit("")).Throws <Exception>();

            A.CallTo(() => _dimensionFactory.Dimension(_becquerel.Name)).Returns(_becquerel);
            A.CallTo(() => _dimensionFactory.Dimension(_inversedTime.Name)).Returns(_inversedTime);
        }