Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin-upstream/develop' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
knelson-farmbeltnorth committed Sep 28, 2024
2 parents ac1c84c + 7640b89 commit 10c1561
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 13 deletions.
4 changes: 2 additions & 2 deletions ISOv4Plugin/ISOv4Plugin.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netstandard2.0</TargetFrameworks>
Expand All @@ -13,7 +13,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="AgGatewayADAPTFramework" Version="3.0.0" />
<PackageReference Include="AgGatewayADAPTFramework" Version="3.0.2" />
</ItemGroup>

<ItemGroup>
Expand Down
41 changes: 35 additions & 6 deletions ISOv4Plugin/Mappers/TimeLogMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -340,8 +340,27 @@ protected IEnumerable<OperationData> ImportTimeLog(ISOTask loggedTask, ISOTimeLo
ISOTime time = GetTimeElementFromTimeLog(isoTimeLog);

//Identify unique devices represented in this TimeLog data
IEnumerable<string> deviceElementIDs = time.DataLogValues.Where(d => !d.ProcessDataDDI.EqualsIgnoreCase("DFFF") && !d.ProcessDataDDI.EqualsIgnoreCase("DFFE"))
List<string> deviceElementIDs = time.DataLogValues.Where(d => !d.ProcessDataDDI.EqualsIgnoreCase("DFFF") && !d.ProcessDataDDI.EqualsIgnoreCase("DFFE"))
.Select(d => d.DeviceElementIdRef).Distinct().ToList();

//Supplement the list with any parent device elements which although don't log data in the TLG
//May require a vrProductIndex working data based on product allocations
HashSet<string> parentsToAdd = new HashSet<string>();
foreach (string deviceElementID in deviceElementIDs)
{
ISODeviceElement isoDeviceElement = TaskDataMapper.DeviceElementHierarchies.GetISODeviceElementFromID(deviceElementID);
if (isoDeviceElement != null)
{
while (isoDeviceElement.Parent != null &&
isoDeviceElement.Parent is ISODeviceElement parentDet)
{
parentsToAdd.Add(parentDet.DeviceElementId);
isoDeviceElement= parentDet;
}
}
}
deviceElementIDs.AddRange(parentsToAdd);

Dictionary<ISODevice, HashSet<string>> loggedDeviceElementsByDevice = new Dictionary<ISODevice, HashSet<string>>();
foreach (string deviceElementID in deviceElementIDs)
{
Expand Down Expand Up @@ -533,6 +552,12 @@ private Dictionary<string, List<ISOProductAllocation>> GetProductAllocationsByDe
ISODeviceElement deviceElement = dvc.DeviceElements.FirstOrDefault(d => d.DeviceElementId == pan.DeviceElementIdRef);
if (deviceElement != null) //Filter PANs by this DVC
{
// If device element was merged with another one, use it instead
var mergedElement = TaskDataMapper.DeviceElementHierarchies.GetMatchingElement(deviceElement.DeviceElementId, true);
if (mergedElement != null)
{
deviceElement = mergedElement.DeviceElement;
}
AddProductAllocationsForDeviceElement(reportedPANs, pan, deviceElement, $"{GetHierarchyPosition(deviceElement)}_{panIndex}");
}
panIndex++;
Expand Down Expand Up @@ -568,13 +593,17 @@ private Dictionary<string, List<ISOProductAllocation>> GetProductAllocationsByDe
private int GetLowestProductAllocationLevel(DeviceHierarchyElement isoDeviceElementHierarchy, Dictionary<string, List<ISOProductAllocation>> isoProductAllocations)
{
int level = -1;
// If device element has direct product allocations, use its Depth.
// If device element or any merged device elements have direct product allocations, use its Depth.
if (isoDeviceElementHierarchy != null &&
isoProductAllocations.TryGetValue(isoDeviceElementHierarchy.DeviceElement.DeviceElementId, out List<ISOProductAllocation> productAllocations) &&
productAllocations.Any(x => x.DeviceElementIdRef == isoDeviceElementHierarchy.DeviceElement.DeviceElementId))
isoProductAllocations.TryGetValue(isoDeviceElementHierarchy.DeviceElement.DeviceElementId, out List<ISOProductAllocation> productAllocations))
{
level = isoDeviceElementHierarchy.Depth;
}
var deviceElementIds = new List<string> { isoDeviceElementHierarchy.DeviceElement.DeviceElementId };
deviceElementIds.AddRange(isoDeviceElementHierarchy.MergedElements.Select(x => x.DeviceElementId));
if (productAllocations.Any(x => deviceElementIds.Contains(x.DeviceElementIdRef)))
{
level = isoDeviceElementHierarchy.Depth;
}
}

// Get max level from children elements
int? maxChildLevel = isoDeviceElementHierarchy?.Children?.Max(x => GetLowestProductAllocationLevel(x, isoProductAllocations));
Expand Down
10 changes: 5 additions & 5 deletions ISOv4Plugin/ObjectModel/DeviceElementHierarchy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,11 @@ public DeviceElementHierarchies(IEnumerable<ISODevice> devices,

public Dictionary<string, DeviceHierarchyElement> Items { get; set; }

public DeviceHierarchyElement GetMatchingElement(string isoDeviceElementId)
public DeviceHierarchyElement GetMatchingElement(string isoDeviceElementId, bool includeMergedElements = false)
{
foreach (DeviceHierarchyElement hierarchy in this.Items.Values)
{
DeviceHierarchyElement foundModel = hierarchy.FromDeviceElementID(isoDeviceElementId);
DeviceHierarchyElement foundModel = hierarchy.FromDeviceElementID(isoDeviceElementId, includeMergedElements);
if (foundModel != null)
{
return foundModel;
Expand Down Expand Up @@ -358,17 +358,17 @@ private static void AddMissingGeometryDefinition(Dictionary<string, List<string>
public DeviceHierarchyElement Parent { get; set; }


public DeviceHierarchyElement FromDeviceElementID(string deviceElementID)
public DeviceHierarchyElement FromDeviceElementID(string deviceElementID, bool includeMergedElements = false)
{
if (DeviceElement?.DeviceElementId == deviceElementID)
if (DeviceElement?.DeviceElementId == deviceElementID || (includeMergedElements && MergedElements.Any(x => x.DeviceElementId == deviceElementID)))
{
return this;
}
else if (Children != null)
{
foreach (DeviceHierarchyElement child in Children)
{
DeviceHierarchyElement childModel = child.FromDeviceElementID(deviceElementID);
DeviceHierarchyElement childModel = child.FromDeviceElementID(deviceElementID, includeMergedElements);
if (childModel != null)
{
return childModel;
Expand Down

0 comments on commit 10c1561

Please sign in to comment.