def create_accounts_by_battles_chart(buckets, watermark_text='@WOTC_Tracker'):
    plt.clf()
    fig = plt.figure(figsize=(11, 8), dpi=150)
    then = (datetime.utcnow() - timedelta(days=1))
    fig.suptitle('Breakdown of accounts by number of battles played for {}'.format(then.strftime('%Y-%m-%d')))
    ax1 = plt.axes()
    ax1.axis('equal')
    size = 0.125
    outer_labels = []
    prev = 0
    for key in buckets['all'].keys():
        parts = key.split('-')
        outer_labels.append('{}-{} battles'.format((int(float(parts[0])) if (parts[0] != '*') else parts[0]), ((int(float(parts[1])) - 1) if (parts[1] != '*') else parts[1])))
    outer_cmap = plt.get_cmap('binary')
    outer_colors = outer_cmap([(i * 10) for i in range(10, (len(buckets['all'].keys()) + 11))])
    (outer_wedges, outer_text, outer_autotext) = ax1.pie(buckets['all'].values(), explode=[0.1 for __ in outer_labels], radius=1, colors=outer_colors, wedgeprops=dict(width=size, edgecolor='w'), autopct='%1.1f%%', pctdistance=1.1)
    bbox_props = dict(boxstyle='square,pad=0.3', fc='w', ec='k', lw=0.72)
    kw = dict(arrowprops=dict(arrowstyle='-'), bbox=bbox_props, zorder=0, va='center')
    for (i, wedge) in enumerate(outer_wedges):
        angle = calc_angle(wedge)
        y = sin((angle * (pi / 180)))
        x = cos((angle * (pi / 180)))
        align = ('right' if (x < 0) else 'left')
        connectionstyle = 'angle,angleA=0,angleB={}'.format(angle)
        kw['arrowprops'].update({'connectionstyle': connectionstyle})
        ax1.annotate(outer_labels[i], xy=(x, y), xytext=((1.35 * ((- 1) if (x < 0) else 1)), (1.4 * y)), horizontalalignment=align, **kw)
    inner_cmap = plt.get_cmap('tab20c')
    pie_flat = list(zip(buckets['xbox'].values(), buckets['ps'].values()))
    inner_labels = []
    for pair in pie_flat:
        inner_labels.extend(['xbox', 'ps'])
    inner_colors = inner_cmap([(1 if (console == 'ps') else 9) for console in inner_labels])
    (inner_wedges, inner_text, inner_autotext) = ax1.pie([item for sublist in pie_flat for item in sublist], explode=[0.1 for __ in inner_labels], radius=(1.05 - size), colors=inner_colors, wedgeprops=dict(width=size, edgecolor='w'), autopct='', pctdistance=0.9)
    for (i, label, wedge, text) in zip(range(len(inner_wedges)), inner_labels, inner_wedges, inner_autotext):
        text.set_text(buckets[label][('other' if ((i // 2) > (len(buckets['all'].keys()) - 1)) else list(buckets['all'].keys())[(i // 2)])])
        angle = calc_angle(wedge)
        if (90 < angle < 270):
            angle += 180
        text.set_rotation(angle)
    groups = [[i, (i + 1)] for i in range(0, len(inner_wedges), 2)]
    radfraction = 0.1
    for group in groups:
        angle = (((inner_wedges[group[(- 1)]].theta2 + inner_wedges[group[0]].theta1) / 2) * (pi / 180))
        for g in group:
            wedge = inner_wedges[g]
            wedge.set_center((((radfraction * wedge.r) * cos(angle)), ((radfraction * wedge.r) * sin(angle))))
    ax1.legend(inner_wedges[(- 2):], ['xbox', 'ps'], loc='lower right')
    fig.text(0.5, 0.5, watermark_text, horizontalalignment='center', verticalalignment='center', transform=ax1.transAxes)
    fig.savefig(BATTLERANGE_PNG)
    del fig
def create_accounts_by_battles_chart(buckets, watermark_text='@WOTC_Tracker'):
    plt.clf()
    fig = plt.figure(figsize=(11, 8), dpi=150)
    then = (datetime.utcnow() - timedelta(days=1))
    fig.suptitle('Breakdown of accounts by number of battles played for {}'.format(then.strftime('%Y-%m-%d')))
    ax1 = plt.axes()
    ax1.axis('equal')
    size = 0.125
    outer_labels = []
    prev = 0
    for key in buckets['all'].keys():
        parts = key.split('-')
        outer_labels.append('{}-{} battles'.format((int(float(parts[0])) if (parts[0] != '*') else parts[0]), ((int(float(parts[1])) - 1) if (parts[1] != '*') else parts[1])))
    outer_cmap = plt.get_cmap('binary')
    outer_colors = outer_cmap([(i * 10) for i in range(10, (len(buckets['all'].keys()) + 11))])
    (outer_wedges, outer_text, outer_autotext) = ax1.pie(buckets['all'].values(), explode=[0.1 for __ in outer_labels], radius=1, colors=outer_colors, wedgeprops=dict(width=size, edgecolor='w'), autopct='%1.1f%%', pctdistance=1.1)
    bbox_props = dict(boxstyle='square,pad=0.3', fc='w', ec='k', lw=0.72)
    kw = dict(arrowprops=dict(arrowstyle='-'), bbox=bbox_props, zorder=0, va='center')
    for (i, wedge) in enumerate(outer_wedges):
        angle = calc_angle(wedge)
        y = sin((angle * (pi / 180)))
        x = cos((angle * (pi / 180)))
        align = ('right' if (x < 0) else 'left')
        connectionstyle = 'angle,angleA=0,angleB={}'.format(angle)
        kw['arrowprops'].update({'connectionstyle': connectionstyle})
        ax1.annotate(outer_labels[i], xy=(x, y), xytext=((1.35 * ((- 1) if (x < 0) else 1)), (1.4 * y)), horizontalalignment=align, **kw)
    inner_cmap = plt.get_cmap('tab20c')
    pie_flat = list(zip(buckets['xbox'].values(), buckets['ps'].values()))
    inner_labels = []
    for pair in pie_flat:
        inner_labels.extend(['xbox', 'ps'])
    inner_colors = inner_cmap([(1 if (console == 'ps') else 9) for console in inner_labels])
    (inner_wedges, inner_text, inner_autotext) = ax1.pie([item for sublist in pie_flat for item in sublist], explode=[0.1 for __ in inner_labels], radius=(1.05 - size), colors=inner_colors, wedgeprops=dict(width=size, edgecolor='w'), autopct=, pctdistance=0.9)
    for (i, label, wedge, text) in zip(range(len(inner_wedges)), inner_labels, inner_wedges, inner_autotext):
        text.set_text(buckets[label][('other' if ((i // 2) > (len(buckets['all'].keys()) - 1)) else list(buckets['all'].keys())[(i // 2)])])
        angle = calc_angle(wedge)
        if (90 < angle < 270):
            angle += 180
        text.set_rotation(angle)
    groups = [[i, (i + 1)] for i in range(0, len(inner_wedges), 2)]
    radfraction = 0.1
    for group in groups:
        angle = (((inner_wedges[group[(- 1)]].theta2 + inner_wedges[group[0]].theta1) / 2) * (pi / 180))
        for g in group:
            wedge = inner_wedges[g]
            wedge.set_center((((radfraction * wedge.r) * cos(angle)), ((radfraction * wedge.r) * sin(angle))))
    ax1.legend(inner_wedges[(- 2):], ['xbox', 'ps'], loc='lower right')
    fig.text(0.5, 0.5, watermark_text, horizontalalignment='center', verticalalignment='center', transform=ax1.transAxes)
    fig.savefig(BATTLERANGE_PNG)
    del fig