Skip to content

Commit

Permalink
Sort the overall functional results by score (#38)
Browse files Browse the repository at this point in the history
  • Loading branch information
big-andy-coates authored Oct 11, 2023
1 parent b3b5107 commit 6d6e352
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 42 deletions.
10 changes: 0 additions & 10 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: /
Expand All @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -60,51 +62,78 @@ public String toString() {
}

private static Table createTable(final Map<SerdeImpl, JsonSchemaTestSuite.Result> results) {
final Map<String, Map<SchemaSpec, Counts>> counts =
final Map<String, Map<String, Counts>> counts = buildCounts(results);

final List<String> specColumns = buildSpecHeaders(counts);

final List<String> headers = new ArrayList<>(specColumns);
headers.add(0, COL_IMPL);

return buildTable(counts, specColumns, headers);
}

private static Map<String, Map<String, Counts>> buildCounts(
final Map<SerdeImpl, JsonSchemaTestSuite.Result> results) {

final Map<String, Map<String, Counts>> counts =
results.entrySet().stream()
.collect(toMap(e -> e.getKey().name(), e -> resultCounts(e.getValue())));

final List<SchemaSpec> specs =
counts.values()
.forEach(
specCounts ->
specCounts.put(
COL_OVERALL,
specCounts.values().stream()
.reduce(new Counts(), Counts::combine)));
return counts;
}

private static Map<String, Counts> resultCounts(final JsonSchemaTestSuite.Result result) {
final Map<String, Counts> 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<String> buildSpecHeaders(final Map<String, Map<String, Counts>> counts) {
final List<String> 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<String> 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<String, Map<String, Counts>> counts,
final List<String> specColumns,
final List<String> headers) {
final Table table = new Table(headers);

counts.forEach((impl, cs) -> populateRow(table.addRow(), impl, cs, specs));
counts.entrySet().stream()
.sorted(
Comparator.<Map.Entry<String, Map<String, Counts>>>comparingDouble(
e1 -> e1.getValue().get(COL_OVERALL).score())
.reversed())
.forEach(e -> populateRow(table.addRow(), e.getKey(), e.getValue(), specColumns));

return table;
}

private static Map<SchemaSpec, Counts> resultCounts(final JsonSchemaTestSuite.Result result) {
final Map<SchemaSpec, Counts> 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<SchemaSpec, Counts> specCounts,
final List<SchemaSpec> specs) {
final Map<String, Counts> specCounts,
final List<String> 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) {
Expand All @@ -130,7 +159,7 @@ private static String formatCell(final Counts counts) {
+ counts.optFailPct()
+ lineSeparator()
+ "score: "
+ counts.score();
+ counts.formattedScore();
}

private static class Counts {
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 6d6e352

Please sign in to comment.