File size: 988 Bytes
dc376d9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import json
import os

LEADERBOARD_FILE = "leaderboard.json"

def load_leaderboard():
    if not os.path.exists(LEADERBOARD_FILE):
        return {}
    with open(LEADERBOARD_FILE, 'r') as f:
        return json.load(f)

def get_fun_stats() -> str:
    leaderboard = load_leaderboard()
    if not leaderboard:
        return "No stats available yet."
    
    total_battles = sum(data['wins'] + data['losses'] for data in leaderboard.values())
    total_wins = sum(data['wins'] for data in leaderboard.values())
    total_losses = sum(data['losses'] for data in leaderboard.values())
    win_rate = (total_wins / total_battles * 100) if total_battles > 0 else 0

    stats_html = f"""
    <ul>
        <li><strong>Total Battles:</strong> {total_battles}</li>
        <li><strong>Total Wins:</strong> {total_wins}</li>
        <li><strong>Total Losses:</strong> {total_losses}</li>
        <li><strong>Overall Win Rate:</strong> {win_rate:.2f}%</li>
    </ul>
    """
    return stats_html