summaryrefslogtreecommitdiff
path: root/examples/dashboard/app.py
diff options
context:
space:
mode:
authorschneefux <schneefux+commit@schneefux.xyz>2017-01-15 00:13:24 +0100
committerschneefux <schneefux+commit@schneefux.xyz>2017-01-15 00:13:24 +0100
commit91cb0aafaf20c0923e44ce058e1740a2e2804876 (patch)
treedc3390e7d79f29871737fa25361542ee3ef2e6ab /examples/dashboard/app.py
parentc70a290673467379230c327a713a4776df5abb6f (diff)
downloadpython-gamelocker-91cb0aafaf20c0923e44ce058e1740a2e2804876.tar.gz
python-gamelocker-91cb0aafaf20c0923e44ce058e1740a2e2804876.zip
hack a quick&dirty flask example
Diffstat (limited to 'examples/dashboard/app.py')
-rw-r--r--examples/dashboard/app.py64
1 files changed, 64 insertions, 0 deletions
diff --git a/examples/dashboard/app.py b/examples/dashboard/app.py
new file mode 100644
index 0000000..ee9de66
--- /dev/null
+++ b/examples/dashboard/app.py
@@ -0,0 +1,64 @@
+#!/usr/bin/python
+# -*- coding: utf-8 -*-
+
+from flask import Flask, render_template
+import json
+import gamelocker
+
+app = Flask(__name__)
+
+@app.route("/")
+def index():
+ api = gamelocker.Gamelocker("aaa.bbb.ccc").vainglory()
+ number = 100
+ matches = api.matches(number)
+
+ # TODO this, is a mess.
+ gameModes = []
+ for match in matches:
+ gmsuccess = False
+ for mode in gameModes:
+ if mode["name"] == match.gameMode:
+ mode["y"] += 1
+ gmsuccess = True
+ break
+ if gmsuccess == False:
+ gameModes.append({"name": match.gameMode, "y": 1})
+
+ players = []
+ picks = dict()
+ for match in matches:
+ for roster in match.rosters:
+ for participant in roster.participants:
+ # --- player stats
+ plsuccess = False
+ for player in players:
+ if player["name"] == participant.player.name:
+ player["data"][0] += 1
+ plsuccess = True
+ break
+ if plsuccess == False:
+ players.append({"name": participant.player.name, "data": [1]})
+
+ # --- hero stats
+ if match.gameMode not in picks:
+ picks[match.gameMode] = dict()
+ if participant.actor not in picks[match.gameMode]:
+ picks[match.gameMode][participant.actor] = 0
+ picks[match.gameMode][participant.actor] += 1
+
+ for p in picks: # flatten
+ heroes = list(picks[p].keys())
+ picks[p] = list(picks[p].values())
+ new_picks = []
+ for k, v in picks.items():
+ new_picks.append({"name": k, "data": v})
+ picks = new_picks
+
+ players = sorted(players, key=lambda k: k["data"][0])
+ players = players[:5]
+
+ return render_template("index.html", gameModeNum=number, gameModes=gameModes, players=players, picks=picks, heroes=heroes)
+
+if __name__ == "__main__":
+ app.run()