| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- """评分详情 score_items 三平台差异 + 50+ 维度/权重(展示层)。"""
- from content_agent.flow_ledger_service import _decision_score_items
- 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_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)
|