test_score_items_platform.py 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. """评分详情 score_items 三平台差异 + 50+ 维度/权重(展示层)。"""
  2. from content_agent.flow_ledger_service import _decision_score_items, _walk_operator_display_status
  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_score_items_prefer_score_weights_from_scorecard():
  30. scorecard = {
  31. "query_relevance_score": 98,
  32. "platform_performance_score": 72.2,
  33. "total_score": 74.06,
  34. "platform_performance_components": [],
  35. "fifty_plus_status": "ok",
  36. "fifty_plus_score": 45,
  37. "fifty_plus_components": {},
  38. "score_weights": {
  39. "query_relevance": 0.4,
  40. "platform_performance": 0.3,
  41. "fifty_plus": 0.3,
  42. },
  43. }
  44. items = _decision_score_items(scorecard, 74.06)
  45. assert _by_label(items, "是否契合需求")["weight"] == 0.4
  46. assert _by_label(items, "平台表现")["weight"] == 0.3
  47. assert _by_label(items, "50+老年受众")["weight"] == 0.3
  48. def test_non_douyin_is_5050_without_fifty():
  49. scorecard = {
  50. "query_relevance_score": 80,
  51. "platform_performance_score": 56,
  52. "total_score": 68,
  53. "platform_performance_components": [
  54. {"field": "statistics.play_count", "value": 9000, "weight": 0.4, "normalized_score": 60},
  55. ],
  56. }
  57. items = _decision_score_items(scorecard, 68)
  58. assert _by_label(items, "是否契合需求")["weight"] == 0.5
  59. assert _by_label(items, "平台表现")["weight"] == 0.5
  60. assert _by_label(items, "50+老年受众") is None
  61. assert all(it.get("group") != "fifty" for it in items)
  62. # 快手特有「播放表现」子项数据驱动透出
  63. assert _by_label(items, "播放表现")["group"] == "platform"
  64. def test_douyin_not_attempted_shows_fifty_unevaluated():
  65. scorecard = {
  66. "query_relevance_score": 40,
  67. "platform_performance_score": 50,
  68. "total_score": 31.5,
  69. "platform_performance_components": [],
  70. "fifty_plus_status": "not_attempted",
  71. }
  72. items = _decision_score_items(scorecard, 31.5)
  73. fifty = _by_label(items, "50+老年受众")
  74. assert fifty is not None
  75. assert fifty["score"] is None
  76. assert fifty["status"] == "not_attempted"
  77. assert fifty["weight"] == 0.3
  78. assert fifty["score_label"] == "未评估"
  79. # 不应出现 fifty 拆解子项
  80. assert all(it.get("group") != "fifty" for it in items)
  81. def test_douyin_not_attempted_uses_score_weights_when_present():
  82. scorecard = {
  83. "query_relevance_score": 40,
  84. "platform_performance_score": 50,
  85. "total_score": 31.5,
  86. "platform_performance_components": [],
  87. "fifty_plus_status": "not_attempted",
  88. "score_weights": {
  89. "query_relevance": 0.35,
  90. "platform_performance": 0.35,
  91. },
  92. }
  93. items = _decision_score_items(scorecard, 31.5)
  94. fifty = _by_label(items, "50+老年受众")
  95. assert _by_label(items, "是否契合需求")["weight"] == 0.35
  96. assert _by_label(items, "平台表现")["weight"] == 0.35
  97. assert fifty.get("weight") is None
  98. def test_budget_exhausted_maps_to_operator_budget_blocked():
  99. assert _walk_operator_display_status("skipped", "budget_exhausted") == "budget_blocked"
  100. assert _walk_operator_display_status("success", "") == "success"