From cab44d993f5acc4377e7e286fc0c1ae8e382599f Mon Sep 17 00:00:00 2001 From: Big Andy <8012398+big-andy-coates@users.noreply.github.com> Date: Wed, 11 Oct 2023 14:58:22 +0100 Subject: [PATCH] Sort the overall functional results by score --- .github/dependabot.yml | 10 -- .../test/perf/testsuite/output/Summary.java | 95 ++++++++++++------- 2 files changed, 63 insertions(+), 42 deletions(-) diff --git a/.github/dependabot.yml b/.github/dependabot.yml index ed49f2f..7493132 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -8,11 +8,6 @@ registries: maven-snapshots: type: maven-repository url: https://s01.oss.sonatype.org/content/repositories/snapshots/ - creek-github-packages: - type: maven-repository - url: https://maven.pkg.github.com/creek-service/* - username: "Creek-Bot-Token" - password: "\u0067hp_LtyvXrQZen3WlKenUhv21Mg6NG38jn0AO2YH" updates: - package-ecosystem: github-actions directory: / @@ -23,11 +18,6 @@ updates: directory: / registries: - maven-snapshots - - creek-github-packages open-pull-requests-limit: 50 - schedule: - interval: monthly - - package-ecosystem: docker - directory: / schedule: interval: monthly \ No newline at end of file diff --git a/src/main/java/org/creekservice/kafka/test/perf/testsuite/output/Summary.java b/src/main/java/org/creekservice/kafka/test/perf/testsuite/output/Summary.java index 5c1fda2..fb0e283 100644 --- a/src/main/java/org/creekservice/kafka/test/perf/testsuite/output/Summary.java +++ b/src/main/java/org/creekservice/kafka/test/perf/testsuite/output/Summary.java @@ -22,7 +22,9 @@ import java.text.NumberFormat; import java.time.Duration; +import java.util.ArrayList; import java.util.Arrays; +import java.util.Comparator; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -60,51 +62,78 @@ public String toString() { } private static Table createTable(final Map results) { - final Map> counts = + final Map> counts = buildCounts(results); + + final List specColumns = buildSpecHeaders(counts); + + final List headers = new ArrayList<>(specColumns); + headers.add(0, COL_IMPL); + + return buildTable(counts, specColumns, headers); + } + + private static Map> buildCounts( + final Map results) { + + final Map> counts = results.entrySet().stream() .collect(toMap(e -> e.getKey().name(), e -> resultCounts(e.getValue()))); - final List specs = + counts.values() + .forEach( + specCounts -> + specCounts.put( + COL_OVERALL, + specCounts.values().stream() + .reduce(new Counts(), Counts::combine))); + return counts; + } + + private static Map resultCounts(final JsonSchemaTestSuite.Result result) { + final Map counts = new HashMap<>(); + Arrays.stream(SchemaSpec.values()).forEach(s -> counts.put(s.name(), new Counts())); + result.visit((spec, r) -> counts.get(spec.name()).add(r)); + return counts; + } + + private static List buildSpecHeaders(final Map> counts) { + final List specColumnHeaders = Arrays.stream(SchemaSpec.values()) + .map(SchemaSpec::name) .filter( - spec -> + name -> counts.values().stream() - .map(map -> map.get(spec)) + .map(map -> map.get(name)) .anyMatch(c -> c.totalTotal() > 0)) .collect(toList()); - final List headers = specs.stream().map(SchemaSpec::name).collect(toList()); - - headers.add(0, COL_IMPL); - headers.add(1, COL_OVERALL); + specColumnHeaders.add(0, COL_OVERALL); + return List.copyOf(specColumnHeaders); + } + private static Table buildTable( + final Map> counts, + final List specColumns, + final List headers) { final Table table = new Table(headers); - counts.forEach((impl, cs) -> populateRow(table.addRow(), impl, cs, specs)); + counts.entrySet().stream() + .sorted( + Comparator.>>comparingDouble( + e1 -> e1.getValue().get(COL_OVERALL).score()) + .reversed()) + .forEach(e -> populateRow(table.addRow(), e.getKey(), e.getValue(), specColumns)); return table; } - private static Map resultCounts(final JsonSchemaTestSuite.Result result) { - final Map counts = new HashMap<>(); - Arrays.stream(SchemaSpec.values()).forEach(s -> counts.put(s, new Counts())); - - result.visit((spec, r) -> counts.get(spec).add(r)); - - return counts; - } - private static void populateRow( final Table.Row row, final String impl, - final Map specCounts, - final List specs) { + final Map specCounts, + final List specColumns) { row.put(COL_IMPL, impl); - - specs.forEach(spec -> row.put(spec.name(), formatCell(specCounts.get(spec)))); - - final Counts overall = specCounts.values().stream().reduce(new Counts(), Counts::combine); - row.put(COL_OVERALL, formatCell(overall)); + specColumns.forEach(col -> row.put(col, formatCell(specCounts.get(col)))); } private static String formatCell(final Counts counts) { @@ -130,7 +159,7 @@ private static String formatCell(final Counts counts) { + counts.optFailPct() + lineSeparator() + "score: " - + counts.score(); + + counts.formattedScore(); } private static class Counts { @@ -183,15 +212,17 @@ String optFailPct() { return percentage(optFail(), optTotal); } - String score() { - final double reqPct = reqTotal == 0 ? 0 : ((double) reqPassed / reqTotal); - final double optPct = optTotal == 0 ? 0 : ((double) optPassed / optTotal); - final double score = - 100 * ((reqPct * REQUIRED_WEIGHT) + optPct) / (REQUIRED_WEIGHT + 1); + String formattedScore() { final NumberFormat nf = NumberFormat.getNumberInstance(); nf.setMinimumFractionDigits(1); nf.setMaximumFractionDigits(1); - return nf.format(score); + return nf.format(score()); + } + + double score() { + final double reqPct = reqTotal == 0 ? 0 : ((double) reqPassed / reqTotal); + final double optPct = optTotal == 0 ? 0 : ((double) optPassed / optTotal); + return 100 * ((reqPct * REQUIRED_WEIGHT) + optPct) / (REQUIRED_WEIGHT + 1); } static Counts combine(final Counts c0, final Counts c1) {