Skip to content

Commit 8989bee

Browse files
authored
DYN-9092: fix port entry issue and refactor (#16326)
1 parent c307684 commit 8989bee

5 files changed

Lines changed: 41 additions & 52 deletions

File tree

src/DynamoCore/Search/NodeAutocompleteSearch.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ internal class ClusterResultItem
283283
internal string Description { get; set; }
284284

285285
[DataMember(Name = "probability")]
286-
internal string Probability { get; set; }
286+
internal double Probability { get; set; }
287287

288288
[DataMember(Name = "entryNodeIndex")]
289289
internal int EntryNodeIndex { get; set; }

src/NodeAutoCompleteViewExtension/ViewModels/DNADropdownViewModel.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System.Windows.Media;
2+
using Dynamo.Search.SearchElements;
23

34
namespace Dynamo.NodeAutoComplete.ViewModels
45
{
@@ -7,5 +8,6 @@ public class DNADropdownViewModel
78
public string Description { get; set; }
89
public string Parameters { get; set; }
910
public ImageSource SmallIcon { get; set; }
11+
internal ClusterResultItem ClusterResultItem { get; set; }
1012
}
1113
}

src/NodeAutoCompleteViewExtension/ViewModels/NodeAutoCompleteBarViewModel.cs

Lines changed: 12 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public class NodeAutoCompleteBarViewModel : SearchViewModel
4949
private bool displayLowConfidence;
5050
private const string nodeAutocompleteMLEndpoint = "MLNodeAutocomplete";
5151
private const string nodeClusterAutocompleteMLEndpoint = "MLNodeClusterAutocomplete";
52-
private const double minClusterConfidenceScore = 0.1;
52+
private const double minClusterConfidenceScore = 0.001;
5353
private static Assembly dynamoCoreWpfAssembly;
5454

5555
private bool _isSingleAutocomplete;
@@ -169,7 +169,7 @@ internal IEnumerable<ClusterResultItem> QualifiedResults
169169
{
170170
return null;
171171
}
172-
return FullResults.Results.Where(x => double.Parse(x.Probability) * 100 > minClusterConfidenceScore);
172+
return FullResults.Results.Where(x => x.Probability > minClusterConfidenceScore);
173173
}
174174
}
175175

@@ -382,7 +382,6 @@ public bool IsDNAClusterPlacementEnabled
382382
internal event Action<NodeModel> ParentNodeRemoved;
383383

384384
internal MLNodeClusterAutoCompletionResponse FullResults { private set; get; }
385-
internal List<SingleResultItem> FullSingleResults { set; get; }
386385
private Guid LastRequestGuid;
387386

388387
/// <summary>
@@ -796,11 +795,7 @@ internal void AddCluster(int filterredIndex)
796795
var currentFilter = FilteredView.Cast<DNADropdownViewModel>().ToList();
797796
var currentItem = filterredIndex >= 0 && filterredIndex < currentFilter.Count ? currentFilter[filterredIndex] : null;
798797

799-
var realCluster = QualifiedResults.FirstOrDefault(x => x.Description.Equals(currentItem.Description));
800-
if (realCluster != null)
801-
{
802-
AddCluster(realCluster);
803-
}
798+
AddCluster(currentItem.ClusterResultItem);
804799
}
805800

806801
// Add Cluster from server result into the workspace
@@ -974,22 +969,7 @@ internal void PopulateAutoComplete()
974969
{
975970
Version = "0.0",
976971
NumberOfResults = fullSingleResults.Count,
977-
Results = fullSingleResults.Select(x => new ClusterResultItem
978-
{
979-
Description = x.Description,
980-
Title = x.Description,
981-
Probability = x.Score.ToString(),
982-
EntryNodeIndex = 0,
983-
EntryNodeInPort = PortViewModel.PortType == PortType.Output ? x.PortToConnect : -1,
984-
EntryNodeOutPort = PortViewModel.PortType == PortType.Input ? x.PortToConnect : -1,
985-
Topology = new TopologyItem
986-
{
987-
Nodes = new List<NodeItem> { new NodeItem {
988-
Id = Guid.NewGuid().ToString(),
989-
Type = new NodeType { Id = x.CreationName } } },
990-
Connections = new List<ConnectionItem>()
991-
}
992-
})
972+
Results = fullSingleResults,
993973
};
994974
}
995975
else
@@ -1012,15 +992,15 @@ internal void PopulateAutoComplete()
1012992
return;
1013993
}
1014994

1015-
FullSingleResults = fullSingleResults ?? FullSingleResults;
1016995
FullResults = fullResults ?? FullResults;
1017996

1018997
IEnumerable<DNADropdownViewModel> comboboxResults;
1019998
if (IsSingleAutocomplete || !IsDisplayingMLRecommendation)
1020999
{
1000+
var singleResults = FullResults.Results as List<SingleResultItem>;
10211001
//getting bitmaps from resources necessarily has to be done in the UI thread
10221002
Dictionary<string, ImageSource> dict = [];
1023-
foreach (var singleResult in FullSingleResults)
1003+
foreach (var singleResult in singleResults)
10241004
{
10251005
if (dict.ContainsKey(singleResult.CreationName))
10261006
{
@@ -1030,18 +1010,20 @@ internal void PopulateAutoComplete()
10301010
SearchViewModelRequestBitmapSource(iconRequest);
10311011
dict[singleResult.CreationName] = iconRequest.Icon;
10321012
}
1033-
comboboxResults = FullSingleResults.Where(x => x.Score * 100 > minClusterConfidenceScore).Select(x => new DNADropdownViewModel
1013+
comboboxResults = QualifiedResults.Select(x => new DNADropdownViewModel
10341014
{
10351015
Description = x.Description,
1036-
Parameters = x.Parameters,
1037-
SmallIcon = dict[x.CreationName],
1016+
Parameters = (x as SingleResultItem).Parameters,
1017+
SmallIcon = dict[(x as SingleResultItem).CreationName],
1018+
ClusterResultItem = x
10381019
});
10391020
}
10401021
else
10411022
{
10421023
comboboxResults = QualifiedResults.Select(x => new DNADropdownViewModel
10431024
{
1044-
Description = x.Description
1025+
Description = x.Description,
1026+
ClusterResultItem = x
10451027
//default icon (cluster) is set in the xaml view
10461028
});
10471029
}
Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,56 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
14
using Dynamo.Graph.Nodes;
25
using Dynamo.Search.SearchElements;
3-
using Dynamo.Wpf.ViewModels;
46

57
namespace Dynamo.NodeAutoComplete.ViewModels
68
{
7-
internal class SingleResultItem
9+
internal class SingleResultItem : ClusterResultItem
810
{
9-
11+
private void InitTopology(int port)
12+
{
13+
EntryNodeIndex = 0;
14+
EntryNodeInPort = port;
15+
EntryNodeOutPort = port;
16+
Topology = new TopologyItem
17+
{
18+
Nodes = new List<NodeItem> { new NodeItem {
19+
Id = Guid.NewGuid().ToString(),
20+
Type = new NodeType { Id = CreationName } } },
21+
Connections = new List<ConnectionItem>()
22+
};
23+
}
1024
public SingleResultItem(NodeSearchElement model, double score = 1.0)
1125
{
1226
Assembly = model.Assembly;
1327
IconName = model.IconName;
1428
Description = model.Name;
1529
Parameters = model.Parameters;
1630
CreationName = model.CreationName;
17-
PortToConnect = model.AutoCompletionNodeElementInfo.PortToConnect;
18-
Score = score;
31+
Probability = score;
32+
Title = Description;
33+
InitTopology(model.AutoCompletionNodeElementInfo.PortToConnect);
1934
}
2035

2136
public SingleResultItem(NodeModel nodeModel, int portToConnect, double score = 1.0)
2237
{
2338
Assembly = nodeModel.GetType().Assembly.GetName().Name;
2439
IconName = nodeModel.GetType().Name;
2540
Description = nodeModel.Name;
26-
CreationName = string.IsNullOrWhiteSpace(nodeModel.CreationName) ? nodeModel.GetOriginalName(): nodeModel.CreationName;
27-
PortToConnect = portToConnect;
28-
Score = score;
29-
}
30-
31-
public SingleResultItem(NodeSearchElementViewModel x) : this(x.Model)
32-
{
33-
//Convert percent to probability
34-
Score = x.AutoCompletionNodeMachineLearningInfo.ConfidenceScore / 100.0;
41+
Parameters = $"({string.Join(", ", nodeModel.InPorts.Select(x => x.Name))})";
42+
CreationName = string.IsNullOrWhiteSpace(nodeModel.CreationName) ? nodeModel.GetOriginalName() : nodeModel.CreationName;
43+
Probability = score;
44+
Title = Description;
45+
InitTopology(portToConnect);
3546
}
3647

3748
internal string Assembly { get; set; }
3849

3950
internal string IconName { get; set; }
4051

41-
internal string Description { get; set; }
42-
4352
internal string Parameters { get; set; }
4453

4554
internal string CreationName { get; set; }
46-
47-
internal int PortToConnect { get; set; }
48-
49-
internal double Score { get; set; }
5055
}
5156
}

src/NodeAutoCompleteViewExtension/Views/NodeAutoCompletePanelView.xaml.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ internal NodeAutocompleteCluster(ClusterResultItem result)
154154
/// <summary>
155155
/// confidence level
156156
/// </summary>
157-
public string Probability => clusterResultItem.Probability;
157+
public double Probability => clusterResultItem.Probability;
158158

159159
/// <summary>
160160
/// Nodes in the node cluster

0 commit comments

Comments
 (0)