Search in sources :

Example 1 with TSMissVHandler

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 };
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) ExecutionContext(org.knime.core.node.ExecutionContext) ColumnRearranger(org.knime.core.data.container.ColumnRearranger) RowKey(org.knime.core.data.RowKey) BufferedDataTable(org.knime.core.node.BufferedDataTable) TSMissVHandler(org.knime.timeseries.node.timemissvaluehandler.tshandler.TSMissVHandler) DataRow(org.knime.core.data.DataRow)

Example 2 with TSMissVHandler

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() };
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) ColumnRearranger(org.knime.core.data.container.ColumnRearranger) TSMissVHandler(org.knime.timeseries.node.timemissvaluehandler.tshandler.TSMissVHandler)

Example 3 with TSMissVHandler

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;
}
Also used : ColumnRearranger(org.knime.core.data.container.ColumnRearranger) DataColumnSpec(org.knime.core.data.DataColumnSpec) DataColumnSpecCreator(org.knime.core.data.DataColumnSpecCreator) TSMissVHandler(org.knime.timeseries.node.timemissvaluehandler.tshandler.TSMissVHandler) SingleCellFactory(org.knime.core.data.container.SingleCellFactory) DataRow(org.knime.core.data.DataRow)

Example 4 with TSMissVHandler

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;
}
Also used : DataColumnSpec(org.knime.core.data.DataColumnSpec) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) TSMissVHandler(org.knime.timeseries.node.timemissvaluehandler.tshandler.TSMissVHandler)

Aggregations

TSMissVHandler (org.knime.timeseries.node.timemissvaluehandler.tshandler.TSMissVHandler)4 ColumnRearranger (org.knime.core.data.container.ColumnRearranger)3 DataColumnSpec (org.knime.core.data.DataColumnSpec)2 DataRow (org.knime.core.data.DataRow)2 DataTableSpec (org.knime.core.data.DataTableSpec)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 DataColumnSpecCreator (org.knime.core.data.DataColumnSpecCreator)1 RowKey (org.knime.core.data.RowKey)1 SingleCellFactory (org.knime.core.data.container.SingleCellFactory)1 BufferedDataTable (org.knime.core.node.BufferedDataTable)1 ExecutionContext (org.knime.core.node.ExecutionContext)1