diff options
| -rw-r--r-- | examples/dashboard/app.py | 64 | ||||
| -rw-r--r-- | examples/dashboard/templates/index.html | 59 |
2 files changed, 123 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() diff --git a/examples/dashboard/templates/index.html b/examples/dashboard/templates/index.html new file mode 100644 index 0000000..ead4fdd --- /dev/null +++ b/examples/dashboard/templates/index.html @@ -0,0 +1,59 @@ +<!DOCTYPE html> +<html lang="en"> + <head> + <meta name="viewport" content="width=device-width, initial-scale=1.0"> + <meta charset="utf-8"> + <title>Vainglory API demo</title> + </head> + <body> + <div id="gameType" style="height: 100%; width: 400px;"></div> + <div id="players" style="height: 100%; width: 400px;"></div> + <div id="picks" style="height: 100%; width: 400px;"></div> + <script src="https://code.jquery.com/jquery-3.1.1.min.js"></script> + <script src="http://code.highcharts.com/highcharts.js"></script> + <script> + $(function () { + Highcharts.chart("gameType", { + chart: { + type: "pie" + }, + title: { + text: "Game modes over the last {{ number }} matches" + }, + series: [{ + data: {{ gameModes|tojson|safe }} + }] + }); + Highcharts.chart("players", { + chart: { + type: "bar" + }, + xAxis: { + categories: ["matches"] + }, + title: { + text: "Most active players" + }, + series: {{ players|tojson|safe }} + }); + Highcharts.chart("picks", { + chart: { + type: "column" + }, + title: { + text: "Popular picks" + }, + plotOptions: { + column: { + stacking: "normal" + } + }, + xAxis: { + categories: {{ heroes|tojson|safe }} + }, + series: {{ picks|tojson|safe }} + }); + }); + </script> + </body> +</html> |
