feat: 用户行为信誉分系统
- User 新增 credit_score 字段(0-200,默认100) - 信誉分影响检测阈值系数:高分降低敏感度,低分提高敏感度 - 发布成功+1分,被拦截-2分;申诉通过+10分,驳回-5分 - 新增手动调整和批量重算信誉分接口 - admin-users 页面显示信誉分进度条,支持编辑调整 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -32,6 +32,15 @@ def _threshold() -> float:
|
||||
return float(row.spam_threshold) if row else 0.75
|
||||
|
||||
|
||||
def _adjusted_threshold(user_credit: int = 100) -> float:
|
||||
"""根据用户信誉分调整阈值"""
|
||||
base_threshold = _threshold()
|
||||
# 系数范围:0.85 - 1.15
|
||||
credit_factor = 1.0 + (user_credit - 100) * 0.0015
|
||||
credit_factor = max(0.85, min(1.15, credit_factor))
|
||||
return base_threshold * credit_factor
|
||||
|
||||
|
||||
@spam_bp.post("/predict")
|
||||
@jwt_required()
|
||||
def predict_one():
|
||||
@@ -46,7 +55,7 @@ def predict_one():
|
||||
|
||||
clf = _ensure_ready()
|
||||
result = clf.predict(text)
|
||||
threshold = _threshold()
|
||||
threshold = _adjusted_threshold(user.credit_score or 100)
|
||||
blocked = float(result["spam_probability"]) >= threshold
|
||||
|
||||
row = SpamPredictionLog(
|
||||
@@ -82,7 +91,7 @@ def predict_batch():
|
||||
clf = _ensure_ready()
|
||||
rows = []
|
||||
results = []
|
||||
threshold = _threshold()
|
||||
threshold = _adjusted_threshold(user.credit_score or 100)
|
||||
|
||||
for text in items:
|
||||
content = (text or "").strip()
|
||||
|
||||
Reference in New Issue
Block a user