public NumericRepresentationValue Simplify(NumericRepresentation representation, IEnumerable<UnitOfMeasureComponent> components, double value) { var finalValue = value; var unitOfMeasureComponents = new Dictionary<string, UnitOfMeasureComponent>(); foreach (var component in components) { finalValue = SimplifyComponent(component, unitOfMeasureComponents, finalValue); } var baseNumber = CombineComponents(unitOfMeasureComponents.Values.ToList(), finalValue); return new NumericRepresentationValue(representation, baseNumber.UnitOfMeasure, baseNumber); }
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); }
/// <summary> /// If an implementer wants to export to a custom DDI or otherwise one that doesn't map, /// the appropriate DDI may be set in the Prescription prior to exporting. /// A ISO11783_DDI representation is as such the first mapping attempted. /// </summary> /// <param name="representation"></param> /// <param name="adaptUnit"></param> /// <returns></returns> private int DetermineVariableDDI(NumericRepresentation representation, UnitOfMeasure adaptUnit) { if (representation != null) { if (representation.CodeSource == RepresentationCodeSourceEnum.ISO11783_DDI) { return(Int32.Parse(representation.Code)); } int?mappedDDI = RepresentationMapper.Map(representation); if (mappedDDI.HasValue) { return(mappedDDI.Value); } } if (adaptUnit != null && UnitFactory.DimensionToDdi.ContainsKey(adaptUnit.Dimension)) { return(UnitFactory.DimensionToDdi[adaptUnit.Dimension]); } TaskDataMapper.AddError($"Unable to determine DDI for Prescription export {representation.Code}.", $"Representation ID : {representation.Id.ReferenceId}", "PrescriptionMapper.DetermineVariableDDI()"); return(0); //Return an invalid DDI }
public NumericRepresentationValue(NumericRepresentation representation, UnitOfMeasure userProvidedUnitOfMeasure, NumericValue value) { Representation = representation; UserProvidedUnitOfMeasure = userProvidedUnitOfMeasure; Value = value; }
public NumericRepresentationValue(NumericRepresentation representation, NumericValue value) { Representation = representation; Value = value; }
public static NumericRepresentationValue Multiply(this NumericRepresentationValue numericRepresentationValue, NumericRepresentationValue right, NumericRepresentation numericRepresentation) { var product = numericRepresentationValue.Multiply(right); return new NumericRepresentationValue(numericRepresentation, product.Value); }
public static NumericRepresentationValue Divide(this NumericRepresentationValue numericRepresentationValue, NumericRepresentationValue denominator, NumericRepresentation numericRepresentation) { var quotient = numericRepresentationValue.Value.Divide(denominator.Value); return new NumericRepresentationValue(numericRepresentation, quotient); }
private ISOTreatmentZone ExportTreatmentZonesForType2(ISOTask task, RasterGridPrescription prescription) { if (prescription.ProductIds == null) { TaskDataMapper.AddError($"No Products are present for Grid Type 2 Prescription export: {prescription.Description}", prescription.Id.ReferenceId.ToString()); return(null); } var lossOfSignalTreatmentZone = new ISOTreatmentZone { TreatmentZoneDesignator = "Loss of GPS", ProcessDataVariables = new List <ISOProcessDataVariable>() }; var outOfFieldTreatmentZone = new ISOTreatmentZone { TreatmentZoneDesignator = "Out of Field", ProcessDataVariables = new List <ISOProcessDataVariable>() }; var defaultTreatmentZone = new ISOTreatmentZone { TreatmentZoneDesignator = "Default", ProcessDataVariables = new List <ISOProcessDataVariable>() }; foreach (var productId in prescription.ProductIds) { var isoUnit = DetermineIsoUnit(prescription.RxProductLookups.First(p => p.ProductId == productId).UnitOfMeasure); string isoProductId = TaskDataMapper.InstanceIDMap.GetISOID(productId) ?? string.Empty; RxProductLookup productLookup = prescription.RxProductLookups.FirstOrDefault(p => p.ProductId == productId); ISOProcessDataVariable lossPDV = ExportProcessDataVariable(productLookup?.LossOfGpsRate ?? prescription.LossOfGpsRate, isoProductId, isoUnit); if (lossPDV != null) { lossOfSignalTreatmentZone.ProcessDataVariables.Add(lossPDV); } ISOProcessDataVariable oofPDV = ExportProcessDataVariable(productLookup?.OutOfFieldRate ?? prescription.OutOfFieldRate, isoProductId, isoUnit); if (oofPDV != null) { outOfFieldTreatmentZone.ProcessDataVariables.Add(oofPDV); } NumericRepresentation defaultRepresentation = productLookup?.LossOfGpsRate.Representation; //We can reuse the loss of gps representation here if it exists if (defaultRepresentation == null) { //Determine the representation based on the unit of the product to be applied var unitDimension = isoUnit.ToAdaptUnit().Dimension; if (UnitFactory.DimensionToDdi.ContainsKey(unitDimension)) { int ddi = UnitFactory.DimensionToDdi[unitDimension]; RepresentationMapper representationMapper = new RepresentationMapper(); var representation = representationMapper.Map(ddi) as NumericRepresentation; if (representation == null) { representation = new NumericRepresentation { Code = ddi.ToString(), CodeSource = RepresentationCodeSourceEnum.ISO11783_DDI }; } } else { TaskDataMapper.AddError($"Unable to identify a default representation: {prescription.Description}", prescription.Id.ReferenceId.ToString()); return(null); } } //Add 0 as the default rate in the PDV; actual values are in the binary var defaultRate = new NumericRepresentationValue(defaultRepresentation, new NumericValue(prescription.RxProductLookups.First(p => p.ProductId == productId).UnitOfMeasure, 0d)); ISOProcessDataVariable defaultPDV = ExportProcessDataVariable(defaultRate, isoProductId, isoUnit); defaultTreatmentZone.ProcessDataVariables.Add(defaultPDV); } if (lossOfSignalTreatmentZone.ProcessDataVariables.Count > 0) { lossOfSignalTreatmentZone.TreatmentZoneCode = 253; task.TreatmentZones.Add(lossOfSignalTreatmentZone); task.PositionLostTreatmentZoneCode = lossOfSignalTreatmentZone.TreatmentZoneCode; } if (outOfFieldTreatmentZone.ProcessDataVariables.Count > 0) { outOfFieldTreatmentZone.TreatmentZoneCode = 254; task.TreatmentZones.Add(outOfFieldTreatmentZone); task.OutOfFieldTreatmentZoneCode = outOfFieldTreatmentZone.TreatmentZoneCode; } defaultTreatmentZone.TreatmentZoneCode = 1; task.TreatmentZones.Add(defaultTreatmentZone); task.DefaultTreatmentZoneCode = defaultTreatmentZone.TreatmentZoneCode; return(defaultTreatmentZone); }