Search in sources :

Example 86 with DoubleCell

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

the class Statistics3Table method createRow.

private DataRow createRow(final String key, final double[] array) {
    int idx = 0;
    DataTableSpec outSpec = createOutSpecNumeric(m_spec);
    DataCell[] data = new DataCell[outSpec.getNumColumns()];
    for (int i = 0; idx < data.length; i++) {
        if (outSpec.getColumnSpec(idx).getName().equals(m_spec.getColumnSpec(i).getName())) {
            if (Double.isNaN(array[i])) {
                data[idx] = DataType.getMissingCell();
            } else {
                data[idx] = new DoubleCell(array[i]);
            }
            idx++;
        }
    }
    return new DefaultRow(key, data);
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) DoubleCell(org.knime.core.data.def.DoubleCell) DataCell(org.knime.core.data.DataCell) BlobWrapperDataCell(org.knime.core.data.container.BlobWrapperDataCell) DefaultRow(org.knime.core.data.def.DefaultRow)

Example 87 with DoubleCell

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

the class Statistics3Table method createRow.

/**
 * Creates a row for the transposed table.
 *
 * @param name The name of the column.
 * @param colIdx The index of column in the computed values.
 * @return The cells according to {@link #STATISTICS_SPECIFICATION}.
 */
private DataCell[] createRow(final String name, final int colIdx) {
    final DataCell[] ret = new DataCell[getStatisticsSpecification().getNumColumns()];
    int i = 0;
    ret[i++] = new StringCell(name);
    ret[i++] = m_minCells[colIdx];
    ret[i++] = m_maxCells[colIdx];
    ret[i++] = new DoubleCell(m_meanValues[colIdx]);
    ret[i++] = new DoubleCell(Math.sqrt(m_varianceValues[colIdx]));
    ret[i++] = new DoubleCell(m_varianceValues[colIdx]);
    ret[i++] = new DoubleCell(m_skewness[colIdx]);
    ret[i++] = new DoubleCell(m_kurtosis[colIdx]);
    ret[i++] = new DoubleCell(m_sum[colIdx]);
    ret[i++] = new IntCell(m_missingValueCnt[colIdx]);
    ret[i++] = new IntCell(m_nanValueCnt[colIdx]);
    ret[i++] = new IntCell(m_posInfinityValueCnt[colIdx]);
    ret[i++] = new IntCell(m_negInfinityValueCnt[colIdx]);
    ret[i++] = Double.isNaN(m_median[colIdx]) ? DataType.getMissingCell() : new DoubleCell(m_median[colIdx]);
    ret[i++] = new IntCell(m_rowCount);
    return ret;
}
Also used : StringCell(org.knime.core.data.def.StringCell) DoubleCell(org.knime.core.data.def.DoubleCell) DataCell(org.knime.core.data.DataCell) BlobWrapperDataCell(org.knime.core.data.container.BlobWrapperDataCell) IntCell(org.knime.core.data.def.IntCell)

Example 88 with DoubleCell

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

the class AffineTransRowIterator method next.

/**
 * {@inheritDoc}
 */
@Override
public DataRow next() {
    AffineTransConfiguration config = m_transtable.getConfiguration();
    int[] indices = m_transtable.getIndicesInConfiguration();
    double[] scales = config.getScales();
    double[] translations = config.getTranslations();
    double[] min = config.getMin();
    double[] max = config.getMax();
    final DataRow in = m_it.next();
    final DataCell[] cells = new DataCell[in.getNumCells()];
    for (int i = 0; i < cells.length; i++) {
        final DataCell oldCell = in.getCell(i);
        if (oldCell.isMissing() || indices[i] == -1) {
            cells[i] = oldCell;
        } else {
            int index = indices[i];
            double interval = max[index] - min[index];
            double oldDouble = ((DoubleValue) oldCell).getDoubleValue();
            double newDouble = scales[index] * oldDouble + translations[index];
            if (!Double.isNaN(min[index])) {
                if (newDouble < min[index]) {
                    if ((min[index] - newDouble) / interval < AffineTransTable.VERY_SMALL) {
                        newDouble = min[index];
                    } else {
                        m_transtable.setErrorMessage("Normalized value is out of bounds." + " Original value: " + oldDouble + " Transformed value: " + newDouble + " Lower Bound: " + min[index]);
                    }
                }
            }
            if (!Double.isNaN(max[index])) {
                if (newDouble > max[index]) {
                    if ((newDouble - max[index]) / interval < AffineTransTable.VERY_SMALL) {
                        newDouble = max[index];
                    } else {
                        m_transtable.setErrorMessage("Normalized value is out of bounds." + " Original value: " + oldDouble + " Transformed value: " + newDouble + " Upper Bound: " + max[index]);
                    }
                }
            }
            cells[i] = new DoubleCell(newDouble);
        }
    }
    return new DefaultRow(in.getKey(), cells);
}
Also used : DoubleValue(org.knime.core.data.DoubleValue) DoubleCell(org.knime.core.data.def.DoubleCell) DataCell(org.knime.core.data.DataCell) DefaultRow(org.knime.core.data.def.DefaultRow) DataRow(org.knime.core.data.DataRow)

Example 89 with DoubleCell

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

the class VariableToTable2NodeModel method execute.

/**
 * {@inheritDoc}
 */
@Override
protected PortObject[] execute(final PortObject[] inData, final ExecutionContext exec) throws Exception {
    DataTableSpec spec = createOutSpec();
    BufferedDataContainer cont = exec.createDataContainer(spec);
    List<Pair<String, FlowVariable.Type>> vars = getVariablesOfInterest();
    DataCell[] specs = new DataCell[vars.size()];
    List<String> lostVariables = new ArrayList<String>();
    for (int i = 0; i < vars.size(); i++) {
        Pair<String, FlowVariable.Type> c = vars.get(i);
        String name = c.getFirst();
        // fallback
        DataCell cell = DataType.getMissingCell();
        switch(c.getSecond()) {
            case DOUBLE:
                try {
                    double dValue = peekFlowVariableDouble(c.getFirst());
                    cell = new DoubleCell(dValue);
                } catch (NoSuchElementException e) {
                    lostVariables.add(name + " (Double)");
                }
                break;
            case INTEGER:
                try {
                    int iValue = peekFlowVariableInt(c.getFirst());
                    cell = new IntCell(iValue);
                } catch (NoSuchElementException e) {
                    lostVariables.add(name + " (Integer)");
                }
                break;
            case STRING:
                try {
                    String sValue = peekFlowVariableString(c.getFirst());
                    sValue = sValue == null ? "" : sValue;
                    cell = new StringCell(sValue);
                } catch (NoSuchElementException e) {
                    lostVariables.add(name + " (String)");
                }
                break;
        }
        specs[i] = cell;
    }
    cont.addRowToTable(new DefaultRow(m_rowID.getStringValue(), specs));
    cont.close();
    return new BufferedDataTable[] { cont.getTable() };
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) BufferedDataContainer(org.knime.core.node.BufferedDataContainer) DoubleCell(org.knime.core.data.def.DoubleCell) ArrayList(java.util.ArrayList) SettingsModelString(org.knime.core.node.defaultnodesettings.SettingsModelString) IntCell(org.knime.core.data.def.IntCell) PortType(org.knime.core.node.port.PortType) DataType(org.knime.core.data.DataType) StringCell(org.knime.core.data.def.StringCell) BufferedDataTable(org.knime.core.node.BufferedDataTable) DataCell(org.knime.core.data.DataCell) DefaultRow(org.knime.core.data.def.DefaultRow) NoSuchElementException(java.util.NoSuchElementException) Pair(org.knime.core.util.Pair) FlowVariable(org.knime.core.node.workflow.FlowVariable)

Example 90 with DoubleCell

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

the class DayRangeOperator method getResultInternal.

/**
 * {@inheritDoc}
 */
@Override
protected DataCell getResultInternal() {
    final DateAndTimeValue min = getMin();
    final DateAndTimeValue max = getMax();
    if (min == null || max == null) {
        return DataType.getMissingCell();
    }
    final long range = max.getUTCTimeInMillis() - min.getUTCTimeInMillis();
    if (range == 0) {
        return new DoubleCell(0);
    }
    return new DoubleCell(range / MS_PER_DAY);
}
Also used : DateAndTimeValue(org.knime.core.data.date.DateAndTimeValue) DoubleCell(org.knime.core.data.def.DoubleCell)

Aggregations

DoubleCell (org.knime.core.data.def.DoubleCell)189 DataCell (org.knime.core.data.DataCell)129 IntCell (org.knime.core.data.def.IntCell)67 DefaultRow (org.knime.core.data.def.DefaultRow)66 StringCell (org.knime.core.data.def.StringCell)65 DataRow (org.knime.core.data.DataRow)57 DataTableSpec (org.knime.core.data.DataTableSpec)55 ArrayList (java.util.ArrayList)42 DataColumnSpec (org.knime.core.data.DataColumnSpec)42 DataColumnSpecCreator (org.knime.core.data.DataColumnSpecCreator)41 BufferedDataContainer (org.knime.core.node.BufferedDataContainer)39 RowKey (org.knime.core.data.RowKey)37 DoubleValue (org.knime.core.data.DoubleValue)35 BufferedDataTable (org.knime.core.node.BufferedDataTable)28 DataColumnDomainCreator (org.knime.core.data.DataColumnDomainCreator)26 InvalidSettingsException (org.knime.core.node.InvalidSettingsException)22 DataType (org.knime.core.data.DataType)20 LinkedHashMap (java.util.LinkedHashMap)17 HashMap (java.util.HashMap)13 Point (java.awt.Point)12