private Dictionary <int, uint> GetMeterValues(SpatialRecord spatialRecord, List <WorkingData> workingDatas) { var dlvsToWrite = new Dictionary <int, uint>(); var workingDatasWithValues = workingDatas.Where(x => spatialRecord.GetMeterValue(x) != null); foreach (WorkingData workingData in workingDatasWithValues) { int order = _dlvOrdersByWorkingDataID[workingData.Id.ReferenceId]; UInt32?value = null; if (workingData is NumericWorkingData) { NumericWorkingData numericMeter = workingData as NumericWorkingData; if (numericMeter != null && spatialRecord.GetMeterValue(numericMeter) != null) { value = _numericValueMapper.Map(numericMeter, spatialRecord); } } else if (workingData is EnumeratedWorkingData) { EnumeratedWorkingData enumeratedMeter = workingData as EnumeratedWorkingData; if (enumeratedMeter != null && spatialRecord.GetMeterValue(enumeratedMeter) != null) { value = _enumeratedValueMapper.Map(enumeratedMeter, new List <WorkingData>() { workingData }, spatialRecord); } } if (value == null) { continue; } else { dlvsToWrite.Add(order, value.Value); } } return(dlvsToWrite); }
private void SetNumericMeterValue(ISOSpatialRow isoSpatialRow, NumericWorkingData meter, SpatialRecord spatialRecord) { var isoValue = isoSpatialRow.SpatialValues.SingleOrDefault(v => v.DataLogValue.DeviceElementIdRef == _workingDataMapper.DataLogValuesByWorkingDataID[meter.Id.ReferenceId].DeviceElementIdRef && v.DataLogValue.ProcessDataDDI == _workingDataMapper.DataLogValuesByWorkingDataID[meter.Id.ReferenceId].ProcessDataDDI); 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); } }
public void GivenIsoSpatialRowWithoutMeterWhenMapThenInterpolatorIsCalled() { 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 { IdType = IdTypeEnum.String, Id = "DLV0" }; meter.Id.UniqueIds.Add(uniqueId); _meters.Add(meter); Map().ToList(); _spatialValueInterpolator.Verify(s => s.Interpolate(It.IsAny <WorkingData>())); }
private bool IsRatioUnitOfMeasure(NumericWorkingData workingData) { return(_ratioDimensions.Contains(workingData.UnitOfMeasure.Dimension)); }
private IEnumerable <WorkingData> Map(ISODataLogValue dlv, IEnumerable <ISOSpatialRow> isoSpatialRows, DeviceElementUse deviceElementUse, int order, List <DeviceElementUse> pendingDeviceElementUses, DeviceElementHierarchy isoDeviceElementHierarchy) { var workingDatas = new List <WorkingData>(); if (_ddis.ContainsKey(dlv.ProcessDataDDI.AsInt32DDI())) { //Numeric Representations NumericWorkingData numericMeter = MapNumericMeter(dlv, deviceElementUse.Id.ReferenceId); DataLogValuesByWorkingDataID.Add(numericMeter.Id.ReferenceId, dlv); ISODeviceElementIDsByWorkingDataID.Add(numericMeter.Id.ReferenceId, dlv.DeviceElementIdRef); workingDatas.Add(numericMeter); return(workingDatas); } var meterCreator = _enumeratedMeterCreatorFactory.GetMeterCreator(dlv.ProcessDataDDI.AsInt32DDI()); if (meterCreator != null) { //Enumerated Representations var isoEnumeratedMeters = meterCreator.CreateMeters(isoSpatialRows, dlv); foreach (ISOEnumeratedMeter enumeratedMeter in isoEnumeratedMeters) { DataLogValuesByWorkingDataID.Add(enumeratedMeter.Id.ReferenceId, dlv); ISODeviceElementIDsByWorkingDataID.Add(enumeratedMeter.Id.ReferenceId, dlv.DeviceElementIdRef); enumeratedMeter.DeviceElementUseId = deviceElementUse.Id.ReferenceId; } workingDatas.AddRange(isoEnumeratedMeters); if (meterCreator is CondensedStateMeterCreator) { UpdateCondensedWorkingDatas(workingDatas, dlv, deviceElementUse, pendingDeviceElementUses, isoDeviceElementHierarchy); } } else { //Proprietary DDIs - report out as numeric value NumericWorkingData proprietaryWorkingData = new NumericWorkingData(); proprietaryWorkingData.Representation = new ApplicationDataModel.Representations.NumericRepresentation { Code = dlv.ProcessDataDDI, CodeSource = RepresentationCodeSourceEnum.ISO11783_DDI }; proprietaryWorkingData.DeviceElementUseId = deviceElementUse.Id.ReferenceId; //Always set unit as count. In SpatialRecordMapper, we will place the DVP unit on the NumericRepresentationValue.UserProvidedUnitOfMeasure //so that consumers can apply any offset/scaling to get to the desired display unit. proprietaryWorkingData.UnitOfMeasure = UnitSystemManager.GetUnitOfMeasure("count"); //Take any information from DPD ISODeviceElement det = isoDeviceElementHierarchy.DeviceElement; if (det != null) { ISODeviceProcessData dpd = det.DeviceProcessDatas.FirstOrDefault(d => d.DDI == dlv.ProcessDataDDI); if (dpd != null) { proprietaryWorkingData.Representation.Description = dpd.Designator; //Update the representation with a name since we have one here. } } DataLogValuesByWorkingDataID.Add(proprietaryWorkingData.Id.ReferenceId, dlv); ISODeviceElementIDsByWorkingDataID.Add(proprietaryWorkingData.Id.ReferenceId, dlv.DeviceElementIdRef); workingDatas.Add(proprietaryWorkingData); } return(workingDatas); }
public static double GetNumericMeterValue(this SpatialRecord record, NumericWorkingData workingData) { var representationValue = (NumericRepresentationValue)record.GetMeterValue(workingData); return(representationValue.Value.Value); }
private static void GetPlantingData(OperationData opData, Catalog catalog) { // Get the distance meter from the Machine/Vehicle level WorkingData distanceMeter = null; IEnumerable <DeviceElementUse> machineDEUs = opData.GetDeviceElementUses(0); foreach (DeviceElementUse deu in machineDEUs) { IEnumerable <WorkingData> workingDatas = deu.GetWorkingDatas(); foreach (WorkingData meter in workingDatas) { switch (meter.Representation.Code) { case "vrDistanceTraveled": distanceMeter = meter; break; } } } // Get the row-level meters for determining status, seeding rates, and product assignment for each row IEnumerable <DeviceElementUse> rowDEUs = opData.GetDeviceElementUses(2); List <RowConfiguration> rows = new List <RowConfiguration>(); NumericWorkingData exampleRowMeter = null; foreach (DeviceElementUse deu in rowDEUs) { // Link to the catalog.DeviceElementConfigurations in order to determine the width of the row. // Row widths are always in inches SectionConfiguration rowConfig = catalog.DeviceElementConfigurations.Find(x => x.Id.ReferenceId == deu.DeviceConfigurationId) as SectionConfiguration; RowConfiguration row = new RowConfiguration() { widthIn = rowConfig.SectionWidth.Value.Value }; IEnumerable <WorkingData> workingDatas = deu.GetWorkingDatas(); foreach (WorkingData meter in workingDatas) { switch (meter.Representation.Code) { case "dtRecordingStatus": row.statusMeter = meter; break; case "vrSeedRateMassActual": case "vrSeedRateSeedsActual": row.appRateMeter = meter; exampleRowMeter = meter as NumericWorkingData; break; case "vrProductIndex": row.productIndexMeter = meter; break; } } rows.Add(row); } string rateUnits = ""; if (exampleRowMeter != null) { rateUnits = exampleRowMeter.UnitOfMeasure.Code; } // Initialize the productSummary dictionary // Each product used in the planting operation is identified in the opData.ProductIds list. Dictionary <int, ProductSummary> productSummaryByProductId = new Dictionary <int, ProductSummary>(); foreach (int productId in opData.ProductIds) { ProductSummary productSummary = new ProductSummary(); productSummary.product = catalog.Products.Find(x => x.Id.ReferenceId == productId); productSummaryByProductId[productId] = productSummary; } // Keep track of the default productId. // Single-product applications will only specify one product and will not use vrProductIndex meters int defaultProductId = opData.ProductIds[0]; // Loop through all the spatial records IEnumerable <SpatialRecord> spatialRecords = opData.GetSpatialRecords(); foreach (SpatialRecord spatialRecord in spatialRecords) { NumericRepresentationValue distance = spatialRecord.GetMeterValue(distanceMeter) as NumericRepresentationValue; double distanceFt = distance.Value.Value; // Loop through each row - we need to examine the status, product assignment, and rate of each row individually foreach (RowConfiguration row in rows) { EnumeratedValue rowStatus = spatialRecord.GetMeterValue(row.statusMeter) as EnumeratedValue; if (rowStatus.Value.Value == "Off") { // Skip inactive rows continue; } int productId = defaultProductId; if (row.productIndexMeter != null) { // Check to see which product is currently being planted by the current row unit // Only used for split planter and multi-hybrid planter NumericRepresentationValue productIndex = spatialRecord.GetMeterValue(row.productIndexMeter) as NumericRepresentationValue; if (productIndex != null) { productId = (int)productIndex.Value.Value; } } // Calculate the number of acres covered by this row unit at this point in time double acres = row.CalculateAcres(distanceFt); productSummaryByProductId[productId].totalAcres += acres; if (row.appRateMeter != null) { NumericRepresentationValue appRate = spatialRecord.GetMeterValue(row.appRateMeter) as NumericRepresentationValue; if (appRate != null) { double rate = appRate.Value.Value; // seeds/ac or lbs/ac double amount = rate * acres; // seeds or lbs productSummaryByProductId[productId].totalAmount += amount; } } } } Console.WriteLine("Planting Sumamry by Variety. Rate Units: " + rateUnits); foreach (ProductSummary productSummary in productSummaryByProductId.Values) { Console.WriteLine(productSummary.ToString()); } }
public List <Feature> MapMultiple(OperationData operation, IEnumerable <SpatialRecord> spatialRecords) { List <DeviceElementUse> deviceElementUses = GetAllSections(operation); List <WorkingData> workingDatas = deviceElementUses.SelectMany(x => x.GetWorkingDatas()).ToList(); // meters // Display representaitons for debug Console.WriteLine($"Contains the following representations: "); foreach (var workingData in workingDatas) { Console.WriteLine($"{workingData.Representation.CodeSource}: {workingData.Representation.Code}"); } Console.WriteLine($""); // inspired by ISOv4Plugin/Mappers/TimeLogMapper List <Feature> features = new List <Feature>(); foreach (SpatialRecord spatialRecord in spatialRecords) { if (spatialRecord.Geometry != null && spatialRecord.Geometry as Point != null) { Dictionary <string, object> properties = new Dictionary <string, object>(); Point location = spatialRecord.Geometry as Point; if (location.X == 0 || location.Y == 0) { continue; } // altitude if (location.Z != null) { properties.Add("Elevation", location.Z); } // timeStamp properties.Add("Timestamp", spatialRecord.Timestamp.ToString()); // meter values var workingDatasWithValues = workingDatas.Where(x => spatialRecord.GetMeterValue(x) != null); foreach (WorkingData workingData in workingDatasWithValues) //.Where(d => _dlvOrdersByWorkingDataID.ContainsKey(d.Id.ReferenceId))) { string key = workingData.Representation.Code; object value = null; string uom = null; if (workingData is EnumeratedWorkingData) { EnumeratedWorkingData enumeratedMeter = workingData as EnumeratedWorkingData; if (enumeratedMeter != null && spatialRecord.GetMeterValue(enumeratedMeter) != null) { EnumeratedValue enumValue = (spatialRecord.GetMeterValue(enumeratedMeter) as EnumeratedValue); value = enumValue.Value.Value.ToString(); } } else if (workingData is NumericWorkingData) { NumericWorkingData numericMeter = workingData as NumericWorkingData; if (numericMeter != null && spatialRecord.GetMeterValue(numericMeter) != null) { NumericRepresentationValue numValue = spatialRecord.GetMeterValue(numericMeter) as NumericRepresentationValue; value = numValue.Value.Value; uom = numValue.Value.UnitOfMeasure.Code; // better key for DDI (hex2int) if (workingData.Representation.CodeSource == RepresentationCodeSourceEnum.ISO11783_DDI) { if (numValue.Designator != null && numValue.Designator != "") { key = numValue.Designator; } else if (workingData.Representation.Description != null && workingData.Representation.Description != "") { key = workingData.Representation.Description; } else { // ILaR cause: key missing in representation system int intKey = int.Parse(key, System.Globalization.NumberStyles.HexNumber); if (_missingDDI.ContainsKey(intKey)) { key = _missingDDI[intKey]; } else { key = "DDI_" + intKey.ToString(); } } } } } else // needed ? { value = spatialRecord.GetMeterValue(workingData); } if (value != null && key != null) { properties.Add(key, value); if (uom != null) { properties.Add(key + "_Uom", uom); } } } // add to FC features.Add(new Feature(PointMapper.MapPoint2Point(spatialRecord.Geometry as Point, _properties.AffineTransformation), properties)); } } return(features); }
public AverageAggregateStrategy(NumericWorkingData workingData) { _workingData = workingData; _spatialValues = new List <double>(); }
private void SetNumericMeterValue(ISOSpatialRow isoSpatialRow, NumericWorkingData meter, SpatialRecord spatialRecord, Dictionary <string, List <ISOProductAllocation> > productAllocations) { var isoValue = isoSpatialRow.SpatialValues.FirstOrDefault(v => v.DataLogValue.ProcessDataDDI != "DFFE" && _workingDataMapper.DataLogValuesByWorkingDataID.ContainsKey(meter.Id.ReferenceId) && v.DataLogValue.DeviceElementIdRef == _workingDataMapper.DataLogValuesByWorkingDataID[meter.Id.ReferenceId].DeviceElementIdRef && v.DataLogValue.ProcessDataDDI == _workingDataMapper.DataLogValuesByWorkingDataID[meter.Id.ReferenceId].ProcessDataDDI); if (isoValue != null) { ADAPT.ApplicationDataModel.Common.UnitOfMeasure userProvidedUnitOfMeasure = meter.UnitOfMeasure; //Default; no display uom provided. var dvp = isoValue.DeviceProcessData?.DeviceValuePresentation; if (dvp != null) { //If a DVP element is present, report out the desired display unit of measure as the UserProvidedUnitOfMeasure. //This will not necessarily map to the Representation.UnitSystem. userProvidedUnitOfMeasure = new ApplicationDataModel.Common.UnitOfMeasure() { Code = dvp.UnitDesignator, Scale = dvp.Scale, Offset = dvp.Offset }; } var value = new NumericRepresentationValue(meter.Representation as NumericRepresentation, userProvidedUnitOfMeasure, new NumericValue(meter.UnitOfMeasure, isoValue.Value)); spatialRecord.SetMeterValue(meter, value); var other = new NumericRepresentationValue(meter.Representation as NumericRepresentation, userProvidedUnitOfMeasure, new NumericValue(meter.UnitOfMeasure, isoValue.Value)); _representationValueInterpolator.SetMostRecentMeterValue(meter, other); } else if (meter.Representation.Code == "vrProductIndex") { string detID = _workingDataMapper.ISODeviceElementIDsByWorkingDataID[meter.Id.ReferenceId]; if (productAllocations.ContainsKey(detID)) //The DeviceElement for this meter exists in the list of allocations { double numericValue = 0d; if (productAllocations[detID].Count == 1 || TimeLogMapper.GetDistinctProductIDs(_taskDataMapper, productAllocations).Count == 1) { //This product is consistent throughout the task on this device element int?adaptProductID = _taskDataMapper.InstanceIDMap.GetADAPTID(productAllocations[detID].Single().ProductIdRef); numericValue = adaptProductID.HasValue ? adaptProductID.Value : 0d; } else if (productAllocations[detID].Count > 1) { //There are multiple product allocations for the device element //Find the product allocation that governs this timestamp ISOProductAllocation relevantPan = productAllocations[detID].FirstOrDefault(p => Offset(p.AllocationStamp.Start) <= spatialRecord.Timestamp && (p.AllocationStamp.Stop == null || Offset(p.AllocationStamp.Stop) >= spatialRecord.Timestamp)); if (relevantPan != null) { int?adaptProductID = _taskDataMapper.InstanceIDMap.GetADAPTID(relevantPan.ProductIdRef); numericValue = adaptProductID.HasValue ? adaptProductID.Value : 0d; } } var value = new NumericRepresentationValue(meter.Representation as NumericRepresentation, meter.UnitOfMeasure, new NumericValue(meter.UnitOfMeasure, numericValue)); spatialRecord.SetMeterValue(meter, value); } } else { var value = _representationValueInterpolator.Interpolate(meter) as NumericRepresentationValue; spatialRecord.SetMeterValue(meter, value); } }
private IEnumerable <WorkingData> Map(ISODataLogValue dlv, IEnumerable <ISOSpatialRow> isoSpatialRows, DeviceElementUse deviceElementUse, int order, List <DeviceElementUse> pendingDeviceElementUses, DeviceElementHierarchy isoDeviceElementHierarchy) { var workingDatas = new List <WorkingData>(); if (_ddis.ContainsKey(dlv.ProcessDataDDI.AsInt32DDI())) { //Numeric Representations NumericWorkingData numericMeter = MapNumericMeter(dlv, deviceElementUse.Id.ReferenceId); DataLogValuesByWorkingDataID.Add(numericMeter.Id.ReferenceId, dlv); ISODeviceElementIDsByWorkingDataID.Add(numericMeter.Id.ReferenceId, dlv.DeviceElementIdRef); workingDatas.Add(numericMeter); return(workingDatas); } var meterCreator = _enumeratedMeterCreatorFactory.GetMeterCreator(dlv.ProcessDataDDI.AsInt32DDI()); if (meterCreator != null) { //Enumerated Representations var isoEnumeratedMeters = meterCreator.CreateMeters(isoSpatialRows); foreach (ISOEnumeratedMeter enumeratedMeter in isoEnumeratedMeters) { DataLogValuesByWorkingDataID.Add(enumeratedMeter.Id.ReferenceId, dlv); ISODeviceElementIDsByWorkingDataID.Add(enumeratedMeter.Id.ReferenceId, dlv.DeviceElementIdRef); enumeratedMeter.DeviceElementUseId = deviceElementUse.Id.ReferenceId; } workingDatas.AddRange(isoEnumeratedMeters); if (meterCreator is CondensedStateMeterCreator) { UpdateCondensedWorkingDatas(workingDatas, dlv, deviceElementUse, pendingDeviceElementUses, isoDeviceElementHierarchy); } } else { //Proprietary DDIs - report out as numeric value NumericWorkingData proprietaryWorkingData = new NumericWorkingData(); proprietaryWorkingData.Representation = new ApplicationDataModel.Representations.NumericRepresentation { Code = dlv.ProcessDataDDI, CodeSource = RepresentationCodeSourceEnum.ISO11783_DDI }; proprietaryWorkingData.DeviceElementUseId = deviceElementUse.Id.ReferenceId; //Take any information from DPDs/DVPs ApplicationDataModel.Common.UnitOfMeasure uom = null; ISODeviceElement det = isoDeviceElementHierarchy.DeviceElement; if (det != null) { ISODeviceProcessData dpd = det.DeviceProcessDatas.FirstOrDefault(d => d.DDI == dlv.ProcessDataDDI); if (dpd != null) { proprietaryWorkingData.Representation.Description = dpd.Designator; //Update the representation with a name since we have one here. ISODeviceValuePresentation dvp = det.Device.DeviceValuePresentations.FirstOrDefault(d => d.ObjectID == dpd.DeviceValuePresentationObjectId); if (dvp != null && dvp.UnitDesignator != null) { if (AgGateway.ADAPT.Representation.UnitSystem.InternalUnitSystemManager.Instance.UnitOfMeasures.Contains(dvp.UnitDesignator)) { //The unit designator used by the OEM will need to match ADAPT for this to work, otherwise we'll need to default to 'count' below //It will likely work for many simple units and will not for work compound units uom = UnitSystemManager.GetUnitOfMeasure(dvp.UnitDesignator); } } } } proprietaryWorkingData.UnitOfMeasure = uom ?? UnitSystemManager.GetUnitOfMeasure("count"); //Best we can do DataLogValuesByWorkingDataID.Add(proprietaryWorkingData.Id.ReferenceId, dlv); ISODeviceElementIDsByWorkingDataID.Add(proprietaryWorkingData.Id.ReferenceId, dlv.DeviceElementIdRef); workingDatas.Add(proprietaryWorkingData); } return(workingDatas); }