Skip to content

Commit

Permalink
Merge pull request #224 from ADAPT/develop
Browse files Browse the repository at this point in the history
Merge to master for release
  • Loading branch information
strhea authored Oct 9, 2024
2 parents bd159bf + 4bda9d2 commit 95e0d19
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
1 change: 1 addition & 0 deletions ISOv4Plugin/Mappers/PartfieldMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};

Expand Down
28 changes: 24 additions & 4 deletions ISOv4Plugin/Mappers/TimeLogMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -564,7 +564,7 @@ private Dictionary<string, List<ISOProductAllocation>> 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<string, List<ISOProductAllocation>> output = reportedPANs.ToDictionary(x => x.Key, x=>
Dictionary<string, List<ISOProductAllocation>> 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
Expand All @@ -583,10 +583,30 @@ private Dictionary<string, List<ISOProductAllocation>> 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);
}

Expand Down

0 comments on commit 95e0d19

Please sign in to comment.