In [90]:
import urllib
import urllib2
import json
from collections import Counter
import matplotlib.pyplot as plt
import matplotlib.cm as cm
%matplotlib inline

In [91]:
query_args = { 'username':'submission'}
encoded_args = urllib.urlencode(query_args)

In [92]:
encoded_args


Out[92]:
'username=submission'

In [93]:
url = 'http://52.25.91.45:8500/api?' + encoded_args
url


Out[93]:
'http://52.25.91.45:8500/api?username=submission'

In [94]:
data = urllib2.urlopen(url).read()

In [95]:
delimiter = "}"
for line in data:
    data1 =  [jsonobj+delimiter for jsonobj in data.split(delimiter) if jsonobj != ""]

In [96]:
json_list = []
for i in data1:
    json_list.append(json.loads(i))

In [97]:
sym = []
for i in range(len(json_list)):
    sym.append(Counter(json_list[i]['symbol']))

In [98]:
sym


Out[98]:
[Counter({u'abstract-method': 2,
          u'bad-continuation': 3,
          u'broad-except': 1,
          u'line-too-long': 15,
          u'redefined-outer-name': 1,
          u'trailing-whitespace': 7,
          u'unused-import': 1,
          u'unused-variable': 2})]

In [101]:
sym = Counter(json_list[0]['symbol'])
sym


Out[101]:
Counter({u'abstract-method': 2,
         u'bad-continuation': 3,
         u'broad-except': 1,
         u'line-too-long': 15,
         u'redefined-outer-name': 1,
         u'trailing-whitespace': 7,
         u'unused-import': 1,
         u'unused-variable': 2})

In [102]:
sym.items()


Out[102]:
[(u'unused-import', 1),
 (u'bad-continuation', 3),
 (u'unused-variable', 2),
 (u'broad-except', 1),
 (u'abstract-method', 2),
 (u'trailing-whitespace', 7),
 (u'redefined-outer-name', 1),
 (u'line-too-long', 15)]

In [103]:
labels = sym.keys()

In [104]:
sizes = [x*10 for x in sym.values()]

In [105]:
# get the color map then pull 1 color from it for each pie wedge we'll draw
color_map = cm.get_cmap('Pastel1')
num_of_colors = len(sizes)
picolors = color_map([x/float(num_of_colors) for x in range(num_of_colors)])

In [106]:
fig = plt.figure(figsize=[8, 8])
ax = fig.add_subplot(111)
piplt = ax.pie(sizes, explode=None, labels=labels, colors=picolors,
                autopct='%1.1f%%', shadow=True, startangle=90)
for pi in piplt[0]:
    pi.set_edgecolor('w')
    
ax.set_title('Quality of Code')
ax.plot()


Out[106]:
[]

In [107]:
len(json_list[0]['symbol'])


Out[107]:
32

In [108]:
hist_errors = []
for i in range(len(json_list)):
    hist_errors.append(len(json_list[i]['symbol']))

In [109]:
fig = plt.figure(figsize=[8, 8])
ax = fig.add_subplot(111)
ax.bar(range(len(hist_errors)), hist_errors, 
       width=0.8, color=picolors[0])
ax.set_ylim([0, 10])
ax.set_title('Progress over all core challenge submission')
ax.plot()


Out[109]:
[]

In [ ]: