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());
}
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;
}
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);
}
Aggregations