带有JUnit样式记录的堆叠栏

时间:2019-10-06 11:37:20

标签: vega vega-lite

我有一个从JUnitXML文件导出的数据集,我想使用Vega-lite创建一个简单的可视化工具,用于每个测试套件的堆叠条。问题在于,在JUnit样式中,您没有获得“成功”的值,而是获得了“测试”字段,该字段是所有类型的测试的总和。

到目前为止,我只是天真地导出为整洁的数据,然后将其映射到x,y和颜色。

Current visualisation

Vega-editor

{
  "$schema": "https://vega.github.io/schema/vega-lite/v4.json",
  "data": {"name": "results"},
  "mark": "bar",
  "encoding": {
    "y": {"field": "name", "type": "nominal"},
    "x": {"aggregate": "sum", "field": "count", "type": "quantitative", "stack": "normalize"},
    "color": {"field": "type"}
  },
  "datasets": {
    "results": [
      {"name": "test_suite_0", "type": "tests", "count": 10},
      {"name": "test_suite_1", "type": "tests", "count": 10},
      {"name": "test_suite_2", "type": "tests", "count": 10},
      {"name": "test_suite_3", "type": "tests", "count": 10},
      {"name": "test_suite_4", "type": "tests", "count": 10},
      {"name": "general-test-suite", "type": "tests", "count": 10},
      {"name": "test_suite_0", "type": "skipped", "count": 2},
      {"name": "test_suite_1", "type": "skipped", "count": 2},
      {"name": "test_suite_2", "type": "skipped", "count": 3},
      {"name": "test_suite_3", "type": "skipped", "count": 4},
      {"name": "test_suite_4", "type": "skipped", "count": 3},
      {"name": "general-test-suite", "type": "skipped", "count": 1},
      {"name": "test_suite_0", "type": "failures", "count": 3},
      {"name": "test_suite_1", "type": "failures", "count": 2},
      {"name": "test_suite_2", "type": "failures", "count": 0},
      {"name": "test_suite_3", "type": "failures", "count": 2},
      {"name": "test_suite_4", "type": "failures", "count": 3},
      {"name": "general-test-suite", "type": "failures", "count": 3},
      {"name": "test_suite_0", "type": "errors", "count": 4},
      {"name": "test_suite_1", "type": "errors", "count": 4},
      {"name": "test_suite_2", "type": "errors", "count": 4},
      {"name": "test_suite_3", "type": "errors", "count": 1},
      {"name": "test_suite_4", "type": "errors", "count": 4},
      {"name": "general-test-suite", "type": "errors", "count": 2}
    ]
  }
}

我想更改测试值以取得成功,这应该是tests-(sum of count of other fields grouped by name)的与众不同之处,但是我不知道如何做。

2 个答案:

答案 0 :(得分:0)

您可以使用聚合转换,然后使用计算转换;这样的东西(vega editor):

{
  "data": {"name": "results"},
  "transform": [
    {
      "aggregate": [
        {"op": "sum", "field": "count", "as": "total"},
        {"op": "max", "field": "count", "as": "tests"}
      ],
      "groupby": ["name"]
    },
    {"calculate": "2 * datum.tests - datum.total", "as": "passed"}
  ],
  "mark": "bar",
  "encoding": {
    "x": {"type": "quantitative", "field": "passed"},
    "y": {"type": "nominal", "field": "name"}
  },
  "datasets": {
    "results": [
      {"count": 10, "name": "test_suite_0", "type": "tests"},
      {"count": 10, "name": "test_suite_1", "type": "tests"},
      {"count": 10, "name": "test_suite_2", "type": "tests"},
      {"count": 10, "name": "test_suite_3", "type": "tests"},
      {"count": 10, "name": "test_suite_4", "type": "tests"},
      {"count": 10, "name": "general-test-suite", "type": "tests"},
      {"count": 2, "name": "test_suite_0", "type": "skipped"},
      {"count": 2, "name": "test_suite_1", "type": "skipped"},
      {"count": 3, "name": "test_suite_2", "type": "skipped"},
      {"count": 4, "name": "test_suite_3", "type": "skipped"},
      {"count": 3, "name": "test_suite_4", "type": "skipped"},
      {"count": 1, "name": "general-test-suite", "type": "skipped"},
      {"count": 3, "name": "test_suite_0", "type": "failures"},
      {"count": 2, "name": "test_suite_1", "type": "failures"},
      {"count": 0, "name": "test_suite_2", "type": "failures"},
      {"count": 2, "name": "test_suite_3", "type": "failures"},
      {"count": 3, "name": "test_suite_4", "type": "failures"},
      {"count": 3, "name": "general-test-suite", "type": "failures"},
      {"count": 4, "name": "test_suite_0", "type": "errors"},
      {"count": 4, "name": "test_suite_1", "type": "errors"},
      {"count": 4, "name": "test_suite_2", "type": "errors"},
      {"count": 1, "name": "test_suite_3", "type": "errors"},
      {"count": 4, "name": "test_suite_4", "type": "errors"},
      {"count": 2, "name": "general-test-suite", "type": "errors"}
    ]
  }
}

enter image description here

答案 1 :(得分:0)

我终于得到了我想要的结果(并意识到它并不像我想象的那样漂亮)。我决定旋转这些列,计算每个测试套件的“通过”量,然后再次折叠以方便绘制:

Vega-editor

output