Search in sources :

Example 1 with AggregationOperator

use of org.knime.base.data.aggregation.AggregationOperator in project knime-core by knime.

the class MovingAggregationTableFactory method getBackwardTable.

private BufferedDataTable getBackwardTable(final ExecutionMonitor exec, final BufferedDataTable table, final BufferedDataContainer dc) throws CanceledExecutionException {
    final int rowCount = table.getRowCount();
    final LinkedList<DataRow> window = new LinkedList<>();
    int rowIdx = 0;
    for (final DataRow row : table) {
        exec.setProgress(rowIdx / (double) rowCount, "Processing row " + rowIdx++ + " of " + rowCount);
        exec.checkCanceled();
        window.add(row);
        final DataCell[] cells = new DataCell[m_ops.length + m_cols2KeepIdxs.length];
        int idx = 0;
        // handle the retained columns
        for (final int colIdx : m_cols2KeepIdxs) {
            cells[idx++] = row.getCell(colIdx);
        }
        final boolean windowFull = window.size() >= m_windowLength;
        for (int i = 0, length = m_ops.length; i < length; i++) {
            if (windowFull || m_handleMissings) {
                final int colIdx = m_aggrColIdxs[i];
                final AggregationOperator op = m_ops[i];
                for (final DataRow windowRow : window) {
                    op.compute(windowRow, colIdx);
                }
                cells[idx++] = op.getResult();
                op.reset();
            } else {
                // the window is not yet full return missing cells
                cells[idx++] = DataType.getMissingCell();
            }
        }
        if (windowFull) {
            // remove the first row only when the window is full
            // not during the missing value handling phase!
            window.removeFirst();
        }
        dc.addRowToTable(new DefaultRow(row.getKey(), cells));
    }
    dc.close();
    return dc.getTable();
}
Also used : AggregationOperator(org.knime.base.data.aggregation.AggregationOperator) DataCell(org.knime.core.data.DataCell) DefaultRow(org.knime.core.data.def.DefaultRow) DataRow(org.knime.core.data.DataRow) LinkedList(java.util.LinkedList)

Example 2 with AggregationOperator

use of org.knime.base.data.aggregation.AggregationOperator in project knime-core by knime.

the class MovingAggregationTableFactory method getCenterTable.

private BufferedDataTable getCenterTable(final ExecutionMonitor exec, final BufferedDataTable table, final BufferedDataContainer dc) throws CanceledExecutionException {
    final int rowCount = table.getRowCount();
    final LinkedList<DataRow> window = new LinkedList<>();
    int rowIdx = 0;
    int centerIdx = -1;
    for (final DataRow row : table) {
        exec.setProgress(rowIdx / (double) rowCount, "Processing row " + rowIdx++ + " of " + rowCount);
        exec.checkCanceled();
        window.add(row);
        // we have to subtract 1 since the indexing of the array starts with 0
        centerIdx = window.size() - m_windowLength / 2 - 1;
        if (centerIdx < 0) {
            // we have to fill the window first
            continue;
        }
        final DataCell[] cells = new DataCell[m_ops.length + m_cols2KeepIdxs.length];
        final DataRow centerRow = window.get(centerIdx);
        int idx = 0;
        // handle the retained columns
        for (final int colIdx : m_cols2KeepIdxs) {
            cells[idx++] = centerRow.getCell(colIdx);
        }
        final boolean windowFull = window.size() >= m_windowLength;
        for (int i = 0, length = m_ops.length; i < length; i++) {
            if (windowFull || m_handleMissings) {
                final int colIdx = m_aggrColIdxs[i];
                final AggregationOperator op = m_ops[i];
                for (final DataRow windowRow : window) {
                    op.compute(windowRow, colIdx);
                }
                cells[idx++] = op.getResult();
                op.reset();
            } else {
                // the window is not yet full return missing cells
                cells[idx++] = DataType.getMissingCell();
            }
        }
        dc.addRowToTable(new DefaultRow(centerRow.getKey(), cells));
        // not during the missing value handling phase!
        if (windowFull) {
            window.removeFirst();
        }
    }
    // we have to handle the remaining rows in the window
    while (window.size() > centerIdx) {
        exec.checkCanceled();
        final DataCell[] cells = new DataCell[m_ops.length + m_cols2KeepIdxs.length];
        int idx = 0;
        final DataRow centerRow = window.get(centerIdx);
        // handle the retained columns
        for (final int colIdx : m_cols2KeepIdxs) {
            cells[idx++] = centerRow.getCell(colIdx);
        }
        for (int i = 0, length = m_ops.length; i < length; i++) {
            if (m_handleMissings) {
                final int colIdx = m_aggrColIdxs[i];
                final AggregationOperator op = m_ops[i];
                for (final DataRow windowRow : window) {
                    op.compute(windowRow, colIdx);
                }
                cells[idx++] = op.getResult();
                op.reset();
            } else {
                // the window is not yet full return missing cells
                cells[idx++] = DataType.getMissingCell();
            }
        }
        window.removeFirst();
        dc.addRowToTable(new DefaultRow(centerRow.getKey(), cells));
    }
    dc.close();
    return dc.getTable();
}
Also used : AggregationOperator(org.knime.base.data.aggregation.AggregationOperator) DataCell(org.knime.core.data.DataCell) DefaultRow(org.knime.core.data.def.DefaultRow) DataRow(org.knime.core.data.DataRow) LinkedList(java.util.LinkedList)

Example 3 with AggregationOperator

use of org.knime.base.data.aggregation.AggregationOperator in project knime-core by knime.

the class MovingAggregationTableFactory method getForwardTable.

private BufferedDataTable getForwardTable(final ExecutionMonitor exec, final BufferedDataTable table, final BufferedDataContainer dc) throws CanceledExecutionException {
    final int rowCount = table.getRowCount();
    final LinkedList<DataRow> window = new LinkedList<>();
    int rowIdx = 0;
    for (final DataRow row : table) {
        exec.setProgress(rowIdx / (double) rowCount, "Processing row " + rowIdx++ + " of " + rowCount);
        exec.checkCanceled();
        window.add(row);
        final boolean windowFull = window.size() >= m_windowLength;
        if (!windowFull) {
            // we have to fill the window first
            continue;
        }
        final DataCell[] cells = new DataCell[m_ops.length + m_cols2KeepIdxs.length];
        final DataRow firstRow = window.getFirst();
        int idx = 0;
        // handle the retained columns
        for (final int colIdx : m_cols2KeepIdxs) {
            cells[idx++] = firstRow.getCell(colIdx);
        }
        for (int i = 0, length = m_ops.length; i < length; i++) {
            final int colIdx = m_aggrColIdxs[i];
            final AggregationOperator op = m_ops[i];
            for (final DataRow windowRow : window) {
                op.compute(windowRow, colIdx);
            }
            cells[idx++] = op.getResult();
            op.reset();
        }
        dc.addRowToTable(new DefaultRow(firstRow.getKey(), cells));
        // remove the first row only when the window is full
        // not during the missing value handling phase!
        window.removeFirst();
    }
    // we have to handle the remaining rows in the window
    while (!window.isEmpty()) {
        exec.checkCanceled();
        final DataCell[] cells = new DataCell[m_ops.length + m_cols2KeepIdxs.length];
        int idx = 0;
        final DataRow firstRow = window.getFirst();
        // handle the retained columns
        for (final int colIdx : m_cols2KeepIdxs) {
            cells[idx++] = firstRow.getCell(colIdx);
        }
        for (int i = 0, length = m_ops.length; i < length; i++) {
            if (m_handleMissings) {
                final int colIdx = m_aggrColIdxs[i];
                final AggregationOperator op = m_ops[i];
                for (final DataRow windowRow : window) {
                    op.compute(windowRow, colIdx);
                }
                cells[idx++] = op.getResult();
                op.reset();
            } else {
                // the window is not yet full return missing cells
                cells[idx++] = DataType.getMissingCell();
            }
        }
        window.removeFirst();
        dc.addRowToTable(new DefaultRow(firstRow.getKey(), cells));
    }
    dc.close();
    return dc.getTable();
}
Also used : AggregationOperator(org.knime.base.data.aggregation.AggregationOperator) DataCell(org.knime.core.data.DataCell) DefaultRow(org.knime.core.data.def.DefaultRow) DataRow(org.knime.core.data.DataRow) LinkedList(java.util.LinkedList)

Example 4 with AggregationOperator

use of org.knime.base.data.aggregation.AggregationOperator in project knime-core by knime.

the class AggregationCellFactory method getCells.

/**
 * {@inheritDoc}
 */
@Override
public DataCell[] getCells(final DataRow row) {
    final DataCell[] cells = new DataCell[m_operators.length];
    for (int i = 0; i < m_operators.length; i++) {
        final AggregationOperator operator = m_operators[i];
        operator.compute(row, m_colIdxs);
        cells[i] = operator.getResult();
        operator.reset();
    }
    return cells;
}
Also used : NamedAggregationOperator(org.knime.base.data.aggregation.NamedAggregationOperator) AggregationOperator(org.knime.base.data.aggregation.AggregationOperator) DataCell(org.knime.core.data.DataCell)

Example 5 with AggregationOperator

use of org.knime.base.data.aggregation.AggregationOperator in project knime-core by knime.

the class MemoryGroupByTable method createResultTable.

private BufferedDataTable createResultTable(final ExecutionContext exec, final DataTableSpec resultSpec) throws CanceledExecutionException {
    final BufferedDataContainer dc = exec.createDataContainer(resultSpec);
    int groupCounter = 0;
    final int size = m_vals.size();
    for (final Entry<GroupKey, ColumnAggregator[]> entry : m_vals.entrySet()) {
        exec.checkCanceled();
        exec.setProgress(groupCounter / (double) size, "Writing group " + groupCounter + " of " + size);
        final GroupKey groupVals = entry.getKey();
        final ColumnAggregator[] colAggregators = entry.getValue();
        final RowKey rowKey = RowKey.createRowKey(groupCounter++);
        final DataCell[] rowVals = new DataCell[groupVals.size() + colAggregators.length];
        // add the group values first
        int valIdx = 0;
        for (final DataCell groupCell : groupVals.getGroupVals()) {
            rowVals[valIdx++] = groupCell;
        }
        // add the aggregation values
        for (final ColumnAggregator colAggr : colAggregators) {
            final AggregationOperator operator = colAggr.getOperator(getGlobalSettings());
            rowVals[valIdx++] = operator.getResult();
            if (operator.isSkipped()) {
                // add skipped groups and the column that causes the skipping
                // into the skipped groups map
                addSkippedGroup(colAggr.getOriginalColName(), operator.getSkipMessage(), groupVals.getGroupVals());
            }
            // reset the operator for the next group
            operator.reset();
        }
        final DataRow newRow = new DefaultRow(rowKey, rowVals);
        dc.addRowToTable(newRow);
        // add hilite mappings if enabled
        if (isEnableHilite()) {
            final Set<RowKey> oldKeys = m_rowKeys.get(groupVals);
            addHiliteMapping(rowKey, oldKeys);
        }
    }
    dc.close();
    return dc.getTable();
}
Also used : AggregationOperator(org.knime.base.data.aggregation.AggregationOperator) BufferedDataContainer(org.knime.core.node.BufferedDataContainer) RowKey(org.knime.core.data.RowKey) DataRow(org.knime.core.data.DataRow) ColumnAggregator(org.knime.base.data.aggregation.ColumnAggregator) DataCell(org.knime.core.data.DataCell) DefaultRow(org.knime.core.data.def.DefaultRow)

Aggregations

AggregationOperator (org.knime.base.data.aggregation.AggregationOperator)13 DataCell (org.knime.core.data.DataCell)7 DataRow (org.knime.core.data.DataRow)6 DefaultRow (org.knime.core.data.def.DefaultRow)6 LinkedList (java.util.LinkedList)3 ColumnAggregator (org.knime.base.data.aggregation.ColumnAggregator)2 NamedAggregationOperator (org.knime.base.data.aggregation.NamedAggregationOperator)2 RowKey (org.knime.core.data.RowKey)2 InvalidSettingsException (org.knime.core.node.InvalidSettingsException)2 NodeSettingsRO (org.knime.core.node.NodeSettingsRO)2 Dimension (java.awt.Dimension)1 Point (java.awt.Point)1 AggregationMethod (org.knime.base.data.aggregation.AggregationMethod)1 DataColumnSpec (org.knime.core.data.DataColumnSpec)1 DataTableSpec (org.knime.core.data.DataTableSpec)1 BufferedDataContainer (org.knime.core.node.BufferedDataContainer)1 NotConfigurableException (org.knime.core.node.NotConfigurableException)1 Pair (org.knime.core.util.Pair)1