[Eva] B5.4: /stats — убрать фильтр по уровню и поле level
This commit is contained in:
+5
-13
@@ -410,21 +410,14 @@ async def get_sentence_stats(request: Request):
|
|||||||
|
|
||||||
pool = await get_pool()
|
pool = await get_pool()
|
||||||
async with pool.acquire() as conn:
|
async with pool.acquire() as conn:
|
||||||
user = await conn.fetchrow(
|
total = await conn.fetchval("SELECT COUNT(*) FROM sentences")
|
||||||
"SELECT current_level FROM users WHERE telegram_id = $1", telegram_id
|
|
||||||
)
|
|
||||||
current_level = user["current_level"] if user else "A1"
|
|
||||||
|
|
||||||
total = await conn.fetchval(
|
|
||||||
"SELECT COUNT(*) FROM sentences WHERE level = $1", current_level
|
|
||||||
)
|
|
||||||
completed = await conn.fetchval(
|
completed = await conn.fetchval(
|
||||||
"SELECT COUNT(*) FROM sentence_progress WHERE user_id = $1 AND level = $2",
|
"SELECT COUNT(*) FROM sentence_progress WHERE user_id = $1 AND completed_at IS NOT NULL",
|
||||||
telegram_id, current_level
|
telegram_id
|
||||||
)
|
)
|
||||||
total_score = await conn.fetchval(
|
total_score = await conn.fetchval(
|
||||||
"SELECT COALESCE(SUM(score), 0) FROM sentence_progress WHERE user_id = $1 AND level = $2",
|
"SELECT COALESCE(SUM(score), 0) FROM sentence_progress WHERE user_id = $1 AND completed_at IS NOT NULL",
|
||||||
telegram_id, current_level
|
telegram_id
|
||||||
)
|
)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
@@ -433,5 +426,4 @@ async def get_sentence_stats(request: Request):
|
|||||||
"remaining": total - (completed or 0),
|
"remaining": total - (completed or 0),
|
||||||
"total_score": total_score or 0,
|
"total_score": total_score or 0,
|
||||||
"progress_percent": round(((completed or 0) / total * 100), 1) if total > 0 else 0,
|
"progress_percent": round(((completed or 0) / total * 100), 1) if total > 0 else 0,
|
||||||
"level": current_level,
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user