Skip to content

Commit

Permalink
Merge pull request #193 from ADAPT/develop
Browse files Browse the repository at this point in the history
Merge for next release
  • Loading branch information
Stuart Rhea authored Sep 28, 2022
2 parents 877f4bb + 8ea789c commit 3e6bbe0
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions ISOv4Plugin/Mappers/TimeLogMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -359,8 +359,8 @@ protected IEnumerable<OperationData> ImportTimeLog(ISOTask loggedTask, ISOTimeLo
//Determine products
Dictionary<string, List<ISOProductAllocation>> deviceProductAllocations = GetProductAllocationsByDeviceElement(loggedTask, dvc);

//Create a separate operation for each product form (liquid, granular or solid).
List<List<string>> deviceElementGroups = SplitElementsByProductForm(deviceProductAllocations, loggedDeviceElementsByDevice[dvc], dvc);
//Create a separate operation for each combination of specific product properties.
List<List<string>> deviceElementGroups = SplitElementsByProductProperties(deviceProductAllocations, loggedDeviceElementsByDevice[dvc], dvc);

foreach (var deviceElementGroup in deviceElementGroups)
{
Expand Down Expand Up @@ -404,18 +404,18 @@ protected IEnumerable<OperationData> ImportTimeLog(ISOTask loggedTask, ISOTimeLo
return null;
}

private List<List<string>> SplitElementsByProductForm(Dictionary<string, List<ISOProductAllocation>> productAllocations, HashSet<string> loggedDeviceElementIds, ISODevice dvc)
private List<List<string>> SplitElementsByProductProperties(Dictionary<string, List<ISOProductAllocation>> productAllocations, HashSet<string> loggedDeviceElementIds, ISODevice dvc)
{
//This function splits device elements logged by single TimeLog into groups based
//on product form referenced by these elements. This is done using following logic:
//on product form/type referenced by these elements. This is done using following logic:
// - determine used products forms and list of device element ids for each form
// - for each product form determine device elements from all other forms
// - remove these device elements and their children from a copy of device hierarchy elements
// - this gives a list of device elements to keep for a product form
var deviceElementIdsByProductForm = productAllocations
.SelectMany(x => x.Value.Select(y => new { Form = GetProductFormByProductAllocation(y), Id = x.Key }))
.Where(x => x.Form.HasValue)
.GroupBy(x => x.Form, x => x.Id)
.SelectMany(x => x.Value.Select(y => new { Product = GetProductByProductAllocation(y), Id = x.Key }))
.Where(x => x.Product != null)
.GroupBy(x => new { x.Product.Form, x.Product.ProductType }, x => x.Id)
.Select(x => x.Distinct().ToList())
.ToList();

Expand All @@ -441,7 +441,7 @@ private List<List<string>> SplitElementsByProductForm(Dictionary<string, List<IS
return deviceElementGroups;
}

private ProductFormEnum? GetProductFormByProductAllocation(ISOProductAllocation pan)
private Product GetProductByProductAllocation(ISOProductAllocation pan)
{
var adaptProductId = TaskDataMapper.InstanceIDMap.GetADAPTID(pan.ProductIdRef);
var adaptProduct = TaskDataMapper.AdaptDataModel.Catalog.Products.FirstOrDefault(x => x.Id.ReferenceId == adaptProductId);
Expand All @@ -451,7 +451,7 @@ private List<List<string>> SplitElementsByProductForm(Dictionary<string, List<IS
{
TaskDataMapper.AddError($"ProductAllocation referencing Product={pan.ProductIdRef} skipped since no matching product found");
}
return adaptProduct?.Form;
return adaptProduct;
}

private List<string> FilterDeviceElementIds(DeviceHierarchyElement deviceHierarchyElement, List<string> idsToRemove)
Expand Down

0 comments on commit 3e6bbe0

Please sign in to comment.