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]:
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]:
In [95]:
kda.plot(kind='scatter', x='deaths', y='kills_assists')
Out[95]:
In [98]:
kda.sort('kills_assists', ascending=False)
Out[98]: