Skip to content
Merged
Show file tree
Hide file tree
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
7 changes: 7 additions & 0 deletions ISOv4Plugin/ExtensionMethods/ExtensionMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,13 @@ public static bool ReverseEquals(this string s1, string s2)
return true;
}

/// <summary>
/// Matches NumericRepresentation by code, accounting for null representation code
/// </summary>
public static bool ContainsCode(this ApplicationDataModel.Representations.Representation representation, string code)
{
return representation?.Code != null && representation.Code.Contains(code);
}

/// <summary>
/// Looks up unit, converts and loads representation
Expand Down
25 changes: 13 additions & 12 deletions ISOv4Plugin/Mappers/TimeLogMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -409,8 +409,7 @@ protected IEnumerable<OperationData> 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)
{
Expand All @@ -428,22 +427,25 @@ protected IEnumerable<OperationData> ImportTimeLog(ISOTask loggedTask, ISOTimeLo
return null;
}

private OperationTypeEnum? GetOperationTypeFromWorkingDatas(List<WorkingData> workingDatas)
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.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<List<string>> SplitElementsByProductProperties(Dictionary<string, List<ISOProductAllocation>> productAllocations, HashSet<string> loggedDeviceElementIds, ISODevice dvc)
Expand Down Expand Up @@ -682,9 +684,6 @@ private void AddProductAllocationsForDeviceElement(Dictionary<string, Dictionary

switch (productCategories.FirstOrDefault())
{
case CategoryEnum.Variety:
return OperationTypeEnum.SowingAndPlanting;

case CategoryEnum.Fertilizer:
case CategoryEnum.NitrogenStabilizer:
case CategoryEnum.Manure:
Expand Down Expand Up @@ -722,7 +721,9 @@ private OperationTypeEnum GetOperationTypeFromLoggingDevices(ISOTime time)
}
}

DeviceOperationType deviceType = representedTypes.FirstOrDefault(t => 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
Expand Down
Loading