Spaces:
Running
Running
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 |