Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Products at different hierarchy levels #223

Merged
merged 1 commit into from
Oct 8, 2024
Merged
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
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
Loading