use of org.knime.core.node.config.Config in project knime-core by knime.
the class FixedPieDataModel method save2File.
/**
* @param directory the directory to write to
* @param exec the {@link ExecutionMonitor} to provide progress messages
* @throws IOException if a file exception occurs
* @throws CanceledExecutionException if the operation was canceled
*/
public void save2File(final File directory, final ExecutionMonitor exec) throws IOException, CanceledExecutionException {
if (exec != null) {
exec.setProgress(0.0, "Start saving histogram data model to file");
}
final File dataFile = new File(directory, CFG_DATA_FILE);
final FileOutputStream os = new FileOutputStream(dataFile);
final GZIPOutputStream dataOS = new GZIPOutputStream(os);
final Config config = new NodeSettings(CFG_DATA);
config.addString(CFG_PIE_COL, m_pieCol);
config.addBoolean(CFG_NUMERIC_PIE_COL, m_numericPieCol);
config.addString(CFG_AGGR_COL, m_aggrCol);
config.addBoolean(CFG_HILITING, supportsHiliting());
config.addBoolean(CFG_DETAILS, detailsAvailable());
config.addBoolean(CFG_IS_COLOR_COLUMN, m_isColorColumn);
if (exec != null) {
exec.setProgress(0.3, "Start saving sections...");
exec.checkCanceled();
}
final Config sectionsConf = config.addConfig(CFG_SECTIONS);
sectionsConf.addInt(CFG_SECTION_COUNT, m_sections.size());
int idx = 0;
for (final PieSectionDataModel section : m_sections) {
final ConfigWO sectionConf = sectionsConf.addConfig(CFG_SECTION + idx++);
section.save2File(sectionConf, exec);
}
if (exec != null) {
exec.setProgress(0.8, "Start saving missing section...");
exec.checkCanceled();
}
final ConfigWO missingSection = sectionsConf.addConfig(CFG_MISSING_SECTION);
m_missingSection.save2File(missingSection, exec);
config.saveToXML(dataOS);
dataOS.flush();
dataOS.close();
os.flush();
os.close();
if (exec != null) {
exec.setProgress(1.0, "Pie data model saved");
}
}
use of org.knime.core.node.config.Config in project knime-core by knime.
the class BoxPlotNodeModel method loadOutliersNew.
private void loadOutliersNew(final NodeSettingsRO columnSubConfig, final DataColumnSpec spec) throws InvalidSettingsException {
double[] mild = columnSubConfig.getDoubleArray(CFG_MILD + spec.getName());
Config mildOutlierSubConfig = columnSubConfig.getConfig(CFG_MILD + CFG_ROW + spec.getName());
Map<Double, Set<RowKey>> mildOutliers = new LinkedHashMap<Double, Set<RowKey>>();
for (int j = 0; j < mild.length; j++) {
// this is for backward compatibility
// good old times where RowID was a DataCell
String[] mildKeys;
try {
mildKeys = mildOutlierSubConfig.getStringArray(CFG_MILD + CFG_ROW + spec.getName() + j);
} catch (InvalidSettingsException e) {
// ok, try to load old data cells
// if this is also not found the ISE is ok
DataCell[] mildKeysOld = mildOutlierSubConfig.getDataCellArray(CFG_MILD + CFG_ROW + spec.getName() + j);
mildKeys = new String[mildKeysOld.length];
for (int i = 0; i < mildKeysOld.length; i++) {
mildKeys[i] = mildKeysOld[i].toString();
}
}
Set<RowKey> keys = new HashSet<RowKey>();
for (int rk = 0; rk < mildKeys.length; rk++) {
keys.add(new RowKey(mildKeys[rk]));
}
mildOutliers.put(mild[j], keys);
}
m_mildOutliers.put(spec.getName(), mildOutliers);
// extreme
Map<Double, Set<RowKey>> extremeOutliers = new LinkedHashMap<Double, Set<RowKey>>();
double[] extreme = columnSubConfig.getDoubleArray(CFG_EXTREME + spec.getName());
Config extrOutlierSubConfig = columnSubConfig.getConfig(CFG_EXTREME + CFG_ROW + spec.getName());
for (int j = 0; j < extreme.length; j++) {
// this is for backward compatibility
// good old times where RowID was a DataCell
String[] extremeKeys;
try {
extremeKeys = extrOutlierSubConfig.getStringArray(CFG_EXTREME + CFG_ROW + spec.getName() + j);
} catch (InvalidSettingsException ise) {
// ok, old data cells
DataCell[] extremeKeysOld = extrOutlierSubConfig.getDataCellArray(CFG_EXTREME + CFG_ROW + spec.getName() + j);
extremeKeys = new String[extremeKeysOld.length];
for (int i = 0; i < extremeKeysOld.length; i++) {
extremeKeys[i] = extremeKeysOld[i].toString();
}
}
Set<RowKey> keys = new HashSet<RowKey>();
for (int rk = 0; rk < extremeKeys.length; rk++) {
keys.add(new RowKey(extremeKeys[rk]));
}
extremeOutliers.put(extreme[j], keys);
}
m_extremeOutliers.put(spec.getName(), extremeOutliers);
}
use of org.knime.core.node.config.Config in project knime-core by knime.
the class SettingsModelColorNameColumns method loadColorColumns.
private static ColorColumn[] loadColorColumns(final String configName, final NodeSettingsRO settings) {
try {
final Config config = settings.getConfig(configName);
final String[] columnNames = config.getStringArray(CFG_COLOR_COLUMN_NAMES);
if (columnNames == null) {
return null;
}
final ColorColumn[] columns = new ColorColumn[columnNames.length];
for (int i = 0, length = columnNames.length; i < length; i++) {
final String columnName = columnNames[i];
final int rgb = config.getInt(columnName);
columns[i] = new ColorColumn(new Color(rgb), columnName);
}
return columns;
} catch (Exception e) {
return null;
}
}
use of org.knime.core.node.config.Config in project knime-core by knime.
the class PieSectionDataModel method loadElements.
/**
* {@inheritDoc}
*/
@Override
protected Collection<PieSubSectionDataModel> loadElements(final ConfigRO config, final ExecutionMonitor exec) throws CanceledExecutionException, InvalidSettingsException {
final int counter = config.getInt(CFG_ELEMENT_COUNT);
final Collection<PieSubSectionDataModel> elements = new ArrayList<PieSubSectionDataModel>(counter);
for (int i = 0; i < counter; i++) {
final Config binConf = config.getConfig(CFG_SECTION_ELEMENT + i);
elements.add(PieSubSectionDataModel.loadFromFile(binConf, exec));
}
exec.checkCanceled();
return elements;
}
use of org.knime.core.node.config.Config in project knime-core by knime.
the class PMMLCompoundPredicate method loadFromPredParams.
/**
* {@inheritDoc}
*/
@Override
public void loadFromPredParams(final Config conf) throws InvalidSettingsException {
assert conf.getString(PMMLPredicate.TYPE_KEY).equals(NAME);
try {
m_op = PMMLBooleanOperator.get(conf.getString(PMMLPredicate.OPERATOR_KEY));
} catch (InstantiationException e) {
throw new InvalidSettingsException(e);
}
setSplitAttribute(conf.getString(PMMLPredicate.ATTRIBUTE_KEY));
int numPredicates = conf.getInt(NUM_PREDICATES);
for (int i = 0; i < numPredicates; i++) {
Config pconf = conf.getConfig(PRED + i);
PMMLPredicate pred = PMMLPredicate.getPredicateForConfig(pconf);
m_predicates.add(pred);
}
}
Aggregations