fix(admin): 优化聊天日志报表
This commit is contained in:
1 parent
c38a56536e
commit
757231e3d5
14 files changed
+584
-108
No files matched your search
@@ -267,6 +267,11 @@ def test_reports(client, admin_headers):
|
||||
assert 'total' in data
|
||||
assert 'by_user' in data
|
||||
assert 'by_agent' in data
|
||||
assert 'user_total' in data
|
||||
assert 'user_page' in data
|
||||
assert 'user_page_size' in data
|
||||
assert 'user_pages' in data
|
||||
assert 'user_top_limit' in data
|
||||
|
||||
response = client.get('/api/admin/reports/feedback', headers=admin_headers)
|
||||
assert response.status_code == 200
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
"""
|
||||
backend/tests/test_hot_faq_aggregator.py
|
||||
|
||||
测试热点 FAQ 离线聚合的核心规则:问句归一化、答案聚类与代表答案选取。
|
||||
测试热点 FAQ 离线聚合的核心规则:问句归一化、代表答案选取。
|
||||
"""
|
||||
from datetime import datetime
|
||||
from types import SimpleNamespace
|
||||
|
||||
from app.services.faq_text_utils import normalize_faq_query
|
||||
from app.services.hot_faq_aggregator import HotFaqAggregator, _LogRow
|
||||
@@ -15,15 +14,19 @@ def test_normalize_faq_query_strips_punctuation_and_space():
|
||||
assert normalize_faq_query('公司几点上班?') == normalize_faq_query('公司 几点上班')
|
||||
|
||||
|
||||
def test_answer_cluster_merges_similar_answers():
|
||||
"""相似度≥阈值的答案应归入同一簇。"""
|
||||
rows = [
|
||||
_LogRow(1, 1, 1, 'q', '工作日8:30到17:30', 100, 10, datetime.utcnow()),
|
||||
_LogRow(2, 2, 1, 'q', '工作日 8:30 到 17:30', 100, 10, datetime.utcnow()),
|
||||
]
|
||||
clusters = HotFaqAggregator._cluster_answers(rows)
|
||||
assert len(clusters) == 1
|
||||
assert len(clusters[0]['rows']) == 2
|
||||
def test_build_candidate_accepts_divergent_answers_when_clustering_disabled(app, monkeypatch):
|
||||
"""答案聚类关闭时,即使答案分歧较大也应生成热点候选。"""
|
||||
monkeypatch.setenv('FAQ_HOT_ANSWER_DOMINANCE', '0.6')
|
||||
with app.app_context():
|
||||
now = datetime.utcnow()
|
||||
rows = [
|
||||
_LogRow(i, i, 1, '上班时间', f'answer variant {i % 3}', 200, 100, now)
|
||||
for i in range(6)
|
||||
]
|
||||
candidate, reason = HotFaqAggregator._build_candidate(1, 'Agent', '上班时间', rows)
|
||||
assert candidate is not None
|
||||
assert reason is None
|
||||
assert candidate.ask_count_7d == 6
|
||||
|
||||
|
||||
def test_pick_representative_prefers_good_feedback():
|
||||
@@ -37,17 +40,3 @@ def test_pick_representative_prefers_good_feedback():
|
||||
assert picked is not None
|
||||
assert picked.chat_log_id == 2
|
||||
assert picked.answer == 'answer B'
|
||||
|
||||
|
||||
def test_build_candidate_rejects_divergent_answers(app, monkeypatch):
|
||||
"""答案分歧过大时应跳过该热点组。"""
|
||||
monkeypatch.setenv('FAQ_HOT_ANSWER_DOMINANCE', '0.6')
|
||||
with app.app_context():
|
||||
now = datetime.utcnow()
|
||||
rows = [
|
||||
_LogRow(i, i, 1, '上班时间', f'answer variant {i % 3}', 200, 100, now)
|
||||
for i in range(6)
|
||||
]
|
||||
candidate, reason = HotFaqAggregator._build_candidate(1, 'Agent', '上班时间', rows)
|
||||
assert candidate is None
|
||||
assert reason and reason.startswith('answer_divergence')
|
||||
Reference in new issue
Block a user