use of org.knime.timeseries.node.timemissvaluehandler.tshandler.TSMissVHandler in project knime-core by knime.
the class TimeMissValueNodeModel method execute.
/**
* {@inheritDoc}
*/
@Override
protected BufferedDataTable[] execute(final BufferedDataTable[] inData, final ExecutionContext exec) throws Exception {
ExecutionContext createExec = exec.createSubExecutionContext(0.4);
DataTableSpec spec = inData[0].getDataTableSpec();
double maxRow = inData[0].getRowCount();
double currRow = 0;
Map<String, TSMissVHandler> nameToMVHandler = checkInputAndCreateHandlerMap(spec);
Map<String, Integer> nameToInt = findColumns(spec, nameToMVHandler);
if (nameToMVHandler.isEmpty()) {
return inData;
}
for (DataRow row : inData[0]) {
RowKey key = row.getKey();
for (String s : nameToInt.keySet()) {
nameToMVHandler.get(s).incomingValue(key, row.getCell(nameToInt.get(s)));
}
createExec.checkCanceled();
createExec.setProgress(++currRow / maxRow, "Preprocessing... Row " + row.getKey().getString());
}
for (String s : nameToMVHandler.keySet()) {
nameToMVHandler.get(s).close();
}
ExecutionContext builtExec = exec.createSubExecutionContext(0.6);
ColumnRearranger colR = createColumnRearranger(nameToMVHandler, nameToInt, inData[0].getDataTableSpec());
BufferedDataTable outTable = exec.createColumnRearrangeTable(inData[0], colR, builtExec);
return new BufferedDataTable[] { outTable };
}
use of org.knime.timeseries.node.timemissvaluehandler.tshandler.TSMissVHandler in project knime-core by knime.
the class TimeMissValueNodeModel method configure.
/**
* {@inheritDoc}
*/
@Override
protected DataTableSpec[] configure(final DataTableSpec[] inSpecs) throws InvalidSettingsException {
DataTableSpec spec = inSpecs[0];
Map<String, TSMissVHandler> nameToMVHandler = checkInputAndCreateHandlerMap(spec);
Map<String, Integer> nameToInt = findColumns(spec, nameToMVHandler);
ColumnRearranger c = createColumnRearranger(nameToMVHandler, nameToInt, spec);
return new DataTableSpec[] { c.createSpec() };
}
use of org.knime.timeseries.node.timemissvaluehandler.tshandler.TSMissVHandler in project knime-core by knime.
the class TimeMissValueNodeModel method createColumnRearranger.
private ColumnRearranger createColumnRearranger(final Map<String, TSMissVHandler> nameToMVHandler, final Map<String, Integer> nameToInt, final DataTableSpec spec) {
ColumnRearranger result = new ColumnRearranger(spec);
for (String thisCol : nameToMVHandler.keySet()) {
final TSMissVHandler mvHandler = nameToMVHandler.get(thisCol);
final int colIndex = spec.findColumnIndex(thisCol);
DataColumnSpec newColSpec = new DataColumnSpecCreator(thisCol, spec.getColumnSpec(thisCol).getType()).createSpec();
SingleCellFactory c = new SingleCellFactory(newColSpec) {
@Override
public DataCell getCell(final DataRow row) {
if (row.getCell(colIndex).isMissing()) {
return mvHandler.getandRemove(row.getKey());
}
return row.getCell(colIndex);
}
};
result.replace(c, nameToInt.get(thisCol));
}
return result;
}
use of org.knime.timeseries.node.timemissvaluehandler.tshandler.TSMissVHandler in project knime-core by knime.
the class TimeMissValueNodeModel method checkInputAndCreateHandlerMap.
private Map<String, TSMissVHandler> checkInputAndCreateHandlerMap(final DataTableSpec spec) throws InvalidSettingsException {
Map<String, TSMissVHandler> nameToMVHandler = new HashMap<String, TSMissVHandler>();
List<String> columnWhichDoNotExist = new ArrayList<>(0);
List<String> columnWithUnexpectedType = new ArrayList<>(0);
// Handle individual configs
for (TimeMissingValueHandlingColSetting set : m_colSettings) {
if (!set.isMetaConfig() && !HandlingMethod.DO_NOTHING.equals(set.getMethod())) {
for (String col : set.getNames()) {
DataColumnSpec colSpec = spec.getColumnSpec(col);
// sanity checks of the configured columns
if (colSpec != null) {
if (!TimeMissingValueHandlingNodeDialogPane.isIncompatible(set.getType(), colSpec)) {
TSMissVHandler handlerForLabel = set.getMethod().createTSMissVHandler();
nameToMVHandler.put(col, handlerForLabel);
} else {
columnWithUnexpectedType.add(col);
}
} else {
columnWhichDoNotExist.add(col);
}
}
}
}
// fill meta for the remaining columns
for (TimeMissingValueHandlingColSetting set : m_colSettings) {
if (set.isMetaConfig() && !HandlingMethod.DO_NOTHING.equals(set.getMethod())) {
for (DataColumnSpec dcs : spec) {
if (!nameToMVHandler.containsKey(dcs.getName())) {
if (!TimeMissingValueHandlingNodeDialogPane.isIncompatible(set.getType(), dcs)) {
nameToMVHandler.put(dcs.getName(), set.getMethod().createTSMissVHandler());
}
}
}
}
}
if (!columnWhichDoNotExist.isEmpty() || !columnWithUnexpectedType.isEmpty()) {
StringBuilder builder = new StringBuilder();
if (!columnWhichDoNotExist.isEmpty()) {
builder.append("Following columns do not exist in input table:\n");
builder.append(ConvenienceMethods.getShortStringFrom(columnWhichDoNotExist, 5));
}
if (!columnWhichDoNotExist.isEmpty() && !columnWithUnexpectedType.isEmpty()) {
builder.append("\n");
}
if (!columnWithUnexpectedType.isEmpty()) {
builder.append("Following columns have an unexpected type:\n");
builder.append(ConvenienceMethods.getShortStringFrom(columnWithUnexpectedType, 5));
}
setWarningMessage(builder.toString());
}
return nameToMVHandler;
}
Aggregations