Search in sources :

Example 11 with Statistics3Table

use of org.knime.base.data.statistics.Statistics3Table in project knime-core by knime.

the class ExtendedStatisticsHTMLNodeView method createTopBottom.

/**
 * @param model
 * @return
 */
private String createTopBottom(final ExtendedStatisticsNodeModel model) {
    final List<String> columnNames = new ArrayList<>();
    final List<Map<DataCell, Integer>> nominals = new ArrayList<>();
    Statistics3Table statTable = model.getStatTable();
    if (statTable != null) {
        int colIdx = 0;
        for (DataColumnSpec spec : statTable.getSpec()) {
            if (model.getStatTable().getNominalValues(colIdx) != null) {
                columnNames.add(spec.getName());
                nominals.add(statTable.getNominalValues(colIdx));
            }
            ++colIdx;
        }
    }
    if (columnNames.isEmpty()) {
        return "";
    }
    StringBuilder buffer = new StringBuilder();
    buffer.append("<html>\n");
    buffer.append("<body>\n");
    buffer.append("<p>&nbsp</p>");
    buffer.append("<table border = \"1\">");
    for (int i = 0; i < columnNames.size(); i++) {
        if (nominals.get(i) != null) {
            buffer.append("<th style=\"white-space: nowrap\">" + columnNames.get(i) + "</th>");
        }
    }
    buffer.append("<tr valign=\"top\">");
    int[] missings = model.getStatTable().getNumberMissingValues();
    for (int i = 0; i < columnNames.size(); i++) {
        if (nominals.get(i) != null) {
            buffer.append("<td style=\"white-space: nowrap\"><strong>" + "No. missings: </strong>" + missings[i] + "</td>");
        }
    }
    buffer.append("</tr><tr valign=\"top\">");
    final int numNomValues = model.numOfNominalValues();
    for (Map<DataCell, Integer> map : nominals) {
        if (map != null) {
            buffer.append("<td nowrap=\"nowrap\">");
            final int size = map.size();
            if (size == 0) {
                buffer.append("<i>contains more than " + getNodeModel().numOfNominalValuesOutput() + " nominal values</i>");
            } else {
                int cnt = 0;
                buffer.append("<strong>Top " + numNomValues + ":</strong><br>");
                for (Map.Entry<DataCell, Integer> e : map.entrySet()) {
                    buffer.append(e.getKey() + " : " + e.getValue() + "<br>");
                    if (++cnt == numNomValues) {
                        break;
                    }
                }
                buffer.append("</td>");
            }
        }
    }
    buffer.append("</tr>");
    buffer.append("</tr><tr valign=\"top\">");
    for (Map<DataCell, Integer> map : nominals) {
        if (map != null) {
            buffer.append("<td style=\"white-space: nowrap\">");
            buffer.append("<strong>Bottom " + numNomValues + ":</strong><br>");
            final int size = map.size();
            if (size >= numNomValues) {
                int cnt = 0;
                for (DataCell c : map.keySet()) {
                    if (cnt >= Math.max(numNomValues, size - numNomValues)) {
                        buffer.append(c.toString() + " : " + map.get(c) + "<br>");
                    }
                    cnt++;
                }
                buffer.append("</td>");
            }
        }
    }
    buffer.append("</tr>");
    buffer.append("</table>");
    buffer.append("<p>&nbsp</p>");
    buffer.append("</body>\n");
    buffer.append("</html>\n");
    buffer.append("");
    return buffer.toString();
}
Also used : ArrayList(java.util.ArrayList) DataColumnSpec(org.knime.core.data.DataColumnSpec) Statistics3Table(org.knime.base.data.statistics.Statistics3Table) DataCell(org.knime.core.data.DataCell) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Aggregations

Statistics3Table (org.knime.base.data.statistics.Statistics3Table)11 DataColumnSpec (org.knime.core.data.DataColumnSpec)6 DataTableSpec (org.knime.core.data.DataTableSpec)4 BufferedDataTable (org.knime.core.node.BufferedDataTable)4 DataCell (org.knime.core.data.DataCell)3 ExecutionContext (org.knime.core.node.ExecutionContext)3 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 LinkedHashSet (java.util.LinkedHashSet)2 Map (java.util.Map)2 ColumnRearranger (org.knime.core.data.container.ColumnRearranger)2 NumberFormat (java.text.NumberFormat)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 Set (java.util.Set)1 HistogramColumn (org.knime.base.data.statistics.HistogramColumn)1 HistogramModel (org.knime.base.data.statistics.HistogramModel)1 DefaultDataArray (org.knime.base.node.util.DefaultDataArray)1 DataColumnDomain (org.knime.core.data.DataColumnDomain)1 DataValue (org.knime.core.data.DataValue)1