完善:质量分析平台查询与分析功能
This commit is contained in:
@@ -93,6 +93,7 @@ QUALITY_DATA_SCHEMA: dict[str, Any] = {
|
||||
"group": {"type": "string", "minLength": 1},
|
||||
"product": {"type": "string", "minLength": 1, "description": "产品规格筛选。"},
|
||||
"projectGroup": {"type": "string", "minLength": 1},
|
||||
"extraFilters": {"type":"object", "additionalProperties":{"type":"array","items":{"type":"string"},"maxItems":50},"description":"catalog的筛选字段key到值数组,例如customerCode或blankProducer;空值为__EMPTY__。"},
|
||||
"includeUnassigned": {"type": "boolean"},
|
||||
},
|
||||
"description": "实际筛选值会原样传递给正式 API;工具不会忽略未知或冲突的筛选。",
|
||||
@@ -334,7 +335,7 @@ def normalize_filters(scope: Any, raw: Any, *, scope_was_explicit: bool) -> tupl
|
||||
raw = {}
|
||||
if not isinstance(raw, dict):
|
||||
raise QualityToolError("filters 必须是对象。")
|
||||
allowed = {"department", "group", "product", "projectGroup", "includeUnassigned"}
|
||||
allowed = {"department", "group", "product", "projectGroup", "extraFilters", "includeUnassigned"}
|
||||
unknown = set(raw) - allowed
|
||||
if unknown:
|
||||
raise QualityToolError(f"filters 含不支持字段:{', '.join(sorted(unknown))}。")
|
||||
@@ -352,6 +353,13 @@ def normalize_filters(scope: Any, raw: Any, *, scope_was_explicit: bool) -> tupl
|
||||
if not value:
|
||||
continue
|
||||
result[field] = value
|
||||
extra = raw.get("extraFilters", {})
|
||||
if not isinstance(extra, dict) or len(extra)>20:
|
||||
raise QualityToolError("extraFilters 必须为字段到值数组的对象。")
|
||||
for key, values in extra.items():
|
||||
if not isinstance(key,str) or not re.fullmatch(r"[a-zA-Z][a-zA-Z0-9_]{0,63}",key) or not isinstance(values,list) or len(values)>50 or any(not isinstance(v,str) or not v.strip() or len(v)>256 for v in values):
|
||||
raise QualityToolError("extraFilters 的字段或值无效。")
|
||||
if extra: result["extraFilters"] = {k:list(dict.fromkeys(v)) for k,v in extra.items() if v}
|
||||
include = raw.get("includeUnassigned", False)
|
||||
if not isinstance(include, bool):
|
||||
raise QualityToolError("filters.includeUnassigned 必须是布尔值。")
|
||||
@@ -385,7 +393,7 @@ class QualityTools:
|
||||
def _call(self, method: str, path: str, params: dict[str, Any] | None = None,
|
||||
payload: dict[str, Any] | None = None) -> dict[str, Any]:
|
||||
params = {key: value for key, value in (params or {}).items() if value is not None}
|
||||
encoded = urlencode(params)
|
||||
encoded = urlencode({k:json.dumps(v,ensure_ascii=False,separators=(",",":")) if isinstance(v,dict) else v for k,v in params.items()})
|
||||
request_path = path + ("?" + encoded if encoded else "")
|
||||
result = self._client().call(request_path, payload, method=method)
|
||||
if not isinstance(result, dict):
|
||||
@@ -447,6 +455,8 @@ class QualityTools:
|
||||
expected = filters.get(key)
|
||||
if context.get(key) != expected:
|
||||
raise QualityToolError(f"正式指标接口未确认 filters.{key}(期望值与返回值不一致);结果已拒绝。")
|
||||
if context.get("extraFilters",{}) != filters.get("extraFilters",{}):
|
||||
raise QualityToolError("正式指标接口未确认新增筛选;结果已拒绝。")
|
||||
if context.get("view") != view:
|
||||
raise QualityToolError(f"正式指标接口未确认 view={view};结果已拒绝。")
|
||||
if context.get("includeUnassigned") != filters.get("includeUnassigned", False):
|
||||
@@ -462,7 +472,7 @@ class QualityTools:
|
||||
params: dict[str, Any] = {"releaseId": release_id, **period, "view": view,
|
||||
"includeUnassigned": filters.get("includeUnassigned", False),
|
||||
"trendGranularity": "month"}
|
||||
for key in ("department", "group", "product", "projectGroup"):
|
||||
for key in ("department", "group", "product", "projectGroup", "extraFilters"):
|
||||
if key in filters:
|
||||
params[key] = filters[key]
|
||||
if row_limit is not None:
|
||||
@@ -613,7 +623,7 @@ class QualityTools:
|
||||
**period}
|
||||
if api_category is not None:
|
||||
params["category"] = api_category
|
||||
for key in ("department", "group", "product", "projectGroup"):
|
||||
for key in ("department", "group", "product", "projectGroup", "extraFilters"):
|
||||
if key in filters:
|
||||
params[key] = filters[key]
|
||||
response = self._call("GET", "/api/analytics/top", params)
|
||||
@@ -872,8 +882,10 @@ class QualityTools:
|
||||
limit: int) -> dict[str, Any]:
|
||||
payload: dict[str, Any] = {"releaseId": release["id"], "stage": stage, "limit": limit, **period,
|
||||
"includeUnassigned": filters.get("includeUnassigned", False)}
|
||||
payload.update({key: filters[key] for key in ("department", "group", "product", "projectGroup") if key in filters})
|
||||
payload.update({key: filters[key] for key in ("department", "group", "product", "projectGroup", "extraFilters") if key in filters})
|
||||
response = self._call("POST", "/api/analysis/tools/details", payload=payload)
|
||||
if isinstance(response.get("range"),dict) and response["range"].get("extraFilters",{}) != filters.get("extraFilters",{}):
|
||||
raise QualityToolError("明细接口未确认新增筛选;结果已拒绝。")
|
||||
range_info = response.get("range")
|
||||
if not isinstance(range_info, dict) or range_info.get("releaseId") != release["id"]:
|
||||
raise QualityToolError("正式明细接口未确认 releaseId;样本结果已拒绝。")
|
||||
@@ -910,6 +922,8 @@ class QualityTools:
|
||||
context = response.get("context")
|
||||
if not isinstance(context, dict):
|
||||
raise QualityToolError("具体缺陷接口未返回 context;无法确认期间和筛选是否生效。")
|
||||
if context.get("extraFilters",{}) != filters.get("extraFilters",{}):
|
||||
raise QualityToolError("具体缺陷接口未确认新增筛选;结果已拒绝。")
|
||||
expected_context = {**period, **filters, "stage": stage, "dimension": dimension,
|
||||
"defect": defect, "category": category}
|
||||
for field in ("year", "month", "quarter", "department", "group", "product", "projectGroup",
|
||||
@@ -951,7 +965,7 @@ class QualityTools:
|
||||
payload: dict[str, Any] = {"releaseId": release["id"], "mode": "top", **period, "stage": stage,
|
||||
"dimension": dimension, "includeUnassigned": filters.get("includeUnassigned", False),
|
||||
"limit": limit}
|
||||
payload.update({key: filters[key] for key in ("department", "group", "product", "projectGroup") if key in filters})
|
||||
payload.update({key: filters[key] for key in ("department", "group", "product", "projectGroup", "extraFilters") if key in filters})
|
||||
if defect is not None:
|
||||
payload["defect"] = defect.strip()
|
||||
if category is not None:
|
||||
@@ -1155,7 +1169,7 @@ class QualityTools:
|
||||
"visibleWeightFields": access_fields,
|
||||
"visibleDefectCategoryCount": len(visible_codes),
|
||||
"dataScope": access.get("scope")},
|
||||
"filters": {"scopePresets": list(SCOPES), "actual": ["department", "group", "product", "projectGroup", "includeUnassigned"]},
|
||||
"filters": {"scopePresets": list(SCOPES), "actual": ["department", "group", "product", "projectGroup", "extraFilters", "includeUnassigned"], "extraFields": access.get("extraFields", [])},
|
||||
"fineDefects": fine_defects,
|
||||
"limitations": access.get("limitations") or [],
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user