diff options
| author | schneefux <schneefux+commit@schneefux.xyz> | 2017-01-15 22:43:52 +0100 |
|---|---|---|
| committer | schneefux <schneefux+commit@schneefux.xyz> | 2017-01-15 22:43:52 +0100 |
| commit | 778e74bbf1f43b7703d1c3230a0a88b5c5f9f573 (patch) | |
| tree | 2ba7913f407002808288257a73673e42654cf853 | |
| parent | 530cba26f5e63e2c9b593dea40ee5d774ac3d2c4 (diff) | |
| download | python-gamelocker-778e74bbf1f43b7703d1c3230a0a88b5c5f9f573.tar.gz python-gamelocker-778e74bbf1f43b7703d1c3230a0a88b5c5f9f573.zip | |
dashboard: more stats
| -rw-r--r-- | examples/dashboard/app.py | 40 | ||||
| -rw-r--r-- | examples/dashboard/templates/index.html | 39 | ||||
| -rw-r--r-- | examples/dashboard/templates/stats.js | 13 | ||||
| -rw-r--r-- | gamelocker/strings.py | 1 |
4 files changed, 84 insertions, 9 deletions
diff --git a/examples/dashboard/app.py b/examples/dashboard/app.py index c4e5e8e..036275e 100644 --- a/examples/dashboard/app.py +++ b/examples/dashboard/app.py @@ -36,11 +36,17 @@ def data(): data["number"] = config.batchsize matches = api.matches(data["number"]) + playersactors = dict() gameModes = dict() durations = dict() players = dict() heroes = dict() picks = dict() + sells = dict() + minions = 0 + potions = 0 + cs = dict() + boots = 0 for match in matches: if match.gameMode not in gameModes: gameModes[match.gameMode] = 0 @@ -63,13 +69,45 @@ def data(): heroes[participant.actor.pretty()] = 0 heroes[participant.actor.pretty()] += 1 + # TODO use id instead of name? + playersactors[participant.player.name] = participant.actor.pretty() + cs[participant.player.name] = participant.stats.minionKills / match.duration * 60 + minions += participant.stats.minionKills + + for item in participant.stats.items: + if item.pretty() in ["Sprint Boots", "Travel Boots", "Journey Boots", "War Treads", "Halcyon Chargers"]: + boots += 1 + + for item in participant.stats.itemUses: + if gamelocker.strings.LazyObject(item).pretty() == "Halcyon Potion": + potions += participant.stats.itemUses[item] + + for sold in participant.stats.itemSells: + item = gamelocker.strings.LazyObject(sold).pretty() + if not item in sells: + sells[item] = 0 + sells[item] += participant.stats.itemSells[sold] + + sells = sorted(sells.items(), key=lambda x: x[1], reverse=True) + data["topsold"] = ", ".join([s[0] for s in sells[0:3]]) + + cs = sorted(cs.items(), key=lambda x: x[1], reverse=True) + data["topcs"] = dict() + data["topcs"]["player"] = cs[0][0] + data["topcs"]["cs"] = round(cs[0][1], 2) + data["topcs"]["actor"] = playersactors[data["topcs"]["player"]] + + data["minions"] = minions + data["boots"] = boots/len(matches) + data["potions"] = round(60*sum(sum(durations.values(), []))/potions, 2) + data["gameModes"] = [{"name": k, "y": v} for k, v in gameModes.items()] data["durations"] = [{"name": k, "data": list(zip([list(durations.keys()).index(k)]*len(v), v))} for k, v in durations.items()] data["picks"] = [{"name": k, "data": list(v.values())} for k, v in picks.items()] data["heroes"] = list(heroes.keys()) - players = sorted(players.items(), key=lambda x: x[1])[:5] + players = sorted(players.items(), key=lambda x: x[1], reverse=True)[:5] data["players"] = [{"name": k, "data": [v]} for k, v in players] cache.set("data", data, timeout=10*60) diff --git a/examples/dashboard/templates/index.html b/examples/dashboard/templates/index.html index d013f3b..d89c7e8 100644 --- a/examples/dashboard/templates/index.html +++ b/examples/dashboard/templates/index.html @@ -8,7 +8,7 @@ </head> <body> <header class="navbar-fixed"> - <nav> + <nav class="blue lighten-1"> <div class="nav-wrapper"> <a href="/" class="brand-logo center">Vainglory API</a> </div> @@ -32,11 +32,33 @@ </div> <!-- #loading --> <noscript><p class="center section">This site requires JavaScript.</p></noscript> - <div class="section"> - <div id="gameType"></div> - <div id="players"></div> - <div id="durations"></div> - <div id="picks"></div> + <div class="section" id="statistics" style="display: none;"> + <div class="section" style="font-size: 2em;"> + <p class="center">Best CS</p> + <p id="cs-player" style="font-weight: bold;" class="center"></p> + <p class="center">with <span id="cs-actor"></span> (<span id="cs-cs"></span> per minute)</p> + </div> + <div class="section" id="gameType"></div> + <div class="section" style="font-size: 2em;"> + <p style="font-weight: bold;" class="center"><span id="minions"></span> Minions</p> + <p class="center">died in the last <span class="number"></span> matches</p> + </div> + <div class="section" id="players"></div> + <div class="section" style="font-size: 2em;"> + <p class="center">Average number of boots per game</p> + <p id="boots" style="font-weight: bold;" class="center"></p> + </div> + <div class="section" id="durations"></div> + <div class="section" style="font-size: 2em;"> + <p class="center">Most sold</p> + <p id="topsold" style="font-weight: bold;" class="center"></p> + </div> + <div class="section" id="picks"></div> + <div class="section" style="font-size: 2em;"> + <p class="center">Every</p> + <p id="potions" style="font-weight: bold;" class="center"></p> + <p class="center">seconds a potion is consumed</p> + </div> </div> <div id="ad" class="center"> @@ -44,7 +66,7 @@ </div> </main> - <footer class="page-footer"> + <footer class="page-footer blue lighten-1"> <div class="container"> <p class="grey-text text-lighten-4">Want to donate Bitcoin? <a class="grey-text text-lighten-3" href="bitcoin:34WgXENFP6vf5zpgDpfTYCLJjWz1RCa2t2">34WgXENFP6vf5zpgDpfTYCLJjWz1RCa2t2</a></p> <p class="grey-text text-lighten-4">View the <a class="grey-text text-lighten-3" href="https://git.schneefux.xyz/schneefux/python-gamelocker">source code</a></p> @@ -62,7 +84,8 @@ <script async type="text/javascript" src="/static/highcharts.js"></script> <script type="text/javascript"> $.getScript("/stats.js", function() { - $("#loading").hide() + $("#loading").hide(); + $("#statistics").show(); }); </script> </body> diff --git a/examples/dashboard/templates/stats.js b/examples/dashboard/templates/stats.js index cb68641..518bce8 100644 --- a/examples/dashboard/templates/stats.js +++ b/examples/dashboard/templates/stats.js @@ -1,4 +1,13 @@ $(function () { + $("#boots").text("{{ stats.boots }}"); + $("#potions").text("{{ stats.potions }}"); + $("#minions").text("{{ stats.minions }}"); + $("#topsold").text("{{ stats.topsold }}"); + $(".number").text("{{ stats.number }}"); + csstat = {{ stats.topcs|tojson|safe }}; + $("#cs-player").text(csstat.player); + $("#cs-actor").text(csstat.actor); + $("#cs-cs").text(csstat.cs); Highcharts.chart("gameType", { chart: { type: "pie" @@ -53,10 +62,14 @@ $(function () { enabled: false }, tickInterval: 1, + min: -0.5, + max: 1.5 }, title: { text: "Game durations" }, series: {{ stats.durations|tojson|safe }} }); + + $(".highcharts-credits").hide(); }); diff --git a/gamelocker/strings.py b/gamelocker/strings.py index 588a3e1..4036c6f 100644 --- a/gamelocker/strings.py +++ b/gamelocker/strings.py @@ -27,6 +27,7 @@ class Stats(dict): return obj def __get(self, name): + # name = LazyObject(name).pretty() # TODO prettify itemUses if name in self: return self.__typeit(self[name]) else: |
