From dbc142819f7ed8e93ca0d4ea3436383b67b9780f Mon Sep 17 00:00:00 2001 From: Leonid Date: Tue, 4 Oct 2022 20:06:10 -0700 Subject: [PATCH] Account for product allocation being at the top device element --- ISOv4Plugin/Mappers/TimeLogMapper.cs | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/ISOv4Plugin/Mappers/TimeLogMapper.cs b/ISOv4Plugin/Mappers/TimeLogMapper.cs index 3238d54..27e2b24 100644 --- a/ISOv4Plugin/Mappers/TimeLogMapper.cs +++ b/ISOv4Plugin/Mappers/TimeLogMapper.cs @@ -366,8 +366,11 @@ protected IEnumerable ImportTimeLog(ISOTask loggedTask, ISOTimeLo { OperationData operationData = new OperationData(); + //Get ids of all device elements in a group including parent element ids + //since product allocations can be at parent elements which are not logging any data. + var elementHierarchyIds = GetISOElementHierarchyIds(deviceElementGroup); Dictionary> productAllocations = deviceProductAllocations - .Where(x => deviceElementGroup.Contains(x.Key)) + .Where(x => elementHierarchyIds.Contains(x.Key)) .ToDictionary(x => x.Key, x => x.Value); List productIDs = GetDistinctProductIDs(TaskDataMapper, productAllocations); @@ -479,6 +482,20 @@ private List FilterDeviceElementIds(DeviceHierarchyElement deviceHierarc return elementIdsToKeep; } + private List GetISOElementHierarchyIds(List deviceElementIds) + { + return deviceElementIds.Aggregate(new { ids = new HashSet(), TaskDataMapper.DeviceElementHierarchies }, (acc, x) => + { + var isoDevElement = acc.DeviceElementHierarchies.GetISODeviceElementFromID(x); + while (isoDevElement != null) + { + acc.ids.Add(isoDevElement.DeviceElementId); + isoDevElement = isoDevElement.Parent as ISODeviceElement; + } + return acc; + }).ids.ToList(); + } + protected virtual ISOTime GetTimeElementFromTimeLog(ISOTimeLog isoTimeLog) { return isoTimeLog.GetTimeElement(this.TaskDataPath);