fix(测试跟踪): 修复测试计划报告统计图精度问题
--bug=1024014 --user=宋天阳 【测试跟踪】 github#22457,测试计划 - 报告处,统计的百分百加起来超过 100% 了 https://www.tapd.cn/55049933/s/1348194
This commit is contained in:
parent
d09e06be1d
commit
78d6854ba6
|
@ -1,85 +1,83 @@
|
|||
<template>
|
||||
<div>
|
||||
<ms-chart v-if="visible && data.length > 0" :options="options" :height="height"/>
|
||||
<div v-if="visible && data.length <= 0" style="height: 300px">
|
||||
|
||||
</div>
|
||||
<ms-chart
|
||||
v-if="visible && data.length > 0"
|
||||
:options="options"
|
||||
:height="height"
|
||||
/>
|
||||
<div v-if="visible && data.length <= 0" style="height: 300px"></div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
|
||||
import MsChart from "./chart/MsChart";
|
||||
export default {
|
||||
name: "MsDoughnutPieChart",
|
||||
components: {MsChart},
|
||||
components: { MsChart },
|
||||
data() {
|
||||
return {
|
||||
visible: false,
|
||||
options: {
|
||||
tooltip: {
|
||||
trigger: 'item'
|
||||
trigger: "item",
|
||||
},
|
||||
legend: {
|
||||
orient: 'vertical',
|
||||
orient: "vertical",
|
||||
right: 50,
|
||||
bottom: '40%',
|
||||
bottom: "40%",
|
||||
formatter: function (name) {
|
||||
return name;
|
||||
}
|
||||
},
|
||||
},
|
||||
series: [
|
||||
{
|
||||
name: this.name,
|
||||
type: 'pie',
|
||||
type: "pie",
|
||||
left: -150,
|
||||
radius: ['40%', '50%'],
|
||||
radius: ["40%", "50%"],
|
||||
avoidLabelOverlap: false,
|
||||
label: {
|
||||
// padding: [10, 10, 20, 10],
|
||||
lineHeight: 35,
|
||||
fontSize: 20,
|
||||
// fontWeight: 'bold',
|
||||
position: 'center',
|
||||
color: 'gray',
|
||||
position: "center",
|
||||
color: "gray",
|
||||
formatter: function (params) {
|
||||
return '';
|
||||
return "";
|
||||
},
|
||||
},
|
||||
labelLine: {
|
||||
show: false
|
||||
show: false,
|
||||
},
|
||||
data: this.data
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
data: this.data,
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
},
|
||||
props: {
|
||||
name: {
|
||||
type: String,
|
||||
default: '数据名称'
|
||||
default: "数据名称",
|
||||
},
|
||||
data: {
|
||||
type: Array,
|
||||
default() {
|
||||
return []
|
||||
}
|
||||
return [];
|
||||
},
|
||||
},
|
||||
height: {
|
||||
type: Number,
|
||||
default() {
|
||||
return 400
|
||||
}
|
||||
}
|
||||
return 400;
|
||||
},
|
||||
},
|
||||
},
|
||||
watch: {
|
||||
data() {
|
||||
this.reload();
|
||||
}
|
||||
},
|
||||
created() {
|
||||
},
|
||||
},
|
||||
created() {},
|
||||
mounted() {
|
||||
this.reload();
|
||||
},
|
||||
|
@ -98,29 +96,43 @@ export default {
|
|||
|
||||
this.options.series[0].data = data;
|
||||
|
||||
this.data.forEach(item => {
|
||||
this.data.forEach((item) => {
|
||||
count += item.value;
|
||||
});
|
||||
|
||||
let total = 0;
|
||||
for (let i = 0; i < data.length; i++) {
|
||||
total += data[i].value;
|
||||
}
|
||||
|
||||
let dataPercentObj = {};
|
||||
let percentCount = 0;
|
||||
for (let i = 0; i < data.length; i++) {
|
||||
let dataName = data[i].name;
|
||||
let value = data[i].value;
|
||||
let percent = 100 - percentCount;
|
||||
if (i !== data.length - 1) {
|
||||
percent = new Number(((value / total) * 100).toFixed(0));
|
||||
percentCount += percent;
|
||||
}
|
||||
dataPercentObj[dataName] = percent;
|
||||
}
|
||||
this.options.legend.formatter = (name) => {
|
||||
let total = 0;
|
||||
let target = 0;
|
||||
for (let i = 0, l = data.length; i < l; i++) {
|
||||
total += data[i].value;
|
||||
if (data[i].name == name) {
|
||||
target = data[i].value;
|
||||
}
|
||||
}
|
||||
return name + ' | ' + target + ' ' + ((target / total) * 100).toFixed(0) + '%';
|
||||
return name + " | " + target + " " + dataPercentObj[name] + "%";
|
||||
};
|
||||
|
||||
this.options.series[0].label.formatter = (params) => {
|
||||
return title + '\n' + count;
|
||||
return title + "\n" + count;
|
||||
};
|
||||
},
|
||||
}
|
||||
}
|
||||
},
|
||||
};
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
</style>
|
||||
<style scoped></style>
|
||||
|
|
|
@ -22,6 +22,7 @@ import io.metersphere.log.utils.ReflexObjectUtil;
|
|||
import io.metersphere.log.vo.DetailColumn;
|
||||
import io.metersphere.log.vo.OperatingLogDetails;
|
||||
import io.metersphere.log.vo.track.TestPlanReference;
|
||||
import io.metersphere.plan.constant.ApiReportStatus;
|
||||
import io.metersphere.plan.dto.TestPlanDTO;
|
||||
import io.metersphere.plan.dto.*;
|
||||
import io.metersphere.plan.job.TestPlanTestJob;
|
||||
|
@ -1507,6 +1508,7 @@ public class TestPlanService {
|
|||
BeanUtils.copyBean(report, testPlanCaseReportResultDTO.getApiPlanReportDTO());
|
||||
planTestPlanApiCaseService.calculateReportByApiCase(testPlanCaseReportResultDTO.getApiPlanReportDTO().getApiAllCases(), report);
|
||||
planTestPlanScenarioCaseService.calculateReportByScenario(testPlanCaseReportResultDTO.getApiPlanReportDTO().getScenarioAllCases(), report);
|
||||
this.sortApiCaseResultCount(report.getApiResult());
|
||||
}
|
||||
if (testPlanCaseReportResultDTO.getLoadPlanReportDTO() != null) {
|
||||
BeanUtils.copyBean(report, testPlanCaseReportResultDTO.getLoadPlanReportDTO());
|
||||
|
@ -1551,6 +1553,48 @@ public class TestPlanService {
|
|||
return report;
|
||||
}
|
||||
|
||||
private void sortApiCaseResultCount(TestPlanApiResultReportDTO apiResult) {
|
||||
if (apiResult != null && CollectionUtils.isNotEmpty(apiResult.getApiCaseData())) {
|
||||
/**
|
||||
*排序方式: 未通过->误报->成功->未执行 未执行的放最后,成功倒数第二,以此类推。
|
||||
* 这样做的目的是因为前台统计百分比时,四舍五入处理之后,有时会出现总百分比加起来不等于100%的情况。
|
||||
* 为了解决这个问题,按照上序排序方式, 排在最后的状态,采用 100-其余百分比总和 来计算。
|
||||
*/
|
||||
List<TestCaseReportStatusResultDTO> oldData = apiResult.getApiCaseData();
|
||||
List<TestCaseReportStatusResultDTO> apiCaseData = new ArrayList<>();
|
||||
|
||||
TestCaseReportStatusResultDTO errorStatusDTO = null;
|
||||
TestCaseReportStatusResultDTO fakeErrorStatusDTO = null;
|
||||
TestCaseReportStatusResultDTO successStatusDTO = null;
|
||||
//因为未执行的状态比较多, 比如停止、未运行、准备中等都属于未执行。所以这里直接用排除法,并用集合接收
|
||||
List<TestCaseReportStatusResultDTO> unExecuteStatusDTOList = new ArrayList<>();
|
||||
|
||||
for (TestCaseReportStatusResultDTO dto : oldData) {
|
||||
if (StringUtils.equalsIgnoreCase(dto.getStatus(), ApiReportStatus.FAKE_ERROR.toString())) {
|
||||
fakeErrorStatusDTO = dto;
|
||||
} else if (StringUtils.equalsIgnoreCase(dto.getStatus(), ApiReportStatus.ERROR.toString())) {
|
||||
errorStatusDTO = dto;
|
||||
} else if (StringUtils.equalsIgnoreCase(dto.getStatus(), ApiReportStatus.SUCCESS.toString())) {
|
||||
successStatusDTO = dto;
|
||||
} else {
|
||||
unExecuteStatusDTOList.add(dto);
|
||||
}
|
||||
}
|
||||
if (errorStatusDTO != null) {
|
||||
apiCaseData.add(errorStatusDTO);
|
||||
}
|
||||
if (fakeErrorStatusDTO != null) {
|
||||
apiCaseData.add(fakeErrorStatusDTO);
|
||||
}
|
||||
if (successStatusDTO != null) {
|
||||
apiCaseData.add(successStatusDTO);
|
||||
}
|
||||
apiCaseData.addAll(unExecuteStatusDTOList);
|
||||
|
||||
apiResult.setApiCaseData(apiCaseData);
|
||||
}
|
||||
}
|
||||
|
||||
public void editReport(TestPlanWithBLOBs testPlanWithBLOBs) {
|
||||
testPlanMapper.updateByPrimaryKeySelective(testPlanWithBLOBs);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue