modified: app.py
This commit is contained in:
98
app.py
98
app.py
@@ -551,18 +551,110 @@ async def hoi4stats(ctx, user: Optional[discord.Member] = None):
|
||||
try:
|
||||
player = await get_or_create_player(target_user.id, target_user.display_name)
|
||||
|
||||
# Get player rankings
|
||||
async with db_pool.acquire() as conn:
|
||||
async with conn.cursor(aiomysql.DictCursor) as cursor:
|
||||
# Get standard rank
|
||||
await cursor.execute(
|
||||
"SELECT COUNT(*) + 1 as rank FROM players WHERE standard_elo > %s",
|
||||
(player['standard_elo'],)
|
||||
)
|
||||
standard_rank_result = await cursor.fetchone()
|
||||
standard_rank = standard_rank_result['rank']
|
||||
|
||||
# Get competitive rank
|
||||
await cursor.execute(
|
||||
"SELECT COUNT(*) + 1 as rank FROM players WHERE competitive_elo > %s",
|
||||
(player['competitive_elo'],)
|
||||
)
|
||||
competitive_rank_result = await cursor.fetchone()
|
||||
competitive_rank = competitive_rank_result['rank']
|
||||
|
||||
# Get total player count
|
||||
await cursor.execute("SELECT COUNT(*) as total FROM players")
|
||||
total_players_result = await cursor.fetchone()
|
||||
total_players = total_players_result['total']
|
||||
|
||||
# Get game statistics
|
||||
await cursor.execute(
|
||||
"SELECT COUNT(*) as total_games, SUM(won) as games_won FROM game_results WHERE discord_id = %s",
|
||||
(target_user.id,)
|
||||
)
|
||||
game_stats = await cursor.fetchone()
|
||||
|
||||
total_games = game_stats['total_games'] or 0
|
||||
games_won = game_stats['games_won'] or 0
|
||||
games_lost = total_games - games_won
|
||||
win_rate = (games_won / total_games * 100) if total_games > 0 else 0
|
||||
|
||||
# Create rank indicators with medals
|
||||
def get_rank_display(rank, total):
|
||||
if rank == 1:
|
||||
return f"🥇 #{rank} of {total}"
|
||||
elif rank == 2:
|
||||
return f"🥈 #{rank} of {total}"
|
||||
elif rank == 3:
|
||||
return f"🥉 #{rank} of {total}"
|
||||
else:
|
||||
return f"#{rank} of {total}"
|
||||
|
||||
embed = discord.Embed(
|
||||
title=f"📊 HOI4 ELO Stats - {target_user.display_name}",
|
||||
color=discord.Color.blue()
|
||||
)
|
||||
|
||||
embed.add_field(name="Standard ELO", value=f"🎯 {player['standard_elo']}", inline=True)
|
||||
embed.add_field(name="Competitive ELO", value=f"🏆 {player['competitive_elo']}", inline=True)
|
||||
embed.add_field(name="Player Since", value=player['created_at'].strftime("%m/%d/%Y"), inline=True)
|
||||
# ELO and Rankings
|
||||
embed.add_field(
|
||||
name="🎯 Standard ELO",
|
||||
value=f"**{player['standard_elo']}** ELO\n{get_rank_display(standard_rank, total_players)}",
|
||||
inline=True
|
||||
)
|
||||
embed.add_field(
|
||||
name="🏆 Competitive ELO",
|
||||
value=f"**{player['competitive_elo']}** ELO\n{get_rank_display(competitive_rank, total_players)}",
|
||||
inline=True
|
||||
)
|
||||
embed.add_field(
|
||||
name="📅 Player Since",
|
||||
value=player['created_at'].strftime("%m/%d/%Y"),
|
||||
inline=True
|
||||
)
|
||||
|
||||
# Game Statistics
|
||||
if total_games > 0:
|
||||
embed.add_field(
|
||||
name="🎮 Games Played",
|
||||
value=f"**{total_games}** total games",
|
||||
inline=True
|
||||
)
|
||||
embed.add_field(
|
||||
name="📈 Win/Loss",
|
||||
value=f"**{games_won}W** / **{games_lost}L**",
|
||||
inline=True
|
||||
)
|
||||
embed.add_field(
|
||||
name="📊 Win Rate",
|
||||
value=f"**{win_rate:.1f}%**",
|
||||
inline=True
|
||||
)
|
||||
else:
|
||||
embed.add_field(
|
||||
name="🎮 Games Played",
|
||||
value="No games played yet",
|
||||
inline=False
|
||||
)
|
||||
|
||||
if target_user.avatar:
|
||||
embed.set_thumbnail(url=target_user.avatar.url)
|
||||
|
||||
# Add percentile information
|
||||
standard_percentile = ((total_players - standard_rank) / total_players * 100) if total_players > 0 else 0
|
||||
competitive_percentile = ((total_players - competitive_rank) / total_players * 100) if total_players > 0 else 0
|
||||
|
||||
embed.set_footer(
|
||||
text=f"Standard: Top {100-standard_percentile:.1f}% | Competitive: Top {100-competitive_percentile:.1f}%"
|
||||
)
|
||||
|
||||
await ctx.send(embed=embed)
|
||||
|
||||
except Exception as e:
|
||||
|
||||
Reference in New Issue
Block a user