count users without gamers

This commit is contained in:
vrubelroman 2025-11-20 02:22:44 +03:00
parent ef9aa3d3df
commit faf6ec0c35
3 changed files with 32 additions and 1 deletions

View file

@ -151,6 +151,19 @@ def get_users():
cursor.execute("SELECT COUNT(*) FROM telegram_users WHERE DATE(created_at) = ?", (today,))
users_today = cursor.fetchone()[0]
# Count users without gamers
cursor.execute("""
SELECT COUNT(DISTINCT tu.user_id)
FROM telegram_users tu
LEFT JOIN user_gamers ug ON tu.user_id = ug.user_id
WHERE ug.id IS NULL
""")
users_without_gamers = cursor.fetchone()[0]
# Calculate percentage
total_users = len(users)
users_without_gamers_percent = round((users_without_gamers / total_users * 100)) if total_users > 0 else 0
# Count new gamers today (from user_gamers table)
cursor.execute("""
SELECT COUNT(DISTINCT g.id)
@ -175,8 +188,10 @@ def get_users():
return jsonify({
'success': True,
'users': users,
'total_users': len(users),
'total_users': total_users,
'users_today': users_today,
'users_without_gamers': users_without_gamers,
'users_without_gamers_percent': users_without_gamers_percent,
'total_gamers': total_gamers,
'gamers_today': gamers_today,
'message_stats': message_stats