import pandas as pd
import numpy as np
import statsmodels.api as sm
data = pd.read_json("Overwatch090317.json")

rank=[x for x in data['rank']] 
level=[x for x in data['level']] 
wins=[x for x in data.get('comp', {})]
# winsdata=[x for x in wins.index[x]]
# wins=[x for x in data['comp'] if x <1E100]  
a=wins[0]
b=a.get('total',{})
b.get('wins',{})
def getWins(x):
    b=x.get('total',{})
    return(b.get('wins',{}))
winsExtracted =[getWins(x) for x in  wins]


#[x for x in rank if x <1e100]
def filterNaN(x):
    if x<1e100:
        return(x)
    else:
        return(0)#0 ->treat NaN as no rank
rankFiltered=[filterNaN(x) for x in rank ]
levelFiltered= [filterNaN(x) for x in level]

from pandas.stats.api import ols
df = pd.DataFrame({"A": rankFiltered, "B": level, "C":wins})
res = ols(y=df['A'], x=df[['B','C']])
res

data.to_xarray()

rankdata=[x for x in data['rank'] if x <1E100] # is x < 'infinity'

import matplotlib.pyplot as plt

"""
Explanation: $\mbox{rank} = \mbox{const}+ B\times \mbox{hoursplayed} + C \times \mbox{wins}$
End of explanation
"""


%matplotlib inline
plt.plot(rankdata)
plt.show()

compdata=data['comp']

compdata.as_matrix()

"""
Explanation: plotting
plot y vs x .plot(array[0],array[1]),
where array[0] is the x-value and  array[1] is the y value
End of explanation
"""


