feat(results): human labels, formatted values, nice bins, date labels, current home
Every metric carries a plain-English label and a display-formatted value (grouping, percent, the field's display format), histogram bins use nice edges with formatted labels, date buckets are labelled by unit, warnings appear only when true, and the Analyses home shows saved analyses, watches and recent runs with honest empty states (and no mojibake). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
c90d6c9866
commit
d8b52113ca
19 files changed
+901
-92
No files matched your search
@@ -64,7 +64,60 @@ import static org.assertj.core.api.Assertions.within;
|
||||
abstract class EngineContractTest extends EngineFixture
|
||||
{
|
||||
/*******************************************************************************
|
||||
** All numeric moments and percentiles agree to 1e-9.
|
||||
** Every emitted key across all profile kinds has a label, on every backend.
|
||||
*******************************************************************************/
|
||||
@Test
|
||||
void presentationAcrossProfileKinds() throws Exception
|
||||
{
|
||||
java.util.Set<String> keys = new java.util.HashSet<>();
|
||||
for(String field : List.of("amount", "quantity", "note", "paid", "order_date", "created"))
|
||||
{
|
||||
ColumnProfile profile = service.columnProfile(column(field));
|
||||
java.util.List<Metric> metrics = new java.util.ArrayList<>(profile.getCounts());
|
||||
if(profile.getNumeric() != null)
|
||||
{
|
||||
metrics.addAll(profile.getNumeric().getMetrics());
|
||||
}
|
||||
if(profile.getText() != null)
|
||||
{
|
||||
metrics.addAll(profile.getText().getMetrics());
|
||||
}
|
||||
if(profile.getDates() != null)
|
||||
{
|
||||
metrics.addAll(profile.getDates().getMetrics());
|
||||
assertThat(profile.getChart().getX().getLabel()).endsWith(" (day)");
|
||||
assertThat(profile.getChart().getSeries().getFirst().getPoints().getFirst().getX().toString()).isEqualTo("2026-01-01");
|
||||
}
|
||||
if(profile.getBooleans() != null)
|
||||
{
|
||||
metrics.addAll(profile.getBooleans());
|
||||
}
|
||||
for(Metric metric : metrics)
|
||||
{
|
||||
keys.add(metric.getKey());
|
||||
assertThat(metric.getLabel()).isEqualTo(com.kingsrook.qbits.dataanalysis.engine.MetricLabels.label(metric.getKey(), metric.getValueType()));
|
||||
assertThat(metric.getFormatted()).isNotBlank();
|
||||
}
|
||||
}
|
||||
assertThat(keys).containsExactlyInAnyOrder("rows", "nonNull", "nulls", "blanks", "distinct", "uniqueness", "min", "max", "mean", "sum", "stddev",
|
||||
"p1", "p5", "p25", "p50", "p75", "p95", "p99", "zeros", "negatives", "outliers", "minLength", "maxLength", "meanLength", "true", "false", "range");
|
||||
ColumnProfile amount = service.columnProfile(column("amount"));
|
||||
assertThat(metric(amount.getNumeric().getMetrics(), "sum").getFormatted()).isEqualTo("$1,170.00");
|
||||
assertThat(amount.getNumeric().getHistogram()).allSatisfy(v -> assertThat(v.getLabel()).contains("$"));
|
||||
Metric uniqueness = metric(amount.getCounts(), "uniqueness");
|
||||
assertThat(uniqueness.getValueType().name()).isEqualTo("PERCENT");
|
||||
assertThat(uniqueness.getValue().toString()).isEqualTo("0.727273");
|
||||
assertThat(uniqueness.getFormatted()).isEqualTo("72.7%");
|
||||
assertThat(metric(service.columnProfile(column("created")).getDates().getMetrics(), "min").getFormatted()).isEqualTo("2026-01-01 06:00");
|
||||
assertThat(service.columnProfile(column("note")).getWarnings()).isEmpty();
|
||||
var table = service.tableProfile(new TableProfileRequest().withTableName("orders").withFields(List.of("note")));
|
||||
assertThat(table.getRowCount().getLabel()).isEqualTo("Rows");
|
||||
assertThat(table.getFields().getFirst().getNulls().getLabel()).isEqualTo("Nulls");
|
||||
assertThat(table.getFields().getFirst().getBlanks().getLabel()).isEqualTo("Blanks");
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
** Decimal moments retain ten significant digits; drills retain exact membership.
|
||||
*******************************************************************************/
|
||||
@Test
|
||||
void numericProfile() throws Exception
|
||||
@@ -80,12 +133,12 @@ abstract class EngineContractTest extends EngineFixture
|
||||
Map.entry("zeros", "2"), Map.entry("negatives", "1"), Map.entry("outliers", "1"));
|
||||
for(var entry : expected.entrySet())
|
||||
{
|
||||
assertMetric(result.getNumeric().getMetrics(), entry.getKey(), entry.getValue());
|
||||
assertMetric(result.getNumeric().getMetrics(), entry.getKey(), new BigDecimal(entry.getValue()).round(new java.math.MathContext(10)).toPlainString());
|
||||
}
|
||||
double[] values = {-10, 0, 0, 10, 10, 20, 20, 30, 40, 50, 1000};
|
||||
double mean = 1170.0 / 11;
|
||||
double variance = java.util.Arrays.stream(values).map(v -> Math.pow(v - mean, 2)).sum() / 10;
|
||||
assertMetric(result.getNumeric().getMetrics(), "stddev", Double.toString(Math.sqrt(variance)));
|
||||
assertMetric(result.getNumeric().getMetrics(), "stddev", BigDecimal.valueOf(Math.sqrt(variance)).round(new java.math.MathContext(10)).toPlainString());
|
||||
assertThat(result.getNumeric().getHistogram()).hasSize(22);
|
||||
assertThat(result.getNumeric().getHistogram().stream().mapToLong(v -> v.getCount()).sum()).isEqualTo(11);
|
||||
assertThat(result.getNumeric().getOutliers()).singleElement().satisfies(v -> assertThat(new BigDecimal(v.getValue().toString())).isEqualByComparingTo("1000"));
|
||||
@@ -156,7 +209,7 @@ abstract class EngineContractTest extends EngineFixture
|
||||
assertThat(table.getFields()).anySatisfy(f ->
|
||||
{
|
||||
assertThat(f.getField()).isEqualTo("note");
|
||||
assertThat(f.getCompleteness().doubleValue()).isCloseTo(8.0 / 12, within(1e-9));
|
||||
assertThat(f.getCompleteness().doubleValue()).isEqualTo(0.666667);
|
||||
});
|
||||
assertThat(table.getCandidateKeys()).anyMatch(k -> k.getFields().equals(List.of("id")));
|
||||
var pairs = service.tableProfile(new TableProfileRequest().withTableName("orders").withFields(List.of("status", "quantity")));
|
||||
@@ -409,7 +462,7 @@ abstract class EngineContractTest extends EngineFixture
|
||||
assertThat(ColumnProfiler.autoBucket(first, first.plusYears(2).plusDays(1))).isEqualTo(AnalysisBackend.DateUnit.MONTH);
|
||||
assertThat(ColumnProfiler.autoBucket(first, first.plusYears(10))).isEqualTo(AnalysisBackend.DateUnit.MONTH);
|
||||
assertThat(ColumnProfiler.autoBucket(first, first.plusYears(10).plusDays(1))).isEqualTo(AnalysisBackend.DateUnit.YEAR);
|
||||
for(AnalysisBackend.DateUnit unit : List.of(AnalysisBackend.DateUnit.WEEK, AnalysisBackend.DateUnit.MONTH, AnalysisBackend.DateUnit.YEAR))
|
||||
for(AnalysisBackend.DateUnit unit : List.of(AnalysisBackend.DateUnit.WEEK, AnalysisBackend.DateUnit.MONTH, AnalysisBackend.DateUnit.QUARTER, AnalysisBackend.DateUnit.YEAR))
|
||||
{
|
||||
var buckets = service.backend("orders").dateBuckets("orders", null, "order_date", unit, java.time.ZoneId.of("America/Chicago"));
|
||||
assertThat(buckets.stream().mapToLong(AnalysisBackend.GroupCount::count).sum()).isEqualTo(12);
|
||||
|
||||
Reference in new issue
Block a user