Example #1
0
def collected_salestax(qstring):
    all_salestax = sorted(salestax(qstring), key=lambda x: x['collector'])
    by_collector = itertools.groupby(all_salestax, lambda x: x['collector'])

    data = dict((k, sum([Decimal(st['tax']) for st in v])) for k, v in by_collector)
    if qstring.get('chart'):
        chart_data = {}
        chart_data['x_vals'] = data.keys()
        series_0 = {'name': 'Sales Tax Collected'}
        series_0['data'] = [data[k] for k in chart_data['x_vals']]
        chart_data['series'] = [series_0]
        return chart_data
    else:
        return data
Example #2
0
def collected_salestax(qstring):
    chart_data = column_chart(title='Tax Collected',
                              y_label='Total',
                              data_labels=True)
    chart_data['plotOptions']['series']['dataLabels']['format'] = '{point.y:,.2f}'

    all_salestax = sorted(sales_api.salestax(qstring), key=lambda x: x['collector'])
    by_collector = itertools.groupby(all_salestax, lambda x: x['collector'])

    data = dict((k, sum([float(st['tax']) for st in v])) for k, v in by_collector)    
    chart_data['xAxis'] = {'categories': data.keys()}
    series_0 = {'name': 'Sales Tax Collected'}
    series_0['data'] = [float(data[k]) for k in chart_data['xAxis']['categories']]
    chart_data['series'] = [series_0]
    return chart_data