Search in sources :

Example 71 with StringCell

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

the class SorterNodeDialogPanel method update.

/**
 * Updates this panel by removing all current selections from the include
 * and exclude list. The include list will contain all column names from the
 * include list afterwards and the corresponding sort order for each column.
 * If the include list is null, all column names from the
 * {@link DataTableSpec} are added to the include list and the sort order is
 * set to 'ascending' for each column.
 *
 * @param spec the spec to retrieve the column names from
 * @param incl the list of columns to include
 * @param sortOrder ascending/descending order for the included columns
 */
public void update(final DataTableSpec spec, final List<DataCell> incl, final boolean[] sortOrder) {
    m_inclMdl.removeAllElements();
    m_exclMdl.removeAllElements();
    m_sortOrder.removeAllElements();
    int interncounter = 0;
    if (spec != null) {
        m_spec = spec;
        if ((incl == null) && (sortOrder == null)) {
            for (int i = 0; i < m_spec.getNumColumns(); i++) {
                final String c = spec.getColumnSpec(i).getName();
                m_inclMdl.addElement(c);
                m_sortOrder.add(true);
            }
        } else {
            for (int i = 0; i < m_spec.getNumColumns(); i++) {
                final String c = spec.getColumnSpec(i).getName();
                if (incl.contains(new StringCell(c))) {
                    m_inclMdl.addElement(c);
                    if (sortOrder[interncounter]) {
                        m_sortOrder.add(true);
                    } else {
                        m_sortOrder.add(false);
                    }
                    interncounter++;
                } else {
                    m_exclMdl.addElement(c);
                }
            }
        }
        repaint();
    }
}
Also used : StringCell(org.knime.core.data.def.StringCell)

Example 72 with StringCell

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

the class Unpivot2NodeModel method execute.

/**
 * {@inheritDoc}
 */
@Override
protected BufferedDataTable[] execute(final BufferedDataTable[] inData, final ExecutionContext exec) throws Exception {
    DataTableSpec inSpec = inData[0].getSpec();
    String[] retainedColumns = m_retainedColumns.applyTo(inSpec).getIncludes();
    String[] valueColumns = m_valueColumns.applyTo(inSpec).getIncludes();
    int[] valueColumnIndices = new int[valueColumns.length];
    for (int i = 0; i < valueColumnIndices.length; i++) {
        valueColumnIndices[i] = inSpec.findColumnIndex(valueColumns[i]);
    }
    int[] orderColumnIdx = new int[retainedColumns.length];
    for (int i = 0; i < orderColumnIdx.length; i++) {
        orderColumnIdx[i] = inSpec.findColumnIndex(retainedColumns[i]);
    }
    final double newRowCnt = inData[0].size() * valueColumns.length;
    final boolean enableHilite = m_enableHilite.getBooleanValue();
    LinkedHashMap<RowKey, Set<RowKey>> map = new LinkedHashMap<RowKey, Set<RowKey>>();
    DataTableSpec outSpec = createOutSpec(inSpec);
    BufferedDataContainer buf = exec.createDataContainer(outSpec);
    final boolean skipMissings = m_missingValues.getBooleanValue();
    for (DataRow row : inData[0]) {
        LinkedHashSet<RowKey> set = new LinkedHashSet<RowKey>();
        FilterColumnRow crow = new FilterColumnRow(row, orderColumnIdx);
        for (int i = 0; i < valueColumns.length; i++) {
            String colName = valueColumns[i];
            DataCell acell = row.getCell(valueColumnIndices[i]);
            if (acell.isMissing() && skipMissings) {
                // skip rows containing missing cells (in Value column(s))
                continue;
            }
            RowKey rowKey = RowKey.createRowKey(buf.size());
            if (enableHilite) {
                set.add(rowKey);
            }
            DefaultRow drow = new DefaultRow(rowKey, new StringCell(row.getKey().getString()), new StringCell(colName), acell);
            buf.addRowToTable(new AppendedColumnRow(rowKey, drow, crow));
            exec.checkCanceled();
            exec.setProgress(buf.size() / newRowCnt);
        }
        if (enableHilite) {
            map.put(crow.getKey(), set);
        }
    }
    buf.close();
    if (enableHilite) {
        m_trans.setMapper(new DefaultHiLiteMapper(map));
    } else {
        m_trans.setMapper(null);
    }
    return new BufferedDataTable[] { buf.getTable() };
}
Also used : LinkedHashSet(java.util.LinkedHashSet) DataTableSpec(org.knime.core.data.DataTableSpec) LinkedHashSet(java.util.LinkedHashSet) Set(java.util.Set) BufferedDataContainer(org.knime.core.node.BufferedDataContainer) RowKey(org.knime.core.data.RowKey) DataRow(org.knime.core.data.DataRow) LinkedHashMap(java.util.LinkedHashMap) 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) DefaultHiLiteMapper(org.knime.core.node.property.hilite.DefaultHiLiteMapper) FilterColumnRow(org.knime.base.data.filter.column.FilterColumnRow) AppendedColumnRow(org.knime.base.data.append.column.AppendedColumnRow)

Example 73 with StringCell

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

the class GlobalTimerinfoNodeModel method execute.

/**
 * {@inheritDoc}
 */
@Override
protected PortObject[] execute(final PortObject[] inData, final ExecutionContext exec) throws Exception {
    BufferedDataTable result0 = NodeTimer.GLOBAL_TIMER.getGlobalStatsTable(exec);
    BufferedDataContainer result1 = exec.createDataContainer(createSpecOut1());
    int rowcount = 0;
    for (IBundleGroupProvider provider : Platform.getBundleGroupProviders()) {
        for (IBundleGroup feature : provider.getBundleGroups()) {
            DataRow row = new DefaultRow(new RowKey("Row " + rowcount++), new StringCell(feature.getIdentifier()), new StringCell(feature.getVersion()));
            result1.addRowToTable(row);
        }
    }
    result1.close();
    return new PortObject[] { result0, result1.getTable() };
}
Also used : IBundleGroup(org.eclipse.core.runtime.IBundleGroup) IBundleGroupProvider(org.eclipse.core.runtime.IBundleGroupProvider) BufferedDataContainer(org.knime.core.node.BufferedDataContainer) RowKey(org.knime.core.data.RowKey) StringCell(org.knime.core.data.def.StringCell) BufferedDataTable(org.knime.core.node.BufferedDataTable) DefaultRow(org.knime.core.data.def.DefaultRow) DataRow(org.knime.core.data.DataRow) PortObject(org.knime.core.node.port.PortObject)

Example 74 with StringCell

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

the class BoxPlotter method updateOutliers.

/**
 * Sets the outliers as dotinfo to the scatterplotter drawing pane to
 * make them selectable and hilite-able.
 * @param yCoordinate the corresponding y coordinate.
 * @param box the box (column).
 * @return the mapped outliers for this column.
 */
protected List<DotInfo> updateOutliers(final Coordinate yCoordinate, final Box box) {
    int height = getDrawingPaneDimension().height - OFFSET;
    List<DotInfo> dotList = new ArrayList<DotInfo>();
    int x = box.getX();
    String colName = box.getColumnName();
    // the mild outliers
    Map<Double, Set<RowKey>> mildOutliers = ((BoxPlotDataProvider) getDataProvider()).getMildOutliers().get(colName);
    for (Map.Entry<Double, Set<RowKey>> entry : mildOutliers.entrySet()) {
        double value = entry.getKey();
        for (RowKey key : entry.getValue()) {
            int y = (int) getScreenYCoordinate(yCoordinate.calculateMappedValue(new DoubleCell(value), height)) - (OFFSET / 2);
            DotInfo dot = new DotInfo(x, y, key, delegateIsHiLit(key), ColorAttr.DEFAULT, 1, 0);
            dot.setXDomainValue(new StringCell(colName));
            dot.setYDomainValue(new DoubleCell(value));
            dot.setShape(ShapeFactory.getShape(ShapeFactory.CIRCLE));
            dotList.add(dot);
        }
    }
    // the extreme outliers
    Map<Double, Set<RowKey>> extremeOutliers = ((BoxPlotDataProvider) getDataProvider()).getExtremeOutliers().get(colName);
    for (Map.Entry<Double, Set<RowKey>> entry : extremeOutliers.entrySet()) {
        double value = entry.getKey();
        for (RowKey key : entry.getValue()) {
            int y = (int) getScreenYCoordinate(yCoordinate.calculateMappedValue(new DoubleCell(value), height)) - (OFFSET / 2);
            DotInfo dot = new DotInfo(x, y, key, delegateIsHiLit(key), ColorAttr.DEFAULT, 1, 0);
            dot.setShape(ShapeFactory.getShape(ShapeFactory.CROSS));
            dot.setXDomainValue(new StringCell(colName));
            dot.setYDomainValue(new DoubleCell(value));
            dotList.add(dot);
        }
    }
    return dotList;
}
Also used : DotInfo(org.knime.base.node.viz.plotter.scatter.DotInfo) LinkedHashSet(java.util.LinkedHashSet) Set(java.util.Set) RowKey(org.knime.core.data.RowKey) DoubleCell(org.knime.core.data.def.DoubleCell) ArrayList(java.util.ArrayList) Point(java.awt.Point) StringCell(org.knime.core.data.def.StringCell) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 75 with StringCell

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

the class BoxPlotter method updatePaintModel.

/**
 * {@inheritDoc}
 */
@Override
public void updatePaintModel() {
    if (getDataProvider() == null || ((BoxPlotDataProvider) getDataProvider()).getStatistics() == null) {
        m_selectedColumns = null;
        return;
    }
    Map<DataColumnSpec, double[]> statistics = ((BoxPlotDataProvider) getDataProvider()).getStatistics();
    DataTableSpec tableSpec = getDataProvider().getDataArray(getDataArrayIdx()).getDataTableSpec();
    if (m_selectedColumns == null) {
        m_selectedColumns = new LinkedHashSet<String>();
        for (DataColumnSpec colName : tableSpec) {
            if (colName.getType().isCompatible(DoubleValue.class)) {
                m_selectedColumns.add(colName.getName());
            }
        }
    }
    ((BoxPlotterProperties) getProperties()).updateColumnSelection(tableSpec, m_selectedColumns);
    // m_selectedColumns = ((BoxPlotterProperties)getProperties())
    // .getColumnFilter().getIncludedColumnList();
    Set<DataCell> columns = new LinkedHashSet<DataCell>();
    for (String colName : m_selectedColumns) {
        int colIdx = tableSpec.findColumnIndex(colName);
        if (colIdx >= 0) {
            columns.add(new StringCell(colName));
        }
    }
    createNominalXCoordinate(columns);
    if (!m_normalize) {
        double min = Double.POSITIVE_INFINITY;
        double max = Double.NEGATIVE_INFINITY;
        for (Map.Entry<DataColumnSpec, double[]> entry : statistics.entrySet()) {
            if (!m_selectedColumns.contains(entry.getKey().getName())) {
                continue;
            }
            double[] stats = entry.getValue();
            min = Math.min(min, stats[BoxPlotNodeModel.MIN]);
            max = Math.max(max, stats[BoxPlotNodeModel.MAX]);
        }
        setPreserve(false);
        if (m_selectedColumns.size() > 0) {
            createYCoordinate(min, max);
        } else {
            // hack to achieve an empty y axis
            createNominalYCoordinate(new LinkedHashSet<DataCell>());
        }
    } else {
        createNormalizedCoordinates(statistics);
    }
    ((BoxPlotterProperties) getProperties()).getColumnFilter().update(getDataProvider().getDataArray(getDataArrayIdx()).getDataTableSpec(), false, m_selectedColumns);
    updateSize();
}
Also used : LinkedHashSet(java.util.LinkedHashSet) DataTableSpec(org.knime.core.data.DataTableSpec) Point(java.awt.Point) DataColumnSpec(org.knime.core.data.DataColumnSpec) StringCell(org.knime.core.data.def.StringCell) DataCell(org.knime.core.data.DataCell) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Aggregations

StringCell (org.knime.core.data.def.StringCell)176 DataCell (org.knime.core.data.DataCell)130 DoubleCell (org.knime.core.data.def.DoubleCell)67 DefaultRow (org.knime.core.data.def.DefaultRow)65 IntCell (org.knime.core.data.def.IntCell)55 DataRow (org.knime.core.data.DataRow)52 DataTableSpec (org.knime.core.data.DataTableSpec)49 ArrayList (java.util.ArrayList)41 DataColumnSpec (org.knime.core.data.DataColumnSpec)37 RowKey (org.knime.core.data.RowKey)36 DataColumnSpecCreator (org.knime.core.data.DataColumnSpecCreator)26 BufferedDataContainer (org.knime.core.node.BufferedDataContainer)26 DataType (org.knime.core.data.DataType)22 LinkedHashSet (java.util.LinkedHashSet)21 BufferedDataTable (org.knime.core.node.BufferedDataTable)20 ColumnRearranger (org.knime.core.data.container.ColumnRearranger)19 InvalidSettingsException (org.knime.core.node.InvalidSettingsException)16 LinkedHashMap (java.util.LinkedHashMap)15 Test (org.junit.Test)15 HashMap (java.util.HashMap)11