diff --git a/ISOv4Plugin/ExtensionMethods/ExtensionMethods.cs b/ISOv4Plugin/ExtensionMethods/ExtensionMethods.cs
index 66a5615..0949024 100644
--- a/ISOv4Plugin/ExtensionMethods/ExtensionMethods.cs
+++ b/ISOv4Plugin/ExtensionMethods/ExtensionMethods.cs
@@ -95,6 +95,13 @@ public static bool ReverseEquals(this string s1, string s2)
return true;
}
+ ///
+ /// Matches NumericRepresentation by code, accounting for null representation code
+ ///
+ public static bool ContainsCode(this ApplicationDataModel.Representations.Representation representation, string code)
+ {
+ return representation?.Code != null && representation.Code.Contains(code);
+ }
///
/// Looks up unit, converts and loads representation
diff --git a/ISOv4Plugin/Mappers/TimeLogMapper.cs b/ISOv4Plugin/Mappers/TimeLogMapper.cs
index f0eccf2..4922ace 100644
--- a/ISOv4Plugin/Mappers/TimeLogMapper.cs
+++ b/ISOv4Plugin/Mappers/TimeLogMapper.cs
@@ -409,8 +409,7 @@ protected IEnumerable ImportTimeLog(ISOTask loggedTask, ISOTimeLo
operationData.GetDeviceElementUses = x => operationData.DeviceElementUses.Where(s => s.Depth == x).ToList();
operationData.PrescriptionId = prescriptionID;
operationData.OperationType = GetOperationTypeFromProductCategory(productIDs) ??
- GetOperationTypeFromWorkingDatas(workingDatas) ??
- GetOperationTypeFromLoggingDevices(time);
+ OverrideOperationTypeFromWorkingDatas(GetOperationTypeFromLoggingDevices(time), workingDatas);
operationData.ProductIds = productIDs;
if (!useDeferredExecution)
{
@@ -428,22 +427,25 @@ protected IEnumerable ImportTimeLog(ISOTask loggedTask, ISOTimeLo
return null;
}
- private OperationTypeEnum? GetOperationTypeFromWorkingDatas(List workingDatas)
+ 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.Code.Contains("Seed")))
+ if (workingDatas.Any(w => w.Representation.ContainsCode("Seed")))
{
return OperationTypeEnum.SowingAndPlanting;
}
- else if (workingDatas.Any(w => w.Representation.Code.Contains("Tillage")))
+ else if (workingDatas.Any(w => w.Representation.ContainsCode("Tillage")))
{
return OperationTypeEnum.Tillage;
}
- if (workingDatas.Any(w => w.Representation.Code.Contains("AppRate")))
+ if (workingDatas.Any(w => w.Representation.ContainsCode("AppRate")))
{
- return OperationTypeEnum.Unknown; //We can't differentiate CropProtection from Fertilizing, but prefer unkonwn to letting implement type set to SowingAndPlanting
+ 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 null;
+ return deviceOperationType;
}
private List> SplitElementsByProductProperties(Dictionary> productAllocations, HashSet loggedDeviceElementIds, ISODevice dvc)
@@ -682,9 +684,6 @@ private void AddProductAllocationsForDeviceElement(Dictionary t.ClientNAMEMachineType >= 2 && t.ClientNAMEMachineType <= 11);
+ DeviceOperationType deviceType = representedTypes.FirstOrDefault(t => t.ClientNAMEMachineType >= 2 && t.ClientNAMEMachineType <= 11 &&
+ t.OperationType != OperationTypeEnum.Unknown);
+
if (deviceType != null)
{
//2-11 represent known types of operations