Skip to content

Instantly share code, notes, and snippets.

@Noxville
Created February 13, 2019 16:28
Show Gist options
  • Save Noxville/14ae47041258041e56e60cc929801948 to your computer and use it in GitHub Desktop.
Save Noxville/14ae47041258041e56e60cc929801948 to your computer and use it in GitHub Desktop.
Simple Ridgeline Plot of Monthly Elo 32 Distributions for Pro Dota 2 teams.
#!/usr/bin/python3
import requests
import joypy
import pandas as pd
import numpy as np
from matplotlib import pyplot as plt
from datetime import date, timedelta
from dateutil.relativedelta import relativedelta
def get_ratings(dt):
print("Getting date {}".format(dt))
r = requests.get(url='http://datdota.com/api/ratings?date={}'.format(dt.strftime('%d-%m-%Y')))
out = []
for t in r.json()['data']:
l = [
t['teamName'],
int(dt.strftime('%d')),
int(dt.strftime('%m')),
int(dt.strftime('%Y')),
dt.strftime('%d-%m-%Y'),
t['glicko2']['rating'],
t['elo32']['current']
]
out.append(l)
return out
data = []
_date = date.today()
while _date > date(2013, 1, 1):
data.extend(get_ratings(_date))
_date -= relativedelta(months=1)
df = pd.DataFrame(data[::-1], columns=['Team', 'Day Of Month', 'Month', 'Year', 'Date', 'Glicko 2', 'Elo 32'])
grouped = df.groupby("Date", sort=False)
months = [str(y[0]) for y in list(grouped.Date.unique())]
labels= [y.split('-')[2] if '-01-' in y else None for y in months]
fig, axes = joypy.joyplot(grouped, column="Elo 32", #range_style='own',
grid="y", linewidth=1, labels=labels, legend=False, figsize=(6,5),
title="Monthly Elo (k=32) Distributions for Professional Dota 2 teams")
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment