In [1]:
%matplotlib inline

import os
import re
import json
import pathlib

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.collections import PatchCollection

import dota
from dota import api

In [2]:
with open(os.path.expanduser('~/') + 'Dropbox/bin/api-keys.txt') as f:
    key = json.load(f)['steam']

h = api.API(key=key)

In [ ]:
details = {}

p = pathlib.Path('../data/pro/')
matches = filter(None, map(lambda x: re.match(r'.*(\d{9}).json$', str(x)),
                           p.iterdir()))

for f in filter(lambda x: x.suffix == '.json', p.iterdir()):
    with f.open() as infile:
        
        details[f.stem] = api.DetailsResponse(json.load(infile))

In [80]:
import itertools

df = pd.concat([x.match_report() for x in itertools.islice(details.values(), 3000)])

In [87]:
CMAP = 'BuPu'
gr = df.groupby(level='hero')
wins = gr['win'].agg(['count', 'mean']).sort('count')

In [85]:
colors = plt.get_cmap(CMAP)(wins['mean'])

fig, ax = plt.subplots(figsize=(10, 30))
wins['count'].plot(kind='barh', ax=ax, color=colors)

p = PatchCollection(ax.patches, cmap=plt.get_cmap(CMAP))
p.set_array(np.array(colors))
p.set_clim([np.ma.min(colors),np.ma.max(colors)])
plt.colorbar(p) 

ax.set_title("Popular Heros (winrate by color)")
ax.set_xlabel("Times Played")


Out[85]:
<matplotlib.text.Text at 0x128064710>

In [94]:
kda = gr[['kills', 'deaths', 'assists']].mean()
kda['kills_assists'] = kda.kills + kda.assists
kda.plot(kind='scatter', x='deaths', y='kills')


Out[94]:
<matplotlib.axes._subplots.AxesSubplot at 0x11a19a610>

In [95]:
kda.plot(kind='scatter', x='deaths', y='kills_assists')


Out[95]:
<matplotlib.axes._subplots.AxesSubplot at 0x11a1d3810>

In [98]:
kda.sort('kills_assists', ascending=False)


Out[98]:
kills deaths assists kills_assists
hero
zuus 6.333333 5.428571 12.285714 18.619048
spectre 7.088000 3.592000 11.288000 18.376000
bloodseeker 7.000000 3.888889 10.444444 17.444444
riki 8.857143 3.685714 8.314286 17.171429
tiny 8.402062 3.896907 8.525773 16.927835
ember_spirit 8.333333 4.242424 8.575758 16.909091
chaos_knight 7.059259 4.681481 9.470370 16.529630
storm_spirit 7.215385 4.474359 8.733333 15.948718
pudge 7.246154 5.646154 8.553846 15.800000
ursa 9.041667 4.020833 6.104167 15.145833
invoker 5.708122 3.928934 9.076142 14.784264
kunkka 4.977143 4.131429 9.782857 14.760000
undying 3.354651 4.930233 11.331395 14.686047
puck 5.362712 4.564407 9.318644 14.681356
sniper 6.913043 3.695652 7.695652 14.608696
wisp 3.010076 5.241814 11.554156 14.564232
venomancer 2.233261 5.613391 12.326134 14.559395
luna 6.087838 3.619369 8.369369 14.457207
disruptor 2.971429 5.257143 11.451429 14.422857
queenofpain 7.430195 4.076299 6.991883 14.422078
mirana 6.035971 3.472422 8.381295 14.417266
tidehunter 3.088889 4.982222 11.311111 14.400000
razor 6.305556 4.411111 8.077778 14.383333
slark 6.641667 4.166667 7.650000 14.291667
batrider 4.368231 4.335740 9.911552 14.279783
gyrocopter 6.152893 3.852617 8.112948 14.265840
skeleton_king 5.363636 3.545455 8.818182 14.181818
tinker 5.631016 4.331551 8.513369 14.144385
rattletrap 3.971963 5.073431 10.132176 14.104139
alchemist 4.019643 4.101786 10.050000 14.069643
morphling 8.108374 2.438424 5.940887 14.049261
furion 4.207292 4.463542 9.776042 13.983333
brewmaster 4.167702 4.229814 9.527950 13.695652
visage 5.224852 4.172781 8.384615 13.609467
sand_king 3.162534 5.443526 10.385675 13.548209
slardar 4.433333 4.033333 9.033333 13.466667
nyx_assassin 3.197644 4.854712 10.253927 13.451571
ancient_apparition 3.723529 4.711765 9.670588 13.394118
viper 5.633094 4.553957 7.690647 13.323741
templar_assassin 7.117978 4.039326 6.162921 13.280899
centaur 4.640000 3.840000 8.640000 13.280000
faceless_void 6.221154 3.961538 6.980769 13.201923
dark_seer 3.431965 4.329374 9.766739 13.198704
night_stalker 5.439153 4.042328 7.724868 13.164021
nevermore 6.707965 4.221239 6.446903 13.154867
sven 5.029630 4.814815 8.074074 13.103704
witch_doctor 3.483871 5.612903 9.612903 13.096774
axe 5.689655 6.068966 7.344828 13.034483
life_stealer 5.662324 3.402823 7.353963 13.016287
magnataur 4.302103 4.401530 8.711281 13.013384
leshrac 3.916031 5.498092 9.097328 13.013359
doom_bringer 4.092511 4.162996 8.881057 12.973568
skywrath_mage 4.444444 4.311111 8.511111 12.955556
weaver 6.031343 3.453731 6.905970 12.937313
dragon_knight 4.483801 3.896328 8.449244 12.933045
earthshaker 2.413428 4.982332 10.469965 12.883392
elder_titan 3.024038 3.884615 9.841346 12.865385
jakiro 2.455852 5.141684 10.355236 12.811088
beastmaster 2.774074 4.485185 9.929630 12.703704
meepo 6.500000 6.750000 6.125000 12.625000
... ... ... ...

103 rows × 4 columns