From 7bc40604c39d50ca5afcbee81e2b1e2fceda3912 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=AD=E5=A4=A7=E6=B7=98=E6=B2=99?= Date: Fri, 3 Apr 2026 16:11:31 +0800 Subject: [PATCH] modify tperf.py for parsing error --- tperf.py | 34 +++++++++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/tperf.py b/tperf.py index 14c2567..fd9f38c 100755 --- a/tperf.py +++ b/tperf.py @@ -394,6 +394,13 @@ def summary_result(data: dict, base: dict) -> dict: "score": 0, } for tc in data: + if tc not in base: + warn(f"基准数据中缺少用例 {tc},跳过该用例的评分汇总(请更新 base.json 或指定 -b)") + continue + base_results = base[tc].get("result") + if not isinstance(base_results, dict): + warn(f"基准数据中用例 {tc} 的 result 无效,跳过") + continue for item in data[tc]["result"]: L0 = data[tc]["result"][item].get("L0", "其他") if L0 not in result_dict["dim"]: @@ -405,7 +412,12 @@ def summary_result(data: dict, base: dict) -> dict: if item in result_dict["dim"][L0]["data"]: raise ValueError(f"重复的性能指标名{item}") value_item = item_data["value"] - value_base = base[tc]["result"][item]["value"] + if item not in base_results: + warn( + f"基准数据中缺少用例 {tc} 的指标 {item},跳过该指标的评分计算(请更新 base.json)" + ) + continue + value_base = base_results[item]["value"] if item_data["type"] == "HIB": if value_base == 0: warn(f"测试用例{tc}性能指标{item}的基准值为0,跳过该指标的评分计算") @@ -430,7 +442,16 @@ def summary_result(data: dict, base: dict) -> dict: } for L0 in result_dict["dim"]: dbg(f"try get score for {L0}") - result_dict["dim"][L0]["score"] = int(safe_weighted_geometric_mean(result_dict["dim"][L0]["data"]) * 10000) + dim_data = result_dict["dim"][L0]["data"] + if not dim_data: + warn( + f"维度 {L0} 下无有效指标参与评分(可能基准数据缺失或均被跳过),该维度得分记为 0" + ) + result_dict["dim"][L0]["score"] = 0 + else: + result_dict["dim"][L0]["score"] = int( + safe_weighted_geometric_mean(dim_data) * 10000 + ) msg(f"{L0} score: {result_dict['dim'][L0]['score']}") result_dict["score"] = sum(result_dict["dim"][L0]["score"] for L0 in result_dict["dim"]) return result_dict @@ -504,7 +525,14 @@ def report_excel(data: dict, base: dict, output: str): item_data.get("type", ""), item_data.get("unit", ""), ] - row_data.append(base[tc_name]["result"][item]["value"]) + if tc_name in base and isinstance(base[tc_name].get("result"), dict): + br = base[tc_name]["result"] + if item in br: + row_data.append(br[item]["value"]) + else: + row_data.append("") + else: + row_data.append("") data_list = [] for loop in loop_list: value = data[loop]["data"][tc_name]["result"][item].get("value", "") -- Gitee