Skip to content

Commit

Permalink
ADM-989 [frontend][backend]: fix the bug that rework ratio is not per…
Browse files Browse the repository at this point in the history
…centage in the metrics csv file (#1566)

* ADM-989 [backend]: add percent sign for metrics csv file

* ADM-989 [frontend]: add percent sign for pipeline change failure rate in the DORA detail page

* ADM-989 [frontend]: fix e2e test

* ADM-989 [frontend][backend]: fix the bug that rework ratio is not percentage in the metrics csv file

* ADM-989 [backend]: fix sonar issues
  • Loading branch information
zhou-yinyuan authored Aug 6, 2024
1 parent 54def8b commit a9a8895
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@
import java.util.stream.Stream;

import static heartbeat.service.report.calculator.ClassificationCalculator.pickDisplayNameFromObj;
import static heartbeat.util.DecimalUtil.formatDecimalFour;
import static heartbeat.util.TimeUtil.convertToSimpleISOFormat;
import static java.util.Optional.ofNullable;
import static java.util.concurrent.TimeUnit.HOURS;
Expand Down Expand Up @@ -422,7 +421,7 @@ private List<String[]> getRowFromRework(Rework rework) {
rows.add(new String[] { REWORK_FIELD, "Total rework times", String.valueOf(rework.getTotalReworkTimes()) });
rows.add(new String[] { REWORK_FIELD, "Total rework cards", String.valueOf(rework.getTotalReworkCards()) });
rows.add(new String[] { REWORK_FIELD, "Rework cards ratio(Total rework cards/Throughput%)",
formatDecimalFour(rework.getReworkCardsRatio()) });
DecimalUtil.formatDecimalTwo(rework.getReworkCardsRatio() * 100) });
return rows;
}

Expand Down Expand Up @@ -522,7 +521,7 @@ private List<String[]> getRowsFromPipelineChangeFailureRate(PipelineChangeFailur
pipelineChangeFailureRateOfPipelines.forEach(pipeline -> rows.add(new String[] { "Pipeline change failure rate",
pipeline.getName() + " / " + extractPipelineStep(pipeline.getStep())
+ " / Pipeline change failure rate(%)",
DecimalUtil.formatDecimalFour(pipeline.getFailureRate() * 100) }));
DecimalUtil.formatDecimalTwo(pipeline.getFailureRate() * 100) }));

AvgPipelineChangeFailureRate avgPipelineChangeFailureRate = pipelineChangeFailureRate
.getAvgPipelineChangeFailureRate();
Expand Down
6 changes: 0 additions & 6 deletions backend/src/main/java/heartbeat/util/DecimalUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ public interface DecimalUtil {

String FORMAT_2_DECIMALS = "0.00";

String FORMAT_4_DECIMALS = "0.0000";

static String formatDecimalTwo(double value) {
DecimalFormat decimalFormat = new DecimalFormat(FORMAT_2_DECIMALS);

Expand All @@ -21,8 +19,4 @@ static String formatDecimalTwo(float value) {
return Objects.equals(decimalFormat.format(value), "0.00") ? "0" : decimalFormat.format(value);
}

static String formatDecimalFour(double value) {
return new DecimalFormat(FORMAT_4_DECIMALS).format(value);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -584,9 +584,9 @@ void shouldConvertMetricDataToCsv() {
{ "Lead time for changes", "Average / Pipeline Lead Time", "0.05" },
{ "Lead time for changes", "Average / Total Lead Time", "0.05" },
{ "Pipeline change failure rate", "Heartbeat / Deploy prod / Pipeline change failure rate(%)",
"0.0000" },
"0" },
{ "Pipeline change failure rate",
"Heartbeat / Check Frontend License / Pipeline change failure rate(%)", "0.0000" },
"Heartbeat / Check Frontend License / Pipeline change failure rate(%)", "0" },
{ "Pipeline change failure rate", "Average / Pipeline change failure rate(%)", "0" },
{ "Pipeline mean time to recovery", "Heartbeat / Deploy prod / Pipeline mean time to recovery",
"0" },
Expand Down Expand Up @@ -791,9 +791,9 @@ void shouldHasContentWhenGetDataFromCsvGivenDataTypeIsMetric() {
{ "Lead time for changes", "Average / Pipeline Lead Time", "0.05" },
{ "Lead time for changes", "Average / Total Lead Time", "0.05" },
{ "Pipeline change failure rate", "Heartbeat / Deploy prod / Pipeline change failure rate(%)",
"0.0000" },
"0" },
{ "Pipeline change failure rate",
"Heartbeat / Check Frontend License / Pipeline change failure rate(%)", "0.0000" },
"Heartbeat / Check Frontend License / Pipeline change failure rate(%)", "0" },
{ "Pipeline change failure rate", "Average / Pipeline change failure rate(%)", "0" },
{ "Pipeline mean time to recovery", "Heartbeat / Deploy prod / Pipeline mean time to recovery",
"0" },
Expand Down Expand Up @@ -876,15 +876,15 @@ void shouldHasNoContentForAveragesWhenGetDataFromCsvGivenDataTypeIsMetricAndTheQ
.build();
String[][] expectedSavedData = new String[][] { { "Group", "Metrics", "Value" },
{ "Rework", "Total rework times", "3" }, { "Rework", "Total rework cards", "3" },
{ "Rework", "Rework cards ratio(Total rework cards/Throughput%)", "0.9900" },
{ "Rework", "Rework cards ratio(Total rework cards/Throughput%)", "99.00" },
{ "Deployment frequency", "Heartbeat / Deploy prod / Deployment frequency(Deployments/Day)",
"0.78" },
{ "Deployment frequency", "Heartbeat / Deploy prod / Deployment frequency(Deployment times)", "1" },
{ "Lead time for changes", "Heartbeat / Deploy prod / PR Lead Time", "0" },
{ "Lead time for changes", "Heartbeat / Deploy prod / Pipeline Lead Time", "0.02" },
{ "Lead time for changes", "Heartbeat / Deploy prod / Total Lead Time", "0.02" },
{ "Pipeline change failure rate", "Heartbeat / Deploy prod / Pipeline change failure rate(%)",
"0.0000" },
"0" },
{ "Pipeline mean time to recovery", "Heartbeat / Deploy prod / Pipeline mean time to recovery",
"0" }, };

Expand Down
27 changes: 0 additions & 27 deletions backend/src/test/java/heartbeat/util/DecimalUtilTest.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
package heartbeat.util;

import org.apache.commons.lang3.tuple.Pair;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

import java.util.List;

class DecimalUtilTest {

@Test
Expand Down Expand Up @@ -88,28 +85,4 @@ void shouldReturnZeroWhenCallFormatDecimalTwoGivenFloatValue() {
Assertions.assertEquals(expected, result);
}

@Test
void testFormatDecimalFour_ZeroValue() {
double value = 0;
String expected = "0.0000";

String result = DecimalUtil.formatDecimalFour(value);

Assertions.assertEquals(expected, result);
}

@Test
void testFormatDecimalFour_NonZeroValue() {
List<Pair<Double, String>> value = List.of(Pair.of(10.25671, "10.2567"), Pair.of(10.25, "10.2500"),
Pair.of(0.000006, "0.0000"));

List<String> result = List.of(DecimalUtil.formatDecimalFour(value.get(0).getLeft()),
DecimalUtil.formatDecimalFour(value.get(1).getLeft()),
DecimalUtil.formatDecimalFour(value.get(2).getLeft()));

Assertions.assertEquals(value.get(0).getRight(), result.get(0));
Assertions.assertEquals(value.get(1).getRight(), result.get(1));
Assertions.assertEquals(value.get(2).getRight(), result.get(2));
}

}
4 changes: 2 additions & 2 deletions frontend/e2e/fixtures/create-new/metric-20240603-20240604.csv
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@
"Classifications","Assignee / Qiuhong Lei(%)","33.33"
"Rework","Total rework times","1"
"Rework","Total rework cards","1"
"Rework","Rework cards ratio(Total rework cards/Throughput%)","0.3333"
"Rework","Rework cards ratio(Total rework cards/Throughput%)","33.33"
"Deployment frequency","Heartbeat / Deploy prod / Deployment frequency(Deployments/Day)","2.00"
"Deployment frequency","Heartbeat / Deploy prod / Deployment frequency(Deployment times)","4"
"Lead time for changes","Heartbeat / Deploy prod / PR Lead Time","10.78"
"Lead time for changes","Heartbeat / Deploy prod / Pipeline Lead Time","0.59"
"Lead time for changes","Heartbeat / Deploy prod / Total Lead Time","11.38"
"Pipeline change failure rate","Heartbeat / Deploy prod / Pipeline change failure rate(%)","0.0000"
"Pipeline change failure rate","Heartbeat / Deploy prod / Pipeline change failure rate(%)","0"
"Pipeline mean time to recovery","Heartbeat / Deploy prod / Pipeline mean time to recovery","0"
4 changes: 2 additions & 2 deletions frontend/e2e/fixtures/create-new/metric-20240605-20240606.csv
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@
"Classifications","Assignee / Man Tang(%)","100.00"
"Rework","Total rework times","1"
"Rework","Total rework cards","1"
"Rework","Rework cards ratio(Total rework cards/Throughput%)","1.0000"
"Rework","Rework cards ratio(Total rework cards/Throughput%)","100.00"
"Deployment frequency","Heartbeat / Deploy prod / Deployment frequency(Deployments/Day)","0.50"
"Deployment frequency","Heartbeat / Deploy prod / Deployment frequency(Deployment times)","1"
"Lead time for changes","Heartbeat / Deploy prod / PR Lead Time","1.86"
"Lead time for changes","Heartbeat / Deploy prod / Pipeline Lead Time","0.36"
"Lead time for changes","Heartbeat / Deploy prod / Total Lead Time","2.22"
"Pipeline change failure rate","Heartbeat / Deploy prod / Pipeline change failure rate(%)","0.0000"
"Pipeline change failure rate","Heartbeat / Deploy prod / Pipeline change failure rate(%)","0"
"Pipeline mean time to recovery","Heartbeat / Deploy prod / Pipeline mean time to recovery","0"
4 changes: 2 additions & 2 deletions frontend/e2e/fixtures/create-new/metric-20240607-20240607.csv
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@
"Classifications","Assignee / YinYuan Zhou(%)","100.00"
"Rework","Total rework times","0"
"Rework","Total rework cards","0"
"Rework","Rework cards ratio(Total rework cards/Throughput%)","0.0000"
"Rework","Rework cards ratio(Total rework cards/Throughput%)","0"
"Deployment frequency","Heartbeat / Deploy prod / Deployment frequency(Deployments/Day)","0"
"Deployment frequency","Heartbeat / Deploy prod / Deployment frequency(Deployment times)","0"
"Lead time for changes","Heartbeat / Deploy prod / PR Lead Time","0"
"Lead time for changes","Heartbeat / Deploy prod / Pipeline Lead Time","0"
"Lead time for changes","Heartbeat / Deploy prod / Total Lead Time","0"
"Pipeline change failure rate","Heartbeat / Deploy prod / Pipeline change failure rate(%)","0.0000"
"Pipeline change failure rate","Heartbeat / Deploy prod / Pipeline change failure rate(%)","0"
"Pipeline mean time to recovery","Heartbeat / Deploy prod / Pipeline mean time to recovery","0"
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@
"Classifications","Assignee / YinYuan Zhou(%)","100.00"
"Rework","Total rework times","0"
"Rework","Total rework cards","0"
"Rework","Rework cards ratio(Total rework cards/Throughput%)","0.0000"
"Rework","Rework cards ratio(Total rework cards/Throughput%)","0"
"Deployment frequency","Heartbeat / Deploy prod / Deployment frequency(Deployments/Day)","1.00"
"Deployment frequency","Heartbeat / Deploy prod / Deployment frequency(Deployment times)","5"
"Lead time for changes","Heartbeat / Deploy prod / PR Lead Time","45.48"
"Lead time for changes","Heartbeat / Deploy prod / Pipeline Lead Time","0.83"
"Lead time for changes","Heartbeat / Deploy prod / Total Lead Time","46.31"
"Pipeline change failure rate","Heartbeat / Deploy prod / Pipeline change failure rate(%)","16.6700"
"Pipeline change failure rate","Heartbeat / Deploy prod / Pipeline change failure rate(%)","16.67"
"Pipeline mean time to recovery","Heartbeat / Deploy prod / Pipeline mean time to recovery","0.78"

0 comments on commit a9a8895

Please sign in to comment.