diff --git a/ISOv4Plugin/Mappers/PartfieldMapper.cs b/ISOv4Plugin/Mappers/PartfieldMapper.cs index e63d7fd..8887a59 100644 --- a/ISOv4Plugin/Mappers/PartfieldMapper.cs +++ b/ISOv4Plugin/Mappers/PartfieldMapper.cs @@ -257,6 +257,7 @@ public Field ImportField(ISOPartfield isoPartfield) fieldBoundary = new FieldBoundary { FieldId = field.Id.ReferenceId, + Description = isoPartfield.Polygons.Select(item => item.PolygonDesignator).FirstOrDefault(attr => attr != null), SpatialData = boundary, }; diff --git a/ISOv4Plugin/Mappers/TimeLogMapper.cs b/ISOv4Plugin/Mappers/TimeLogMapper.cs index 63e82b4..66c554d 100644 --- a/ISOv4Plugin/Mappers/TimeLogMapper.cs +++ b/ISOv4Plugin/Mappers/TimeLogMapper.cs @@ -564,7 +564,7 @@ private Dictionary> GetProductAllocationsByDe } // Sort product allocations for each DeviceElement using it's position among ancestors. // This arranges PANs on each DET in reverse order: ones from lowest DET in hierarchy having precedence over ones from top. - Dictionary> output = reportedPANs.ToDictionary(x => x.Key, x=> + Dictionary> output = reportedPANs.ToDictionary(x => x.Key, x => { var allocations = x.Value.OrderByDescending(y => y.Key).Select(y => y.Value).ToList(); // Check if there are any indirect allocations: ones that came from parent device element @@ -583,10 +583,30 @@ private Dictionary> GetProductAllocationsByDe .Select(x => TaskDataMapper.DeviceElementHierarchies.GetMatchingElement(x)) .Where(x => x != null) .FirstOrDefault(); - int lowestLevel = GetLowestProductAllocationLevel(det?.GetRootDeviceElementHierarchy(), output); - // Remove allocations for all other levels + + var rootElement = det?.GetRootDeviceElementHierarchy(); + int lowestLevel = GetLowestProductAllocationLevel(rootElement, output); + var elementAtLowestDepth = rootElement?.GetElementsAtDepth(lowestLevel).FirstOrDefault(); + + // Keep allocations for lowest level or for elements of the same type and without children. + // This handles scenario where device hierarchy for different products have different lengths: + // - one with 4 levels and Unit device element at the lowest level + // - one with 3 levels and Unit device element at the lowest level return output - .Where(x => TaskDataMapper.DeviceElementHierarchies.GetMatchingElement(x.Key)?.Depth == lowestLevel) + .Where(x => + { + var matchingElement = TaskDataMapper.DeviceElementHierarchies.GetMatchingElement(x.Key); + if (matchingElement == null) + { + return false; + } + if (matchingElement.Depth == lowestLevel) + { + return true; + } + return matchingElement.Type == elementAtLowestDepth?.Type && + (matchingElement.Children == null || matchingElement.Children.Count == 0); + }) .ToDictionary(x => x.Key, x => x.Value); }