From b98b3d7f7050909406d62b8817e93ccf99fc5589 Mon Sep 17 00:00:00 2001 From: jesusalvino <96534278+jesusalvino@users.noreply.github.com> Date: Wed, 23 Nov 2022 18:47:53 -0500 Subject: [PATCH] Dyn 5427 confidence threshold autocomplete ml (#13562) * Hide Nodes * Update UI with Expander * Node Autocomplete Section Done * Set default number of results as 10 * restoring version * restoring entire file * Connect the confidence level and nuber of result settings * Fix * Labels * Naming changes * Updating the Settings properties for copy test --- .../Configuration/PreferenceSettings.cs | 18 +++ .../NodeAutoCompleteSearchControl.xaml | 2 +- .../Properties/Resources.Designer.cs | 62 ++++++-- .../Properties/Resources.en-US.resx | 25 ++- src/DynamoCoreWpf/Properties/Resources.resx | 25 ++- .../ViewModels/Menu/PreferencesViewModel.cs | 149 ++++++++++++++---- .../Search/NodeAutoCompleteSearchViewModel.cs | 7 +- .../Views/Menu/PreferencesView.xaml | 143 ++++++++++++++--- .../Views/Menu/PreferencesView.xaml.cs | 39 +++++ test/settings/DynamoSettings-NewSettings.xml | 3 + 10 files changed, 382 insertions(+), 91 deletions(-) diff --git a/src/DynamoCore/Configuration/PreferenceSettings.cs b/src/DynamoCore/Configuration/PreferenceSettings.cs index d643381379f..0db5ad20c50 100644 --- a/src/DynamoCore/Configuration/PreferenceSettings.cs +++ b/src/DynamoCore/Configuration/PreferenceSettings.cs @@ -497,6 +497,21 @@ public string PythonTemplateFilePath /// public bool EnableNodeAutoComplete { get; set; } + /// + /// This defines if user wants to hide the nodes below a specific confidenc level. + /// + public bool HideNodesBelowSpecificConfidenceLevel { get; set; } + + /// + /// This defines the level of confidence related to the ML recommendation. + /// + public int MLRecommendationConfidenceLevel { get; set; } + + /// + /// This defines the number of results of the ML recommendation + /// + public int MLRecommendationNumberOfResults { get; set; } + /// /// This defines if user wants to see the enabled Dynamo Notification Center. /// @@ -736,6 +751,9 @@ public PreferenceSettings() IsIronPythonDialogDisabled = false; ShowTabsAndSpacesInScriptEditor = false; EnableNodeAutoComplete = true; + HideNodesBelowSpecificConfidenceLevel = false; + MLRecommendationConfidenceLevel = 10; + MLRecommendationNumberOfResults = 10; EnableNotificationCenter = true; isStaticSplashScreenEnabled = true; DefaultPythonEngine = string.Empty; diff --git a/src/DynamoCoreWpf/Controls/NodeAutoCompleteSearchControl.xaml b/src/DynamoCoreWpf/Controls/NodeAutoCompleteSearchControl.xaml index ddda2794b65..a6565988f5d 100644 --- a/src/DynamoCoreWpf/Controls/NodeAutoCompleteSearchControl.xaml +++ b/src/DynamoCoreWpf/Controls/NodeAutoCompleteSearchControl.xaml @@ -330,7 +330,7 @@ - // This code was generated by a tool. // Runtime Version:4.0.30319.42000 @@ -3371,6 +3371,24 @@ public static string HideClassicNodeLibrary { } } + /// + /// Looks up a localized string similar to Hide nodes below a specified confidence level. + /// + public static string HideNodesBelowSpecificConfidenceLevel { + get { + return ResourceManager.GetString("HideNodesBelowSpecificConfidenceLevel", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Confidence level appears next to each recommended node and represents estimated probability that the node is a good choice. When toggled on, this setting hides recommended nodes that don’t meet the specified confidence level. You can click the Low Confidence header to show the nodes.. + /// + public static string HideNodesBelowSpecificConfidenceLevelInfo { + get { + return ResourceManager.GetString("HideNodesBelowSpecificConfidenceLevelInfo", resourceCulture); + } + } + /// /// Looks up a localized string similar to Hide Wires. /// @@ -3884,15 +3902,6 @@ public static string LogoutMenuItemText { } } - /// - /// Looks up a localized string similar to ML Recommendation. - /// - public static string MachineLearning { - get { - return ResourceManager.GetString("MachineLearning", resourceCulture); - } - } - /// /// Looks up a localized string similar to You must provide a Major version as a non-negative integer.. /// @@ -4495,6 +4504,15 @@ public static string MinorVersionNonNegative { } } + /// + /// Looks up a localized string similar to Numbers of results. + /// + public static string MLRecommendationNumberOfResults { + get { + return ResourceManager.GetString("MLRecommendationNumberOfResults", resourceCulture); + } + } + /// /// Looks up a localized string similar to More. /// @@ -4838,7 +4856,7 @@ public static string NullString { } /// - /// Looks up a localized string similar to Object type. + /// Looks up a localized string similar to Node Type Match. /// public static string ObjectType { get { @@ -6401,7 +6419,7 @@ public static string PortViewContextMenuUserDefaultValue { } /// - /// Looks up a localized string similar to Default method. + /// Looks up a localized string similar to Default Ranking Method. /// public static string PreferencesNodeAutocompleteMethod { get { @@ -6531,7 +6549,7 @@ public static string PreferencesViewEmptyStyleWarning { } /// - /// Looks up a localized string similar to Node Autocomplete. + /// Looks up a localized string similar to Enable Node Autocomplete. /// public static string PreferencesViewEnableNodeAutoComplete { get { @@ -6629,6 +6647,15 @@ public static string PreferencesViewMarkdownDirectoryTooltip { } } + /// + /// Looks up a localized string similar to Node Autocomplete. + /// + public static string PreferencesViewNodeAutocomplete { + get { + return ResourceManager.GetString("PreferencesViewNodeAutocomplete", resourceCulture); + } + } + /// /// Looks up a localized string similar to Notification Center. /// @@ -7569,6 +7596,15 @@ public static string RecentFileNumberInfo { } } + /// + /// Looks up a localized string similar to Recommended Nodes. + /// + public static string RecommendedNodes { + get { + return ResourceManager.GetString("RecommendedNodes", resourceCulture); + } + } + /// /// Looks up a localized string similar to Please check if you intended to render this amount of geometry, and consider turning off the preview of other nodes within your graph, lowering the amount of Geometry you wish to render, or turning down the render precision.. /// diff --git a/src/DynamoCoreWpf/Properties/Resources.en-US.resx b/src/DynamoCoreWpf/Properties/Resources.en-US.resx index 76e7e4666f3..8c9835aeca5 100644 --- a/src/DynamoCoreWpf/Properties/Resources.en-US.resx +++ b/src/DynamoCoreWpf/Properties/Resources.en-US.resx @@ -2262,7 +2262,7 @@ Uninstall the following packages: {0}? Preferences | Features | Python | Default Python Engine - Node Autocomplete + Enable Node Autocomplete Preferences | Features | Experimental | Enable Node Auto Complete @@ -2321,15 +2321,15 @@ Uninstall the following packages: {0}? Label used in the general tab - Default method + Default Ranking Method Label used in the features tab - Object type + Node Type Match Label used in the features tab - - ML Recommendation + + Recommended Nodes Label used in the features tab @@ -3316,6 +3316,19 @@ You can manage this in Preferences -> Security. You can import custom settings here, which will overwrite your current settings. If you'd like to preserve a copy of your current settings, export them before importing new settings. Settings not shown in the Preferences panel will be applied once Dynamo and any host program restarts. Import Preferences Info. + + Node Autocomplete + Preferences | Features | Node Autocomplete + + + Hide nodes below a specified confidence level + + + Confidence level appears next to each recommended node and represents estimated probability that the node is a good choice. When toggled on, this setting hides recommended nodes that don’t meet the specified confidence level. You can click the Low Confidence header to show the nodes. + + + Numbers of results + Import Import Preferences Text. @@ -3472,4 +3485,4 @@ In certain complex graphs or host program scenarios, Automatic mode may cause in When toggled on, a preview of the node’s output will be displayed when hovering over the bottom of a node. - \ No newline at end of file + diff --git a/src/DynamoCoreWpf/Properties/Resources.resx b/src/DynamoCoreWpf/Properties/Resources.resx index 6d16126aa32..996dedc4dcf 100644 --- a/src/DynamoCoreWpf/Properties/Resources.resx +++ b/src/DynamoCoreWpf/Properties/Resources.resx @@ -2482,7 +2482,7 @@ Uninstall the following packages: {0}? Preferences | Features | Python | Default Python Engine - Node Autocomplete + Enable Node Autocomplete Preferences | Features | Experimental | Enable Node Auto Complete @@ -2537,15 +2537,15 @@ Uninstall the following packages: {0}? Label used in the general tab - Default method + Default Ranking Method Label used in the features tab - Object type + Node Type Match Label used in the features tab - - ML Recommendation + + Recommended Nodes Label used in the features tab @@ -3303,6 +3303,19 @@ You can manage this in Preferences -> Security. You can import custom settings here, which will overwrite your current settings. If you'd like to preserve a copy of your current settings, export them before importing new settings. Settings not shown in the Preferences panel will be applied once Dynamo and any host program restarts. Import Preferences Info. + + Node Autocomplete + Preferences | Features | Node Autocomplete + + + Hide nodes below a specified confidence level + + + Confidence level appears next to each recommended node and represents estimated probability that the node is a good choice. When toggled on, this setting hides recommended nodes that don’t meet the specified confidence level. You can click the Low Confidence header to show the nodes. + + + Numbers of results + Import Import Preferences Text. @@ -3459,4 +3472,4 @@ In certain complex graphs or host program scenarios, Automatic mode may cause in When toggled on, a preview of the node’s output will be displayed when hovering over the bottom of a node. - \ No newline at end of file + diff --git a/src/DynamoCoreWpf/ViewModels/Menu/PreferencesViewModel.cs b/src/DynamoCoreWpf/ViewModels/Menu/PreferencesViewModel.cs index 34fc57d7c65..679ed98bdac 100644 --- a/src/DynamoCoreWpf/ViewModels/Menu/PreferencesViewModel.cs +++ b/src/DynamoCoreWpf/ViewModels/Menu/PreferencesViewModel.cs @@ -255,33 +255,7 @@ public bool RunSettingsIsChecked } RaisePropertyChanged(nameof(RunSettingsIsChecked)); } - } - - /// - /// Controls if the the Node autocomplete Machine Learning option is checked for the radio buttons - /// - public bool NodeAutocompleteMachineLearningIsChecked - { - get - { - return preferenceSettings.DefaultNodeAutocompleteSuggestion == NodeAutocompleteSuggestion.MLRecommendation; - } - set - { - if (value) - { - preferenceSettings.DefaultNodeAutocompleteSuggestion = NodeAutocompleteSuggestion.MLRecommendation; - nodeAutocompleteSuggestion = NodeAutocompleteSuggestion.MLRecommendation; - } - else - { - preferenceSettings.DefaultNodeAutocompleteSuggestion = NodeAutocompleteSuggestion.ObjectType; - nodeAutocompleteSuggestion = NodeAutocompleteSuggestion.ObjectType; - } - dynamoViewModel.HomeSpaceViewModel.NodeAutoCompleteSearchViewModel.PopulateAutoCompleteCandidates(); - RaisePropertyChanged(nameof(nodeAutocompleteSuggestion)); - } - } + } /// /// Controls the IsChecked property in the Show Run Preview toogle button @@ -530,9 +504,7 @@ public void AddStyle(StyleItem style) }); RaisePropertyChanged(nameof(StyleItemsList)); } - - - + /// /// This flag will be in true when the Style that user is trying to add already exists (otherwise will be false - Default) /// @@ -837,6 +809,24 @@ public bool ShowWhitespaceIsChecked } } + /// + /// Controls the IsChecked property in the "Notification Center" toogle button + /// + public bool NotificationCenterIsChecked + { + get + { + return preferenceSettings.EnableNotificationCenter; + } + set + { + preferenceSettings.EnableNotificationCenter = value; + RaisePropertyChanged(nameof(NotificationCenterIsChecked)); + } + } + + #region [ Node Autocomplete ] + /// /// Controls the IsChecked property in the "Node autocomplete" toogle button /// @@ -850,25 +840,114 @@ public bool NodeAutocompleteIsChecked { preferenceSettings.EnableNodeAutoComplete = value; RaisePropertyChanged(nameof(NodeAutocompleteIsChecked)); + RaisePropertyChanged(nameof(EnableHideNodesToggle)); + RaisePropertyChanged(nameof(EnableConfidenceLevelSlider)); } } /// - /// Controls the IsChecked property in the "Notification Center" toogle button + /// Controls if the the Node autocomplete Machine Learning option is checked for the radio buttons /// - public bool NotificationCenterIsChecked + public bool NodeAutocompleteMachineLearningIsChecked { get { - return preferenceSettings.EnableNotificationCenter; + return preferenceSettings.DefaultNodeAutocompleteSuggestion == NodeAutocompleteSuggestion.MLRecommendation; } set { - preferenceSettings.EnableNotificationCenter = value; - RaisePropertyChanged(nameof(NotificationCenterIsChecked)); + if (value) + { + preferenceSettings.DefaultNodeAutocompleteSuggestion = NodeAutocompleteSuggestion.MLRecommendation; + nodeAutocompleteSuggestion = NodeAutocompleteSuggestion.MLRecommendation; + } + else + { + preferenceSettings.DefaultNodeAutocompleteSuggestion = NodeAutocompleteSuggestion.ObjectType; + nodeAutocompleteSuggestion = NodeAutocompleteSuggestion.ObjectType; + } + + dynamoViewModel.HomeSpaceViewModel.NodeAutoCompleteSearchViewModel.ResetAutoCompleteSearchViewState(); + RaisePropertyChanged(nameof(nodeAutocompleteSuggestion)); + RaisePropertyChanged(nameof(NodeAutocompleteMachineLearningIsChecked)); + RaisePropertyChanged(nameof(EnableHideNodesToggle)); + RaisePropertyChanged(nameof(EnableConfidenceLevelSlider)); } } + /// + /// Contains the numbers of result of the ML recommendation + /// + public int MLRecommendationNumberOfResults + { + get + { + return preferenceSettings.MLRecommendationNumberOfResults; + } + set + { + preferenceSettings.MLRecommendationNumberOfResults = value; + RaisePropertyChanged(nameof(MLRecommendationNumberOfResults)); + } + } + + /// + /// Controls the IsChecked property in the "Hide nodes below a specific confidence level" toogle button + /// + public bool HideNodesBelowSpecificConfidenceLevelIsChecked + { + get + { + return preferenceSettings.HideNodesBelowSpecificConfidenceLevel; + } + set + { + preferenceSettings.HideNodesBelowSpecificConfidenceLevel = value; + RaisePropertyChanged(nameof(HideNodesBelowSpecificConfidenceLevelIsChecked)); + RaisePropertyChanged(nameof(EnableConfidenceLevelSlider)); + } + } + + /// + /// Contains the confidence level of a ML recommendation + /// + public int MLRecommendationConfidenceLevel + { + get + { + return preferenceSettings.MLRecommendationConfidenceLevel; + } + set + { + preferenceSettings.MLRecommendationConfidenceLevel = value; + RaisePropertyChanged(nameof(MLRecommendationConfidenceLevel)); + } + } + + /// + /// If the user can click on the Hide Nodes toggle + /// + public bool EnableHideNodesToggle + { + get + { + return NodeAutocompleteIsChecked && NodeAutocompleteMachineLearningIsChecked; + } + } + + /// + /// If the user can click on the confidence level Slider + /// + public bool EnableConfidenceLevelSlider + { + get + { + return NodeAutocompleteIsChecked && NodeAutocompleteMachineLearningIsChecked && HideNodesBelowSpecificConfidenceLevelIsChecked; + } + } + + #endregion + /// /// Controls the IsChecked property in the "Enable T-spline nodes" toogle button /// diff --git a/src/DynamoCoreWpf/ViewModels/Search/NodeAutoCompleteSearchViewModel.cs b/src/DynamoCoreWpf/ViewModels/Search/NodeAutoCompleteSearchViewModel.cs index 2ed8d4acbcf..724c84cd725 100644 --- a/src/DynamoCoreWpf/ViewModels/Search/NodeAutoCompleteSearchViewModel.cs +++ b/src/DynamoCoreWpf/ViewModels/Search/NodeAutoCompleteSearchViewModel.cs @@ -35,9 +35,6 @@ public class NodeAutoCompleteSearchViewModel : SearchViewModel private bool displayAutocompleteMLStaticPage; private bool displayLowConfidence; private const string nodeAutocompleteMLEndpoint = "MLNodeAutocomplete"; - private double confidenceThresholdPercentage = 10; - private int numberOfResults = 10; - /// /// Cache of default node suggestions, use it in case where @@ -153,7 +150,7 @@ private void InitializeDefaultAutoCompleteCandidates() internal MLNodeAutoCompletionRequest GenerateRequestForMLAutocomplete() { // Intialize request for the the ML API - MLNodeAutoCompletionRequest request = new MLNodeAutoCompletionRequest(AssemblyHelper.GetDynamoVersion().ToString(), numberOfResults); + MLNodeAutoCompletionRequest request = new MLNodeAutoCompletionRequest(AssemblyHelper.GetDynamoVersion().ToString(), dynamoViewModel.PreferenceSettings.MLRecommendationNumberOfResults); var nodeInfo = PortViewModel.PortModel.Owner; var portInfo = PortViewModel.PortModel; @@ -355,7 +352,7 @@ internal void DisplayMachineLearningResults() foreach (var result in results) { - if (result.AutoCompletionNodeMachineLearningInfo.ConfidenceScore >= confidenceThresholdPercentage) + if (result.AutoCompletionNodeMachineLearningInfo.ConfidenceScore >= dynamoViewModel.PreferenceSettings.MLRecommendationConfidenceLevel) { FilteredHighConfidenceResults = FilteredHighConfidenceResults.Append(result); } diff --git a/src/DynamoCoreWpf/Views/Menu/PreferencesView.xaml b/src/DynamoCoreWpf/Views/Menu/PreferencesView.xaml index 80a2f94b09d..b1c90119cf6 100644 --- a/src/DynamoCoreWpf/Views/Menu/PreferencesView.xaml +++ b/src/DynamoCoreWpf/Views/Menu/PreferencesView.xaml @@ -546,6 +546,7 @@ + @@ -701,18 +702,17 @@ - - - + + Header="{x:Static p:Resources.PreferencesViewNodeAutocomplete}"> - @@ -722,36 +722,35 @@ VerticalAlignment="Center" IsChecked="{Binding Path=NodeAutocompleteIsChecked}" Style="{StaticResource EllipseToggleButton1}"/> - - + + + + + + + + + + + - + = (i * 10) + 1 && confidenceLevel <= (i + 1) * 10) + { + break; + } + } + } + return value; + } + + private void sliderConfidenceLevel_ValueChanged(object sender, RoutedPropertyChangedEventArgs e) + { + displayConfidenceLevel(); + } + + private void displayConfidenceLevel() + { + if (this.lblConfidenceLevel != null && this.lblConfidenceLevelLabelStart != null) + { + int confidenceLevel = (int)lblConfidenceLevel.Content; + + int left = ((int)lblConfidenceLevel.Content * 3) + getExtraLeftSpace(confidenceLevel); + this.lblConfidenceLevel.Margin = new Thickness(left, -15, 0, 0); + } + } } } diff --git a/test/settings/DynamoSettings-NewSettings.xml b/test/settings/DynamoSettings-NewSettings.xml index 40b7d904e5a..77f3a929b0e 100644 --- a/test/settings/DynamoSettings-NewSettings.xml +++ b/test/settings/DynamoSettings-NewSettings.xml @@ -62,6 +62,9 @@ true true false + true + 99 + 5 false false