Skip to content

Commit a19cf05

Browse files
authored
Merge pull request #251 from ADAPT/develop
Merge to master for release
2 parents 78cf09b + 7c25a8d commit a19cf05

File tree

4 files changed

+42
-10
lines changed

4 files changed

+42
-10
lines changed

ISOv4Plugin/Mappers/GuidancePatternMapper.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,10 @@ public IEnumerable<GuidancePattern> ImportGuidancePatterns(IEnumerable<ISOGuidan
215215
foreach (ISOGuidancePattern isoGuidancePattern in isoGuidancePatterns)
216216
{
217217
GuidancePattern adaptGuidancePattern = ImportGuidancePattern(isoGuidancePattern);
218-
adaptGuidancePatterns.Add(adaptGuidancePattern);
218+
if (adaptGuidancePattern != null)
219+
{
220+
adaptGuidancePatterns.Add(adaptGuidancePattern);
221+
}
219222
}
220223

221224
//Add the patterns to the Catalog
@@ -236,7 +239,13 @@ public GuidancePattern ImportGuidancePattern(ISOGuidancePattern isoGuidancePatte
236239
GuidancePattern pattern = null;
237240
LineStringMapper lineStringMapper = new LineStringMapper(TaskDataMapper);
238241
PointMapper pointMapper = new PointMapper(TaskDataMapper);
239-
var isoLineString = isoGuidancePattern.LineString ?? new ISOLineString();
242+
ISOLineString isoLineString = isoGuidancePattern.LineString;
243+
if ((isoLineString?.Points?.Count ?? 0) == 0)
244+
{
245+
TaskDataMapper.AddError($"Guidance pattern {isoGuidancePattern.GuidancePatternDesignator} is invalid. Skipping.");
246+
return null;
247+
}
248+
240249
switch (isoGuidancePattern.GuidancePatternType)
241250
{
242251
case ISOGuidancePatternType.AB:

ISOv4Plugin/Mappers/Manufacturers/CNH.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,8 @@ public IEnumerable<OperationData> PostProcessOperationData(TaskDataMapper taskDa
254254
}
255255

256256
if (!string.IsNullOrEmpty(cropNameFromTask) &&
257-
operationData.OperationType != OperationTypeEnum.DataCollection &&
257+
(operationData.OperationType == OperationTypeEnum.Harvesting ||
258+
operationData.OperationType == OperationTypeEnum.ForageHarvesting) &&
258259
(operationData.ProductIds == null || operationData.ProductIds.Count == 0))
259260
{
260261
operationData.ProductIds = new List<int>

ISOv4Plugin/Mappers/TimeLogMapper.cs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,9 @@ protected IEnumerable<OperationData> ImportTimeLog(ISOTask loggedTask, ISOTimeLo
408408
operationData.DeviceElementUses = sectionMapper.ConvertToBaseTypes(sections.ToList());
409409
operationData.GetDeviceElementUses = x => operationData.DeviceElementUses.Where(s => s.Depth == x).ToList();
410410
operationData.PrescriptionId = prescriptionID;
411-
operationData.OperationType = GetOperationTypeFromProductCategory(productIDs) ?? GetOperationTypeFromLoggingDevices(time);
411+
operationData.OperationType = GetOperationTypeFromProductCategory(productIDs) ??
412+
GetOperationTypeFromWorkingDatas(workingDatas) ??
413+
GetOperationTypeFromLoggingDevices(time);
412414
operationData.ProductIds = productIDs;
413415
if (!useDeferredExecution)
414416
{
@@ -426,6 +428,24 @@ protected IEnumerable<OperationData> ImportTimeLog(ISOTask loggedTask, ISOTimeLo
426428
return null;
427429
}
428430

431+
private OperationTypeEnum? GetOperationTypeFromWorkingDatas(List<WorkingData> workingDatas)
432+
{
433+
//Harvest/ForageHarvest omitted intentionally to be determined from machine type vs. working data
434+
if (workingDatas.Any(w => w.Representation.Code.Contains("Seed")))
435+
{
436+
return OperationTypeEnum.SowingAndPlanting;
437+
}
438+
else if (workingDatas.Any(w => w.Representation.Code.Contains("Tillage")))
439+
{
440+
return OperationTypeEnum.Tillage;
441+
}
442+
if (workingDatas.Any(w => w.Representation.Code.Contains("AppRate")))
443+
{
444+
return OperationTypeEnum.Unknown; //We can't differentiate CropProtection from Fertilizing, but prefer unkonwn to letting implement type set to SowingAndPlanting
445+
}
446+
return null;
447+
}
448+
429449
private List<List<string>> SplitElementsByProductProperties(Dictionary<string, List<ISOProductAllocation>> productAllocations, HashSet<string> loggedDeviceElementIds, ISODevice dvc)
430450
{
431451
//This function splits device elements logged by single TimeLog into groups based

ISOv4Plugin/Plugin.cs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,15 @@ public void Export(ApplicationDataModel.ADM.ApplicationDataModel dataModel, stri
4141
ISO11783_TaskData taskData = taskDataMapper.Export(dataModel);
4242

4343
//Serialize the ISO model to XML
44-
TaskDocumentWriter writer = new TaskDocumentWriter();
45-
writer.WriteTaskData(outputPath, taskData);
46-
47-
//Serialize the Link List
48-
if (taskData.Version > 3)
44+
using (TaskDocumentWriter writer = new TaskDocumentWriter())
4945
{
50-
writer.WriteLinkList(outputPath, taskData.LinkList);
46+
writer.WriteTaskData(outputPath, taskData);
47+
48+
//Serialize the Link List
49+
if (taskData.Version > 3)
50+
{
51+
writer.WriteLinkList(outputPath, taskData.LinkList);
52+
}
5153
}
5254
}
5355

0 commit comments

Comments
 (0)