From 3b86e3b13a4dc4803b8c0e6fcb28c9b09a8b601e Mon Sep 17 00:00:00 2001 From: Andrew Vardeman Date: Wed, 21 Jan 2026 09:39:32 -0600 Subject: [PATCH] Consolidate operation-getting methods and return SowingAndPlanting for Variety products again --- ISOv4Plugin/Mappers/TimeLogMapper.cs | 58 ++++++++++++++++------------ 1 file changed, 33 insertions(+), 25 deletions(-) diff --git a/ISOv4Plugin/Mappers/TimeLogMapper.cs b/ISOv4Plugin/Mappers/TimeLogMapper.cs index 6bbe43d..65bf980 100644 --- a/ISOv4Plugin/Mappers/TimeLogMapper.cs +++ b/ISOv4Plugin/Mappers/TimeLogMapper.cs @@ -412,8 +412,7 @@ protected IEnumerable ImportTimeLog(ISOTask loggedTask, ISOTimeLo operationData.DeviceElementUses = sectionMapper.ConvertToBaseTypes(sections.ToList()); operationData.GetDeviceElementUses = x => operationData.DeviceElementUses.Where(s => s.Depth == x).ToList(); operationData.PrescriptionId = prescriptionID; - operationData.OperationType = GetOperationTypeFromProductCategory(productIDs) ?? - OverrideOperationTypeFromWorkingDatas(GetOperationTypeFromLoggingDevices(time), workingDatas); + operationData.OperationType = GetOperationType(productIDs, time, workingDatas); operationData.ProductIds = productIDs; if (!useDeferredExecution) { @@ -431,27 +430,6 @@ protected IEnumerable ImportTimeLog(ISOTask loggedTask, ISOTimeLo return null; } - private OperationTypeEnum OverrideOperationTypeFromWorkingDatas(OperationTypeEnum deviceOperationType, List workingDatas) - { - //Harvest/ForageHarvest omitted intentionally to be determined from machine type vs. working data - if (workingDatas.Any(w => w.Representation.ContainsCode("Seed"))) - { - return OperationTypeEnum.SowingAndPlanting; - } - else if (workingDatas.Any(w => w.Representation.ContainsCode("Tillage"))) - { - return OperationTypeEnum.Tillage; - } - if (workingDatas.Any(w => w.Representation.ContainsCode("AppRate"))) - { - if (deviceOperationType != OperationTypeEnum.Fertilizing && deviceOperationType != OperationTypeEnum.CropProtection) - { - return OperationTypeEnum.Unknown; //We can't differentiate CropProtection from Fertilizing, but prefer unknown to letting implement type set to SowingAndPlanting - } - } - return deviceOperationType; - } - private List> SplitElementsByProductProperties(Dictionary> productAllocations, HashSet loggedDeviceElementIds, ISODevice dvc) { //This function splits device elements logged by single TimeLog into groups based @@ -678,7 +656,7 @@ private void AddProductAllocationsForDeviceElement(Dictionary productIds) + private OperationTypeEnum GetOperationType(List productIds, ISOTime time, List workingDatas) { var productCategories = productIds .Select(x => TaskDataMapper.AdaptDataModel.Catalog.Products.FirstOrDefault(y => y.Id.ReferenceId == x)) @@ -686,8 +664,22 @@ private void AddProductAllocationsForDeviceElement(Dictionary x.Category) .ToList(); + var deviceOperationType = GetOperationTypeFromLoggingDevices(time); + + // Prefer product category to determine operation type where possible switch (productCategories.FirstOrDefault()) { + case CategoryEnum.Variety: + // It's technically an error to log Harvesting as a variety product, + // but this was observed by Ag Leader in a CNH Pro1200 file in August 2025 + // (see https://github.com/ADAPT/ISOv4Plugin/pull/256) + if (deviceOperationType == OperationTypeEnum.Harvesting) + { + return deviceOperationType; + } + + return OperationTypeEnum.SowingAndPlanting; + case CategoryEnum.Fertilizer: case CategoryEnum.NitrogenStabilizer: case CategoryEnum.Manure: @@ -700,7 +692,23 @@ private void AddProductAllocationsForDeviceElement(Dictionary w.Representation.ContainsCode("Seed"))) + { + return OperationTypeEnum.SowingAndPlanting; + } + if (workingDatas.Any(w => w.Representation.ContainsCode("Tillage"))) + { + return OperationTypeEnum.Tillage; + } + if (workingDatas.Any(w => w.Representation.ContainsCode("AppRate"))) + { + if (deviceOperationType != OperationTypeEnum.Fertilizing && deviceOperationType != OperationTypeEnum.CropProtection) + { + return OperationTypeEnum.Unknown; // We can't differentiate CropProtection from Fertilizing, but prefer unknown to letting implement type set to SowingAndPlanting + } + } + return deviceOperationType; } }