2024-09-30 16:39:43 +02:00
|
|
|
import requests
|
|
|
|
from flask import Flask, jsonify, render_template
|
|
|
|
|
2024-10-03 15:34:30 +02:00
|
|
|
users = {
|
|
|
|
"local_klink": "Francis",
|
2024-10-07 17:45:04 +02:00
|
|
|
"naive_persian": "Vincent",
|
2024-10-07 18:28:44 +02:00
|
|
|
"punctual_pyroar": "Seppe",
|
2024-10-09 14:31:05 +02:00
|
|
|
"unmotivated_tentacruel": "Tybo",
|
2024-10-09 14:50:28 +02:00
|
|
|
"outgoing_torchic": "Mathieu",
|
2024-10-09 14:54:44 +02:00
|
|
|
"mercurial_celebi": "Rune",
|
2024-10-17 17:59:17 +02:00
|
|
|
"sloppy_golem": "Elias",
|
2024-10-03 15:34:30 +02:00
|
|
|
}
|
2024-09-30 16:39:43 +02:00
|
|
|
|
2024-10-03 15:34:30 +02:00
|
|
|
def get_game_data():
|
2024-10-11 11:51:55 +02:00
|
|
|
res = requests.get("https://botbattle.be/api/games?num=5000")
|
2024-10-03 15:34:30 +02:00
|
|
|
return sorted(res.json(), key=lambda x: x['gid'])
|
2024-09-30 16:39:43 +02:00
|
|
|
|
|
|
|
def get_data():
|
|
|
|
res = requests.get("https://botbattle.be/api/leaderboard")
|
|
|
|
return res.json()
|
|
|
|
|
2024-10-03 15:34:30 +02:00
|
|
|
def process_game_data(game_data):
|
|
|
|
bots: dict[str, dict] = {}
|
|
|
|
|
|
|
|
min_elo: int | None = None
|
|
|
|
max_elo: int | None = None
|
|
|
|
|
|
|
|
for game in game_data:
|
|
|
|
for user in game['users']:
|
|
|
|
username = user['username']
|
|
|
|
if username in users:
|
|
|
|
if username not in bots:
|
|
|
|
if min_elo is None:
|
|
|
|
min_elo = user['elo']
|
|
|
|
max_elo = user['elo']
|
|
|
|
bots[username] = {'x': [], 'y': [], 'color_ring': user['color_ring'], 'color_body': user['color_body']}
|
|
|
|
|
|
|
|
if user['elo'] < min_elo:
|
|
|
|
min_elo = user['elo']
|
|
|
|
elif user['elo'] > max_elo:
|
|
|
|
max_elo = user['elo']
|
|
|
|
|
|
|
|
bots[username]['x'].append(game['gid'])
|
|
|
|
bots[username]['y'].append(user['elo'])
|
|
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
'bots': bots,
|
|
|
|
'min_elo': min_elo,
|
|
|
|
'max_elo': max_elo,
|
2024-10-11 11:51:55 +02:00
|
|
|
'min_game': game_data[0]['gid'],
|
|
|
|
'max_game': game_data[-1]['gid'],
|
2024-10-03 15:34:30 +02:00
|
|
|
}
|
2024-09-30 16:39:43 +02:00
|
|
|
|
|
|
|
def filter_date(data):
|
|
|
|
data = sorted(data, key=lambda x: x["elo"], reverse=True)
|
2024-10-03 15:34:30 +02:00
|
|
|
filtered = []
|
|
|
|
|
|
|
|
for i, user in enumerate(data):
|
|
|
|
user["global_position"] = i + 1
|
|
|
|
|
|
|
|
if user['username'] not in users:
|
|
|
|
continue
|
|
|
|
|
|
|
|
filtered.append(user)
|
|
|
|
user['name'] = users[user['username']]
|
|
|
|
|
2024-09-30 16:39:43 +02:00
|
|
|
return filtered
|
|
|
|
|
|
|
|
|
|
|
|
app = Flask(__name__)
|
|
|
|
|
|
|
|
|
|
|
|
@app.route("/")
|
|
|
|
def index():
|
|
|
|
data = get_data()
|
|
|
|
filtered = filter_date(data)
|
|
|
|
return render_template("index.html", data=filtered)
|
|
|
|
|
|
|
|
|
|
|
|
@app.route("/leaderboard")
|
|
|
|
def leaderboard():
|
|
|
|
data = get_data()
|
2024-10-03 15:34:30 +02:00
|
|
|
return jsonify(filter_date(data))
|
2024-09-30 16:39:43 +02:00
|
|
|
|
2024-10-03 15:34:30 +02:00
|
|
|
@app.route("/graph")
|
|
|
|
def graph():
|
|
|
|
data = get_game_data()
|
|
|
|
return jsonify(process_game_data(data))
|
2024-09-30 16:39:43 +02:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
2024-10-04 16:49:53 +02:00
|
|
|
app.run(host='0.0.0.0')
|