Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 33 additions & 25 deletions ISOv4Plugin/Mappers/TimeLogMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -412,8 +412,7 @@ protected IEnumerable<OperationData> 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)
{
Expand All @@ -431,27 +430,6 @@ protected IEnumerable<OperationData> ImportTimeLog(ISOTask loggedTask, ISOTimeLo
return null;
}

private OperationTypeEnum OverrideOperationTypeFromWorkingDatas(OperationTypeEnum deviceOperationType, List<WorkingData> 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<List<string>> SplitElementsByProductProperties(Dictionary<string, List<ISOProductAllocation>> productAllocations, HashSet<string> loggedDeviceElementIds, ISODevice dvc)
{
//This function splits device elements logged by single TimeLog into groups based
Expand Down Expand Up @@ -678,16 +656,30 @@ private void AddProductAllocationsForDeviceElement(Dictionary<string, Dictionary
}
}

private OperationTypeEnum? GetOperationTypeFromProductCategory(List<int> productIds)
private OperationTypeEnum GetOperationType(List<int> productIds, ISOTime time, List<WorkingData> workingDatas)
{
var productCategories = productIds
.Select(x => TaskDataMapper.AdaptDataModel.Catalog.Products.FirstOrDefault(y => y.Id.ReferenceId == x))
.Where(x => x != null && x.Category != CategoryEnum.Unknown)
.Select(x => 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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The issue is due to Mappers/Manufacturers/CNH.cs @ 290. It is more of framework limitation than an error since Category lacks an enumeration item for Harvested Commodity. Arguably the "right" fix would be for us to add that to the framework and then make these changes, but the conditional you have here will probably cover us in all cases. The other possibility is to determine the harvested product by using reflection on the type. I'm fine with this going out like this for now, however.

// (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:
Expand All @@ -700,7 +692,23 @@ private void AddProductAllocationsForDeviceElement(Dictionary<string, Dictionary
return OperationTypeEnum.CropProtection;

default:
return null;
//Harvest/ForageHarvest omitted intentionally to be determined from machine type vs. working data
if (workingDatas.Any(w => 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;
}
}

Expand Down
Loading