From bd23e185eb91d86e20bc740f48ca8f6300795153 Mon Sep 17 00:00:00 2001 From: littlejian <17816869670@163.com> Date: Fri, 12 Nov 2021 17:49:59 +0800 Subject: [PATCH] fix: Recovery pass rate and execution rate statistics (#3040) --- .../components/executeInfo/render.go | 33 +++++++++++++++---- 1 file changed, 26 insertions(+), 7 deletions(-) diff --git a/modules/openapi/component-protocol/scenarios/auto-test-scenes/components/executeInfo/render.go b/modules/openapi/component-protocol/scenarios/auto-test-scenes/components/executeInfo/render.go index 9e66a8033a9..73d9aeca514 100644 --- a/modules/openapi/component-protocol/scenarios/auto-test-scenes/components/executeInfo/render.go +++ b/modules/openapi/component-protocol/scenarios/auto-test-scenes/components/executeInfo/render.go @@ -156,16 +156,35 @@ func (i *ComponentFileInfo) Render(ctx context.Context, c *apistructs.Component, if rsp.Status == apistructs.PipelineStatusNoNeedBySystem { i.Data["status"] = "无需执行" } - - execHistory, err := i.CtxBdl.Bdl.GetAutoTestExecHistory(i.State.PipelineID) + res, err := i.CtxBdl.Bdl.GetPipelineReportSet(i.State.PipelineID, []string{"api-test"}) if err != nil { - i.Data["autoTestExecPercent"] = "-" - i.Data["autoTestSuccessPercent"] = "-" - } else { - i.Data["autoTestExecPercent"] = fmt.Sprintf("%.2f", execHistory.ExecuteRate) - i.Data["autoTestSuccessPercent"] = fmt.Sprintf("%.2f", execHistory.PassRate) + return err + } + if res != nil && len(res.Reports) > 0 && res.Reports[0].Meta != nil { + value, err := json.Marshal(res.Reports[0].Meta) + if err != nil { + i.Data["autoTestExecPercent"] = "-" + i.Data["autoTestSuccessPercent"] = "-" + goto Label + } + var report reportNew + err = json.Unmarshal(value, &report) + if err != nil { + i.Data["autoTestExecPercent"] = "-" + i.Data["autoTestSuccessPercent"] = "-" + goto Label + } + i.Data["autoTestNum"] = report.APITotalNum + if report.APITotalNum == 0 { + i.Data["autoTestExecPercent"] = "0.00%" + i.Data["autoTestSuccessPercent"] = "0.00%" + } else { + i.Data["autoTestExecPercent"] = strconv.FormatFloat(100-float64(report.APINotExecNum)/float64(report.APITotalNum)*100, 'f', 2, 64) + "%" + i.Data["autoTestSuccessPercent"] = strconv.FormatFloat(float64(report.APISuccessNum)/float64(report.APITotalNum)*100, 'f', 2, 64) + "%" + } } } +Label: i.Props = make(map[string]interface{}) i.Props["fields"] = []PropColumn{ {