test_score_items_platform.py 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. """评分详情 score_items 三平台差异 + 50+ 维度/权重(展示层)。"""
  2. from content_agent.flow_ledger_service import _decision_score_items
  3. def _by_label(items, label):
  4. return next((it for it in items if it["label"] == label), None)
  5. def test_douyin_ok_emits_fifty_dimension_and_weights():
  6. scorecard = {
  7. "query_relevance_score": 98,
  8. "platform_performance_score": 72.2,
  9. "total_score": 73,
  10. "platform_performance_components": [
  11. {"field": "statistics.digg_count", "value": 130096, "weight": 0.4, "normalized_score": 55.7},
  12. ],
  13. "fifty_plus_status": "ok",
  14. "fifty_plus_score": 45,
  15. "fifty_plus_components": {"tgi_score": 55, "percent_score": 30, "band_tgi": 110, "band_percent": 30},
  16. }
  17. items = _decision_score_items(scorecard, 73)
  18. assert _by_label(items, "是否契合需求")["weight"] == 0.35
  19. assert _by_label(items, "平台表现")["weight"] == 0.35
  20. fifty = _by_label(items, "50+老年受众")
  21. assert fifty["group"] == "main" and fifty["weight"] == 0.3 and fifty["status"] == "ok"
  22. assert fifty["score"] == 45
  23. tgi = _by_label(items, "TGI 表现")
  24. assert tgi["group"] == "fifty" and tgi["weight"] == 0.6
  25. assert _by_label(items, "占比表现")["weight"] == 0.4
  26. # 平台子项带结构化权重
  27. assert _by_label(items, "点赞表现")["group"] == "platform"
  28. assert _by_label(items, "点赞表现")["weight"] == 0.4
  29. def test_non_douyin_is_5050_without_fifty():
  30. scorecard = {
  31. "query_relevance_score": 80,
  32. "platform_performance_score": 56,
  33. "total_score": 68,
  34. "platform_performance_components": [
  35. {"field": "statistics.play_count", "value": 9000, "weight": 0.4, "normalized_score": 60},
  36. ],
  37. }
  38. items = _decision_score_items(scorecard, 68)
  39. assert _by_label(items, "是否契合需求")["weight"] == 0.5
  40. assert _by_label(items, "平台表现")["weight"] == 0.5
  41. assert _by_label(items, "50+老年受众") is None
  42. assert all(it.get("group") != "fifty" for it in items)
  43. # 快手特有「播放表现」子项数据驱动透出
  44. assert _by_label(items, "播放表现")["group"] == "platform"
  45. def test_douyin_not_attempted_shows_fifty_unevaluated():
  46. scorecard = {
  47. "query_relevance_score": 40,
  48. "platform_performance_score": 50,
  49. "total_score": 31.5,
  50. "platform_performance_components": [],
  51. "fifty_plus_status": "not_attempted",
  52. }
  53. items = _decision_score_items(scorecard, 31.5)
  54. fifty = _by_label(items, "50+老年受众")
  55. assert fifty is not None
  56. assert fifty["score"] is None
  57. assert fifty["status"] == "not_attempted"
  58. assert fifty["weight"] == 0.3
  59. assert fifty["score_label"] == "未评估"
  60. # 不应出现 fifty 拆解子项
  61. assert all(it.get("group") != "fifty" for it in items)