Esempio n. 1
0
 public static void AddToSource(this NumericValue numericValue, NumericValue secondNumber)
 {
    if (secondNumber != null)
    {
       numericValue.Value += secondNumber.ConvertToUnit(numericValue.UnitOfMeasure.ToInternalUom());
    }
 }
Esempio n. 2
0
      public static NumericValue Multiply(NumericValue left, NumericValue right)
      {
         var decomposer = new UnitOfMeasureDecomposer();
         var leftComponents = decomposer.GetComponents(left.UnitOfMeasure.ToInternalUom(), 1);
         var rightComponents = decomposer.GetComponents(right.UnitOfMeasure.ToInternalUom(), 1);
         var allComponents = leftComponents.Union(rightComponents).ToList();

         return new UnitOfMeasureComponentSimplifier().Simplify(allComponents, left.Value * right.Value);
      }
Esempio n. 3
0
        private static void LoadArea(string inputValue, Field field)
        {
            long areaValue;
            if (inputValue.ParseValue(out areaValue) == false || areaValue < 0)
                return;

            var numericValue = new NumericValue(new CompositeUnitOfMeasure("m2").ToModelUom(), areaValue);
            field.Area = new NumericRepresentationValue(RepresentationInstanceList.vrReportedFieldArea.ToModelRepresentation(), numericValue.UnitOfMeasure, numericValue);
        }
Esempio n. 4
0
      public void GivenBaseNumberWhenSetTargetThenTargetUnitOfMeasureIsSet()
      {
         var sourceUom = InternalUnitSystemManager.Instance.UnitOfMeasures["ft"];
         var targetUom = InternalUnitSystemManager.Instance.UnitOfMeasures["in"];
         var baseNumber = new NumericValue(sourceUom.ToModelUom(), (double)12.0);

         baseNumber.ConvertToUnit(targetUom);
         Assert.AreEqual(targetUom.DomainID, baseNumber.UnitOfMeasure.Code);
      }
Esempio n. 5
0
      public void GivenBaseNumberWhenConvertUomThenValueIsSet()
      {
         var sourceUom = InternalUnitSystemManager.Instance.UnitOfMeasures["ft"];
         var targetUom = InternalUnitSystemManager.Instance.UnitOfMeasures["in"];
         var baseNumber = new NumericValue(sourceUom.ToModelUom(), 12.0);

         baseNumber.ConvertToUnit(targetUom);
         Assert.AreEqual(144.0, baseNumber.Value, Epsilon);
      }
      public void GivenSourceValueWhenCreatedThenSourceValue()
      {
         var representation = RepresentationInstanceList.vrAirTemperature.ToModelRepresentation();
         var uom = InternalUnitSystemManager.Instance.UnitOfMeasures["C"].ToModelUom();
         var numericValue = new NumericValue(uom, 5);

         var numericRepresentationValue = new NumericRepresentationValue(representation, numericValue);

         Assert.AreEqual(5, numericRepresentationValue.Value.Value);
      }
Esempio n. 7
0
        private static NumericRepresentationValue GetShiftValue(string inputValue)
        {
            long shift;
            if (!inputValue.ParseValue(out shift))
                return null;

            var shiftUnitOfMeasure = UnitSystemManager.GetUnitOfMeasure("mm");
            var numericValue = new NumericValue(shiftUnitOfMeasure, shift);
            return new NumericRepresentationValue(null, numericValue.UnitOfMeasure, numericValue);
        }
      public void GivenTwoVariableNumbersWithSameUomWhenAddedThenSourceValueIsSum()
      {
         var uom = InternalUnitSystemManager.Instance.UnitOfMeasures["C"].ToModelUom();
         var originalValue = new NumericValue(uom, 22);
         var originalRep = new NumericRepresentationValue(RepresentationInstanceList.vrAirTemperature.ToModelRepresentation(), originalValue);
         var secondNumber = new NumericValue(uom, 11);

         var result = originalRep.Add(secondNumber);
         Assert.IsInstanceOf<NumericRepresentationValue>(result);
         Assert.AreEqual(33, result.Value.Value);
      }
      public void GivenRepresentationAndUomIdWhenCreateVariableNumberShouldSetRepAndUom()
      {
         var representationTag = RepresentationInstanceList.vrAirTemperature.ToModelRepresentation();
         var uom = InternalUnitSystemManager.Instance.UnitOfMeasures["C"].ToModelUom();
         var numericValue = new NumericValue(uom, 1.23);

         var numericRepresentationValue = new NumericRepresentationValue(representationTag, numericValue);

         Assert.AreEqual(representationTag.Code, numericRepresentationValue.Representation.Code);
         Assert.AreEqual(uom.Code, numericRepresentationValue.Value.UnitOfMeasure.Code);
      }
Esempio n. 10
0
      public static NumericValue Divide(NumericValue numerator, NumericValue denominator)
      {
         if (denominator.Value == 0.0)
            throw new DivideByZeroException();

         var decomposer = new UnitOfMeasureDecomposer();
         var numeratorComponets = decomposer.GetComponents(numerator.UnitOfMeasure.ToInternalUom(), 1);
         var denominatorComponents = decomposer.GetComponents(denominator.UnitOfMeasure.ToInternalUom(), -1);
         var allComponents = numeratorComponets.Union(denominatorComponents).ToList();
         return new UnitOfMeasureComponentSimplifier().Simplify(allComponents, numerator.Value / denominator.Value);
      }
Esempio n. 11
0
        private static NumericRepresentationValue GetAccuracy(string accuracyValue)
        {
            double accuracy;
            if (accuracyValue.ParseValue(out accuracy) == false ||
                accuracy < 0 || accuracy > 65)
                return null;

            var accuracyUnitOfMeasure = UnitSystemManager.GetUnitOfMeasure("m");
            var numericValue = new NumericValue(accuracyUnitOfMeasure, accuracy);
            var numericRepresentation = new NumericRepresentation
            {
                DecimalDigits = 1,
                MaxValue = new NumericValue(accuracyUnitOfMeasure, 65),
                MinValue = new NumericValue(accuracyUnitOfMeasure, 0),
            };
            return new NumericRepresentationValue(numericRepresentation, numericValue.UnitOfMeasure, numericValue);
        }
Esempio n. 12
0
      public void GivenBaseNumberAndDoubleWhenSubtractFromSourceShouldSubtractFromSource()
      {
         var firstNumber = new NumericValue(_mileUnitOfMeasure.ToModelUom(), 42.24);
         firstNumber.SubtractFromSource(12.13);

         Assert.AreEqual(30.11, firstNumber.Value, Epsilon);
      }
Esempio n. 13
0
 public NumericRepresentationValue(NumericRepresentation representation, UnitOfMeasure userProvidedUnitOfMeasure, NumericValue value)
 {
     Representation = representation;
     UserProvidedUnitOfMeasure = userProvidedUnitOfMeasure;
     Value = value;
 }
Esempio n. 14
0
 public NumericRepresentationValue(NumericRepresentation representation, NumericValue value)
 {
     Representation = representation;
     Value = value;
 }
Esempio n. 15
0
        private void LoadTotalQuantity(XmlNode inputNode, ProductMix productMix)
        {
            var quantityValue = inputNode.GetXmlNodeValue("@G");

            double quantity;
            if (!double.TryParse(quantityValue, NumberStyles.Float, CultureInfo.InvariantCulture, out quantity))
                return;

            var unit = LoadUnit(inputNode);
            var userUnit = _taskDocument.Units.FindById(inputNode.GetXmlNodeValue("@D"));

            var numericValue = new NumericValue(unit.ToAdaptUnit(), unit.ConvertFromIsoUnit(quantity));
            productMix.TotalQuantity = new NumericRepresentationValue(null, userUnit.ToAdaptUnit(), numericValue);
        }
Esempio n. 16
0
        private Ingredient LoadProductRelation(XmlNode productRelationNode, ProductMix productMix)
        {
            var productId = productRelationNode.GetXmlNodeValue("@A");
            var productQuantity = productRelationNode.GetXmlNodeValue("@B");

            if (string.IsNullOrEmpty(productId) || string.IsNullOrEmpty(productQuantity))
                return null;

            long quantity;
            if (!long.TryParse(productQuantity, NumberStyles.Integer, CultureInfo.InvariantCulture, out quantity) ||
                quantity < 0)
                return null;

            Product product;
            if (_taskDocument.Products.TryGetValue(productId, out product) == false)
                return null;

            var unit = _taskDocument.UnitsByItemId.FindById(productId);
            var numericValue = new NumericValue(unit.ToAdaptUnit(), unit.ConvertFromIsoUnit(quantity));

            var ingredient = new ActiveIngredient
            {
                Description = product.Description,
            };

            var productComponent = new ProductComponent
            {
                IngredientId = product.Id.ReferenceId,
                Quantity = new NumericRepresentationValue(null, numericValue.UnitOfMeasure, numericValue)
            };

            if (productMix.ProductComponents == null)
                productMix.ProductComponents = new List<ProductComponent>();
            productMix.ProductComponents.Add(productComponent);

            return ingredient;
        }
Esempio n. 17
0
 public void GivenUnitOfMeasureWhenCreatedThenTargetValueDefaultsToSourceValue()
 {
    var sourceUom = InternalUnitSystemManager.Instance.UnitOfMeasures["m"];
    var baseNumber = new NumericValue(sourceUom.ToModelUom(), 6.89);
    Assert.AreEqual(baseNumber.Value, baseNumber.Value);
 }
Esempio n. 18
0
      public void GivenNullWhenSubtractFromSourceShoulReturnSourceValue()
      {
         var number = new NumericValue(InternalUnitSystemManager.Instance.UnitOfMeasures["cm"].ToModelUom(), 4.25);
         number.SubtractFromSource(null);

         Assert.AreEqual(4.25, number.Value, Epsilon);
      }
Esempio n. 19
0
 public NumericRepresentationValue(NumericRepresentation representation, NumericValue value)
 {
     Representation = representation;
     Value          = value;
 }
 public static NumericRepresentationValue Subtract(this NumericRepresentationValue numericRepresentationValue, NumericValue secondNumber)
 {
    var difference = numericRepresentationValue.Value.Subtract(secondNumber);
    return new NumericRepresentationValue(numericRepresentationValue.Representation, difference);
 }
 public static NumericRepresentationValue Add(this NumericRepresentationValue numericRepresentationValue, NumericValue secondNumber)
 {
    var sum = numericRepresentationValue.Value.Add(secondNumber);
    return new NumericRepresentationValue(numericRepresentationValue.Representation, sum);
 }
Esempio n. 22
0
      public void GivenBaseNumberWhenSubtractBaseNumberFromSourceShouldSubtractValueFromSourceValue()
      {
         var number = new NumericValue(_mileUnitOfMeasure.ToModelUom(), 9.876);
         var secondNumber = new NumericValue(_mileUnitOfMeasure.ToModelUom(), 1.234);

         number.SubtractFromSource(secondNumber);

         Assert.AreEqual(8.642, number.Value);
      }
Esempio n. 23
0
 public void GivenValueWhenCreatedThenSourceValueIsSet()
 {
    var sourceUom = InternalUnitSystemManager.Instance.UnitOfMeasures["ft"];
    var baseNumber = new NumericValue(sourceUom.ToModelUom(), 12.0);
    Assert.AreEqual(12.0, baseNumber.Value);
 }
 public static NumericRepresentationValue Multiply(this NumericRepresentationValue numericRepresentationValue, NumericValue right)
 {
    var product = numericRepresentationValue.Value.Multiply(right);
    return new NumericRepresentationValue(numericRepresentationValue.Representation, product);
 }
 public static void SubtractFromSource(this NumericRepresentationValue numericRepresentationValue, NumericValue secondNumber)
 {
    numericRepresentationValue.Value.SubtractFromSource(secondNumber);
 }
Esempio n. 26
0
      public void GivenBaseNumberWhenSubtractBaseNumberWithDifferentUnitOfMeasureThenShouldConvertAndSubtractFromSource()
      {
         var firstNumber = new NumericValue(InternalUnitSystemManager.Instance.UnitOfMeasures["cm"].ToModelUom(), 3.54);
         var secondNumber = new NumericValue(InternalUnitSystemManager.Instance.UnitOfMeasures["in"].ToModelUom(), 1);

         firstNumber.SubtractFromSource(secondNumber);

         Assert.AreEqual(1, firstNumber.Value, Epsilon);
      }
 public static void AddToSource(this NumericRepresentationValue numericRepresentationValue, NumericValue secondNumber)
 {
    numericRepresentationValue.Value.AddToSource(secondNumber);
 }
Esempio n. 28
0
      public void GivenTwoBaseNumbersWithSameUomWhenAddedShouldReturnNewBaseNumberWithSumAsSourceValue()
      {
         var uom = InternalUnitSystemManager.Instance.UnitOfMeasures["C"];
         var originalNumber = new NumericValue(uom.ToModelUom(), 22);
         var secondNumber = new NumericValue(uom.ToModelUom(), 11);

         var result = originalNumber.Add(secondNumber);
         Assert.AreEqual(33, result.Value);
      }
 public static NumericRepresentationValue Divide(this NumericRepresentationValue numericRepresentationValue, NumericValue denominator)
 {
    var quotient = numericRepresentationValue.Value.Divide(denominator);
    return new NumericRepresentationValue(numericRepresentationValue.Representation, quotient);
 }
Esempio n. 30
0
      public void GivenBaseNumberWhenAddBaseNumberThenResultIsInOriginalUom()
      {
         var originalUom = InternalUnitSystemManager.Instance.UnitOfMeasures["m"];
         var originalNumber = new NumericValue(originalUom.ToModelUom(), 1.75);

         var secondUom = InternalUnitSystemManager.Instance.UnitOfMeasures["ft"];
         var secondNumber = new NumericValue(secondUom.ToModelUom(), 3.5);

         var expected = 2.8168; //1.75m + (3.5ft -> m)
         var actual = originalNumber.Add(secondNumber);
         Assert.AreEqual(expected, actual.Value, Epsilon);
      }
Esempio n. 31
0
 public NumericRepresentationValue(NumericRepresentation representation, UnitOfMeasure userProvidedUnitOfMeasure, NumericValue value)
 {
     Representation            = representation;
     UserProvidedUnitOfMeasure = userProvidedUnitOfMeasure;
     Value = value;
 }
Esempio n. 32
0
      public static VariableValue ConvertCdf(VariableValue variableValue, string targetUnit)
      {
         if (variableValue.UnitOfMeasure == targetUnit)
         {
            return variableValue;
         }

         var sourceUnitOfMeasure = GetUomCdf(variableValue.UnitOfMeasure);
         var targetUnitOfMeasure = GetUomCdf(targetUnit);
         var bn = new NumericValue(sourceUnitOfMeasure.ToModelUom(), variableValue.Value);
         bn.ConvertToUnit(targetUnitOfMeasure);
         var convertedValue = bn.Value;
         return new VariableValue(variableValue.Representation, targetUnit, convertedValue);
      }