1. 侧边栏:根据角色过滤菜单,无可访问子菜单时隐藏父菜单 2. Dashboard:智能工牌分析、统计卡片、最近考试仅对学员显示 3. 快捷操作:根据角色显示不同的操作入口 4. 欢迎语:根据角色显示不同的欢迎信息 5. 学习天数:改为基于注册日期计算(至少为1天) 6. 成长路径:AI分析按钮仅对学员显示 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -47,20 +47,23 @@ async def get_current_user_statistics(
|
||||
获取当前用户学习统计
|
||||
|
||||
返回字段:
|
||||
- learningDays: 学习天数(按陪练会话开始日期去重)
|
||||
- learningDays: 学习天数(从注册日期到今天的天数,至少为1)
|
||||
- totalHours: 学习总时长(小时,取整到1位小数)
|
||||
- practiceQuestions: 练习题数(答题记录条数汇总)
|
||||
- averageScore: 平均成绩(已提交考试的平均分,保留1位小数)
|
||||
- examsCompleted: 已完成考试数量
|
||||
"""
|
||||
try:
|
||||
from datetime import date
|
||||
user_id = current_user.id
|
||||
|
||||
# 学习天数:按会话开始日期去重
|
||||
learning_days_stmt = select(func.count(func.distinct(func.date(TrainingSession.start_time)))).where(
|
||||
TrainingSession.user_id == user_id
|
||||
)
|
||||
learning_days = (await db.scalar(learning_days_stmt)) or 0
|
||||
# 学习天数:从注册日期到今天的天数(至少为1天)
|
||||
if current_user.created_at:
|
||||
registration_date = current_user.created_at.date() if hasattr(current_user.created_at, 'date') else current_user.created_at
|
||||
learning_days = (date.today() - registration_date).days + 1 # +1 是因为注册当天也算第1天
|
||||
learning_days = max(1, learning_days) # 确保至少为1
|
||||
else:
|
||||
learning_days = 1
|
||||
|
||||
# 总时长(小时)
|
||||
total_seconds_stmt = select(func.coalesce(func.sum(TrainingSession.duration_seconds), 0)).where(
|
||||
|
||||
Reference in New Issue
Block a user