Search in sources :

Example 6 with DataValue

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

the class AscendingNumericTickPolicyStrategy method makeTicks.

private Double[] makeTicks(final double min, final double max, final int count) {
    double minimum = Math.min(min, max);
    minimum = (minimum <= Double.NEGATIVE_INFINITY ? -Double.MAX_VALUE : minimum);
    double maximum = Math.max(min, max);
    maximum = (maximum >= Double.POSITIVE_INFINITY ? Double.MAX_VALUE : maximum);
    if (count == 1) {
        return new Double[] { (minimum + maximum) / 2 };
    }
    // so step is <= Double.MAX_VALUE
    double step = Math.log10((maximum - minimum) / count);
    double base = Math.floor(step);
    double frac = step - base;
    if (minimum == maximum || Double.isInfinite(step) || Double.isNaN(step) || Double.isInfinite(base) || Double.isNaN(base) || Double.isInfinite(frac) || Double.isNaN(frac)) {
        return new Double[] { (minimum + maximum) / 2 };
    }
    ArrayList<Double> result = new ArrayList<Double>();
    if (frac < 0.1) {
        frac = 1;
    } else if (frac < 0.4) {
        frac = 2;
    } else if (frac < 0.6) {
        frac = 2.5;
    } else if (frac < 0.8) {
        frac = 5;
    } else {
        frac = 1;
        base += frac;
    }
    step = frac * Math.pow(10, base);
    double value = minimum;
    while (value + 0.55 * step < maximum) {
        if (result.size() == 0 || result.get(result.size() - 1) + EPSILON * step < value) {
            boolean add = true;
            for (DataValue v : getValues()) {
                if (v instanceof DoubleValue) {
                    double desVal = ((DoubleValue) v).getDoubleValue();
                    if (value + EPSILON * step > desVal && value < desVal) {
                        add = false;
                    } else if (value - EPSILON * step < desVal && value > desVal) {
                        add = false;
                    }
                }
            }
            if (add) {
                result.add(value);
            }
        }
        int m = 1;
        while (value + m * step == value) {
            m++;
        }
        value += m * step;
    }
    if (result.get(result.size() - 1) < maximum) {
        // enough space?
        if (result.get(result.size() - 1) + EPSILON * step > maximum) {
            result.remove(result.size() - 1);
        }
        result.add(maximum);
    }
    for (DataValue v : getValues()) {
        if (v instanceof DoubleValue) {
            double val = ((DoubleValue) v).getDoubleValue();
            if (!result.contains(val) && val > minimum && val < maximum) {
                result.add(val);
            }
        }
    }
    Collections.sort(result);
    return result.toArray(new Double[0]);
}
Also used : DataValue(org.knime.core.data.DataValue) DoubleValue(org.knime.core.data.DoubleValue) ArrayList(java.util.ArrayList)

Example 7 with DataValue

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

the class Axis method createToolTip.

private String createToolTip(final CoordinateMapping coordMapping) {
    String tooltip = "";
    for (DataValue v : coordMapping.getValues()) {
        if (v == null) {
            continue;
        }
        if (v instanceof DoubleValue) {
            double value = ((DoubleValue) v).getDoubleValue();
            if (Double.isNaN(value) || Double.isInfinite(value)) {
                continue;
            }
            tooltip += new BigDecimal(value, new MathContext(25)) + " ";
        } else {
            tooltip += v.toString() + " ";
        }
    }
    return tooltip.trim();
}
Also used : DataValue(org.knime.core.data.DataValue) DoubleValue(org.knime.core.data.DoubleValue) BigDecimal(java.math.BigDecimal) MathContext(java.math.MathContext)

Example 8 with DataValue

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

the class AccuracyScorerNodeModel method sort.

/**
 * @param order The cells to sort.
 */
private void sort(final DataCell[] order) {
    if (order.length == 0) {
        return;
    }
    DataType type = order[0].getType();
    for (DataCell dataCell : order) {
        type = DataType.getCommonSuperType(type, dataCell.getType());
    }
    final Comparator<DataCell> comparator;
    switch(m_sortingStrategy) {
        case InsertionOrder:
            if (m_sortingReversed) {
                reverse(order);
            }
            return;
        case Unsorted:
            return;
        case Lexical:
            if (StringCell.TYPE.isASuperTypeOf(type)) {
                Comparator<String> stringComparator;
                Collator instance = Collator.getInstance();
                // do not try to combine characters
                instance.setDecomposition(Collator.NO_DECOMPOSITION);
                // case and accents matter.
                instance.setStrength(Collator.IDENTICAL);
                @SuppressWarnings("unchecked") Comparator<String> collator = (Comparator<String>) (Comparator<?>) instance;
                stringComparator = collator;
                comparator = new StringValueComparator(stringComparator);
            } else if (DoubleCell.TYPE.isASuperTypeOf(type)) {
                comparator = new DataValueComparator() {

                    @Override
                    protected int compareDataValues(final DataValue v1, final DataValue v2) {
                        String s1 = v1.toString();
                        String s2 = v2.toString();
                        return s1.compareTo(s2);
                    }
                };
            } else {
                throw new IllegalStateException("Lexical sorting strategy is not supported.");
            }
            break;
        case Numeric:
            if (DoubleCell.TYPE.isASuperTypeOf(type)) {
                comparator = type.getComparator();
            } else {
                throw new IllegalStateException("Numerical sorting strategy is not supported.");
            }
            break;
        default:
            throw new IllegalStateException("Unrecognized sorting strategy: " + m_sortingStrategy);
    }
    Arrays.sort(order, comparator);
    if (m_sortingReversed) {
        reverse(order);
    }
}
Also used : DataValue(org.knime.core.data.DataValue) DataType(org.knime.core.data.DataType) DataCell(org.knime.core.data.DataCell) DataValueComparator(org.knime.core.data.DataValueComparator) Collator(java.text.Collator) StringValueComparator(org.knime.base.util.StringValueComparator) DataValueComparator(org.knime.core.data.DataValueComparator) Comparator(java.util.Comparator) StringValueComparator(org.knime.base.util.StringValueComparator)

Example 9 with DataValue

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

the class NominalValue method getNominalValues.

/**
 * @param colIndex
 * @return nominal values of the column
 * @since 3.5
 */
public Map<DataValue, Integer> getNominalValues(final int colIndex) {
    Iterator it = m_nominalValues[colIndex].entrySet().iterator();
    Map<DataValue, Integer> output = new HashMap<DataValue, Integer>(m_nominalValues[colIndex].size());
    while (it.hasNext()) {
        @SuppressWarnings("unchecked") Map.Entry<DataCell, MutableInteger> pair = (Map.Entry<DataCell, MutableInteger>) it.next();
        // if (!pair.getKey().isMissing()) {
        output.put(pair.getKey(), pair.getValue().intValue());
        // } //else {
        // output.put(((MissingCell)pair.getKey()).toString(), pair.getValue().intValue());
        // }
        // System.out.println( + " = " + );
        // avoids a ConcurrentModificationException
        it.remove();
    }
    return output;
}
Also used : MutableInteger(org.knime.core.util.MutableInteger) DataValue(org.knime.core.data.DataValue) HashMap(java.util.HashMap) MutableInteger(org.knime.core.util.MutableInteger) Iterator(java.util.Iterator) DataCell(org.knime.core.data.DataCell) HashMap(java.util.HashMap) Map(java.util.Map)

Example 10 with DataValue

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

the class AggregationMethods method getCompatibleMethodGroupList.

/**
 * @param type the {@link DataType} to check
 * @return the aggregation methods that are compatible
 * with the given {@link DataType} grouped by the supported data type
 * @since 2.6
 */
public static List<Entry<String, List<AggregationMethod>>> getCompatibleMethodGroupList(final DataType type) {
    final Map<Class<? extends DataValue>, List<AggregationMethod>> methodGroups = AggregationMethods.getCompatibleMethodGroups(type);
    final Set<Entry<Class<? extends DataValue>, List<AggregationMethod>>> methodSet = methodGroups.entrySet();
    final List<String> labels = new ArrayList<>(methodSet.size());
    final Map<String, List<AggregationMethod>> labelSet = new HashMap<>(methodSet.size());
    for (final Entry<Class<? extends DataValue>, List<AggregationMethod>> entry : methodSet) {
        final String label = getUserTypeLabel(entry.getKey());
        labels.add(label);
        labelSet.put(label, entry.getValue());
    }
    Collections.sort(labels);
    final List<Entry<String, List<AggregationMethod>>> list = new ArrayList<>(methodSet.size());
    for (final String label : labels) {
        final List<AggregationMethod> methods = labelSet.get(label);
        final Entry<String, List<AggregationMethod>> entry = new Map.Entry<String, List<AggregationMethod>>() {

            @Override
            public String getKey() {
                return label;
            }

            @Override
            public List<AggregationMethod> getValue() {
                return methods;
            }

            @Override
            public List<AggregationMethod> setValue(final List<AggregationMethod> value) {
                return methods;
            }
        };
        list.add(entry);
    }
    return list;
}
Also used : DataValue(org.knime.core.data.DataValue) CollectionDataValue(org.knime.core.data.collection.CollectionDataValue) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ArrayList(java.util.ArrayList) SettingsModelString(org.knime.core.node.defaultnodesettings.SettingsModelString) Entry(java.util.Map.Entry) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList)

Aggregations

DataValue (org.knime.core.data.DataValue)28 DataCell (org.knime.core.data.DataCell)9 DoubleValue (org.knime.core.data.DoubleValue)8 ArrayList (java.util.ArrayList)7 HashMap (java.util.HashMap)7 DataType (org.knime.core.data.DataType)6 HashSet (java.util.HashSet)5 Map (java.util.Map)5 DataTableSpec (org.knime.core.data.DataTableSpec)5 StringCell (org.knime.core.data.def.StringCell)5 LinkedHashMap (java.util.LinkedHashMap)4 LinkedHashSet (java.util.LinkedHashSet)4 Set (java.util.Set)4 DataColumnSpec (org.knime.core.data.DataColumnSpec)4 DataRow (org.knime.core.data.DataRow)3 DefaultRow (org.knime.core.data.def.DefaultRow)3 ActionEvent (java.awt.event.ActionEvent)2 ActionListener (java.awt.event.ActionListener)2 FileInputStream (java.io.FileInputStream)2 JMenu (javax.swing.JMenu)2