private static void AreEqual(XmlNode tlgNode, string currentPath, OperationData operationData)
        {
            var isoSpatialRecords   = GetIsoSpatialRecords(tlgNode.Attributes["A"].Value, currentPath).ToList();
            var adaptSpatialRecords = operationData.GetSpatialRecords().ToList();

            var sections = operationData.GetAllSections();
            var meters   = sections.SelectMany(x => x.GetWorkingDatas()).ToList();

            SpatialRecordAssert.AreEqual(isoSpatialRecords, adaptSpatialRecords, meters);
        }
示例#2
0
        private void ExportSpatialRecords(string documentsPath, OperationData operationData)
        {
            var fileName = string.Format(DatacardConstants.OperationDataFile, operationData.Id.ReferenceId);
            var filePath = Path.Combine(documentsPath, fileName);

            if (operationData.GetSpatialRecords == null)
            {
                _protobufSerializer.WriteSpatialRecords(filePath, new List <SpatialRecord>());
                return;
            }

            var spatialRecords = operationData.GetSpatialRecords();

            _protobufSerializer.WriteSpatialRecords(filePath, spatialRecords);
        }
        private void ExportSpatialRecords(IBaseSerializer baseSerializer, string documentsPath, OperationData operationData)
        {
            var fileName = string.Format(DatacardConstants.OperationDataFile, operationData.Id.ReferenceId);
            var filePath = Path.Combine(documentsPath, fileName);

            if (operationData.GetSpatialRecords == null)
            {
                baseSerializer.SerializeWithLengthPrefix(new List <SpatialRecord>(), filePath);
                return;
            }

            var spatialRecords = operationData.GetSpatialRecords();

            baseSerializer.SerializeWithLengthPrefix(spatialRecords, filePath);
        }
示例#4
0
        private static void AreEqual(OperationData operationData, List <TimeScope> timeScopes, TLG tlg, string cardPath)
        {
            var fileName             = tlg.A + ".xml";
            var tlgXmlHeaderFilePath = Path.Combine(cardPath, "TASKDATA", fileName);

            Assert.IsTrue(File.Exists(tlgXmlHeaderFilePath));

            var tims = new XmlReader().ReadTlgXmlData(cardPath, fileName);

            TimAssert.AreEqual(timeScopes, tims);

            var sections            = operationData.GetAllSections();
            var meters              = sections.SelectMany(x => x.GetWorkingDatas()).ToList();
            var adaptSpatialRecords = operationData.GetSpatialRecords();
            var binaryReader        = new BinaryReader();
            var isoSpatialRecords   = binaryReader.Read(cardPath, tlg.A + ".bin", tims.First());

            IsoSpatialRecordAssert.AreEqual(adaptSpatialRecords, meters, isoSpatialRecords);
        }
        public DataTable ProcessOperationData(OperationData operationData)
        {
            _dataTable = new DataTable();

            if (operationData.GetSpatialRecords != null)
            {
                var spatialRecords = operationData.GetSpatialRecords().ToList();
                var meters         = GetWorkingData(operationData);

                CreateColumns(meters);

                foreach (var spatialRecord in spatialRecords)
                {
                    CreateRow(meters, spatialRecord);
                }

                UpdateColumnNamesWithUom(meters, spatialRecords);
            }

            return(_dataTable);
        }
示例#6
0
        private void ProcessData(TreeNode treeNode)
        {
            var objectWithIndex = (ObjectWithIndex)treeNode.Tag;
            var element         = objectWithIndex.Element;

            workingDataComboBox.Visible = false;
            if (element is FieldBoundary)
            {
                _boundaryProcessor.ProcessBoundary(element as FieldBoundary);
                _tabControlViewer.SelectedTab = _tabPageSpatial;
            }
            else if (element is GuidanceGroup)
            {
                _guidanceProcessor.ProcessGuidance(element as GuidanceGroup, _model.ApplicationDataModels[objectWithIndex.ApplicationDataModelIndex].Catalog.GuidancePatterns);
                _tabControlViewer.SelectedTab = _tabPageSpatial;
            }
            else if (element is GuidancePattern)
            {
                _guidanceProcessor.ProccessGuidancePattern(element as GuidancePattern);
                _tabControlViewer.SelectedTab = _tabPageSpatial;
            }
            else if (element is OperationData)
            {
                OperationData        operation      = element as OperationData;
                List <SpatialRecord> spatialRecords = new List <SpatialRecord>();
                if (operation.GetSpatialRecords != null)
                {
                    spatialRecords = operation.GetSpatialRecords().ToList(); //Iterate the records once here for multiple consumers below
                }
                _dataGridViewRawData.DataSource = _operationDataProcessor.ProcessOperationData(operation, spatialRecords);
                ApplicationDataModel.ADM.ApplicationDataModel model = _model.ApplicationDataModels[objectWithIndex.ApplicationDataModelIndex];
                _spatialRecordProcessor.ProcessOperation(operation, spatialRecords, _model.ApplicationDataModels[objectWithIndex.ApplicationDataModelIndex].Catalog);
                workingDataComboBox.Visible    = true;
                workingDataComboBox.DataSource = _spatialRecordProcessor.WorkingDataList;
            }
            else if (element is Prescription)
            {
                _prescriptionProcessor.ProcessPrescription(element as Prescription);
            }
        }
示例#7
0
        private TLG Map(OperationData operationData, string taskDataPath, TaskDocumentWriter taskDocumentWriter)
        {
            var tlgId = operationData.Id.FindIsoId() ?? "TLG" + operationData.Id.ReferenceId;

            taskDocumentWriter.Ids.Add(tlgId, operationData.Id);

            var tlg = new TLG {
                A = tlgId
            };
            var sections       = operationData.GetAllSections();
            var meters         = sections.SelectMany(x => x.GetWorkingDatas()).ToList();
            var spatialRecords = operationData.GetSpatialRecords != null?operationData.GetSpatialRecords() : null;

            var timHeader = _timHeaderMapper.Map(meters);

            _xmlReader.WriteTlgXmlData(taskDataPath, tlg.A + ".xml", timHeader);

            var binFilePath = Path.Combine(taskDataPath, tlg.A + ".bin");

            _binaryWriter.Write(binFilePath, meters, spatialRecords);

            return(tlg);
        }
        private static void GetHarvestData(OperationData opData, Catalog catalog)
        {
            WorkingData distanceMeter = null;
            WorkingData moistureMeter = null;
            WorkingData wetMassMeter  = null;
            WorkingData dryYieldMeter = 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;

                    case "vrHarvestMoisture":
                        moistureMeter = meter;
                        break;

                    case "vrYieldWetMass":
                        wetMassMeter = meter;
                        break;

                    case "vrYieldVolume":
                        dryYieldMeter = meter;
                        break;
                    }
                }
            }

            // Active width is kept on Level 1 which indicates the header
            WorkingData widthMeter = null;
            IEnumerable <DeviceElementUse> headDEUs = opData.GetDeviceElementUses(1);

            foreach (DeviceElementUse deu in headDEUs)
            {
                IEnumerable <WorkingData> workingDatas = deu.GetWorkingDatas();
                foreach (WorkingData meter in workingDatas)
                {
                    switch (meter.Representation.Code)
                    {
                    case "vrEquipmentWidth":
                        widthMeter = meter;
                        break;
                    }
                }
            }

            double totalArea       = 0;
            double totalWetMass    = 0;
            double totalDryBushels = 0;
            double totalMoisture   = 0;

            // Loop through all the spatial records to get total area, wet mass, and moisture.
            IEnumerable <SpatialRecord> spatialRecords = opData.GetSpatialRecords();

            foreach (SpatialRecord spatialRecord in spatialRecords)
            {
                // Calculate the area
                NumericRepresentationValue distance = spatialRecord.GetMeterValue(distanceMeter) as NumericRepresentationValue;
                NumericRepresentationValue width    = spatialRecord.GetMeterValue(widthMeter) as NumericRepresentationValue;

                double distanceFt = distance.Value.Value;
                double widthFt    = width.Value.Value;

                double squareFeet = distanceFt * widthFt;
                double acres      = squareFeet / SQUARE_FEET_PER_ACRE;
                totalArea += acres;

                NumericRepresentationValue wetMass = spatialRecord.GetMeterValue(wetMassMeter) as NumericRepresentationValue;

                double wetMassLbs = wetMass.Value.Value;    // lbs
                totalWetMass += wetMassLbs;

                NumericRepresentationValue moisture = spatialRecord.GetMeterValue(moistureMeter) as NumericRepresentationValue;

                double moisturePct = moisture.Value.Value;  // %
                totalMoisture += moisturePct * wetMassLbs;  // Only used for calculating weighted average

                NumericRepresentationValue dryVol = spatialRecord.GetMeterValue(dryYieldMeter) as NumericRepresentationValue;

                double dryVolBu = dryVol.Value.Value;    // bu
                totalDryBushels += dryVolBu;
            }

            double averageMoisture = totalMoisture / totalWetMass;

            string result = String.Format("Area: {0:F2}\tWetMass: {1:F2}\tMoisture: {2:F2}\tDryBushels: {3:F2}", totalArea, totalWetMass, averageMoisture, totalDryBushels);

            Console.WriteLine(result);
        }
        private static void GetAsAppliedData(OperationData opData, Catalog catalog)
        {
            WorkingData areaMeter    = null;
            WorkingData appRateMeter = null;
            IEnumerable <DeviceElementUse> headDEUs = opData.GetDeviceElementUses(1);

            foreach (DeviceElementUse deu in headDEUs)
            {
                IEnumerable <WorkingData> workingDatas = deu.GetWorkingDatas();
                foreach (WorkingData meter in workingDatas)
                {
                    switch (meter.Representation.Code)
                    {
                    case "vrDeltaArea":
                        areaMeter = meter;
                        break;

                    case "vrAppRateVolumeActual":
                        appRateMeter = meter;
                        break;
                    }
                }
            }

            double totalArea   = 0;
            double totalAmount = 0;

            string rateUnits = "";

            // Loop through all the spatial records to get total area and total amount
            IEnumerable <SpatialRecord> spatialRecords = opData.GetSpatialRecords();

            foreach (SpatialRecord spatialRecord in spatialRecords)
            {
                // Calculate the area
                NumericRepresentationValue area = spatialRecord.GetMeterValue(areaMeter) as NumericRepresentationValue;

                double acres = area.Value.Value;
                totalArea += acres;

                NumericRepresentationValue appRate = spatialRecord.GetMeterValue(appRateMeter) as NumericRepresentationValue;
                rateUnits = appRate.Value.UnitOfMeasure.Code;

                double rate   = appRate.Value.Value; // gal/ac
                double amount = rate * acres;        // gal
                totalAmount += amount;
            }

            double averageRate = totalAmount / totalArea;

            Console.WriteLine("Application Summary:");

            string result = String.Format("Area: {0:F2}\tAmount: {1:F2}\tRate: {2:F2} {3}", totalArea, totalAmount, averageRate, rateUnits);

            Console.WriteLine(result);

            if (opData.ProductIds.Count > 0)
            {
                Console.WriteLine("Product Details:");
                Product product = catalog.Products.Find(x => x.Id.ReferenceId == opData.ProductIds[0]);

                result = String.Format("Product Description: {0}", product.Description);
                Console.WriteLine(result);

                if (product.ProductComponents.Count > 0)
                {
                    Console.WriteLine("Product Components:");

                    // Calculate the total rates for each type of ProductComponent in the MixProduct
                    double volumeTotalRate = 0;
                    double massTotalRate   = 0;
                    foreach (ProductComponent component in product.ProductComponents)
                    {
                        if (component.Quantity.Value.UnitOfMeasure.Dimension == UnitOfMeasureDimensionEnum.Volume)
                        {
                            // gal
                            volumeTotalRate += component.Quantity.Value.Value;
                        }
                        else if (component.Quantity.Value.UnitOfMeasure.Dimension == UnitOfMeasureDimensionEnum.Mass)
                        {
                            // lb
                            massTotalRate += component.Quantity.Value.Value;
                        }
                    }

                    // Determine the correct total applied date for the MixProduct
                    double totalRate = volumeTotalRate;
                    if (totalRate == 0)
                    {
                        // The volumeTotalRate will be 0 for dry product mixes
                        totalRate = massTotalRate;
                    }

                    // Calculate the total units of tank mix actually applied to the field.
                    //  This is important to be able to determine the actual proportion of each ProductComponent
                    double totalUnitsOfMixProduct = totalAmount / volumeTotalRate;

                    foreach (ProductComponent component in product.ProductComponents)
                    {
                        Product componentProduct = catalog.Products.Find(x => x.Id.ReferenceId == component.IngredientId);
                        double  componentRate    = component.Quantity.Value.Value;

                        // Calculate the total amount of the product component
                        double componentAmount     = totalUnitsOfMixProduct * componentRate;
                        double componentActualRate = componentAmount / totalArea;

                        result = String.Format("Component: {0}\tAmount: {1:F2}\tRate: {2:F2} {3}/ac", componentProduct.Description, componentAmount, componentActualRate, component.Quantity.Value.UnitOfMeasure.Code);
                        Console.WriteLine(result);
                    }
                }
            }
        }
        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());
            }
        }
示例#11
0
 public static IEnumerable <SpatialRecord> GetSpatialRecordsSafely(this OperationData operationData)
 {
     return(operationData.GetSpatialRecords == null
         ? Enumerable.Empty <SpatialRecord>()
         : operationData.GetSpatialRecords());
 }