Search in sources :

Example 6 with DataTableSpec

use of org.knime.core.data.DataTableSpec in project knime-core by knime.

the class RuleEngineVariable2PortsNodeModel method configure.

/**
 * {@inheritDoc}
 */
@Override
protected PortObjectSpec[] configure(final PortObjectSpec[] inSpecs) throws InvalidSettingsException {
    String warning = RuleEngine2PortsNodeModel.autoGuessRuleColumnName(inSpecs, m_settings);
    if (warning != null) {
        setWarningMessage(warning);
    }
    DataTableSpec ruleTableSpec = (DataTableSpec) inSpecs[RuleEngine2PortsNodeModel.RULE_PORT];
    // unknown table structure
    if (ruleTableSpec == null) {
        return null;
    }
    CheckUtils.checkSettingNotNull(ruleTableSpec.getColumnSpec(m_settings.getRuleColumn()), "No rule column in the rules table with name: " + m_settings.getRuleColumn());
    return new PortObjectSpec[] { FlowVariablePortObjectSpec.INSTANCE };
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) PortObjectSpec(org.knime.core.node.port.PortObjectSpec) FlowVariablePortObjectSpec(org.knime.core.node.port.flowvariable.FlowVariablePortObjectSpec)

Example 7 with DataTableSpec

use of org.knime.core.data.DataTableSpec in project knime-core by knime.

the class MovingAverageNodeModel method configure.

/**
 * {@inheritDoc}
 */
@Override
protected DataTableSpec[] configure(final DataTableSpec[] inSpecs) throws InvalidSettingsException {
    DataTableSpec inSpec = inSpecs[0];
    // define column name on which to apply MA
    if ((m_columnNames.getIncludeList().size() == 0) && (m_columnNames.getExcludeList().size() == 0)) {
        // auto-configure
        List<String> autoConfiguredInclList = new ArrayList<String>();
        for (DataColumnSpec colSpec : inSpec) {
            if (colSpec.getType().isCompatible(DoubleValue.class)) {
                autoConfiguredInclList.add(colSpec.getName());
            }
        }
        m_columnNames.setIncludeList(autoConfiguredInclList);
        setWarningMessage("Auto-configure: selected all double columns!");
    }
    if (m_columnNames.getIncludeList().isEmpty()) {
        setWarningMessage("No double columns selected: input will be same as output!");
    }
    // check for the existence of the selected columns
    for (String colName : m_columnNames.getIncludeList()) {
        if (!inSpecs[0].containsName(colName)) {
            throw new InvalidSettingsException("Column \"" + colName + "\" not found in input data!");
        }
    }
    // define moving average window length
    int winLength = m_winLength.getIntValue();
    if (winLength == -1) {
        throw new InvalidSettingsException("Window length is not selected.");
    }
    // define weight function
    String kindOfMAModelString;
    try {
        kindOfMAModelString = m_kindOfMAModel.getStringValue();
    } catch (IllegalArgumentException e) {
        throw new InvalidSettingsException(e.getMessage(), e);
    }
    if (kindOfMAModelString == null) {
        throw new InvalidSettingsException("No weight function selected.");
    } else {
        // create one MA-compute engine per column (overkill, I know
        // but much easier to reference later on in our DataCellFactory)
        MA_METHODS method = MA_METHODS.getPolicy4Label(kindOfMAModelString);
        if (MA_METHODS.getCenteredMethods().contains(method) && winLength % 2 == 0) {
            throw new InvalidSettingsException("For centered methods, the window size has to be uneven");
        }
        m_mas = new MovingAverage[inSpecs[0].getNumColumns()];
        for (int i = 0; i < inSpecs[0].getNumColumns(); i++) {
            m_mas[i] = method.getMAObject(winLength);
        }
    }
    ColumnRearranger c = createColRearranger(inSpecs[0]);
    return new DataTableSpec[] { c.createSpec() };
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) DataColumnSpec(org.knime.core.data.DataColumnSpec) ColumnRearranger(org.knime.core.data.container.ColumnRearranger) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) ArrayList(java.util.ArrayList) SettingsModelFilterString(org.knime.core.node.defaultnodesettings.SettingsModelFilterString) SettingsModelString(org.knime.core.node.defaultnodesettings.SettingsModelString)

Example 8 with DataTableSpec

use of org.knime.core.data.DataTableSpec in project knime-core by knime.

the class DateFieldExtractorNodeModel method configure.

/**
 * {@inheritDoc}
 */
@Override
protected DataTableSpec[] configure(final DataTableSpec[] inSpecs) throws InvalidSettingsException {
    DataTableSpec inSpec = inSpecs[0];
    // contains timestamp?
    if (!inSpec.containsCompatibleType(DateAndTimeValue.class)) {
        throw new InvalidSettingsException("No timestamp found in input table!");
    }
    // currently selected column still there?
    String selectedColName = m_selectedColumn.getStringValue();
    if (selectedColName != null && !selectedColName.isEmpty()) {
        if (!inSpec.containsName(selectedColName)) {
            throw new InvalidSettingsException("Column " + selectedColName + " not found in input spec!");
        }
    } else {
        // no value set: auto-configure -> choose first timeseries
        for (DataColumnSpec colSpec : inSpec) {
            if (colSpec.getType().isCompatible(DateAndTimeValue.class)) {
                String colName = colSpec.getName();
                m_selectedColumn.setStringValue(colName);
                setWarningMessage("Auto-configure: selected " + colName);
                break;
            }
        }
    }
    // create outputspec
    ColumnRearranger colRearranger = createColumnRearranger(inSpec).getColumnRearranger();
    return new DataTableSpec[] { colRearranger.createSpec() };
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) DataColumnSpec(org.knime.core.data.DataColumnSpec) ColumnRearranger(org.knime.core.data.container.ColumnRearranger) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) DateAndTimeValue(org.knime.core.data.date.DateAndTimeValue) SettingsModelString(org.knime.core.node.defaultnodesettings.SettingsModelString)

Example 9 with DataTableSpec

use of org.knime.core.data.DataTableSpec 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 10 with DataTableSpec

use of org.knime.core.data.DataTableSpec in project knime-core by knime.

the class MaskTimeNodeModel method configure.

/**
 * {@inheritDoc}
 */
@Override
protected DataTableSpec[] configure(final DataTableSpec[] inSpecs) throws InvalidSettingsException {
    DataTableSpec inSpec = inSpecs[0];
    // check if there is a date and tme column in niput spec
    if (!inSpec.containsCompatibleType(DateAndTimeValue.class)) {
        throw new InvalidSettingsException("Input table must contain at least one column " + "containing time!");
    }
    // do we have a selected column?
    String selectedCol = m_selectedColumn.getStringValue();
    if (selectedCol != null && !selectedCol.isEmpty()) {
        // if yes -> exists in input spec?
        if (!inSpec.containsName(selectedCol)) {
            throw new InvalidSettingsException("Selected column " + selectedCol + "not found in input table!");
        }
    } else {
        // if no -> auto-configure: select first date and time column
        for (DataColumnSpec colSpec : inSpec) {
            if (colSpec.getType().isCompatible(DateAndTimeValue.class)) {
                String colName = colSpec.getName();
                m_selectedColumn.setStringValue(colName);
                setWarningMessage("Auto-configure: selected column " + colName + "!");
            }
        }
    }
    return new DataTableSpec[] { createOutputSpec(inSpec) };
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) DataColumnSpec(org.knime.core.data.DataColumnSpec) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) DateAndTimeValue(org.knime.core.data.date.DateAndTimeValue) SettingsModelString(org.knime.core.node.defaultnodesettings.SettingsModelString)

Aggregations

DataTableSpec (org.knime.core.data.DataTableSpec)938 DataColumnSpec (org.knime.core.data.DataColumnSpec)340 InvalidSettingsException (org.knime.core.node.InvalidSettingsException)306 ColumnRearranger (org.knime.core.data.container.ColumnRearranger)228 BufferedDataTable (org.knime.core.node.BufferedDataTable)226 DataCell (org.knime.core.data.DataCell)186 DataRow (org.knime.core.data.DataRow)170 DataColumnSpecCreator (org.knime.core.data.DataColumnSpecCreator)136 SettingsModelString (org.knime.core.node.defaultnodesettings.SettingsModelString)129 DataType (org.knime.core.data.DataType)109 ArrayList (java.util.ArrayList)106 PortObjectSpec (org.knime.core.node.port.PortObjectSpec)98 DoubleValue (org.knime.core.data.DoubleValue)94 DefaultRow (org.knime.core.data.def.DefaultRow)92 BufferedDataContainer (org.knime.core.node.BufferedDataContainer)90 ExecutionContext (org.knime.core.node.ExecutionContext)68 PortObject (org.knime.core.node.port.PortObject)66 PMMLPortObjectSpec (org.knime.core.node.port.pmml.PMMLPortObjectSpec)62 CanceledExecutionException (org.knime.core.node.CanceledExecutionException)61 RowKey (org.knime.core.data.RowKey)59