|
11 | 11 | import org.apache.commons.text.CaseUtils;
|
12 | 12 |
|
13 | 13 | import java.util.ArrayList;
|
| 14 | +import java.util.HashMap; |
14 | 15 | import java.util.List;
|
15 | 16 | import java.util.Map;
|
16 | 17 | import java.util.stream.Collectors;
|
@@ -56,7 +57,10 @@ public List<TableColumn> getColumns() {
|
56 | 57 | columns.add(createIdColumn());
|
57 | 58 | columns.add(createNameColumn());
|
58 | 59 |
|
59 |
| - item.getResult().keySet().forEach(property -> columns.add(createResultColumn(property))); |
| 60 | + item.getResult().keySet().forEach(property -> { |
| 61 | + columns.add(createResultAbsoluteColumn(property)); |
| 62 | + columns.add(createResultRelativeColumn(property)); |
| 63 | + }); |
60 | 64 |
|
61 | 65 | columns.add(createDistributionColumn());
|
62 | 66 |
|
@@ -87,14 +91,22 @@ protected TableColumn createNameColumn() {
|
87 | 91 | .build();
|
88 | 92 | }
|
89 | 93 |
|
90 |
| - protected TableColumn createResultColumn(String property) { |
| 94 | + protected TableColumn createResultAbsoluteColumn(String property) { |
91 | 95 | return new TableColumn.ColumnBuilder()
|
92 |
| - .withDataPropertyKey(property) |
93 |
| - .withHeaderLabel(CaseUtils.toCamelCase(property, true)) |
| 96 | + .withDataPropertyKey(String.format("%s-absolute", property)) |
| 97 | + .withHeaderLabel(String.format("# %s", CaseUtils.toCamelCase(property, true))) |
94 | 98 | .withHeaderClass(TableColumn.ColumnCss.NUMBER)
|
95 | 99 | .build();
|
96 | 100 | }
|
97 | 101 |
|
| 102 | + protected TableColumn createResultRelativeColumn(String property) { |
| 103 | + return new TableColumn.ColumnBuilder() |
| 104 | + .withDataPropertyKey(String.format("%s-relative", property)) |
| 105 | + .withHeaderLabel(String.format("%s (in %%)", CaseUtils.toCamelCase(property, true))) |
| 106 | + .withHeaderClass(TableColumn.ColumnCss.PERCENTAGE) |
| 107 | + .build(); |
| 108 | + } |
| 109 | + |
98 | 110 | protected TableColumn createDistributionColumn() {
|
99 | 111 | return new TableColumn.ColumnBuilder()
|
100 | 112 | .withDataPropertyKey("distribution")
|
@@ -145,21 +157,26 @@ public DetailedCell<String> getDistribution() {
|
145 | 157 | * @return the result.
|
146 | 158 | */
|
147 | 159 | @JsonAnyGetter
|
148 |
| - public Map<String, Integer> getResult() { |
149 |
| - return item.getResult(); |
| 160 | + public Map<String, Number> getResult() { |
| 161 | + Map<String, Number> result = new HashMap<>(); |
| 162 | + |
| 163 | + item.getResult().forEach((String key, Integer value) -> { |
| 164 | + result.put(String.format("%s-absolute", key), value); |
| 165 | + result.put(String.format("%s-relative", key), (value / (double) item.getTotal())); |
| 166 | + }); |
| 167 | + |
| 168 | + return result; |
150 | 169 | }
|
151 | 170 |
|
152 | 171 | protected DetailedCell<String> createColoredResultColumn(final Item item) {
|
153 | 172 | List<ContainerTag> spans = new ArrayList<>();
|
154 | 173 |
|
155 |
| - int total = item.getResult().values().stream().reduce(0, Integer::sum); |
156 |
| - |
157 | 174 | for (Map.Entry<String, String> color : colorProvider.getColorMapping().entrySet()) {
|
158 | 175 | String id = color.getKey();
|
159 | 176 | String hex = color.getValue();
|
160 | 177 |
|
161 | 178 | int val = item.getResult().get(id);
|
162 |
| - double percentage = (val / (double) total) * 100; |
| 179 | + double percentage = (val / (double) item.getTotal()) * 100; |
163 | 180 |
|
164 | 181 | spans.add(span()
|
165 | 182 | .withTitle(String.format("%s: %.2f%%", id, percentage))
|
|
0 commit comments