diff --git a/main.py b/main.py
index d39758b..98ca9f3 100644
--- a/main.py
+++ b/main.py
@@ -1,18 +1,70 @@
import requests
from flask import Flask, jsonify, render_template
-users = {"local_klink": "Francis"}
+users = {
+ "local_klink": "Francis",
+ "awful_lickilicky": "geen-zeuser",
+ "decisive_grookey": "geen",
+ "sweet_munna": "geen",
+ "lazy_pichu": "geen",
+ "stupid_magikarp": "geen",
+ "superficial_gigalith": "geen",
+ "ugly_kingdra": "geen",
+}
+def get_game_data():
+ res = requests.get("https://botbattle.be/api/games")
+ return sorted(res.json(), key=lambda x: x['gid'])
def get_data():
res = requests.get("https://botbattle.be/api/leaderboard")
return res.json()
+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,
+ 'game': game_data[-1]['gid'],
+ }
def filter_date(data):
data = sorted(data, key=lambda x: x["elo"], reverse=True)
- filtered = list(filter(lambda x: x["username"] in users.keys(), data))
- [dict.update(item, position=index + 1, name=users[item["username"]]) for index, item in enumerate(filtered)]
+ 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']]
+
return filtered
@@ -29,9 +81,12 @@ def index():
@app.route("/leaderboard")
def leaderboard():
data = get_data()
- filtered = filter_date(data)
- return jsonify(filtered)
+ return jsonify(filter_date(data))
+@app.route("/graph")
+def graph():
+ data = get_game_data()
+ return jsonify(process_game_data(data))
if __name__ == "__main__":
app.run()
diff --git a/templates/index.html b/templates/index.html
index a5e54d7..55bd9cf 100644
--- a/templates/index.html
+++ b/templates/index.html
@@ -1,32 +1,53 @@
{% extends "header.html" %} {% block content %}
-
-
-
-
- Position |
- Name |
- Elo |
- Username |
-
-
-
- {% for row in data %}
-
- {{ row['position'] }} |
- {{ row['name'] }} |
- {{ row['elo'] }} |
- {{ row['username'] }} |
-
- {% endfor %}
-
-
+
+
+ Zeus Leaderboard - CeneBotBattle
+
+
+
+
+
+
+
+
+
+
+ Position |
+ Name |
+ Elo |
+ Username |
+
+
+
+ {% for row in data %}
+
+ {{ row['global_position'] }} |
+ {{ row['name'] }} |
+ {{ row['elo'] }} |
+ {{ row['username'] }} |
+
+ {% endfor %}
+
+
+
+
+
+
+
+
+
{% endblock %}