V10.433 improve competitor review diagnostics
This commit is contained in:
@@ -102,6 +102,15 @@ MATCH_DIAGNOSTIC_REASON_LABELS = {
|
||||
"price_ratio_extreme": "價差極端",
|
||||
"price_ratio_wide": "價差過大",
|
||||
"catalog_count_omission": "目錄入數待確認",
|
||||
"makeup_usage_conflict": "彩妝用途不同",
|
||||
"makeup_finish_conflict": "妝效質地不同",
|
||||
"nail_tool_function_conflict": "工具功能不同",
|
||||
"schick_razor_line_conflict": "除毛刀品線不同",
|
||||
"variant_descriptor_conflict": "款式描述不同",
|
||||
"variant_selection_review": "多款任選待確認",
|
||||
"strong_exact_spec_match": "強規格同款",
|
||||
"strong_product_line_match": "商品線強吻合",
|
||||
"shared_model_token": "型號一致",
|
||||
}
|
||||
MATCH_TYPE_LABELS = {
|
||||
"exact": "高信心同款",
|
||||
@@ -203,25 +212,36 @@ def _empty_manual_review_summary() -> dict[str, Any]:
|
||||
}
|
||||
|
||||
|
||||
def _extract_match_diagnostic_reasons(diagnostic_text: Any) -> list[dict[str, str]]:
|
||||
def _extract_match_diagnostic_reasons(
|
||||
diagnostic_text: Any,
|
||||
diagnostic_payload: Optional[dict[str, Any]] = None,
|
||||
) -> list[dict[str, str]]:
|
||||
"""Translate matcher diagnostics into short operator-facing reason chips."""
|
||||
text_value = str(diagnostic_text or "")
|
||||
if not text_value:
|
||||
return []
|
||||
raw_reasons: list[Any] = []
|
||||
if isinstance(diagnostic_payload, dict):
|
||||
payload_reasons = diagnostic_payload.get("reasons")
|
||||
if isinstance(payload_reasons, list):
|
||||
raw_reasons.extend(payload_reasons)
|
||||
elif isinstance(payload_reasons, str):
|
||||
raw_reasons.extend(payload_reasons.replace("|", ",").split(","))
|
||||
|
||||
reason_blob = ""
|
||||
for part in text_value.split(";"):
|
||||
key, _, value = part.strip().partition("=")
|
||||
if key.strip() == "reasons":
|
||||
reason_blob = value.strip()
|
||||
break
|
||||
if not reason_blob:
|
||||
if text_value:
|
||||
reason_blob = ""
|
||||
for part in text_value.split(";"):
|
||||
key, _, value = part.strip().partition("=")
|
||||
if key.strip() == "reasons":
|
||||
reason_blob = value.strip()
|
||||
break
|
||||
if reason_blob:
|
||||
raw_reasons.extend(reason_blob.replace("|", ",").split(","))
|
||||
if not raw_reasons:
|
||||
return []
|
||||
|
||||
reasons: list[dict[str, str]] = []
|
||||
seen: set[str] = set()
|
||||
for raw_reason in reason_blob.replace("|", ",").split(","):
|
||||
code = raw_reason.strip()
|
||||
for raw_reason in raw_reasons:
|
||||
code = str(raw_reason or "").strip()
|
||||
if not code or code in seen:
|
||||
continue
|
||||
seen.add(code)
|
||||
@@ -262,7 +282,7 @@ def _format_competitor_review_item(row: dict[str, Any]) -> dict[str, Any]:
|
||||
price_basis = diagnostic_payload.get("price_basis") or _tag_suffix(tags, "price_basis") or ""
|
||||
alert_tier = diagnostic_payload.get("alert_tier") or _tag_suffix(tags, "alert_tier") or ""
|
||||
evidence_flags = diagnostic_payload.get("evidence_flags") or []
|
||||
diagnostic_reasons = _extract_match_diagnostic_reasons(match_diagnostic)
|
||||
diagnostic_reasons = _extract_match_diagnostic_reasons(match_diagnostic, diagnostic_payload)
|
||||
return {
|
||||
"sku": str(item.get("sku") or ""),
|
||||
"name": item.get("name") or "",
|
||||
|
||||
Reference in New Issue
Block a user