Search in sources :

Example 1 with NodeTripleProvider

use of org.knime.workbench.workflowcoach.data.NodeTripleProvider in project knime-core by knime.

the class NodeRecommendationManager method loadRecommendations.

/**
 * (Re-)Loads the recommendations for the node recommendation engine from the currently active node triple providers.
 *
 * @throws Exception if something went wrong while loading the statistics (e.g. a corrupt file)
 * @see #getNodeTripleProviders()
 */
public void loadRecommendations() throws Exception {
    // read from multiple frequency sources
    List<NodeTripleProvider> providers = getNodeTripleProviders();
    List<Map<String, List<NodeRecommendation>>> recommendations = new ArrayList<>(providers.size());
    for (NodeTripleProvider provider : providers) {
        if (provider.isEnabled() && !updateRequired(provider)) {
            Map<String, List<NodeRecommendation>> recommendationMap = new HashMap<>();
            recommendations.add(recommendationMap);
            provider.getNodeTriples().forEach(nf -> fillRecommendationsMap(recommendationMap, nf));
            // aggregate multiple occurring id's
            // but apply a different aggregation method to source nodes
            BiConsumer<NodeRecommendation, NodeRecommendation> avgAggr = (np1, np2) -> {
                np1.increaseFrequency(np2.getFrequency(), 1);
            };
            BiConsumer<NodeRecommendation, NodeRecommendation> sumAggr = (np1, np2) -> {
                np1.increaseFrequency(np2.getFrequency(), 0);
            };
            recommendationMap.keySet().stream().forEach(s -> {
                if (s.equals(SOURCE_NODES_KEY)) {
                    aggregate(recommendationMap.get(s), sumAggr);
                } else {
                    aggregate(recommendationMap.get(s), avgAggr);
                }
            });
        }
    }
    // end for
    m_recommendations = recommendations;
    m_listeners.stream().forEach(l -> l.updated());
}
Also used : NativeNodeContainer(org.knime.core.node.workflow.NativeNodeContainer) NodeType(org.knime.core.node.NodeFactory.NodeType) NodeTripleProvider(org.knime.workbench.workflowcoach.data.NodeTripleProvider) HashMap(java.util.HashMap) CoreException(org.eclipse.core.runtime.CoreException) NodeTripleProviderFactory(org.knime.workbench.workflowcoach.data.NodeTripleProviderFactory) ConnectionType(org.knime.core.node.workflow.ConnectionContainer.ConnectionType) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) NodeContainer(org.knime.core.node.workflow.NodeContainer) UpdatableNodeTripleProvider(org.knime.workbench.workflowcoach.data.UpdatableNodeTripleProvider) NodeLogger(org.knime.core.node.NodeLogger) Map(java.util.Map) IConfigurationElement(org.eclipse.core.runtime.IConfigurationElement) BiConsumer(java.util.function.BiConsumer) IExtensionPoint(org.eclipse.core.runtime.IExtensionPoint) IExtension(org.eclipse.core.runtime.IExtension) IPreferenceChangeListener(org.eclipse.core.runtime.preferences.IEclipsePreferences.IPreferenceChangeListener) NodeTriple(org.knime.core.node.NodeTriple) Set(java.util.Set) Collectors(java.util.stream.Collectors) WorkflowCoachPreferenceInitializer(org.knime.workbench.workflowcoach.prefs.WorkflowCoachPreferenceInitializer) RepositoryManager(org.knime.workbench.repository.RepositoryManager) NodeInfo(org.knime.core.node.NodeInfo) Objects(java.util.Objects) DefaultScope(org.eclipse.core.runtime.preferences.DefaultScope) ConnectionContainer(org.knime.core.node.workflow.ConnectionContainer) List(java.util.List) NodeTemplate(org.knime.workbench.repository.model.NodeTemplate) InstanceScope(org.eclipse.core.runtime.preferences.InstanceScope) Platform(org.eclipse.core.runtime.Platform) Collections(java.util.Collections) HashMap(java.util.HashMap) NodeTripleProvider(org.knime.workbench.workflowcoach.data.NodeTripleProvider) UpdatableNodeTripleProvider(org.knime.workbench.workflowcoach.data.UpdatableNodeTripleProvider) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map)

Example 2 with NodeTripleProvider

use of org.knime.workbench.workflowcoach.data.NodeTripleProvider in project knime-core by knime.

the class WorkflowCoachPreferencePage method performOk.

/**
 * {@inheritDoc}
 */
@Override
public boolean performOk() {
    IPreferenceStore prefStore = getPreferenceStore();
    List<NodeTripleProvider> providers = NodeRecommendationManager.getInstance().getNodeTripleProviders();
    // check whether the selected providers need an update
    for (NodeTripleProvider ntp : providers) {
        if (ntp instanceof CommunityTripleProvider) {
            if (m_checkCommunityProvider.getSelection() && ((CommunityTripleProvider) ntp).updateRequired()) {
                setErrorMessage("Please update the community node usage statistics.");
            }
        }
    }
    if (m_checkCommunityProvider.getSelection()) {
        // make sure that the user statistics are sent when the community node recommendation is used
        KNIMECorePlugin.getDefault().getPreferenceStore().setValue(HeadlessPreferencesConstants.P_SEND_ANONYMOUS_STATISTICS, true);
    }
    // store values
    prefStore.setValue(WorkflowCoachPreferenceInitializer.P_COMMUNITY_NODE_TRIPLE_PROVIDER, m_checkCommunityProvider.getSelection());
    if (m_noAutoUpdateButton.getSelection()) {
        prefStore.setValue(WorkflowCoachPreferenceInitializer.P_AUTO_UPDATE_SCHEDULE, WorkflowCoachPreferenceInitializer.NO_AUTO_UPDATE);
    } else if (m_weeklyUpdateButton.getSelection()) {
        prefStore.setValue(WorkflowCoachPreferenceInitializer.P_AUTO_UPDATE_SCHEDULE, WorkflowCoachPreferenceInitializer.WEEKLY_UPDATE);
    } else if (m_monthlyUpdateButton.getSelection()) {
        prefStore.setValue(WorkflowCoachPreferenceInitializer.P_AUTO_UPDATE_SCHEDULE, WorkflowCoachPreferenceInitializer.MONTHLY_UPDATE);
    }
    return true;
}
Also used : CommunityTripleProvider(org.knime.workbench.workflowcoach.data.CommunityTripleProvider) NodeTripleProvider(org.knime.workbench.workflowcoach.data.NodeTripleProvider) UpdatableNodeTripleProvider(org.knime.workbench.workflowcoach.data.UpdatableNodeTripleProvider) IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore)

Example 3 with NodeTripleProvider

use of org.knime.workbench.workflowcoach.data.NodeTripleProvider in project knime-core by knime.

the class WorkflowCoachPreferencePage method onUpate.

/**
 * Called when the update button has been pressed.
 */
private void onUpate() {
    Display.getDefault().syncExec(() -> {
        m_updateButton.setEnabled(false);
        m_lastUpdate.setText("Updating ...");
        m_lastUpdate.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_BLACK));
        setValid(false);
    });
    // update the currently enabled providers
    List<UpdatableNodeTripleProvider> toUpdate = new ArrayList<>();
    for (NodeTripleProvider ntp : NodeRecommendationManager.getInstance().getNodeTripleProviders()) {
        if (m_checkCommunityProvider.getSelection() && (ntp instanceof CommunityTripleProvider)) {
            toUpdate.add((CommunityTripleProvider) ntp);
        }
    }
    UpdateJob.schedule(e -> {
        if (e.isPresent()) {
            Display.getDefault().syncExec(() -> {
                m_updateButton.setEnabled(true);
                m_lastUpdate.setText("Update failed.");
                setErrorMessage("Error loading the community node recommendations:" + e.get().getMessage() + ". Please check your internet connection.");
                if (!m_checkCommunityProvider.getSelection()) {
                    setValid(true);
                }
            });
        } else {
            Display.getDefault().syncExec(() -> {
                m_updateButton.setEnabled(true);
                m_lastUpdate.setText("Update finished!");
                setValid(true);
                setErrorMessage(null);
            });
        }
    }, toUpdate, false);
}
Also used : CommunityTripleProvider(org.knime.workbench.workflowcoach.data.CommunityTripleProvider) UpdatableNodeTripleProvider(org.knime.workbench.workflowcoach.data.UpdatableNodeTripleProvider) ArrayList(java.util.ArrayList) NodeTripleProvider(org.knime.workbench.workflowcoach.data.NodeTripleProvider) UpdatableNodeTripleProvider(org.knime.workbench.workflowcoach.data.UpdatableNodeTripleProvider)

Aggregations

NodeTripleProvider (org.knime.workbench.workflowcoach.data.NodeTripleProvider)3 UpdatableNodeTripleProvider (org.knime.workbench.workflowcoach.data.UpdatableNodeTripleProvider)3 ArrayList (java.util.ArrayList)2 CommunityTripleProvider (org.knime.workbench.workflowcoach.data.CommunityTripleProvider)2 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Map (java.util.Map)1 Objects (java.util.Objects)1 Set (java.util.Set)1 BiConsumer (java.util.function.BiConsumer)1 Collectors (java.util.stream.Collectors)1 CoreException (org.eclipse.core.runtime.CoreException)1 IConfigurationElement (org.eclipse.core.runtime.IConfigurationElement)1 IExtension (org.eclipse.core.runtime.IExtension)1 IExtensionPoint (org.eclipse.core.runtime.IExtensionPoint)1 Platform (org.eclipse.core.runtime.Platform)1 DefaultScope (org.eclipse.core.runtime.preferences.DefaultScope)1 IPreferenceChangeListener (org.eclipse.core.runtime.preferences.IEclipsePreferences.IPreferenceChangeListener)1