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> </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> </p>");
buffer.append("</body>\n");
buffer.append("</html>\n");
buffer.append("");
return buffer.toString();
}
Aggregations