Esempio n. 1
0
        private static void WriteTotalQuantity(XmlWriter writer, NumericRepresentationValue quantity)
        {
            if (quantity == null || quantity.Value == null)
                return;

            writer.WriteXmlAttribute("G", quantity.Value.Value.ToString("F0", CultureInfo.InvariantCulture));
        }
        public void GivenOperationDataWithSpatialRecordDataWithNumericRepValueWhenProcessOperationDAtaThenRowsAreAdded()
        {
            var harvestMoistureMeter = new NumericWorkingData { Representation = RepresentationInstanceList.vrHarvestMoisture.ToModelRepresentation() };
            _workingDatas.Add(harvestMoistureMeter);
            _deviceElementUses.Add(0, new List<DeviceElementUse>
            {
                new DeviceElementUse
                {
                    Depth = 0,
                    GetWorkingDatas = () => _workingDatas,
                }
            });

            var spatialRecord = new SpatialRecord();
            var numericRepresentation = new NumericRepresentationValue(RepresentationInstanceList.vrHarvestMoisture.ToModelRepresentation(), UnitSystemManager.GetUnitOfMeasure("prcnt"), new NumericValue(UnitSystemManager.GetUnitOfMeasure("prcnt"), 3.0));

            spatialRecord.SetMeterValue(harvestMoistureMeter, numericRepresentation);

            _spatialRecords.Add(spatialRecord);

            var dataTable = _operationDataProcessor.ProcessOperationData(_operationData);

            Assert.AreEqual(1, dataTable.Rows.Count);
            Assert.AreEqual(numericRepresentation.Value.Value.ToString(), dataTable.Rows[0][0]);
        }
Esempio n. 3
0
        private void AddDataVariable(TreatmentZone treatmentZone, NumericRepresentationValue value, string productId, IsoUnit unit)
        {
            if (value != null && value.Value != null)
            {
                var targetValue = value.Value.Value;

                // Convert input value to Iso unit
                var adaptUnit = unit.ToAdaptUnit();
                UnitOfMeasure userUnit = null;
                if (adaptUnit != null && value.Value.UnitOfMeasure != null &&
                    adaptUnit.Dimension == value.Value.UnitOfMeasure.Dimension)
                {
                    userUnit = value.Value.UnitOfMeasure;
                    targetValue = _unitConverter.Convert(userUnit.ToInternalUom(), adaptUnit.ToInternalUom(), targetValue);
                }

                var dataVariable = new DataVariable
                {
                    ProductId = productId,
                    Value = targetValue,
                    IsoUnit = unit,
                    UserUnit = userUnit
                };

                treatmentZone.Variables.Add(dataVariable);
            }
        }
 public void GivenDefaultConstructorWhenCreatedThenValuesAreNull()
 {
     var representationValue = new NumericRepresentationValue();
     Assert.IsNull(representationValue.Representation);
     Assert.IsNull(representationValue.UserProvidedUnitOfMeasure);
     Assert.IsNull(representationValue.Value);
 }
Esempio n. 5
0
        private static string GetAccuracy(NumericRepresentationValue accuracyValue)
        {
            if (accuracyValue == null || accuracyValue.Value == null)
                return null;

            var accuracy = accuracyValue.Value.ConvertToUnit(InternalUnitSystemManager.Instance.UnitOfMeasures["m"]);

            return accuracy.ToString(CultureInfo.InvariantCulture);
        }
Esempio n. 6
0
 private static void WriteArea(XmlWriter writer, NumericRepresentationValue area)
 {
     if (area == null || area.Value == null || area.Value.Value < 0)
         writer.WriteAttributeString("D", "0");
     else
     {
         var fieldArea = area.Value.ConvertToUnit(new CompositeUnitOfMeasure("m2"));
         writer.WriteAttributeString("D", fieldArea.ToString(CultureInfo.InvariantCulture));
     }
 }
Esempio n. 7
0
 private double GetResolution(NumericRepresentationValue value)
 {
     var ddi = _representationMapper.Map(value.Representation);
     var resolution = 1d;
     if (_ddis.ContainsKey(ddi.GetValueOrDefault()))
     {
         resolution = _ddis[ddi.GetValueOrDefault()].Resolution;
     }
     return resolution;
 }
        public void GivenSpatialRecordWithResolutionOfOneWhenMapThenValueIsReturned()
        {
            var numericRepresentationValue = new NumericRepresentationValue(RepresentationInstanceList.vrLongitude.ToModelRepresentation(), new NumericValue(UnitSystemManager.GetUnitOfMeasure("arcdeg"), 85));
            _spatialRecord.SetMeterValue(_meter, numericRepresentationValue);

            _representationMapperMock.Setup(x => x.Map(numericRepresentationValue.Representation)).Returns(116);

            var result = _mapper.Map(_meter, _spatialRecord);
            Assert.AreEqual(numericRepresentationValue.Value.Value, result);
        }
      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);
      }
        public void GivenNumericRepresentationValueOfTotalTypeWhenInterpolateThenRepresentationValueIsZero()
        {
            var previousRepresentationValue = new NumericRepresentationValue(RepresentationInstanceList.vrYieldMass.ToModelRepresentation(), new NumericValue(UnitSystemManager.GetUnitOfMeasure("m2"), 1.0));
            _interpolator.SetMostRecentMeterValue(_numericMeter, previousRepresentationValue);

            var result = _interpolator.Interpolate(_numericMeter);

            var numericRepresentationValue = result as NumericRepresentationValue;
            Assert.AreEqual(0, numericRepresentationValue.Value.Value);
        }
      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);
      }
 public static NumericRepresentationValue Add(this NumericRepresentationValue numericRepresentationValue, NumericRepresentationValue secondNumber)
 {
    var sum = numericRepresentationValue.Value.Add(secondNumber.Value);
    return new NumericRepresentationValue(numericRepresentationValue.Representation, sum);
 }
 public static void SubtractFromSource(this NumericRepresentationValue numericRepresentationValue, NumericRepresentationValue secondNumber)
 {
    numericRepresentationValue.Value.SubtractFromSource(secondNumber.Value);
 }
 public static void AddToSource(this NumericRepresentationValue numericRepresentationValue, NumericRepresentationValue secondNumber)
 {
    numericRepresentationValue.Value.AddToSource(secondNumber.Value);
 }
 public static NumericRepresentationValue Divide(this NumericRepresentationValue numericRepresentationValue, NumericRepresentationValue denominator)
 {
    var quotient = numericRepresentationValue.Value.Divide(denominator.Value);
    return new NumericRepresentationValue(numericRepresentationValue.Representation, quotient);
 }
 public static NumericRepresentationValue Multiply(this NumericRepresentationValue numericRepresentationValue, NumericRepresentationValue right, NumericRepresentation numericRepresentation)
 {
    var product = numericRepresentationValue.Multiply(right);
    return new NumericRepresentationValue(numericRepresentation, product.Value);
 }
Esempio n. 18
0
        private TreatmentZone WriteTreatmentZones(XmlWriter writer, RasterGridPrescription prescription)
        {
            if (prescription.ProductIds == null)
                return null;

            var lossOfSignalTreatmentZone = new TreatmentZone { Name = "Loss of GPS", Variables = new List<DataVariable>() };
            var outOfFieldTreatmentZone = new TreatmentZone { Name = "Out of Field", Variables = new List<DataVariable>() };
            var defaultTreatmentZone = new TreatmentZone { Name = "Default", Variables = new List<DataVariable>() };

            var defaultRate = new NumericRepresentationValue(null, new NumericValue(prescription.RxProductLookups.First().UnitOfMeasure, 0));
            var isoUnit = DetermineIsoUnit(prescription.RxProductLookups.First().UnitOfMeasure);

            foreach (var productId in prescription.ProductIds)
            {
                var isoProductId = TaskWriter.Products.FindById(productId) ?? TaskWriter.CropVarieties.FindById(productId);

                AddDataVariable(lossOfSignalTreatmentZone, prescription.LossOfGpsRate, isoProductId, isoUnit);
                AddDataVariable(outOfFieldTreatmentZone, prescription.OutOfFieldRate, isoProductId, isoUnit);
                AddDataVariable(defaultTreatmentZone, defaultRate, isoProductId, isoUnit);
            }

            var lossOfSignalZoneId = "253";
            if (lossOfSignalTreatmentZone.Variables.Count > 0)
                writer.WriteXmlAttribute("I", lossOfSignalZoneId);

            var outOfFieldZoneId = "254";
            if (outOfFieldTreatmentZone.Variables.Count > 0)
                writer.WriteXmlAttribute("J", outOfFieldZoneId);

            TreatmentZoneWriter.Write(writer, "1", defaultTreatmentZone);
            if (lossOfSignalTreatmentZone.Variables.Count > 0)
                TreatmentZoneWriter.Write(writer, lossOfSignalZoneId, lossOfSignalTreatmentZone);
            if (outOfFieldTreatmentZone.Variables.Count > 0)
                TreatmentZoneWriter.Write(writer, outOfFieldZoneId, outOfFieldTreatmentZone);

            return defaultTreatmentZone;
        }
      public void GivenVariableNumbersWithTypesThatSimplifyToScalarTypeWhenMultiplyThenShouldHaveScalarUnit()
      {
         var leftUom = InternalUnitSystemManager.Instance.UnitOfMeasures["ft1sec-1"].ToModelUom();
         var leftValue = new NumericValue(leftUom, 21.848);
         var left = new NumericRepresentationValue(RepresentationInstanceList.vrDistanceTraveled.ToModelRepresentation(), leftValue);
         var rightUom = InternalUnitSystemManager.Instance.UnitOfMeasures["sec"].ToModelUom();
         var rightValue = new NumericValue(rightUom, 9.18);
         var right = new NumericRepresentationValue(RepresentationInstanceList.vrDistanceTraveled.ToModelRepresentation(), rightValue);

         var product = left.Multiply(right, RepresentationInstanceList.vrDistanceTraveled.ToModelRepresentation());
         Assert.AreEqual("ft", product.Value.UnitOfMeasure.Code);
         //Assert.IsInstanceOf<ScalarUnitOfMeasure>(product.Value.UnitOfMeasure.Scale);??
      }
        public void GivenOperationDataWithSpatialRecordDataWithNumericRepValueWhenProcessOperationDataThenColumnNamesContainUom()
        {
            var harvestMoistureMeter = new NumericWorkingData { Representation = RepresentationInstanceList.vrHarvestMoisture.ToModelRepresentation() };
            _workingDatas.Add(harvestMoistureMeter);
            _deviceElementUses.Add(0, new List<DeviceElementUse>
            {
                new DeviceElementUse
                {
                    Depth = 0,
                    GetWorkingDatas = () => _workingDatas,
                }
            });

            var spatialRecord = new SpatialRecord();
            var numericRepresentation = new NumericRepresentationValue(RepresentationInstanceList.vrHarvestMoisture.ToModelRepresentation(), UnitSystemManager.GetUnitOfMeasure("prcnt"), new NumericValue(UnitSystemManager.GetUnitOfMeasure("prcnt"), 3.0));

            spatialRecord.SetMeterValue(harvestMoistureMeter, numericRepresentation);

            _spatialRecords.Add(spatialRecord);

            var dataTable = _operationDataProcessor.ProcessOperationData(_operationData);

            var expectedColumnName = _workingDatas.First().Representation.Code + "-" + _workingDatas.First().Id.ReferenceId + "-0-" +  numericRepresentation.Value.UnitOfMeasure.Code;
            Assert.AreEqual(expectedColumnName, dataTable.Columns[0].ColumnName);
        }
      public void GivenTwoVariableNumbersWhenAddedThenRepresentationIsOriginal()
      {
         var originalUom = _ftUnitOfMeasure.ToModelUom();
         var originalValue = new NumericValue(originalUom, 22);
         var originalNumber = new NumericRepresentationValue(RepresentationInstanceList.vrDistanceTraveled.ToModelRepresentation(), originalValue);

         var secondUom = InternalUnitSystemManager.Instance.UnitOfMeasures["m"].ToModelUom();
         var secondValue = new NumericValue(secondUom, 11);
         var secondNumber = new NumericRepresentationValue(RepresentationInstanceList.vrElevation.ToModelRepresentation(), secondValue);

         var result = originalNumber.Add(secondNumber);
         Assert.AreSame(RepresentationInstanceList.vrDistanceTraveled.DomainId, result.Representation.Code);
      }
 public static NumericRepresentationValue Subtract(this NumericRepresentationValue numericRepresentationValue, NumericRepresentationValue secondNumber)
 {
    var difference = numericRepresentationValue.Value.Subtract(secondNumber.Value);
    return new NumericRepresentationValue(numericRepresentationValue.Representation, difference);
 }
      public void GivenVariableNumberWhenToStringShouldPrettyPrint()
      {
         var uom = _ftUnitOfMeasure.ToModelUom();
         var value = new NumericValue(uom, 12.34);
         var number = new NumericRepresentationValue(RepresentationInstanceList.vrABShiftTrack.ToModelRepresentation(), uom, value);

         var result = number.ToString();

         Assert.AreEqual("12.34 ft (vrABShiftTrack)", result);
      }
      public void GivenVariableNumberAndDoubleWhenSubtractFromSourceShouldDoThat()
      {
         var uom = _ftUnitOfMeasure.ToModelUom();
         var value = new NumericValue(uom, 24.68);
         var number = new NumericRepresentationValue(RepresentationInstanceList.vrABShiftTrack.ToModelRepresentation(), value);
         number.SubtractFromSource(10.11);

         Assert.AreEqual(14.57, number.Value.Value);
      }
      public void GivenVariableNumberWithCompositeUnitOfMeasureWhenMultiplyVariableNumberWithCompositeUnitOfMeasureThenCombinedUnitOfMeasure()
      {
         var uom = InternalUnitSystemManager.Instance.UnitOfMeasures["ft1sec-1"].ToModelUom();
         var leftValue = new NumericValue(uom, 21.848);
         var left = new NumericRepresentationValue(RepresentationInstanceList.vrDistanceTraveled.ToModelRepresentation(), leftValue);
         var rightValue = new NumericValue(uom, 9.18);
         var right = new NumericRepresentationValue(RepresentationInstanceList.vrDistanceTraveled.ToModelRepresentation(), rightValue);

         var product = left.Multiply(right, RepresentationInstanceList.vrDistanceTraveled.ToModelRepresentation());
         Assert.AreSame(RepresentationInstanceList.vrDistanceTraveled.ToModelRepresentation().Code, product.Representation.Code);
         Assert.AreEqual("ft2[sec2]-1", product.Value.UnitOfMeasure.Code);
         Assert.AreEqual(200.56464, product.Value.Value);
      }
Esempio n. 26
0
        private void SetNumericMeterValue(ISOSpatialRow isoSpatialRow, NumericWorkingData meter, SpatialRecord spatialRecord)
        {
            var isoValue = isoSpatialRow.SpatialValues.SingleOrDefault(v => v.Id == meter.Id.FindIntIsoId());

            if (isoValue != null)
            {
                var value = new NumericRepresentationValue(meter.Representation as NumericRepresentation, meter.UnitOfMeasure, new NumericValue(meter.UnitOfMeasure, isoValue.Value));
                spatialRecord.SetMeterValue(meter, value);

                var other = new NumericRepresentationValue(meter.Representation as NumericRepresentation, meter.UnitOfMeasure, new NumericValue(meter.UnitOfMeasure, isoValue.Value));
                _representationValueInterpolator.SetMostRecentMeterValue(meter, other);
            }
            else
            {
                var value = _representationValueInterpolator.Interpolate(meter) as NumericRepresentationValue;
                spatialRecord.SetMeterValue(meter, value);
            }
        }
Esempio n. 27
0
        public void GivenIsoSpatialRowsWithoutNumericMeterOnSecondWhenMapThenSecondValueIsInterpolator()
        {
            var spatialValue = new SpatialValue
            {
                Id = 0,
                Value = 12.3
            };
            _isoSpatialRow.SpatialValues = new List<SpatialValue> { spatialValue };

            var isoSpatialRow2 = new ISOSpatialRow { SpatialValues = new List<SpatialValue>() };

            _isoSpatialRows = new List<ISOSpatialRow> {_isoSpatialRow, isoSpatialRow2};

            var meter = new NumericWorkingData
            {
                Representation = RepresentationInstanceList.vrAvgHarvestMoisture.ToModelRepresentation(),
                DeviceElementUseId = 1,
                UnitOfMeasure = UnitSystemManager.GetUnitOfMeasure("prcnt")
            };

            var uniqueId = new UniqueId
            {
                CiTypeEnum = CompoundIdentifierTypeEnum.String,
                Id = "DLV0"
            };
            meter.Id.UniqueIds.Add(uniqueId);
            _meters.Add(meter);

            var numericRepresentation = new NumericRepresentationValue(meter.Representation as NumericRepresentation,
                    meter.UnitOfMeasure, new NumericValue(meter.UnitOfMeasure, 2.3));

            _spatialValueInterpolator.Setup(s => s.Interpolate(meter)).Returns(numericRepresentation);

            var result = Map().ToList();

            Assert.AreEqual(numericRepresentation, result[1].GetMeterValue(meter) as NumericRepresentationValue);
        }
      public void GivenVariableNumberWhenAddVariableNumberToSourceShouldDoThat()
      {
         var uom = _ftUnitOfMeasure.ToModelUom();
         var firstValue = new NumericValue(uom, 24.68);
         var secondValue = new NumericValue(uom, 10.11);
         var firstNumber = new NumericRepresentationValue(RepresentationInstanceList.vrABShiftTrack.ToModelRepresentation(), firstValue);
         var secondNumber = new NumericRepresentationValue(RepresentationInstanceList.vrABShiftTrack.ToModelRepresentation(), secondValue);

         firstNumber.AddToSource(secondNumber);
         Assert.AreEqual(34.79, firstNumber.Value.Value);
      }
      public void GivenVariableNumberWithCompositeUnitOfMeasureWhenMultiplyVariableNumberWithCompositeUnitOfMeasureThenUnitsCancel()
      {
         var leftUom = InternalUnitSystemManager.Instance.UnitOfMeasures["ft1sec1"].ToModelUom();
         var leftValue = new NumericValue(leftUom, 5.15);
         var left = new NumericRepresentationValue(RepresentationInstanceList.vrDistanceTraveled.ToModelRepresentation(), leftValue);
         var rightUom = InternalUnitSystemManager.Instance.UnitOfMeasures["ft1sec-1"].ToModelUom();
         var rightValue = new NumericValue(rightUom, 7.89);
         var right = new NumericRepresentationValue(RepresentationInstanceList.vrDistanceTraveled.ToModelRepresentation(), rightValue);

         var product = left.Multiply(right, RepresentationInstanceList.vrDistanceTraveled.ToModelRepresentation());
         Assert.AreSame(RepresentationInstanceList.vrDistanceTraveled.ToModelRepresentation().Code, product.Representation.Code);
         Assert.AreEqual("ft2", product.Value.UnitOfMeasure.Code);
         Assert.AreEqual(40.6335, product.Value.Value);
      }
        public void GivenNumericRepresentationValueWhenInterpolateThenRepresentationValue()
        {
            var representationValue = new NumericRepresentationValue(RepresentationInstanceList.vrReportedFieldArea.ToModelRepresentation(), new NumericValue(UnitSystemManager.GetUnitOfMeasure("m2"), 1.0));

            _interpolator.SetMostRecentMeterValue(_numericMeter, representationValue);
            var result = _interpolator.Interpolate(_numericMeter);

            Assert.IsInstanceOf<NumericRepresentationValue>(result);
        }