Search in sources :

Example 96 with IntCell

use of org.knime.core.data.def.IntCell in project knime-core by knime.

the class JoinerJoinAnyTest method toIntegerArray.

/**
 * Get the data of an DataTable as an integer array.
 * @param dataTable the data table
 * @return the data as an integer array
 */
private Integer[][] toIntegerArray(final BufferedDataTable dataTable) {
    int rowCount = ConvenienceMethods.checkTableSize(dataTable.size());
    int colCount = dataTable.getDataTableSpec().getNumColumns();
    Integer[][] data = new Integer[rowCount][colCount];
    RowIterator iter = dataTable.iterator();
    int r = 0;
    while (iter.hasNext()) {
        DataRow row = iter.next();
        Iterator<DataCell> cellIter = row.iterator();
        int c = 0;
        while (cellIter.hasNext()) {
            DataCell cell = cellIter.next();
            data[r][c] = !cell.isMissing() ? ((IntCell) cell).getIntValue() : null;
            c++;
        }
        r++;
    }
    return data;
}
Also used : RowIterator(org.knime.core.data.RowIterator) DataCell(org.knime.core.data.DataCell) DataRow(org.knime.core.data.DataRow) IntCell(org.knime.core.data.def.IntCell)

Example 97 with IntCell

use of org.knime.core.data.def.IntCell in project knime-core by knime.

the class SorterNodeModelTest method generateUnitMatrixTable.

/**
 * This method produces a unit matrix -<code>DataTable</code>.
 *
 * @param dimension of the matrix
 * @return Unit matrix
 */
public DefaultTable generateUnitMatrixTable(final int dimension) {
    // generate Column names and types
    String[] columnNames = new String[dimension];
    for (int i = 0; i < dimension; i++) {
        columnNames[i] = "col" + i;
    }
    DataType[] columnTypes = new DataType[dimension];
    for (int i = 0; i < dimension; i++) {
        columnTypes[i] = IntCell.TYPE;
    }
    DataRow[] unitmatrix = new DataRow[dimension];
    for (int i = 0; i < dimension; i++) {
        DataCell[] myRow = new DataCell[dimension];
        for (int j = 0; j < dimension; j++) {
            if (i == j) {
                myRow[j] = new IntCell(1);
            } else {
                myRow[j] = new IntCell(0);
            }
        }
        DataRow temprow = new DefaultRow(Integer.toString(i), myRow);
        unitmatrix[i] = temprow;
    }
    return new DefaultTable(unitmatrix, columnNames, columnTypes);
}
Also used : DefaultTable(org.knime.core.data.def.DefaultTable) DataType(org.knime.core.data.DataType) DataCell(org.knime.core.data.DataCell) DefaultRow(org.knime.core.data.def.DefaultRow) DataRow(org.knime.core.data.DataRow) IntCell(org.knime.core.data.def.IntCell)

Example 98 with IntCell

use of org.knime.core.data.def.IntCell in project knime-core by knime.

the class AbstractHistogramPlotter method createColumnSpec.

/**
 * Returns <code>DataColumnSpec</code> object with the given properties.
 *
 * @param columnName name of the column.
 * @param type the <code>DataType</code> of the column
 * @param lowerBound the lower bound if available if not set it to
 * <code>Double.NaN</code> @param upperBoundthe upper bound if available if
 * not set it to <code>Double.NaN</code>
 * @param values the possible values for nominal types or <code>null</code>
 * for discrete types
 * @return the <code>DataColumnSpec</code> object created using the
 * given values
 */
private DataColumnSpec createColumnSpec(final String columnName, final DataType type, final double lowerBound, final double upperBound, final Set<DataCell> values) {
    final DataColumnDomainCreator domainCreator = new DataColumnDomainCreator();
    if (!Double.isNaN(lowerBound) && !Double.isNaN(upperBound)) {
        DataCell lowerBoundCell = null;
        DataCell upperBoundCell = null;
        if (type.isCompatible(IntValue.class)) {
            lowerBoundCell = new IntCell((int) lowerBound);
            upperBoundCell = new IntCell((int) upperBound);
        } else {
            lowerBoundCell = new DoubleCell(lowerBound);
            upperBoundCell = new DoubleCell(upperBound);
        }
        domainCreator.setLowerBound(lowerBoundCell);
        domainCreator.setUpperBound(upperBoundCell);
    }
    if (values != null && values.size() > 0) {
        domainCreator.setValues(values);
    }
    final DataColumnSpecCreator specCreator = new DataColumnSpecCreator(columnName, type);
    specCreator.setDomain(domainCreator.createDomain());
    final DataColumnSpec spec = specCreator.createSpec();
    return spec;
}
Also used : DataColumnSpecCreator(org.knime.core.data.DataColumnSpecCreator) DataColumnSpec(org.knime.core.data.DataColumnSpec) DoubleCell(org.knime.core.data.def.DoubleCell) DataColumnDomainCreator(org.knime.core.data.DataColumnDomainCreator) DataCell(org.knime.core.data.DataCell) IntCell(org.knime.core.data.def.IntCell)

Example 99 with IntCell

use of org.knime.core.data.def.IntCell in project knime-core by knime.

the class ExtractTableDimensionNodeModel method execute.

/**
 * {@inheritDoc}
 */
@Override
protected BufferedDataTable[] execute(final BufferedDataTable[] inData, final ExecutionContext exec) throws Exception {
    BufferedDataTable data = inData[0];
    BufferedDataContainer bdc = exec.createDataContainer(createDataTableSpec());
    int noRows = data.getRowCount();
    int noCols = data.getDataTableSpec().getNumColumns();
    bdc.addRowToTable(new DefaultRow(DEF_NOROWS_VAR, new DataCell[] { new IntCell(noRows) }));
    bdc.addRowToTable(new DefaultRow(DEF_NOCOLS_VAR, new DataCell[] { new IntCell(noCols) }));
    bdc.close();
    pushFlowVariableInt(DEF_NOROWS_VAR, noRows);
    pushFlowVariableInt(DEF_NOCOLS_VAR, noCols);
    return new BufferedDataTable[] { bdc.getTable() };
}
Also used : BufferedDataContainer(org.knime.core.node.BufferedDataContainer) BufferedDataTable(org.knime.core.node.BufferedDataTable) DataCell(org.knime.core.data.DataCell) DefaultRow(org.knime.core.data.def.DefaultRow) IntCell(org.knime.core.data.def.IntCell)

Example 100 with IntCell

use of org.knime.core.data.def.IntCell in project knime-core by knime.

the class TimerinfoNodeModel method execute.

/**
 * {@inheritDoc}
 */
@Override
protected PortObject[] execute(final PortObject[] inData, final ExecutionContext exec) throws Exception {
    BufferedDataContainer result = exec.createDataContainer(createSpec());
    WorkflowManager wfm = NodeContext.getContext().getWorkflowManager();
    for (NodeContainer nc : wfm.getNodeContainers()) {
        NodeTimer nt = nc.getNodeTimer();
        DataRow row = new DefaultRow(new RowKey("Node " + nc.getID().getIndex()), new StringCell(nc.getName()), nt.getLastExecutionDuration() >= 0 ? new LongCell(nt.getLastExecutionDuration()) : DataType.getMissingCell(), new LongCell(nt.getExecutionDurationSinceReset()), new LongCell(nt.getExecutionDurationSinceStart()), new IntCell(nt.getNrExecsSinceReset()), new IntCell(nt.getNrExecsSinceStart()), new StringCell(nc.getID().toString()), new StringCell(nc instanceof NativeNodeContainer ? ((NativeNodeContainer) nc).getNodeModel().getClass().getName() : "n/a"));
        result.addRowToTable(row);
    }
    result.close();
    return new PortObject[] { result.getTable() };
}
Also used : LongCell(org.knime.core.data.def.LongCell) BufferedDataContainer(org.knime.core.node.BufferedDataContainer) RowKey(org.knime.core.data.RowKey) StringCell(org.knime.core.data.def.StringCell) NodeTimer(org.knime.core.node.workflow.NodeTimer) WorkflowManager(org.knime.core.node.workflow.WorkflowManager) NativeNodeContainer(org.knime.core.node.workflow.NativeNodeContainer) NodeContainer(org.knime.core.node.workflow.NodeContainer) DefaultRow(org.knime.core.data.def.DefaultRow) DataRow(org.knime.core.data.DataRow) FlowVariablePortObject(org.knime.core.node.port.flowvariable.FlowVariablePortObject) PortObject(org.knime.core.node.port.PortObject) NativeNodeContainer(org.knime.core.node.workflow.NativeNodeContainer) IntCell(org.knime.core.data.def.IntCell)

Aggregations

IntCell (org.knime.core.data.def.IntCell)109 DataCell (org.knime.core.data.DataCell)79 DoubleCell (org.knime.core.data.def.DoubleCell)67 StringCell (org.knime.core.data.def.StringCell)55 DefaultRow (org.knime.core.data.def.DefaultRow)46 DataRow (org.knime.core.data.DataRow)33 DataTableSpec (org.knime.core.data.DataTableSpec)21 RowKey (org.knime.core.data.RowKey)21 ArrayList (java.util.ArrayList)20 DataType (org.knime.core.data.DataType)20 LongCell (org.knime.core.data.def.LongCell)14 BufferedDataContainer (org.knime.core.node.BufferedDataContainer)14 DataColumnSpecCreator (org.knime.core.data.DataColumnSpecCreator)12 BufferedDataTable (org.knime.core.node.BufferedDataTable)12 Test (org.junit.Test)11 DataColumnSpec (org.knime.core.data.DataColumnSpec)11 ColumnRearranger (org.knime.core.data.container.ColumnRearranger)9 InvalidSettingsException (org.knime.core.node.InvalidSettingsException)9 DataContainer (org.knime.core.data.container.DataContainer)8 DateAndTimeValue (org.knime.core.data.date.DateAndTimeValue)8