Search in sources :

Example 6 with BufferedDataTable

use of org.knime.core.node.BufferedDataTable in project knime-core by knime.

the class NodeOutputView method updateDataTable.

/*
     *  Put (static and simple) content of one output port table into table.
     */
private void updateDataTable(final NodeContainer nc, final int port) {
    assert Display.getCurrent().getThread() == Thread.currentThread();
    // display data table
    ((StackLayout) m_stackPanel.getLayout()).topControl = m_tableViewPanel;
    m_stackPanel.layout();
    m_info.setText("Port Output");
    m_tableView.setDataTable(null);
    // check if we can display something at all:
    int index = port;
    if (nc instanceof SingleNodeContainer) {
        // we don't care about (hidden) variable OutPort
        index++;
    }
    if (nc.getNrOutPorts() <= index) {
        // no (real) port available
        m_errorLabel.setText("No output ports");
        ((StackLayout) m_stackPanel.getLayout()).topControl = m_errorLabel;
        m_stackPanel.layout();
        return;
    }
    NodeOutPort nop = nc.getOutPort(index);
    PortObject po = nop.getPortObject();
    if ((po == null) || !(po instanceof BufferedDataTable)) {
        // no table in port - ignore.
        m_errorLabel.setText("Unknown or no PortObject");
        ((StackLayout) m_stackPanel.getLayout()).topControl = m_errorLabel;
        m_stackPanel.layout();
        return;
    }
    // retrieve table
    m_tableView.setDataTable((DataTable) po);
    m_tableView.repaint();
}
Also used : BufferedDataTable(org.knime.core.node.BufferedDataTable) NodeOutPort(org.knime.core.node.workflow.NodeOutPort) PortObject(org.knime.core.node.port.PortObject) Point(org.eclipse.swt.graphics.Point) SingleNodeContainer(org.knime.core.node.workflow.SingleNodeContainer)

Example 7 with BufferedDataTable

use of org.knime.core.node.BufferedDataTable in project knime-core by knime.

the class TimeDifferenceNodeModel method execute.

/**
 * {@inheritDoc}
 */
@Override
protected BufferedDataTable[] execute(final BufferedDataTable[] inData, final ExecutionContext exec) throws Exception {
    // get the selected granularity level
    final Granularity g = Granularity.valueOf(m_granularity.getStringValue());
    // create rearranger
    ColumnRearranger rearranger = new ColumnRearranger(inData[0].getDataTableSpec());
    String typeofref = m_typeofreference.getStringValue();
    if (typeofref.equals(TimeDifferenceNodeDialog.CFG_COLUMN)) {
        // append the new column with single cell factory
        rearranger.append(new SingleCellFactory(createOutputColumnSpec(inData[0].getDataTableSpec(), m_newColName.getStringValue())) {

            /**
             * Value for the new column is based on the values of two column
             * of the row (first and second date column), the selected
             * granularity, and the fraction digits for rounding.
             *
             * @param row the current row
             * @return the difference between the two date values with the
             *         given granularity and rounding
             */
            @Override
            public DataCell getCell(final DataRow row) {
                DataCell cell1 = row.getCell(m_col1Idx);
                DataCell cell2 = row.getCell(m_col2Idx);
                if ((cell1.isMissing()) || (cell2.isMissing())) {
                    return DataType.getMissingCell();
                }
                long first = ((DateAndTimeValue) cell1).getUTCTimeInMillis();
                long last = ((DateAndTimeValue) cell2).getUTCTimeInMillis();
                return getRoundedTimeDifference(first, last, g);
            }
        });
    } else if (typeofref.equals(TimeDifferenceNodeDialog.CFG_ROW_DIFF)) {
        // option for producing the time difference between current and the
        // previous row.
        // append the new column with single cell factory
        rearranger.append(new SingleCellFactory(createOutputColumnSpec(inData[0].getDataTableSpec(), m_newColName.getStringValue())) {

            /**
             * saves the previous time value (contained in the last row)
             */
            private DateAndTimeValue m_previous = null;

            /**
             * Value for the new column is based on the values of the
             * current row and the value of the previous row.
             * Therefore both rows must contain a DateAndTimeValue,
             * the selected granularity, and the fraction digits for
             * rounding.
             *
             * @param row the current row
             * @return the difference between the two date values with the
             *         given granularity and rounding
             */
            @Override
            public DataCell getCell(final DataRow row) {
                DataCell cell1 = row.getCell(m_col1Idx);
                // value
                if ((cell1.isMissing()) || !cell1.getType().isCompatible(DateAndTimeValue.class)) {
                    m_previous = null;
                    return DataType.getMissingCell();
                }
                // (e.g. we are in the first row)
                if (m_previous == null) {
                    m_previous = (DateAndTimeValue) cell1;
                    return DataType.getMissingCell();
                }
                long first = m_previous.getUTCTimeInMillis();
                long last = ((DateAndTimeValue) cell1).getUTCTimeInMillis();
                m_previous = (DateAndTimeValue) cell1;
                return getRoundedTimeDifference(first, last, g);
            }
        });
    } else {
        final long time;
        if (typeofref.equals(TimeDifferenceNodeDialog.CFG_FIXDATE)) {
            time = m_timemodel.getCalendar().getTimeInMillis();
        } else {
            time = System.currentTimeMillis() + TimeZone.getDefault().getOffset(System.currentTimeMillis());
        }
        // append the new column with single cell factory
        rearranger.append(new SingleCellFactory(createOutputColumnSpec(inData[0].getDataTableSpec(), m_newColName.getStringValue())) {

            /**
             * Value for the new column is based on the values of two column
             * of the row (first and second date column), the selected
             * granularity, and the fraction digits for rounding.
             *
             * @param row the current row
             * @return the difference between the two date values with the
             *         given granularity and rounding
             */
            @Override
            public DataCell getCell(final DataRow row) {
                DataCell cell1 = row.getCell(m_col1Idx);
                if ((cell1.isMissing())) {
                    return DataType.getMissingCell();
                }
                long first = ((DateAndTimeValue) cell1).getUTCTimeInMillis();
                return getRoundedTimeDifference(first, time, g);
            }
        });
    }
    BufferedDataTable out = exec.createColumnRearrangeTable(inData[0], rearranger, exec);
    return new BufferedDataTable[] { out };
}
Also used : ColumnRearranger(org.knime.core.data.container.ColumnRearranger) DateAndTimeValue(org.knime.core.data.date.DateAndTimeValue) BufferedDataTable(org.knime.core.node.BufferedDataTable) DataCell(org.knime.core.data.DataCell) SettingsModelString(org.knime.core.node.defaultnodesettings.SettingsModelString) SingleCellFactory(org.knime.core.data.container.SingleCellFactory) DataRow(org.knime.core.data.DataRow)

Example 8 with BufferedDataTable

use of org.knime.core.node.BufferedDataTable in project knime-core by knime.

the class ExtractTimeWindowNodeModel method execute.

/**
 * {@inheritDoc}
 */
@Override
protected BufferedDataTable[] execute(final BufferedDataTable[] inData, final ExecutionContext exec) throws Exception {
    boolean useTime = m_fromDate.useTime() || m_toDate.useTime();
    BufferedDataTable in = inData[0];
    DataTableSpec outs = in.getDataTableSpec();
    final int colIndex = outs.findColumnIndex(m_columnName.getStringValue());
    BufferedDataContainer t = exec.createDataContainer(outs);
    final long totalRowCount = in.size();
    int currentIteration = 0;
    try {
        for (DataRow r : in) {
            // increment before printing to achieve a 1-based index
            currentIteration++;
            exec.checkCanceled();
            exec.setProgress(currentIteration / (double) totalRowCount, "Processing row " + currentIteration);
            DataCell cell = r.getCell(colIndex);
            if (cell.isMissing()) {
                // do not include missing values -> skip it
                continue;
            }
            Calendar time = ((DateAndTimeValue) cell).getUTCCalendarClone();
            // which is implemented as a real < or >
            if (!useTime) {
                DateAndTimeCell.resetTimeFields(time);
            }
            if (time.compareTo(m_fromDate.getCalendar()) >= 0 && time.compareTo(m_toDate.getCalendar()) <= 0) {
                t.addRowToTable(r);
            }
        }
    } finally {
        t.close();
    }
    return new BufferedDataTable[] { t.getTable() };
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) BufferedDataContainer(org.knime.core.node.BufferedDataContainer) DateAndTimeValue(org.knime.core.data.date.DateAndTimeValue) Calendar(java.util.Calendar) SettingsModelCalendar(org.knime.timeseries.util.SettingsModelCalendar) BufferedDataTable(org.knime.core.node.BufferedDataTable) DataCell(org.knime.core.data.DataCell) DataRow(org.knime.core.data.DataRow)

Example 9 with BufferedDataTable

use of org.knime.core.node.BufferedDataTable in project knime-core by knime.

the class MaskTimeNodeModel method execute.

/**
 * {@inheritDoc}
 */
@Override
protected BufferedDataTable[] execute(final BufferedDataTable[] inData, final ExecutionContext exec) throws Exception {
    BufferedDataTable in = inData[0];
    ColumnRearranger rearranger = createRearranger(in.getDataTableSpec());
    BufferedDataTable out = exec.createColumnRearrangeTable(in, rearranger, exec);
    if (m_nrInvalids > 0) {
        String warningMessage = "Produced " + m_nrInvalids + " missing values due to " + "masking of the only existing field!";
        if (m_onlyInvalids) {
            // only invalids -> different message
            warningMessage = "Produced only missing values " + "-> wrong field masked?";
        }
        setWarningMessage(warningMessage);
    }
    return new BufferedDataTable[] { out };
}
Also used : ColumnRearranger(org.knime.core.data.container.ColumnRearranger) BufferedDataTable(org.knime.core.node.BufferedDataTable) SettingsModelString(org.knime.core.node.defaultnodesettings.SettingsModelString)

Example 10 with BufferedDataTable

use of org.knime.core.node.BufferedDataTable 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)

Aggregations

BufferedDataTable (org.knime.core.node.BufferedDataTable)460 DataTableSpec (org.knime.core.data.DataTableSpec)221 ColumnRearranger (org.knime.core.data.container.ColumnRearranger)148 DataRow (org.knime.core.data.DataRow)130 BufferedDataContainer (org.knime.core.node.BufferedDataContainer)104 PortObject (org.knime.core.node.port.PortObject)102 DataCell (org.knime.core.data.DataCell)93 InvalidSettingsException (org.knime.core.node.InvalidSettingsException)66 DataColumnSpec (org.knime.core.data.DataColumnSpec)65 DefaultRow (org.knime.core.data.def.DefaultRow)63 RowKey (org.knime.core.data.RowKey)59 ExecutionMonitor (org.knime.core.node.ExecutionMonitor)55 PMMLPortObject (org.knime.core.node.port.pmml.PMMLPortObject)54 CanceledExecutionException (org.knime.core.node.CanceledExecutionException)50 ExecutionContext (org.knime.core.node.ExecutionContext)47 SettingsModelString (org.knime.core.node.defaultnodesettings.SettingsModelString)44 IOException (java.io.IOException)43 ArrayList (java.util.ArrayList)37 LinkedHashMap (java.util.LinkedHashMap)31 Test (org.junit.Test)30