Skip to content

Commit ff76015

Browse files
committed
fix port entry issue and refactor
1 parent 6de8441 commit ff76015

5 files changed

Lines changed: 32 additions & 48 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: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
using System;
12
using System.Windows.Media;
3+
using Dynamo.Search.SearchElements;
24

35
namespace Dynamo.NodeAutoComplete.ViewModels
46
{
@@ -7,5 +9,6 @@ public class DNADropdownViewModel
79
public string Description { get; set; }
810
public string Parameters { get; set; }
911
public ImageSource SmallIcon { get; set; }
12+
internal ClusterResultItem ClusterResultItem { get; set; }
1013
}
1114
}

src/NodeAutoCompleteViewExtension/ViewModels/NodeAutoCompleteBarViewModel.cs

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

5454
private bool _isSingleAutocomplete;
@@ -168,7 +168,7 @@ internal IEnumerable<ClusterResultItem> QualifiedResults
168168
{
169169
return null;
170170
}
171-
return FullResults.Results.Where(x => double.Parse(x.Probability) * 100 > minClusterConfidenceScore);
171+
return FullResults.Results.Where(x => x.Probability > minClusterConfidenceScore);
172172
}
173173
}
174174

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

383383
internal MLNodeClusterAutoCompletionResponse FullResults { private set; get; }
384-
internal List<SingleResultItem> FullSingleResults { set; get; }
385384
private Guid LastRequestGuid;
386385

387386
/// <summary>
@@ -784,11 +783,7 @@ internal void AddCluster(int filterredIndex)
784783
var currentFilter = FilteredView.Cast<DNADropdownViewModel>().ToList();
785784
var currentItem = filterredIndex >= 0 && filterredIndex < currentFilter.Count ? currentFilter[filterredIndex] : null;
786785

787-
var realCluster = QualifiedResults.FirstOrDefault(x => x.Description.Equals(currentItem.Description));
788-
if (realCluster != null)
789-
{
790-
AddCluster(realCluster);
791-
}
786+
AddCluster(currentItem.ClusterResultItem);
792787
}
793788

794789
// Add Cluster from server result into the workspace
@@ -960,22 +955,7 @@ internal void PopulateAutoComplete()
960955
{
961956
Version = "0.0",
962957
NumberOfResults = fullSingleResults.Count,
963-
Results = fullSingleResults.Select(x => new ClusterResultItem
964-
{
965-
Description = x.Description,
966-
Title = x.Description,
967-
Probability = x.Score.ToString(),
968-
EntryNodeIndex = 0,
969-
EntryNodeInPort = PortViewModel.PortType == PortType.Output ? x.PortToConnect : -1,
970-
EntryNodeOutPort = PortViewModel.PortType == PortType.Input ? x.PortToConnect : -1,
971-
Topology = new TopologyItem
972-
{
973-
Nodes = new List<NodeItem> { new NodeItem {
974-
Id = Guid.NewGuid().ToString(),
975-
Type = new NodeType { Id = x.CreationName } } },
976-
Connections = new List<ConnectionItem>()
977-
}
978-
})
958+
Results = fullSingleResults,
979959
};
980960
}
981961
else
@@ -998,15 +978,15 @@ internal void PopulateAutoComplete()
998978
return;
999979
}
1000980

1001-
FullSingleResults = fullSingleResults ?? FullSingleResults;
1002981
FullResults = fullResults ?? FullResults;
1003982

1004983
IEnumerable<DNADropdownViewModel> comboboxResults;
1005984
if (IsSingleAutocomplete || !IsDisplayingMLRecommendation)
1006985
{
986+
var singleResults = FullResults.Results as List<SingleResultItem>;
1007987
//getting bitmaps from resources necessarily has to be done in the UI thread
1008988
Dictionary<string, ImageSource> dict = [];
1009-
foreach (var singleResult in FullSingleResults)
989+
foreach (var singleResult in singleResults)
1010990
{
1011991
if (dict.ContainsKey(singleResult.CreationName))
1012992
{
@@ -1016,18 +996,20 @@ internal void PopulateAutoComplete()
1016996
SearchViewModelRequestBitmapSource(iconRequest);
1017997
dict[singleResult.CreationName] = iconRequest.Icon;
1018998
}
1019-
comboboxResults = FullSingleResults.Where(x => x.Score * 100 > minClusterConfidenceScore).Select(x => new DNADropdownViewModel
999+
comboboxResults = QualifiedResults.Select(x => new DNADropdownViewModel
10201000
{
10211001
Description = x.Description,
1022-
Parameters = x.Parameters,
1023-
SmallIcon = dict[x.CreationName],
1002+
Parameters = (x as SingleResultItem).Parameters,
1003+
SmallIcon = dict[(x as SingleResultItem).CreationName],
1004+
ClusterResultItem = x
10241005
});
10251006
}
10261007
else
10271008
{
10281009
comboboxResults = QualifiedResults.Select(x => new DNADropdownViewModel
10291010
{
1030-
Description = x.Description
1011+
Description = x.Description,
1012+
ClusterResultItem = x
10311013
//default icon (cluster) is set in the xaml view
10321014
});
10331015
}
Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1+
using System;
2+
using System.Collections.Generic;
13
using Dynamo.Search.SearchElements;
2-
using Dynamo.Wpf.ViewModels;
34

45
namespace Dynamo.NodeAutoComplete.ViewModels
56
{
6-
internal class SingleResultItem
7+
internal class SingleResultItem : ClusterResultItem
78
{
89

910
public SingleResultItem(NodeSearchElement model, double score = 1.0)
@@ -13,28 +14,26 @@ public SingleResultItem(NodeSearchElement model, double score = 1.0)
1314
Description = model.Name;
1415
Parameters = model.Parameters;
1516
CreationName = model.CreationName;
16-
PortToConnect = model.AutoCompletionNodeElementInfo.PortToConnect;
17-
Score = score;
18-
}
19-
20-
public SingleResultItem(NodeSearchElementViewModel x) : this(x.Model)
21-
{
22-
//Convert percent to probability
23-
Score = x.AutoCompletionNodeMachineLearningInfo.ConfidenceScore / 100.0;
17+
Probability = score;
18+
Title = Description;
19+
EntryNodeIndex = 0;
20+
EntryNodeInPort = model.AutoCompletionNodeElementInfo.PortToConnect;
21+
EntryNodeOutPort = model.AutoCompletionNodeElementInfo.PortToConnect;
22+
Topology = new TopologyItem
23+
{
24+
Nodes = new List<NodeItem> { new NodeItem {
25+
Id = Guid.NewGuid().ToString(),
26+
Type = new NodeType { Id = CreationName } } },
27+
Connections = new List<ConnectionItem>()
28+
};
2429
}
2530

2631
internal string Assembly { get; set; }
2732

2833
internal string IconName { get; set; }
2934

30-
internal string Description { get; set; }
31-
3235
internal string Parameters { get; set; }
3336

3437
internal string CreationName { get; set; }
35-
36-
internal int PortToConnect { get; set; }
37-
38-
internal double Score { get; set; }
3938
}
4039
}

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)