39 lines
1.6 KiB
Python
39 lines
1.6 KiB
Python
|
|
"""
|
|||
|
|
用户行为指纹模型 — 用户的数字行为特征向量和偏好权重
|
|||
|
|
"""
|
|||
|
|
import uuid
|
|||
|
|
from datetime import datetime
|
|||
|
|
from sqlalchemy import Column, String, Text, DateTime, JSON, Float, Integer
|
|||
|
|
from app.core.database import Base
|
|||
|
|
|
|||
|
|
|
|||
|
|
class UserFingerprint(Base):
|
|||
|
|
"""用户行为数字指纹"""
|
|||
|
|
__tablename__ = "user_fingerprints"
|
|||
|
|
|
|||
|
|
id = Column(String(36), primary_key=True, default=lambda: str(uuid.uuid4()))
|
|||
|
|
user_id = Column(String(36), nullable=False, unique=True, index=True, comment="用户ID")
|
|||
|
|
|
|||
|
|
# 各场景偏好权重 (0-1 浮点数,JSON)
|
|||
|
|
# 示例: {"code_review": {"security": 0.4, "performance": 0.3, "readability": 0.2, "style": 0.1}}
|
|||
|
|
preference_weights = Column(JSON, nullable=True, comment="偏好权重")
|
|||
|
|
|
|||
|
|
# 决策规则 (if-then 规则列表,JSON)
|
|||
|
|
# 示例: [{"if": "files_changed > 10 and no_tests", "then": "request_tests"}]
|
|||
|
|
decision_rules = Column(JSON, nullable=True, comment="决策规则")
|
|||
|
|
|
|||
|
|
# 行为统计
|
|||
|
|
total_behaviors = Column(Integer, default=0, comment="总行为数")
|
|||
|
|
behaviors_by_category = Column(JSON, nullable=True, comment="按类别的行为分布")
|
|||
|
|
avg_response_time_ms = Column(Integer, nullable=True, comment="平均响应时间(ms)")
|
|||
|
|
|
|||
|
|
# 模型版本
|
|||
|
|
model_version = Column(String(20), default="1.0", comment="指纹模型版本")
|
|||
|
|
last_trained_at = Column(DateTime, nullable=True, comment="上次训练时间")
|
|||
|
|
|
|||
|
|
created_at = Column(DateTime, default=datetime.now)
|
|||
|
|
updated_at = Column(DateTime, default=datetime.now, onupdate=datetime.now)
|
|||
|
|
|
|||
|
|
def __repr__(self):
|
|||
|
|
return f"<UserFingerprint(user={self.user_id}, version={self.model_version})>"
|