Skip to content

Commit

Permalink
Merge pull request #37 from jenkinsci/one-column
Browse files Browse the repository at this point in the history
add view handling for one-column data
  • Loading branch information
simonsymhoven authored Sep 6, 2022
2 parents 06e4e80 + ad0bedc commit 25322cf
Show file tree
Hide file tree
Showing 16 changed files with 298 additions and 62 deletions.
101 changes: 95 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<h1 align="center">Nested Data Reporting Plugin</h1>

<p align="center">
Jenkins plugin to report data from nested json as pie-charts, trend-charts and data tables.
Jenkins plugin to report data from nested data as pie-charts, trend-charts and data tables.
<br />
<a href="https://github.com/jenkinsci/nested-data-reporting-plugin/blob/master/README.md"><strong>Explore the docs »</strong></a>
<br />
Expand All @@ -29,7 +29,7 @@

## Introduction

This plugin reports data from a nested json file as pie-charts, trend-charts and data tables.
This plugin reports data from a nested data file as pie-charts, trend-charts and data tables.
If an item has `items`, the `result` will be computed automatically for this parent item.
An example json file looks like this:

Expand Down Expand Up @@ -96,6 +96,8 @@ An example json file looks like this:
}
```

![ui](etc/ui-3.8.0.png)

To check your json you can use the [json schema](src/main/resources/report.json) to validate it.

> ⚠️ **Color Mapping**:
Expand All @@ -104,6 +106,97 @@ To check your json you can use the [json schema](src/main/resources/report.json)
> items and assigns a color to each attribute, which is used for the graphical representation. Otherwise
> a default color `#E9E9E9` is used for the missing property!
If your items only have one result, the visualization is different from the default one,
because the representation then makes no sense. Instead of the attributes of the result object,
the keys of the individual items are used as the basis for distribution. For example:

```
{
"items": [
{
"id": "Aktie",
"name": "Aktie",
"items": [
{
"id": "Aktie_1",
"name": "Aktie 1",
"result": {
"incorrect": 3541
}
},
{
"id": "Aktie_2",
"name": "Aktie 2",
"result": {
"incorrect": 4488
}
},
{
"id": "Aktie_3",
"name": "Aktie 3",
"result": {
"incorrect": 2973
}
}
]
},
{
"id": "Not_Found",
"name": "Not_Found",
"result": {
"incorrect": 8701
}
},
{
"id": "Renten",
"name": "Renten",
"items": [
{
"id": "Rente_1",
"name": "Rente1",
"result": {
"incorrect": 5762
}
},
{
"id": "Rente_2",
"name": "Rente2",
"result": {
"incorrect": 2271
}
}
]
},
{
"id": "Derivat",
"name": "Derivat",
"result": {
"incorrect": 2271
}
}
],
"colors": {
"Aktie": "#EF9A9A",
"Aktie_1": "#FFF59D",
"Aktie_2": "#A5D6A7",
"Aktie_3": "#FFCE30",
"Not_Found": "#E83845",
"Renten": "#E389B9",
"Rente_1": "#746AB0",
"Rente_2": "#288BA8",
"Derivat": "#0088FF"
}
}
```

Then your dashboard looks like this:
![ui](etc/ui-3.8.0-oc.png)


### Supported file formats

* JSON
* YAML/YML

### Visualization

Expand All @@ -129,10 +222,6 @@ The limited visualization from version **2.3.0** is thus resolved.
> of course represented in the aggregation of the first two levels.~~

### Example

![ui](etc/ui-3.2.0.png)

## Getting started

### Pipeline Step
Expand Down
5 changes: 3 additions & 2 deletions etc/Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ pipeline {
stage('Publish Data') {
steps {
checkout scm
publishReport reportFile: "etc/result.yaml"
}
publishReport reportFile: "etc/result.json", displayType: "dual"
publishReport reportFile: "etc/result-oc.json", displayType: "dual"
}
}
}
}
76 changes: 76 additions & 0 deletions etc/result-oc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
{
"items": [
{
"id": "Aktie",
"name": "Aktie",
"items": [
{
"id": "Aktie_1",
"name": "Aktie 1",
"result": {
"incorrect": 3541
}
},
{
"id": "Aktie_2",
"name": "Aktie 2",
"result": {
"incorrect": 4488
}
},
{
"id": "Aktie_3",
"name": "Aktie 3",
"result": {
"incorrect": 2973
}
}
]
},
{
"id": "Not_Found",
"name": "Not_Found",
"result": {
"incorrect": 8701
}
},
{
"id": "Renten",
"name": "Renten",
"items": [
{
"id": "Rente_1",
"name": "Rente1",
"result": {
"incorrect": 5762
}
},
{
"id": "Rente_2",
"name": "Rente2",
"result": {
"incorrect": 2271
}
}
]
},
{
"id": "Derivat",
"name": "Derivat",
"result": {
"incorrect": 2271
}
}
],
"colors": {
"Aktie": "#EF9A9A",
"Aktie_1": "#FFF59D",
"Aktie_2": "#A5D6A7",
"Aktie_3": "#FFCE30",
"Not_Found": "#E83845",
"Renten": "#E389B9",
"Rente_1": "#746AB0",
"Rente_2": "#288BA8",
"Derivat": "#0088FF"
}
}
28 changes: 11 additions & 17 deletions etc/result.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,26 @@
"name": "Aktie",
"items": [
{
"id": "Aktien1",
"name": "Aktien1",
"id": "Aktie_1",
"name": "Aktie 1",
"result": {
"incorrect": 3541,
"manually": 58,
"accurate": 6399
}
},
{
"id": "Aktie2",
"name": "Aktie2",
"id": "Aktie_2",
"name": "Aktie 2",
"result": {
"incorrect": 4488,
"manually": 55,
"accurate": 5456
}
},
{
"id": "Aktie3",
"name": "Aktie3",
"id": "Aktie_3",
"name": "Aktie 3",
"result": {
"incorrect": 2973,
"manually": 72,
Expand All @@ -36,17 +36,11 @@
{
"id": "Not_Found",
"name": "Not_Found",
"items": [
{
"id": "Not_Found",
"name": "Not_Found",
"result": {
"incorrect": 8701,
"manually": 0,
"accurate": 1298
}
}
]
"result": {
"incorrect": 8701,
"manually": 0,
"accurate": 1298
}
},
{
"id": "Renten",
Expand Down
Binary file removed etc/ui-3.2.0.png
Binary file not shown.
Binary file added etc/ui-3.8.0-oc.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added etc/ui-3.8.0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 2 additions & 5 deletions src/main/java/io/jenkins/plugins/reporter/ItemViewModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,7 @@ public String getDisplayName() {
*/
@SuppressWarnings("unused") // Called by jelly view
public String getItemDataModel() {
PieChartModel model = new PieChartModel(item.getId());
item.getResult().forEach((key, value) -> model.add(new PieData(key, value),
report.getColor(key)));
return new JacksonFacade().toJson(model);
return new JacksonFacade().toJson(item.getPieChartModel(report));
}

/**
Expand Down Expand Up @@ -125,7 +122,7 @@ public String getBuildTrend(final String configuration) {
}

return new JacksonFacade().toJson(new TrendChart().create(history, ChartModelConfiguration.fromJson(configuration),
new ItemSeriesBuilder(item), report));
new ItemSeriesBuilder(item), report, item.getItems()));
}

@SuppressWarnings("unused") // Called by jelly view
Expand Down
10 changes: 6 additions & 4 deletions src/main/java/io/jenkins/plugins/reporter/PublishReportStep.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import io.jenkins.plugins.reporter.model.Report;
import io.jenkins.plugins.reporter.model.Result;
import jenkins.tasks.SimpleBuildStep;
import org.apache.commons.lang3.StringUtils;
import org.everit.json.schema.Schema;
import org.everit.json.schema.ValidationException;
import org.everit.json.schema.loader.SchemaClient;
Expand All @@ -35,7 +34,6 @@
import java.io.Serializable;
import java.util.Arrays;
import java.util.Locale;
import java.util.Optional;

/**
* Publishes a report: Stores the created report in an {@link ReportAction}. The result is attached to the {@link Run}
Expand All @@ -46,8 +44,10 @@
@Extension
public class PublishReportStep extends Builder implements SimpleBuildStep, Serializable {

@Deprecated
private String jsonString;

@Deprecated
private String jsonFile;

private String displayType;
Expand All @@ -59,6 +59,7 @@ public PublishReportStep() {
super();
}

@Deprecated
public String getJsonString() {
return jsonString;
}
Expand All @@ -67,14 +68,15 @@ public String getJsonString() {
* use {@link #setReportFile(String)} instead.
*/
@DataBoundSetter
@Deprecated
public void setJsonString(final String jsonString) {
this.jsonString = jsonString;
}


@Deprecated
public String getJsonFile() {
return jsonFile;
}


/**
* use {@link #setReportFile(String)} instead.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public String getDisplayName() {

@Override
public String getUrlName() {
return ReportJobAction.ID;
return ReportJobAction.ID + "-" + report.hashCode();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import io.jenkins.plugins.reporter.charts.TrendChart;
import io.jenkins.plugins.reporter.model.Report;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Optional;

Expand Down Expand Up @@ -55,9 +56,10 @@ protected LinesChartModel createChartModel(String configuration) {
.filter(Optional::isPresent).findFirst().orElse(Optional.empty());

if (reportAction.isPresent()) {
return new TrendChart().create(createBuildHistory(), modelConfiguration, new ReportSeriesBuilder(), reportAction.get().getReport());
return new TrendChart().create(createBuildHistory(), modelConfiguration, new ReportSeriesBuilder(),
reportAction.get().getReport(), reportAction.get().getReport().getResult().getItems());
}

return new TrendChart().create(createBuildHistory(), modelConfiguration, new ReportSeriesBuilder(), new Report());
return new TrendChart().create(createBuildHistory(), modelConfiguration, new ReportSeriesBuilder(), new Report(), new ArrayList<>());
}
}
Loading

0 comments on commit 25322cf

Please sign in to comment.