use of org.knime.core.node.config.ConfigRO in project knime-core by knime.
the class FixedPieDataModel method loadFromFile.
/**
* @param directory the directory to write to
* @param exec the {@link ExecutionMonitor} to provide progress messages
* @return the data model
* wasn't valid
* @throws IOException if a file exception occurs
* @throws CanceledExecutionException if the operation was canceled
* @throws InvalidSettingsException if the file is invalid
*/
@SuppressWarnings("unchecked")
public static FixedPieDataModel loadFromFile(final File directory, final ExecutionMonitor exec) throws IOException, CanceledExecutionException, InvalidSettingsException {
if (exec != null) {
exec.setProgress(0.0, "Start reading data from file");
}
final File settingsFile = new File(directory, CFG_DATA_FILE);
final FileInputStream is = new FileInputStream(settingsFile);
final GZIPInputStream inData = new GZIPInputStream(is);
final ConfigRO config = NodeSettings.loadFromXML(inData);
final String pieCol = config.getString(CFG_PIE_COL);
final boolean numericPieCol = config.getBoolean(CFG_NUMERIC_PIE_COL);
final String aggrCol = config.getString(CFG_AGGR_COL);
final boolean supportHiliting = config.getBoolean(CFG_HILITING);
final boolean detailsAvailable = config.getBoolean(CFG_DETAILS);
if (exec != null) {
exec.setProgress(0.3, "Loading sections...");
exec.checkCanceled();
}
final Config sectionsConf = config.getConfig(CFG_SECTIONS);
final int counter = sectionsConf.getInt(CFG_SECTION_COUNT);
final List<PieSectionDataModel> sections = new ArrayList<PieSectionDataModel>(counter);
for (int i = 0; i < counter; i++) {
final Config sectionConf = sectionsConf.getConfig(CFG_SECTION + i);
sections.add(PieSectionDataModel.loadFromFile(sectionConf, exec));
}
if (exec != null) {
exec.setProgress(0.9, "Loading missing section...");
exec.checkCanceled();
}
final Config missingConf = sectionsConf.getConfig(CFG_MISSING_SECTION);
final PieSectionDataModel missingSection = PieSectionDataModel.loadFromFile(missingConf, exec);
final boolean isColorColumn;
if (config.containsKey(CFG_IS_COLOR_COLUMN)) {
isColorColumn = config.getBoolean(CFG_IS_COLOR_COLUMN);
} else {
isColorColumn = false;
// reset the color of all elements
for (final PieSectionDataModel section : sections) {
section.setColor(Color.BLACK);
}
}
if (exec != null) {
exec.setProgress(1.0, "Pie data model loaded ");
}
// close the stream
inData.close();
is.close();
return new FixedPieDataModel(pieCol, numericPieCol, aggrCol, sections, missingSection, supportHiliting, detailsAvailable, isColorColumn);
}
use of org.knime.core.node.config.ConfigRO in project knime-core by knime.
the class DataCellStringMapper method load.
/**
* Reads a {@link DataCellStringMapper} from given {@link ConfigRO}.
*
* @param config to read the mapper from
* @return A new {@link DataCellStringMapper} object.
* @throws InvalidSettingsException If the settings could not be read.
*/
public static DataCellStringMapper load(final ConfigRO config) throws InvalidSettingsException {
HashMap<String, DataCell> tmpstringToCell = new HashMap<String, DataCell>();
HashMap<DataCell, String> tmpcellToString = new HashMap<DataCell, String>();
ConfigRO keyConfig = config.getConfig(CFG_STRINGTOCELL);
for (String key : keyConfig.keySet()) {
DataCell cell = keyConfig.getDataCell(key);
tmpstringToCell.put(key, cell);
tmpcellToString.put(cell, key);
}
HashMap<String, String> tmporigstringToString = new HashMap<String, String>();
HashMap<String, String> tmpstringToOrigstring = new HashMap<String, String>();
keyConfig = config.getConfig(CFG_ORIGSTRINGTOSTRING);
for (String key : keyConfig.keySet()) {
String value = keyConfig.getString(key);
tmporigstringToString.put(key, value);
tmpstringToOrigstring.put(value, key);
}
int tmpuniqueIndex = config.getInt(CFG_UNIQUEINDEX);
return new DataCellStringMapper(tmpcellToString, tmporigstringToString, tmpstringToCell, tmpstringToOrigstring, tmpuniqueIndex);
}
use of org.knime.core.node.config.ConfigRO in project knime-core by knime.
the class BinDataModel method loadFromFile.
/**
* @param config the config object to use
* @param exec the {@link ExecutionMonitor} to provide progress messages
* @return the {@link ColorColumn}
* @throws CanceledExecutionException if the operation is canceled
* @throws InvalidSettingsException if the config object is invalid
*/
public static BinDataModel loadFromFile(final ConfigRO config, final ExecutionMonitor exec) throws CanceledExecutionException, InvalidSettingsException {
final String caption = config.getString(CFG_X_CAPTION);
final Double lowerBound;
final Double upperBound;
if (config.getBoolean(CFG_HAS_BOUNDARIES)) {
lowerBound = new Double(config.getDouble(CFG_LOWER_BOUND));
upperBound = new Double(config.getDouble(CFG_UPPER_BOUND));
} else {
lowerBound = null;
upperBound = null;
}
final ConfigRO barsConf = config.getConfig(CFG_BARS);
final int barCounter = barsConf.getInt(CFG_BAR_COUNTER);
final Map<Color, BarDataModel> bars = new HashMap<Color, BarDataModel>(barCounter);
for (int i = 0; i < barCounter; i++) {
final Config binConf = barsConf.getConfig(CFG_BAR + i);
final BarDataModel bar = BarDataModel.loadFromFile(binConf, exec);
bars.put(bar.getColor(), bar);
}
exec.checkCanceled();
return new BinDataModel(caption, lowerBound, upperBound, bars);
}
use of org.knime.core.node.config.ConfigRO in project knime-core by knime.
the class FixedHistogramDataModel method loadFromFile.
/**
* @param directory the directory to write to
* @param exec the {@link ExecutionMonitor} to provide progress messages; must not be <code>null</code>
* @return the histogram data model
* @throws InvalidSettingsException if the x column specification
* wasn't valid
* @throws IOException if a file exception occurs
* @throws CanceledExecutionException if the operation is canceled
*/
public static FixedHistogramDataModel loadFromFile(final File directory, final ExecutionMonitor exec) throws InvalidSettingsException, IOException, CanceledExecutionException {
exec.setProgress(0.0, "Start reading data from file");
final ConfigRO config;
final FileInputStream is;
final GZIPInputStream inData;
try {
final File settingsFile = new File(directory, CFG_DATA_FILE);
is = new FileInputStream(settingsFile);
inData = new GZIPInputStream(is);
config = NodeSettings.loadFromXML(inData);
} catch (final FileNotFoundException e) {
throw e;
} catch (final IOException e) {
LOGGER.error("Unable to load histogram data: " + e.getMessage());
throw new IOException("Please reexecute the histogram node. " + "(For details see log file)");
}
final Config xConfig = config.getConfig(CFG_X_COL_SPEC);
final DataColumnSpec xColSpec = DataColumnSpec.load(xConfig);
final boolean binNominal = config.getBoolean(CFG_NOMINAL);
AggregationMethod aggrMethod = AggregationMethod.getDefaultMethod();
try {
aggrMethod = AggregationMethod.getMethod4Command(config.getString(CFG_AGGR_METHOD));
} catch (final Exception e) {
// Take the default method
}
exec.setProgress(0.1, "Binning column specification loaded");
exec.setProgress("Loading aggregation columns...");
final Config aggrConf = config.getConfig(CFG_AGGR_COLS);
final int aggrColCounter = aggrConf.getInt(CFG_AGGR_COL_COUNTER);
final ArrayList<ColorColumn> aggrCols = new ArrayList<ColorColumn>(aggrColCounter);
for (int i = 0; i < aggrColCounter; i++) {
final Config aggrColConf = aggrConf.getConfig(CFG_COLOR_COL + i);
aggrCols.add(ColorColumn.loadFromFile(aggrColConf, exec));
}
exec.setProgress(0.3, "Loading bins...");
final ConfigRO binsConf = config.getConfig(CFG_BINS);
final int binCounter = binsConf.getInt(CFG_BIN_COUNTER);
final List<BinDataModel> bins = new ArrayList<BinDataModel>(binCounter);
for (int i = 0; i < binCounter; i++) {
final Config binConf = binsConf.getConfig(CFG_BIN + i);
bins.add(BinDataModel.loadFromFile(binConf, exec));
}
final Config missingConfig = binsConf.getConfig(CFG_MISSING_BIN);
final BinDataModel missingBin = BinDataModel.loadFromFile(missingConfig, exec);
BinDataModel invalidBin = null;
if (binsConf.containsKey(CFG_INVALID_BIN)) {
final Config invalidConfig = binsConf.getConfig(CFG_INVALID_BIN);
invalidBin = BinDataModel.loadFromFile(invalidConfig, exec);
}
exec.setProgress(0.9, "Loading element colors...");
final ConfigRO colorColsConf = config.getConfig(CFG_COLOR_COLS);
final int counter = colorColsConf.getInt(CFG_ROW_COLOR_COUNTER);
final SortedSet<Color> rowColors = new TreeSet<Color>(HSBColorComparator.getInstance());
for (int i = 0; i < counter; i++) {
rowColors.add(new Color(colorColsConf.getInt(CFG_ROW_COLOR + i)));
}
exec.setProgress(1.0, "Histogram data model loaded ");
// close the stream
inData.close();
is.close();
return new FixedHistogramDataModel(xColSpec, aggrMethod, aggrCols, binNominal, bins, missingBin, invalidBin, rowColors);
}
use of org.knime.core.node.config.ConfigRO in project knime-core by knime.
the class InteractiveHistogramDataModel method loadFromFile.
/**
* @param dataDir the data directory to read from
* @param exec the {@link ExecutionMonitor}
* @return the {@link InteractiveHistogramDataModel}
* @throws IOException if the file is invalid
* @throws InvalidSettingsException if a setting is invalid
* @throws CanceledExecutionException if the process was canceled
*/
public static InteractiveHistogramDataModel loadFromFile(final File dataDir, final ExecutionMonitor exec) throws IOException, InvalidSettingsException, CanceledExecutionException {
final File settingFile = new File(dataDir, CFG_SETTING_FILE);
final FileInputStream is = new FileInputStream(settingFile);
final GZIPInputStream inData = new GZIPInputStream(is);
final ConfigRO config = NodeSettings.loadFromXML(inData);
final ConfigRO colorColsConf = config.getConfig(CFG_COLOR_COLS);
final int counter = colorColsConf.getInt(CFG_ROW_COLOR_COUNTER);
final List<Color> rowColors = new ArrayList<Color>();
for (int i = 0; i < counter; i++) {
rowColors.add(new Color(colorColsConf.getInt(CFG_ROW_COLOR + i)));
}
exec.checkCanceled();
final File dataFile = new File(dataDir, CFG_DATA_FILE);
final ContainerTable table = DataContainer.readFromZip(dataFile);
final int rowCount = table.getRowCount();
final DefaultDataArray dataArray = new DefaultDataArray(table, 1, rowCount, exec);
return new InteractiveHistogramDataModel(dataArray, rowColors);
}
Aggregations