| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117 |
- """评分详情 score_items 三平台差异 + 50+ 维度/权重(展示层)。"""
- from content_agent.flow_ledger_service import _decision_score_items, _walk_operator_display_status
- def _by_label(items, label):
- return next((it for it in items if it["label"] == label), None)
- def test_douyin_ok_emits_fifty_dimension_and_weights():
- scorecard = {
- "query_relevance_score": 98,
- "platform_performance_score": 72.2,
- "total_score": 73,
- "platform_performance_components": [
- {"field": "statistics.digg_count", "value": 130096, "weight": 0.4, "normalized_score": 55.7},
- ],
- "fifty_plus_status": "ok",
- "fifty_plus_score": 45,
- "fifty_plus_components": {"tgi_score": 55, "percent_score": 30, "band_tgi": 110, "band_percent": 30},
- }
- items = _decision_score_items(scorecard, 73)
- assert _by_label(items, "是否契合需求")["weight"] == 0.35
- assert _by_label(items, "平台表现")["weight"] == 0.35
- fifty = _by_label(items, "50+老年受众")
- assert fifty["group"] == "main" and fifty["weight"] == 0.3 and fifty["status"] == "ok"
- assert fifty["score"] == 45
- tgi = _by_label(items, "TGI 表现")
- assert tgi["group"] == "fifty" and tgi["weight"] == 0.6
- assert _by_label(items, "占比表现")["weight"] == 0.4
- # 平台子项带结构化权重
- assert _by_label(items, "点赞表现")["group"] == "platform"
- assert _by_label(items, "点赞表现")["weight"] == 0.4
- def test_score_items_prefer_score_weights_from_scorecard():
- scorecard = {
- "query_relevance_score": 98,
- "platform_performance_score": 72.2,
- "total_score": 74.06,
- "platform_performance_components": [],
- "fifty_plus_status": "ok",
- "fifty_plus_score": 45,
- "fifty_plus_components": {},
- "score_weights": {
- "query_relevance": 0.4,
- "platform_performance": 0.3,
- "fifty_plus": 0.3,
- },
- }
- items = _decision_score_items(scorecard, 74.06)
- assert _by_label(items, "是否契合需求")["weight"] == 0.4
- assert _by_label(items, "平台表现")["weight"] == 0.3
- assert _by_label(items, "50+老年受众")["weight"] == 0.3
- def test_non_douyin_is_5050_without_fifty():
- scorecard = {
- "query_relevance_score": 80,
- "platform_performance_score": 56,
- "total_score": 68,
- "platform_performance_components": [
- {"field": "statistics.play_count", "value": 9000, "weight": 0.4, "normalized_score": 60},
- ],
- }
- items = _decision_score_items(scorecard, 68)
- assert _by_label(items, "是否契合需求")["weight"] == 0.5
- assert _by_label(items, "平台表现")["weight"] == 0.5
- assert _by_label(items, "50+老年受众") is None
- assert all(it.get("group") != "fifty" for it in items)
- # 快手特有「播放表现」子项数据驱动透出
- assert _by_label(items, "播放表现")["group"] == "platform"
- def test_douyin_not_attempted_shows_fifty_unevaluated():
- scorecard = {
- "query_relevance_score": 40,
- "platform_performance_score": 50,
- "total_score": 31.5,
- "platform_performance_components": [],
- "fifty_plus_status": "not_attempted",
- }
- items = _decision_score_items(scorecard, 31.5)
- fifty = _by_label(items, "50+老年受众")
- assert fifty is not None
- assert fifty["score"] is None
- assert fifty["status"] == "not_attempted"
- assert fifty["weight"] == 0.3
- assert fifty["score_label"] == "未评估"
- # 不应出现 fifty 拆解子项
- assert all(it.get("group") != "fifty" for it in items)
- def test_douyin_not_attempted_uses_score_weights_when_present():
- scorecard = {
- "query_relevance_score": 40,
- "platform_performance_score": 50,
- "total_score": 31.5,
- "platform_performance_components": [],
- "fifty_plus_status": "not_attempted",
- "score_weights": {
- "query_relevance": 0.35,
- "platform_performance": 0.35,
- },
- }
- items = _decision_score_items(scorecard, 31.5)
- fifty = _by_label(items, "50+老年受众")
- assert _by_label(items, "是否契合需求")["weight"] == 0.35
- assert _by_label(items, "平台表现")["weight"] == 0.35
- assert fifty.get("weight") is None
- def test_budget_exhausted_maps_to_operator_budget_blocked():
- assert _walk_operator_display_status("skipped", "budget_exhausted") == "budget_blocked"
- assert _walk_operator_display_status("success", "") == "success"
|