Пример #1
0
def get_image_url(obj):
    """
    Returns URL for the static image
    """
    height = 210

    trans = []
    fuzzy = []
    labels_left = []
    labels_right = []

    stats = get_sorted_stats(obj)
    for stat in stats:
        t = stat.translated_perc
        trans.append(t)
        labels_left.append(stat.language.name.encode('utf-8'))
        labels_right.append("%s%%" % t)

    labels_left.reverse()
    labels_right.reverse()

    chart = StackedHorizontalBarChart(
        width = 350,
        height = 14 + 13 * len(stats),
        x_range=(0, 100))
    chart.set_bar_width(9)
    chart.set_colours(['78dc7d', 'dae1ee', 'efefef']) # Green, dark gray, light gray
    chart.set_axis_labels(Axis.LEFT, labels_left)
    chart.set_axis_labels(Axis.RIGHT, labels_right)
    chart.add_data(trans)
    return chart.get_url()
Пример #2
0
def get_image_url(obj, project=False):
    """
    Returns URL for the static image
    """
    height = 210

    trans = []
    fuzzy = []
    labels_left = []
    labels_right = []

    stats = get_sorted_stats(obj, project)
    for stat in stats:
        t = stat.translated_perc
        trans.append(t)
        labels_left.append(stat.language.name.encode('utf-8'))
        labels_right.append("%s%%" % t)

    labels_left.reverse()
    labels_right.reverse()

    chart = StackedHorizontalBarChart(width=350,
                                      height=14 + 13 * len(stats),
                                      x_range=(0, 100))
    chart.set_bar_width(9)
    chart.set_colours(['78dc7d', 'dae1ee',
                       'efefef'])  # Green, dark gray, light gray
    chart.set_axis_labels(Axis.LEFT, labels_left)
    chart.set_axis_labels(Axis.RIGHT, labels_right)
    chart.add_data(trans)
    return chart.get_url()
Пример #3
0
def _get_definitionlookups_bar(datas, width, height,
                               background_color=None, colour=None):
    max_ = max(max(v[1]) for v in datas)
    chart = StackedHorizontalBarChart(width, height, x_range=(0, max_ + int(.1*max_)))
        
    chart.add_data([x[1][0] for x in datas])
    chart.add_data([x[1][1] for x in datas])


    # 222
    labels = [x[0].encode('utf8') for x in datas][::-1] # 223
    import urllib
    #print [urllib.quote(str(a)) for a in labels]
    
    #print list(labels)
    chart.set_axis_labels(pygooglechart.Axis.LEFT, labels)
    chart.set_legend(['Looked up','Not looked up'])
    chart.set_colours(['ff9900','ffebcc'])
    chart.add_marker(0, '', 'N*f1*%', '000000', 10)
    
    if background_color:
        chart.fill_solid(chart.BACKGROUND, background_color)
    if colour:
        chart.set_colours([colour])
    return chart.get_url()
    
        
Пример #4
0
def __fullfile_chart(title,data,labels,color):
    chart=StackedHorizontalBarChart(WIDTH, len(data)*40,x_range=[0,__max_x(data)])
    chart.set_colours([color])
    chart.add_data(data)
    chart.set_axis_labels(Axis.TOP,[title])
    chart.set_axis_labels(Axis.LEFT,labels)
    chart.set_axis_labels(Axis.RIGHT, __r_labels(data))
    file_name='%s_%s.png' % (title.replace(' ','_').lower(),datetime.now().strftime('%Y-%m-%d'))
    chart.download(file_name)
    return file_name
Пример #5
0
def bar_chart_cve(data, labels, filename, title):
    chart = StackedHorizontalBarChart(settings.width, settings.height,
                                      x_range=(0, 10))
    chart.set_bar_width(10)
    chart.set_title(title)
    chart.set_legend([ 'Impacto','Exploitabilidade'])
    chart.set_colours(['0000ff', 'ff0000'])
    chart.set_legend_position('r')
    chart.set_axis_labels(Axis.LEFT, labels)
    chart.add_data(data)
    chart.download(filename)
Пример #6
0
def stacked_horizontal():
    chart = StackedHorizontalBarChart(400, 200,
                                      x_range=(0, 35))
    chart.set_bar_width(10)
    chart.set_colours(['00ff00', 'ff0000','ACff0C','B0ffE0','C0ffFF'])
    chart.add_data([1,2,3,4,5])
    chart.set_title('This is title')
    chart.set_legend( ['a','b','c','d','e'])
    chart.set_axis_labels('y', ['aa','bb','cc','dd','ee'])
    chart.annotated_data()
    chart.download('bar-horizontal-stacked.png')
Пример #7
0
def bar_chart_cve(data, labels, filename, title):
    chart = StackedHorizontalBarChart(settings.width,
                                      settings.height,
                                      x_range=(0, 10))
    chart.set_bar_width(10)
    chart.set_title(title)
    chart.set_legend(['Impacto', 'Exploitabilidade'])
    chart.set_colours(['0000ff', 'ff0000'])
    chart.set_legend_position('r')
    chart.set_axis_labels(Axis.LEFT, labels)
    chart.add_data(data)
    chart.download(filename)
    def display_user_stats(self, type="pie", filepath="chart.png"):
        """ filepath = display, filepath = url, filepath = real filepath"""
        """displays the number of VMs a user is running"""
        """ types supported pie, bar"""

        values = []
        label_values = []

        #        print self.users
        
        max_v = 0
        for name in self.users:
            number = self.users[name]['count']
            values.append(number)
            label_values.append(name + ":" + str(number))
            max_v = max(max_v, number)

        # print values
        # print label_values

        if type == "pie": 
            chart = PieChart3D(500, 200)
            chart.set_pie_labels(label_values)
        if type == "bar":
            chart = StackedHorizontalBarChart(500,200,
                                            x_range=(0, max_v))
            # the labels seem wrong, not sure why i have to call reverse
            chart.set_axis_labels('y', reversed(label_values))
            # setting the x axis labels
            left_axis = range(0, max_v + 1, 1)
            left_axis[0] = ''
            chart.set_axis_labels(Axis.BOTTOM, left_axis)

            chart.set_bar_width(10)
            chart.set_colours(['00ff00', 'ff0000'])

        # Add some data
        chart.add_data(values)

        # Assign the labels to the pie data

        if filepath == "display":
            #os.system ("open -a /Applications/Safari.app " + '"' + url + '"')
            os.system ("open " + filepath)
        elif filepath == "url":
            url = chart.get_url()
            print url
        else:
            Utility.ensure_dir(filepath)
            chart.download(filepath)
Пример #9
0
def generate_bar_chart_by_agency_from_local():
    
    # initialize lists
    agency_names = []
    counts = []
    colours = []
    combined = []
    i = 0
            
    # get data 
    for a in Agency.objects.all():
        qset = FedRegDoc.objects.filter(agencies__name=a.name)
        if a.name:
            agency_names.append(a.name)
            counts.append(qset.count())
        elif a.raw_name:
            agency_names.append(a.raw_name)
            counts.append(qset.count())

    # the following section is a hack to order the chart properly
    len_counts = len(counts)
    while i < len_counts:
        combined.append((agency_names[i], counts[i]))
        i += 1
    i=0
    combined = sorted(combined, key=lambda c: c[1], reverse=True)
    #print "combined", combined
    counts = []
    agency_names = []
    while i < len_counts:
        counts.append(combined[i][1])
        agency_names.append(combined[i][0])
        i += 1
    agency_names.reverse()
    
    # set up chart
    chart = StackedHorizontalBarChart(600, 400, y_range=[0, max(counts)+10])
    chart.set_colours(['0000FF'])
    chart.set_axis_labels(Axis.LEFT, agency_names)
    chart.add_data(counts)
    chart.set_bar_width(10)
    chart_url = chart.get_url()
    #print "chart_url by agency", chart_url
    
    return chart_url
def Chart():
    aa = scraperwiki.datastore.retrieve({'Wards':None})
    d = defaultdict(int)
    for a in aa:
        pp = a['data']['Wards']
        d[pp] += 1
    print d
    chart = StackedHorizontalBarChart(700, 425, x_range=(0, 200), colours=["556600"])
    chart.set_legend(['Planning apps'])
    chart.set_bar_width(8)
    axis = sorted(d.keys())
    data = [d[x] for x in axis]
    chart.set_axis_labels(Axis.LEFT, axis)
    chart.set_axis_labels(Axis.BOTTOM, map(str, range(0,100,10)))
    chart.add_data(data)
    graph_url = chart.get_url()
    print graph_url
    scraperwiki.sqlite.save_var("chart", graph_url)
Пример #11
0
    def get_bar_chart_image(self, data, **kw):
        """ Return image path of downloaded image from google charts api"""

        if len(data['y']) == 0:
            return ''

        from pygooglechart import StackedHorizontalBarChart, Axis

        width = int(kw.get('width', 400))
        height = int(kw.get('height', 250))

        max_y = max(data['y'])

        chart = StackedHorizontalBarChart(width,
                                          height,
                                          x_range=[0, max_y],
                                          y_range=[0, len(data['x'])])

        chart.add_data(data['y'])
        chart.set_colours(['76A4FB'])
        chart.set_axis_labels(Axis.LEFT, data['x'])
        bottom_labels = [
            utils.intcomma(x) for x in range(0, max_y + 1, (max_y) / 5)
        ]
        chart.set_axis_labels(Axis.BOTTOM, bottom_labels)

        #Generate an hash from arguments
        kw_hash = hash(tuple(sorted(kw.items())))
        data_hash = hash(
            tuple(sorted([(k, tuple(v)) for k, v in data.iteritems()])))
        args_hash = str(kw_hash) + str(data_hash)

        image_path = os.path.join(TARGET_DIR, "%s.png" % args_hash)

        if bool(kw.get('refresh', False)) or args_hash not in self.charts:
            #Get image from google chart api
            chart.download(image_path)
            if args_hash not in self.charts:
                self.charts.append(args_hash)
            self._p_changed = True

        return image_path
Пример #12
0
def Chart():
    aa = scraperwiki.datastore.retrieve({'Wards': None})
    d = defaultdict(int)
    for a in aa:
        pp = a['data']['Wards']
        d[pp] += 1
    print d
    chart = StackedHorizontalBarChart(700,
                                      425,
                                      x_range=(0, 200),
                                      colours=["556600"])
    chart.set_legend(['Planning apps'])
    chart.set_bar_width(8)
    axis = sorted(d.keys())
    data = [d[x] for x in axis]
    chart.set_axis_labels(Axis.LEFT, axis)
    chart.set_axis_labels(Axis.BOTTOM, map(str, range(0, 100, 10)))
    chart.add_data(data)
    graph_url = chart.get_url()
    print graph_url
    scraperwiki.sqlite.save_var("chart", graph_url)
    def get_bar_chart_image(self, data, **kw):
        """ Return image path of downloaded image from google charts api"""

        if len(data['y']) == 0:
            return ''

        from pygooglechart import StackedHorizontalBarChart, Axis

        width = int(kw.get('width', 400))
        height = int(kw.get('height', 250))

        max_y = max(data['y'])

        chart = StackedHorizontalBarChart(width, height,
                                        x_range=[0, max_y],
                                        y_range=[0, len(data['x'])])


        chart.add_data(data['y'])
        chart.set_colours(['76A4FB'])
        chart.set_axis_labels(Axis.LEFT, data['x'])
        bottom_labels = [utils.intcomma(x) for x in range(0, max_y + 1, (max_y)/5)]
        chart.set_axis_labels(Axis.BOTTOM, bottom_labels)

        #Generate an hash from arguments
        kw_hash = hash(tuple(sorted(kw.items())))
        data_hash = hash(tuple(sorted([(k, tuple(v))
            for k, v in data.iteritems()])))
        args_hash = str(kw_hash) + str(data_hash)

        image_path = os.path.join(TARGET_DIR, "%s.png" % args_hash)

        if bool(kw.get('refresh', False)) or args_hash not in self.charts:
            #Get image from google chart api
            chart.download(image_path)
            if args_hash not in self.charts:
                self.charts.append(args_hash)
            self._p_changed = True

        return image_path
Пример #14
0
def _bar_graph(data,
               legends,
               axis_labels,
               size,
               steps,
               type=StackedVerticalBarChart,
               multiline=False):

    if multiline:
        max_values = []
        min_values = []
        for row in data:
            max_values.append(max(row))
            min_values.append(min(row))
        max_value = max(max_values)
        min_value = min(min_values)
    else:
        max_value = max(data)
        min_value = min(data)

    #validando si hay datos para hacer grafico
    if max_value == 0:
        return None

    step = ((max_value * 1.05) - (min_value * 0.95)) / steps

    #validando en caso de el paso sea menor que uno y de cero en la conversion
    if step < 1:
        step = 1

    tope = int(round(max_value * 1.05))
    if tope < max_value:
        tope += 2
    else:
        tope += 1

    left_axis = range(int(round(min_value * 0.95)), tope, int(step))
    left_axis[0] = ''

    if type == StackedHorizontalBarChart:
        graph = StackedHorizontalBarChart(size[0],
                                          size[1],
                                          x_range=(0, max_value * 1.05))
        graph.set_axis_labels(Axis.BOTTOM, left_axis)
        if axis_labels:
            graph.set_axis_labels(Axis.LEFT, axis_labels)
    elif type == StackedVerticalBarChart:
        graph = StackedVerticalBarChart(size[0],
                                        size[1],
                                        y_range=(0, max_value * 1.05))
        graph.set_axis_labels(Axis.LEFT, left_axis)
        if axis_labels:
            graph.set_axis_labels(Axis.BOTTOM, axis_labels)
    elif type == GroupedHorizontalBarChart:
        graph = GroupedHorizontalBarChart(size[0],
                                          size[1],
                                          x_range=(0, max_value * 1.05))
        graph.set_axis_labels(Axis.BOTTOM, left_axis)
        if axis_labels:
            graph.set_axis_labels(Axis.LEFT, axis_labels)
        graph.set_bar_spacing(5)
    elif type == GroupedVerticalBarChart:
        graph = GroupedVerticalBarChart(size[0],
                                        size[1],
                                        y_range=(0, max_value * 1.05))
        graph.set_axis_labels(Axis.LEFT, left_axis)
        if axis_labels:
            graph.set_axis_labels(Axis.BOTTOM, axis_labels)
        graph.set_bar_spacing(5)
    else:
        pass  #raise exception

    if multiline:
        for fila in data:
            graph.add_data(fila)
    else:
        graph.add_data(data)

    graph.set_colours(
        ['FFBC13', '22A410', 'E6EC23', '2B2133', 'BD0915', '3D43BD'])
    graph.set_bar_width(44)
    graph.set_legend(legends)
    graph.set_legend_position('b')

    return graph
Пример #15
0
def _bar_graph(data, legends, axis_labels, size, steps,  
                    type=StackedVerticalBarChart, multiline=False):
    
    if multiline:
        max_values = []
        min_values = [] 
        for row in data:
            max_values.append(max(row))
            min_values.append(min(row))
        max_value = max(max_values)
        min_value = min(min_values)
    else:
        max_value = max(data)
        min_value = min(data)

    #validando si hay datos para hacer grafico
    if max_value==0:
        return None

    step = ((max_value*1.05)-(min_value*0.95))/steps
    
    #validando en caso de el paso sea menor que uno y de cero en la conversion
    if step<1:
        step = 1    

    tope = int(round(max_value*1.05))
    if tope < max_value:
        tope+=2
    else:
        tope+=1

    left_axis = range(int(round(min_value*0.95)), tope, int(step))
    left_axis[0]=''

    if type==StackedHorizontalBarChart:
        graph = StackedHorizontalBarChart(size[0], size[1], x_range=(0, max_value*1.05))
        graph.set_axis_labels(Axis.BOTTOM, left_axis)
        if axis_labels:
            graph.set_axis_labels(Axis.LEFT, axis_labels)
    elif type==StackedVerticalBarChart:
        graph = StackedVerticalBarChart(size[0], size[1], y_range=(0, max_value*1.05))
        graph.set_axis_labels(Axis.LEFT, left_axis)
        if axis_labels:
            graph.set_axis_labels(Axis.BOTTOM, axis_labels)
    elif type==GroupedHorizontalBarChart:
        graph = GroupedHorizontalBarChart(size[0], size[1], x_range=(0, max_value*1.05))
        graph.set_axis_labels(Axis.BOTTOM, left_axis)
        if axis_labels:
            graph.set_axis_labels(Axis.LEFT, axis_labels)
        graph.set_bar_spacing(5)
    elif type==GroupedVerticalBarChart:
        graph = GroupedVerticalBarChart(size[0], size[1], y_range=(0, max_value*1.05))
        graph.set_axis_labels(Axis.LEFT, left_axis)
        if axis_labels: 
            graph.set_axis_labels(Axis.BOTTOM, axis_labels)
        graph.set_bar_spacing(5)
    else:
        pass #raise exception


    if multiline:
        for fila in data:
            graph.add_data(fila)
    else:
        graph.add_data(data)
    
    graph.set_colours(COLORS)
    graph.set_bar_width(32)
    graph.set_legend(legends)
    graph.set_legend_position('b')
    
    
    return graph
Пример #16
0
https://github.com/gak/pygooglechart/blob/master/examples/bar.py

from pygooglechart import StackedHorizontalBarChart, StackedVerticalBarChart, \
    GroupedHorizontalBarChart, GroupedVerticalBarChart

	
	new_chart = StackedHorizontalBarChart(800,600)
>>> data_list=[]
>>> for item in data:
	if item == '':
		item = 0
	data_list.append(item)

	
>>> labels = []
>>> labels = data_dict.keys()
>>> new_chart.set_axis_labels('y', labels)
0
>>> data_list=[]
>>> for item in data:
	if item == '':
		item = 0
	data_list.append(item)
new_chart.set_colours(['D6F8F8'])
Пример #17
0
def main_dashboard(request):
    
    today, created = DailyStats.objects.get_or_create(day=date.today())
    if today.users == 0:
        today.users = 1

    # ---- Daily usage ----
    enddate = date.today()
    #startdate = enddate - timedelta(weeks=60)
    startdate = enddate - timedelta(weeks=4)
    averageusage = DailyStats.objects.filter(day__range=(startdate, enddate)).order_by('day')
    days = []
    signins = []
    posts = []
    replies = []
    whiteboards = []
    signups = []
    listsignups = []
    listupgrades = []
    deletions = []
    numUsers = []
    numRegularMembers = []
    regupgrades = []
    renewals = []
    regdowngrades = []
    for s in averageusage:
        days.append(s.day.strftime("%B %y"))
        signins.append(s.signins)
        posts.append(s.posts)
        replies.append(s.replies)
        whiteboards.append(s.whiteboardEdits)
        signups.append(s.signups)
        listsignups.append(s.mailinglistsignups)
        listupgrades.append(s.mailinglistupgrades)
        deletions.append(s.deletions)
        numUsers.append(s.users)
        numRegularMembers.append(s.regularmembers)
        regupgrades.append(s.regupgrades)
        renewals.append(s.renewals)
        regdowngrades.append(s.regdowngrades)

    xaxis = []
    #for i in range(0, len(days), 1):    # this will make limited test data look better
    for i in range(0, len(days), len(days)/8):
        xaxis.append(days[i])

    # ---- Daily usage ----
    dailyUsageChart = SimpleLineChart(600, 450, y_range=(0, max(signins)))
    #chart.add_data(avgsignins)
    dailyUsageChart.add_data(posts)
    dailyUsageChart.add_data(replies)
    dailyUsageChart.add_data(signins)
    dailyUsageChart.add_data(whiteboards)

    dailyUsageChart.set_colours(['ff0000', 'ffff00', '00ff00', '0000ff'])
    dailyUsageChart.set_legend(['posts', 'replies', 'signins', 'whiteboards'])
    dailyUsageChart.set_legend_position('b')

    #yaxis = range(0, max_signins + 1, 2)    # this will make limited test data look better
    yaxis = range(0, max(signins), max(signins)/10)
    yaxis[0] = ''
    dailyUsageChart.set_axis_labels(Axis.LEFT, yaxis)
    dailyUsageChart.set_axis_labels(Axis.BOTTOM, xaxis)
        
    dailyUsage = dailyUsageChart.get_url()
    
    # ---- Account changes ----
    accountChangesChart = SimpleLineChart(600, 450, y_range=(0, 25))
    accountChangesChart.add_data(signups)
    accountChangesChart.add_data(listsignups)
    accountChangesChart.add_data(listupgrades)
    accountChangesChart.add_data(deletions)

    accountChangesChart.set_colours(['ff0000', 'ffff00', '00ff00', '0000ff'])
    accountChangesChart.set_legend(['account signups', 'email signups', 'email upgrades', 'deletions'])
    accountChangesChart.set_legend_position('b')

    #yaxis = range(0, 25, 2)    # this will make limited test data look better
    yaxis = range(0, min(max(listsignups), 10), max(max(listsignups)/10, 1))
    yaxis[0] = ''
    accountChangesChart.set_axis_labels(Axis.LEFT, yaxis)
    accountChangesChart.set_axis_labels(Axis.BOTTOM, xaxis)
        
    accountChanges = accountChangesChart.get_url()
    
    # ---- Membership ----
    membershipChart = SimpleLineChart(600, 450, y_range=(42000, 52000))
    membershipChart.add_data(numUsers)
    membershipChart.add_data(numRegularMembers)

    membershipChart.set_colours(['ff0000', '0000ff'])
    membershipChart.set_legend(['total users', 'regular members'])
    membershipChart.set_legend_position('b')

    yaxis = range(42000, 52000, 1000)
    yaxis[0] = ''
    yaxis2 = range(0, 1500, 50)
    yaxis2[0] = ''
    membershipChart.set_axis_labels(Axis.LEFT, yaxis)
    membershipChart.set_axis_labels(Axis.RIGHT, yaxis2)
    membershipChart.set_axis_labels(Axis.BOTTOM, xaxis)
        
    membershipChart = membershipChart.get_url()
    
    # ---- Account changes ----
    membershipChangesChart = SimpleLineChart(600, 450, y_range=(0, 10))
    membershipChangesChart.add_data(regupgrades)
    membershipChangesChart.add_data(renewals)
    membershipChangesChart.add_data(regdowngrades)

    membershipChangesChart.set_colours(['ff0000', 'ffff00', '00ff00'])
    membershipChangesChart.set_legend(['regular upgrades', 'renewals', 'regular downgrades'])
    membershipChangesChart.set_legend_position('b')

    #yaxis = range(0, 25, 2)    # the same.
    yaxis = range(0,
                  max(max(regupgrades), max(regdowngrades), max(renewals)),
                  max(max(max(regupgrades), max(regdowngrades), max(renewals))/10, 1))
    yaxis[0] = ''
    membershipChangesChart.set_axis_labels(Axis.LEFT, yaxis)
    membershipChangesChart.set_axis_labels(Axis.BOTTOM, xaxis)
        
    membershipChanges = membershipChangesChart.get_url()
    
    # ---- Status breakdown ----
    statusBreakdownChart = PieChart3D(600, 240)
    mlistmembers = today.users - today.regularmembers - today.associatemembers
    statusBreakdownChart.add_data([mlistmembers + 1,            # FIXME: the +1 is needed so pygoogle doesn't crash (it doesn't handle zeroes well)
                                   today.associatemembers + 1,
                                   today.regularmembers + 1])

    statusBreakdownChart.set_colours(['ff0000', 'ffff00', '00ff00'])
    statusBreakdownChart.set_pie_labels(["mailing list members",
                                         "associate members",
                                         "regular members"])
    statusBreakdown = statusBreakdownChart.get_url()
    
    # ---- Membership breakdown ----
    chapters = Network.objects.filter(chapter_info__isnull=False, is_active=True)
    chapternames = []
    chaptermembers = []
    for chapter in chapters:
        chapternames.append(chapter.slug)
        chaptermembers.append(chapter.members.all().count())
    
    membershipBreakdownChart = StackedHorizontalBarChart(500, 500,
                                                         x_range=(0, max(chaptermembers)))
    membershipBreakdownChart.add_data(chaptermembers)
    yaxis = range(0, max(chaptermembers), 10)
    yaxis[0] = ''
    membershipBreakdownChart.set_axis_labels(Axis.BOTTOM, yaxis)
    membershipBreakdownChart.set_axis_labels(Axis.LEFT,
                                             chapternames)
    membershipBreakdownChart.set_bar_width(330 / len(chapternames))
    membershipBreakdown = membershipBreakdownChart.get_url()
    
    # ---- Province breakdown ----
    profiletype = ContentType.objects.get_for_model(MemberProfile)
    addresses = Address.objects.filter(content_type=profiletype)
    totalprov = Address.objects.filter(content_type=profiletype).count() + 1     # FIXME
    
    provinces = []
    provincecount = []
    provincelist = list(pycountry.subdivisions.get(country_code='CA'))
    for p in provincelist:
        pcode = p.code.split('-')[1]
        provincecount2 = Address.objects.filter(content_type=profiletype,
                                                province=pcode).count()
        if provincecount2 == 0:
            provincecount2 = 1
        provincecount.append(provincecount2)                                
        provinces.append(pcode + " (%d%%)" % (provincecount2*100/totalprov))
    #provinces = sorted(provinces)
    
    provinceBreakdownChart = PieChart3D(600, 240)
    provinceBreakdownChart.add_data(provincecount)

    #provinceBreakdownChart.set_colours(['ff0000', 'ffff00', '00ff00'])
    provinceBreakdownChart.set_pie_labels(provinces)
    provinceBreakdown = provinceBreakdownChart.get_url()

    # ---- Gender breakdown ----
    males = MemberProfile.objects.filter(gender='M').count() + 1
    females = MemberProfile.objects.filter(gender='F').count() + 1
    genderunknown = MemberProfile.objects.filter(gender__isnull=True).count() + 1 #FIXME
    gendertotal = males + females + genderunknown
    genderBreakdownChart = PieChart3D(600, 240)
    genderBreakdownChart.add_data([males, females, genderunknown])

    genderBreakdownChart.set_colours(['ff0000', 'ffff00', '00ff00'])
    genderBreakdownChart.set_pie_labels(['Male (%d%%)' % (males*100/gendertotal),
                                         'Female (%d%%)' % (females*100/gendertotal),
                                         'Unspecified (%d%%)' % (genderunknown*100/gendertotal)])
    genderBreakdown = genderBreakdownChart.get_url()

    # ---- Student breakdown ----
    students = User.objects.filter(studentrecord__graduation_date__isnull=True).count() + 1
    nonstudents = User.objects.filter(workrecord__end_date__isnull=True).count() + 1
    # yeah, i know, not 100% accurate since a student can have a part-time job
    studentBreakdownChart = PieChart3D(600, 240)
    studentBreakdownChart.add_data([students, nonstudents])

    studentBreakdownChart.set_colours(['ff0000', '00ff00'])
    studentBreakdownChart.set_pie_labels(['Students', 'Non-students'])
    studentBreakdown = studentBreakdownChart.get_url()

    # ---- Language breakdown ----
    preferen = MemberProfile.objects.filter(language='E').count() + 1
    preferfr = MemberProfile.objects.filter(language='F').count() + 1
    prefernone = MemberProfile.objects.filter(language__isnull=True).count() + 1
    languageBreakdownChart = PieChart3D(600, 240)
    languageBreakdownChart.add_data([preferen, preferfr, prefernone])

    languageBreakdownChart.set_colours(['ff0000', 'ffff00', '00ff00'])
    languageBreakdownChart.set_pie_labels(['english', 'french', 'not specified'])
    languageBreakdown = languageBreakdownChart.get_url()

    # ---- Post breakdown ----
    postspublic = GroupTopic.objects.filter(parent_group__visibility='E',
                                            parent_group__parent__isnull=True).count() + 1
    postsprivate = GroupTopic.objects.filter(parent_group__parent__isnull=True
                                             ).exclude(parent_group__visibility='E').count() + 1
    postspublicchapter = GroupTopic.objects.filter(parent_group__visibility='E',
                                            parent_group__parent__isnull=False).count() + 1
    postsprivatechapter = GroupTopic.objects.filter(parent_group__parent__isnull=False
                                                    ).exclude(parent_group__visibility='E').count() + 1
    postcount = postspublic + postsprivate + postspublicchapter + postsprivatechapter 
    postBreakdownChart = PieChart3D(600, 240)
    postBreakdownChart.add_data([postspublic, postspublicchapter, postsprivatechapter, postsprivate])

    #postBreakdownChart.set_colours(['ff0000', 'ffff00', '00ff00'])
    postBreakdownChart.set_pie_labels(['public', 'public chapter', 'private chapter', 'private'])
    postBreakdown = postBreakdownChart.get_url()

    # ---- Login distribution ----
    logincount = []
    malelogins = []
    femalelogins = []
    for i in range(0,30):
        logincount.append(MemberProfile.objects.filter(login_count__gte=i).count())
        malelogins.append(MemberProfile.objects.filter(login_count__gte=i, gender='M').count())
        femalelogins.append(MemberProfile.objects.filter(login_count__gte=i, gender='F').count())
    
    loginDistribution = SimpleLineChart(600, 450, y_range=(0, 9000))
    loginDistribution.add_data(logincount)
    loginDistribution.add_data(malelogins)
    loginDistribution.add_data(femalelogins)

    loginDistribution.set_colours(['ff0000', '0000ff', '00ff00'])
    loginDistribution.set_legend(['logins', 'male', 'female'])
    loginDistribution.set_legend_position('b')

    yaxis = range(0, 9000, 500)    # that last number should be 25 or 50.  but for testing...
    yaxis[0] = ''
    loginDistribution.set_axis_labels(Axis.LEFT, yaxis)
    loginDistribution.set_axis_labels(Axis.BOTTOM, range(0, 30))
        
    loginDistribution = loginDistribution.get_url()
    
    # ---- Login recency ----
    loginrecent = []
    loginrecentdate = []
    thedate = date(date.today().year - 1,
                   date.today().month,
                   1)
    skip = False
    while thedate.year != date.today().year or thedate.month != date.today().month:
        if thedate.month == 12:
            enddate = date(year=thedate.year + 1,
                           month=1, day=1)
        else:
            enddate = date(year=thedate.year,
                           month=thedate.month + 1,
                           day=1)
        loginrecent.append(MemberProfile.objects.filter(previous_login__range=(thedate, enddate)).count())
        if not skip:
            loginrecentdate.append(thedate.strftime("%B %y"))
        else:
            loginrecentdate.append("")
        skip = not skip
        thedate = enddate

    loginRecency = SimpleLineChart(600, 450, y_range=(0, max(loginrecent)+1))
    loginRecency.add_data(loginrecent)

    yaxis = range(0, max(loginrecent), max(max(loginrecent)/10, 1))    # that last number should be 25 or 50.  but for testing...
    if len(yaxis) == 0:
        yaxis.append(10)
        yaxis.append(10)
    yaxis[0] = ''
    loginRecency.set_axis_labels(Axis.LEFT, yaxis)
    loginRecency.set_axis_labels(Axis.BOTTOM, loginrecentdate)
        
    loginRecency = loginRecency.get_url()
    
    # ---- Age distribution ----
    ages = []
    for age in range(15, 75):
        year = date.today().year - age
        ages.append(MemberProfile.objects.filter(date_of_birth__year=year).count())
    
    ageDistribution = SimpleLineChart(600, 450, y_range=(0, max(ages)+1))
    ageDistribution.add_data(ages)

    yaxis = range(0, max(ages)+1, 50)
    yaxis[0] = ''
    ageDistribution.set_axis_labels(Axis.LEFT, yaxis)
    ageDistribution.set_axis_labels(Axis.BOTTOM, range(15, 75, 5))
        
    ageDistribution = ageDistribution.get_url()
    
    # ---- Finally! ----
    return render_to_response("stats/dashboard.html",
                              {"signins": today.signins,
                               "posts": today.posts,
                               "replies": today.replies,
                               "signups": today.signups,
                               "listsignups": today.mailinglistsignups,
                               "listupgrades": today.mailinglistupgrades,
                               "deletions": today.deletions,
                               "regupgrades": today.regupgrades,
                               "regdowngrades": today.regdowngrades,
                               "renewals": today.renewals,
                               "totalusers": today.users,
                               "dailyUsage": dailyUsage,
                               "accountChanges": accountChanges,
                               "membershipChart": membershipChart,
                               "membershipChanges": membershipChanges,
                               "statusBreakdown": statusBreakdown,
                               "mlistmembers": mlistmembers,
                               "mlistmemberspercent": mlistmembers * 100 / today.users,
                               "associatemembers": today.associatemembers,
                               "associatememberspercent": today.associatemembers * 100 / today.users,
                               "regularmembers": today.regularmembers,
                               "regularmemberspercent": today.regularmembers * 100 / today.users,
                               "membershipBreakdown": membershipBreakdown,
                               "provinceBreakdown": provinceBreakdown,
                               "provincecount": totalprov,
                               "genderBreakdown": genderBreakdown,
                               "studentBreakdown": studentBreakdown,
                               "languageBreakdown": languageBreakdown,
                               "postBreakdown": postBreakdown,
                               "loginDistribution": loginDistribution,
                               "loginRecency": loginRecency,
                               "ageDistribution": ageDistribution
                              },
                              context_instance=RequestContext(request))
Пример #18
0
def __bar_graphic__(data, legends, axis_labels, size, steps,  
                    type=StackedVerticalBarChart, multiline=False):
    
    if multiline:
        max_values = []
        min_values = [] 
        for row in data:
            max_values.append(max(row))
            min_values.append(min(row))
        max_value = max(max_values)
        min_value = min(min_values)
    else:
        max_value = max(data)
        min_value = min(data)

    step = ((max_value*1.05)-(min_value*0.95))/steps
    left_axis = range(int(min_value*0.95), int(max_value*1.05), int(step))
    left_axis[0]=''

    if type==StackedHorizontalBarChart:
        graph = StackedHorizontalBarChart(size[0], size[1], x_range=(0, max_value*1.05))
        graph.set_axis_labels(Axis.BOTTOM, left_axis)
        graph.set_axis_labels(Axis.LEFT, axis_labels)
    elif type==StackedVerticalBarChart:
        graph = StackedVerticalBarChart(size[0], size[1], y_range=(0, max_value*1.05))
        graph.set_axis_labels(Axis.LEFT, left_axis)
        graph.set_axis_labels(Axis.BOTTOM, axis_labels)
    elif type==GroupedHorizontalBarChart:
        graph = GroupedHorizontalBarChart(size[0], size[1], x_range=(0, max_value*1.05))
        graph.set_axis_labels(Axis.BOTTOM, left_axis)
        graph.set_axis_labels(Axis.LEFT, axis_labels)
        graph.set_bar_spacing(5)
    elif type==GroupedVerticalBarChart:
        graph = GroupedVerticalBarChart(size[0], size[1], y_range=(0, max_value*1.05))
        graph.set_axis_labels(Axis.LEFT, left_axis)
        graph.set_axis_labels(Axis.BOTTOM, axis_labels)
        graph.set_bar_spacing(5)
    else:
        pass #raise exception


    if multiline:
        for fila in data:
            graph.add_data(fila)
    else:
        graph.add_data(data)
    
    graph.set_colours([ 'FFBC13','22A410','E6EC23','2B2133','BD0915','3D43BD'])
    graph.set_bar_width(40)
    graph.set_legend(legends)
    graph.set_legend_position('b')
    
    
    return graph
Пример #19
0
def main_dashboard(request):

    today, created = DailyStats.objects.get_or_create(day=date.today())
    if today.users == 0:
        today.users = 1

    # ---- Daily usage ----
    enddate = date.today()
    #startdate = enddate - timedelta(weeks=60)
    startdate = enddate - timedelta(weeks=4)
    averageusage = DailyStats.objects.filter(
        day__range=(startdate, enddate)).order_by('day')
    days = []
    signins = []
    posts = []
    replies = []
    whiteboards = []
    signups = []
    listsignups = []
    listupgrades = []
    deletions = []
    numUsers = []
    numRegularMembers = []
    regupgrades = []
    renewals = []
    regdowngrades = []
    for s in averageusage:
        days.append(s.day.strftime("%B %y"))
        signins.append(s.signins)
        posts.append(s.posts)
        replies.append(s.replies)
        whiteboards.append(s.whiteboardEdits)
        signups.append(s.signups)
        listsignups.append(s.mailinglistsignups)
        listupgrades.append(s.mailinglistupgrades)
        deletions.append(s.deletions)
        numUsers.append(s.users)
        numRegularMembers.append(s.regularmembers)
        regupgrades.append(s.regupgrades)
        renewals.append(s.renewals)
        regdowngrades.append(s.regdowngrades)

    xaxis = []
    #for i in range(0, len(days), 1):    # this will make limited test data look better
    for i in range(0, len(days), len(days) / 8):
        xaxis.append(days[i])

    # ---- Daily usage ----
    dailyUsageChart = SimpleLineChart(600, 450, y_range=(0, max(signins)))
    #chart.add_data(avgsignins)
    dailyUsageChart.add_data(posts)
    dailyUsageChart.add_data(replies)
    dailyUsageChart.add_data(signins)
    dailyUsageChart.add_data(whiteboards)

    dailyUsageChart.set_colours(['ff0000', 'ffff00', '00ff00', '0000ff'])
    dailyUsageChart.set_legend(['posts', 'replies', 'signins', 'whiteboards'])
    dailyUsageChart.set_legend_position('b')

    #yaxis = range(0, max_signins + 1, 2)    # this will make limited test data look better
    yaxis = range(0, max(signins), max(signins) / 10)
    yaxis[0] = ''
    dailyUsageChart.set_axis_labels(Axis.LEFT, yaxis)
    dailyUsageChart.set_axis_labels(Axis.BOTTOM, xaxis)

    dailyUsage = dailyUsageChart.get_url()

    # ---- Account changes ----
    accountChangesChart = SimpleLineChart(600, 450, y_range=(0, 25))
    accountChangesChart.add_data(signups)
    accountChangesChart.add_data(listsignups)
    accountChangesChart.add_data(listupgrades)
    accountChangesChart.add_data(deletions)

    accountChangesChart.set_colours(['ff0000', 'ffff00', '00ff00', '0000ff'])
    accountChangesChart.set_legend(
        ['account signups', 'email signups', 'email upgrades', 'deletions'])
    accountChangesChart.set_legend_position('b')

    #yaxis = range(0, 25, 2)    # this will make limited test data look better
    yaxis = range(0, min(max(listsignups), 10), max(max(listsignups) / 10, 1))
    yaxis[0] = ''
    accountChangesChart.set_axis_labels(Axis.LEFT, yaxis)
    accountChangesChart.set_axis_labels(Axis.BOTTOM, xaxis)

    accountChanges = accountChangesChart.get_url()

    # ---- Membership ----
    membershipChart = SimpleLineChart(600, 450, y_range=(42000, 52000))
    membershipChart.add_data(numUsers)
    membershipChart.add_data(numRegularMembers)

    membershipChart.set_colours(['ff0000', '0000ff'])
    membershipChart.set_legend(['total users', 'regular members'])
    membershipChart.set_legend_position('b')

    yaxis = range(42000, 52000, 1000)
    yaxis[0] = ''
    yaxis2 = range(0, 1500, 50)
    yaxis2[0] = ''
    membershipChart.set_axis_labels(Axis.LEFT, yaxis)
    membershipChart.set_axis_labels(Axis.RIGHT, yaxis2)
    membershipChart.set_axis_labels(Axis.BOTTOM, xaxis)

    membershipChart = membershipChart.get_url()

    # ---- Account changes ----
    membershipChangesChart = SimpleLineChart(600, 450, y_range=(0, 10))
    membershipChangesChart.add_data(regupgrades)
    membershipChangesChart.add_data(renewals)
    membershipChangesChart.add_data(regdowngrades)

    membershipChangesChart.set_colours(['ff0000', 'ffff00', '00ff00'])
    membershipChangesChart.set_legend(
        ['regular upgrades', 'renewals', 'regular downgrades'])
    membershipChangesChart.set_legend_position('b')

    #yaxis = range(0, 25, 2)    # the same.
    yaxis = range(
        0, max(max(regupgrades), max(regdowngrades), max(renewals)),
        max(max(max(regupgrades), max(regdowngrades), max(renewals)) / 10, 1))
    yaxis[0] = ''
    membershipChangesChart.set_axis_labels(Axis.LEFT, yaxis)
    membershipChangesChart.set_axis_labels(Axis.BOTTOM, xaxis)

    membershipChanges = membershipChangesChart.get_url()

    # ---- Status breakdown ----
    statusBreakdownChart = PieChart3D(600, 240)
    mlistmembers = today.users - today.regularmembers - today.associatemembers
    statusBreakdownChart.add_data([
        mlistmembers +
        1,  # FIXME: the +1 is needed so pygoogle doesn't crash (it doesn't handle zeroes well)
        today.associatemembers + 1,
        today.regularmembers + 1
    ])

    statusBreakdownChart.set_colours(['ff0000', 'ffff00', '00ff00'])
    statusBreakdownChart.set_pie_labels(
        ["mailing list members", "associate members", "regular members"])
    statusBreakdown = statusBreakdownChart.get_url()

    # ---- Membership breakdown ----
    chapters = Network.objects.filter(chapter_info__isnull=False,
                                      is_active=True)
    chapternames = []
    chaptermembers = []
    for chapter in chapters:
        chapternames.append(chapter.slug)
        chaptermembers.append(chapter.members.all().count())

    membershipBreakdownChart = StackedHorizontalBarChart(
        500, 500, x_range=(0, max(chaptermembers)))
    membershipBreakdownChart.add_data(chaptermembers)
    yaxis = range(0, max(chaptermembers), 10)
    yaxis[0] = ''
    membershipBreakdownChart.set_axis_labels(Axis.BOTTOM, yaxis)
    membershipBreakdownChart.set_axis_labels(Axis.LEFT, chapternames)
    membershipBreakdownChart.set_bar_width(330 / len(chapternames))
    membershipBreakdown = membershipBreakdownChart.get_url()

    # ---- Province breakdown ----
    profiletype = ContentType.objects.get_for_model(MemberProfile)
    addresses = Address.objects.filter(content_type=profiletype)
    totalprov = Address.objects.filter(
        content_type=profiletype).count() + 1  # FIXME

    provinces = []
    provincecount = []
    provincelist = list(pycountry.subdivisions.get(country_code='CA'))
    for p in provincelist:
        pcode = p.code.split('-')[1]
        provincecount2 = Address.objects.filter(content_type=profiletype,
                                                province=pcode).count()
        if provincecount2 == 0:
            provincecount2 = 1
        provincecount.append(provincecount2)
        provinces.append(pcode + " (%d%%)" %
                         (provincecount2 * 100 / totalprov))
    #provinces = sorted(provinces)

    provinceBreakdownChart = PieChart3D(600, 240)
    provinceBreakdownChart.add_data(provincecount)

    #provinceBreakdownChart.set_colours(['ff0000', 'ffff00', '00ff00'])
    provinceBreakdownChart.set_pie_labels(provinces)
    provinceBreakdown = provinceBreakdownChart.get_url()

    # ---- Gender breakdown ----
    males = MemberProfile.objects.filter(gender='M').count() + 1
    females = MemberProfile.objects.filter(gender='F').count() + 1
    genderunknown = MemberProfile.objects.filter(
        gender__isnull=True).count() + 1  #FIXME
    gendertotal = males + females + genderunknown
    genderBreakdownChart = PieChart3D(600, 240)
    genderBreakdownChart.add_data([males, females, genderunknown])

    genderBreakdownChart.set_colours(['ff0000', 'ffff00', '00ff00'])
    genderBreakdownChart.set_pie_labels([
        'Male (%d%%)' % (males * 100 / gendertotal),
        'Female (%d%%)' % (females * 100 / gendertotal),
        'Unspecified (%d%%)' % (genderunknown * 100 / gendertotal)
    ])
    genderBreakdown = genderBreakdownChart.get_url()

    # ---- Student breakdown ----
    students = User.objects.filter(
        studentrecord__graduation_date__isnull=True).count() + 1
    nonstudents = User.objects.filter(
        workrecord__end_date__isnull=True).count() + 1
    # yeah, i know, not 100% accurate since a student can have a part-time job
    studentBreakdownChart = PieChart3D(600, 240)
    studentBreakdownChart.add_data([students, nonstudents])

    studentBreakdownChart.set_colours(['ff0000', '00ff00'])
    studentBreakdownChart.set_pie_labels(['Students', 'Non-students'])
    studentBreakdown = studentBreakdownChart.get_url()

    # ---- Language breakdown ----
    preferen = MemberProfile.objects.filter(language='E').count() + 1
    preferfr = MemberProfile.objects.filter(language='F').count() + 1
    prefernone = MemberProfile.objects.filter(
        language__isnull=True).count() + 1
    languageBreakdownChart = PieChart3D(600, 240)
    languageBreakdownChart.add_data([preferen, preferfr, prefernone])

    languageBreakdownChart.set_colours(['ff0000', 'ffff00', '00ff00'])
    languageBreakdownChart.set_pie_labels(
        ['english', 'french', 'not specified'])
    languageBreakdown = languageBreakdownChart.get_url()

    # ---- Post breakdown ----
    postspublic = GroupTopic.objects.filter(
        parent_group__visibility='E',
        parent_group__parent__isnull=True).count() + 1
    postsprivate = GroupTopic.objects.filter(
        parent_group__parent__isnull=True).exclude(
            parent_group__visibility='E').count() + 1
    postspublicchapter = GroupTopic.objects.filter(
        parent_group__visibility='E',
        parent_group__parent__isnull=False).count() + 1
    postsprivatechapter = GroupTopic.objects.filter(
        parent_group__parent__isnull=False).exclude(
            parent_group__visibility='E').count() + 1
    postcount = postspublic + postsprivate + postspublicchapter + postsprivatechapter
    postBreakdownChart = PieChart3D(600, 240)
    postBreakdownChart.add_data(
        [postspublic, postspublicchapter, postsprivatechapter, postsprivate])

    #postBreakdownChart.set_colours(['ff0000', 'ffff00', '00ff00'])
    postBreakdownChart.set_pie_labels(
        ['public', 'public chapter', 'private chapter', 'private'])
    postBreakdown = postBreakdownChart.get_url()

    # ---- Login distribution ----
    logincount = []
    malelogins = []
    femalelogins = []
    for i in range(0, 30):
        logincount.append(
            MemberProfile.objects.filter(login_count__gte=i).count())
        malelogins.append(
            MemberProfile.objects.filter(login_count__gte=i,
                                         gender='M').count())
        femalelogins.append(
            MemberProfile.objects.filter(login_count__gte=i,
                                         gender='F').count())

    loginDistribution = SimpleLineChart(600, 450, y_range=(0, 9000))
    loginDistribution.add_data(logincount)
    loginDistribution.add_data(malelogins)
    loginDistribution.add_data(femalelogins)

    loginDistribution.set_colours(['ff0000', '0000ff', '00ff00'])
    loginDistribution.set_legend(['logins', 'male', 'female'])
    loginDistribution.set_legend_position('b')

    yaxis = range(
        0, 9000,
        500)  # that last number should be 25 or 50.  but for testing...
    yaxis[0] = ''
    loginDistribution.set_axis_labels(Axis.LEFT, yaxis)
    loginDistribution.set_axis_labels(Axis.BOTTOM, range(0, 30))

    loginDistribution = loginDistribution.get_url()

    # ---- Login recency ----
    loginrecent = []
    loginrecentdate = []
    thedate = date(date.today().year - 1, date.today().month, 1)
    skip = False
    while thedate.year != date.today().year or thedate.month != date.today(
    ).month:
        if thedate.month == 12:
            enddate = date(year=thedate.year + 1, month=1, day=1)
        else:
            enddate = date(year=thedate.year, month=thedate.month + 1, day=1)
        loginrecent.append(
            MemberProfile.objects.filter(
                previous_login__range=(thedate, enddate)).count())
        if not skip:
            loginrecentdate.append(thedate.strftime("%B %y"))
        else:
            loginrecentdate.append("")
        skip = not skip
        thedate = enddate

    loginRecency = SimpleLineChart(600, 450, y_range=(0, max(loginrecent) + 1))
    loginRecency.add_data(loginrecent)

    yaxis = range(0, max(loginrecent), max(
        max(loginrecent) / 10,
        1))  # that last number should be 25 or 50.  but for testing...
    if len(yaxis) == 0:
        yaxis.append(10)
        yaxis.append(10)
    yaxis[0] = ''
    loginRecency.set_axis_labels(Axis.LEFT, yaxis)
    loginRecency.set_axis_labels(Axis.BOTTOM, loginrecentdate)

    loginRecency = loginRecency.get_url()

    # ---- Age distribution ----
    ages = []
    for age in range(15, 75):
        year = date.today().year - age
        ages.append(
            MemberProfile.objects.filter(date_of_birth__year=year).count())

    ageDistribution = SimpleLineChart(600, 450, y_range=(0, max(ages) + 1))
    ageDistribution.add_data(ages)

    yaxis = range(0, max(ages) + 1, 50)
    yaxis[0] = ''
    ageDistribution.set_axis_labels(Axis.LEFT, yaxis)
    ageDistribution.set_axis_labels(Axis.BOTTOM, range(15, 75, 5))

    ageDistribution = ageDistribution.get_url()

    # ---- Finally! ----
    return render_to_response(
        "stats/dashboard.html", {
            "signins": today.signins,
            "posts": today.posts,
            "replies": today.replies,
            "signups": today.signups,
            "listsignups": today.mailinglistsignups,
            "listupgrades": today.mailinglistupgrades,
            "deletions": today.deletions,
            "regupgrades": today.regupgrades,
            "regdowngrades": today.regdowngrades,
            "renewals": today.renewals,
            "totalusers": today.users,
            "dailyUsage": dailyUsage,
            "accountChanges": accountChanges,
            "membershipChart": membershipChart,
            "membershipChanges": membershipChanges,
            "statusBreakdown": statusBreakdown,
            "mlistmembers": mlistmembers,
            "mlistmemberspercent": mlistmembers * 100 / today.users,
            "associatemembers": today.associatemembers,
            "associatememberspercent":
            today.associatemembers * 100 / today.users,
            "regularmembers": today.regularmembers,
            "regularmemberspercent": today.regularmembers * 100 / today.users,
            "membershipBreakdown": membershipBreakdown,
            "provinceBreakdown": provinceBreakdown,
            "provincecount": totalprov,
            "genderBreakdown": genderBreakdown,
            "studentBreakdown": studentBreakdown,
            "languageBreakdown": languageBreakdown,
            "postBreakdown": postBreakdown,
            "loginDistribution": loginDistribution,
            "loginRecency": loginRecency,
            "ageDistribution": ageDistribution
        },
        context_instance=RequestContext(request))
Пример #20
0
from pygooglechart import SimpleLineChart, StackedHorizontalBarChart, StackedVerticalBarChart, \
    GroupedHorizontalBarChart, GroupedVerticalBarChart
from pygooglechart import PieChart2D
from pygooglechart import PieChart3D
import os
import sys

ROOT = os.path.dirname(os.path.abspath(__file__))
sys.path.insert(0, os.path.join(ROOT, '..'))


l = [0, 0, 0, 1, 1, 1, 3, 4, 5, 5, 6, 6, 6, 6, 7, 7, 7, 8, 11, 17, 20, 26, 36, 36, 38, 42, 47, 49, 54, 59, 59, 66, 66, 67, 68, 69, 77, 85, 86, 87, 88, 93, 115, 116, 121, 122, 137, 152, 173, 180, 181, 183, 191, 202, 203, 208, 233, 238, 241, 247, 262, 263, 268, 271, 273, 308, 325, 343, 346, 360, 365, 378, 410, 419, 479, 490, 535, 550, 550, 562, 608, 655, 670, 687, 709, 716, 745, 758, 769, 801, 807, 897, 899, 904, 907, 929, 1074, 1106, 1120, 1120, 1357, 1421, 3049]
a = ['\xd0\xa8\xd0\xb5\xd0\xb2\xd1\x80\xd0\xbe\xd0\xbb\xd0\xb5 \xd1\x84\xd0\xb8\xd0\xb5\xd1\x81\xd1\x82\xd0\xb0 ', '\xd0\x9c\xd0\xb5\xd1\x80\xd1\x81\xd0\xb5\xd0\xb4\xd0\xb5\xd1\x81 e230', '\xd0\x9c\xd0\xb5\xd1\x80\xd1\x81\xd0\xb5\xd0\xb4\xd0\xb5\xd1\x81 gl320', '\xd0\x9c\xd0\xb5\xd1\x80\xd1\x81\xd0\xb5\xd0\xb4\xd0\xb5\xd1\x81 c230', '\xd0\x9c\xd0\xb5\xd1\x80\xd1\x81\xd0\xb5\xd0\xb4\xd0\xb5\xd1\x81 cl500', '\xd0\x9c\xd0\xb5\xd1\x80\xd1\x81\xd0\xb5\xd0\xb4\xd0\xb5\xd1\x81 e220', '\xd0\x9c\xd0\xb5\xd1\x80\xd1\x81\xd0\xb5\xd0\xb4\xd0\xb5\xd1\x81 e320', '\xd0\x9c\xd0\xb5\xd1\x80\xd1\x81\xd0\xb5\xd0\xb4\xd0\xb5\xd1\x81 e240', '\xd0\x9c\xd0\xb5\xd1\x80\xd1\x81\xd0\xb5\xd0\xb4\xd0\xb5\xd1\x81 g500', '\xd0\x9c\xd0\xb5\xd1\x80\xd1\x81\xd0\xb5\xd0\xb4\xd0\xb5\xd1\x81 ml350', '\xd0\x9c\xd0\xb5\xd1\x80\xd1\x81\xd0\xb5\xd0\xb4\xd0\xb5\xd1\x81 c200', '\xd0\x9c\xd0\xb5\xd1\x80\xd1\x81\xd0\xb5\xd0\xb4\xd0\xb5\xd1\x81 c220', '\xd0\x9c\xd0\xb5\xd1\x80\xd1\x81\xd0\xb5\xd0\xb4\xd0\xb5\xd1\x81 ml320', '\xd0\x9c\xd0\xb5\xd1\x80\xd1\x81\xd0\xb5\xd0\xb4\xd0\xb5\xd1\x81 viano', '\xd0\x91\xd0\x9c\xd0\x92 325', '\xd0\x91\xd0\x9c\xd0\x92 530', '\xd0\x9c\xd0\xb5\xd1\x80\xd1\x81\xd0\xb5\xd0\xb4\xd0\xb5\xd1\x81 e200', '\xd0\x9c\xd0\xb5\xd1\x80\xd1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xd0\xba\xd0\xbe\xd0\xb4\xd0\xb0 \xd0\xbe\xd0\xba\xd1\x82\xd0\xb0\xd0\xb2\xd0\xb8\xd1\x8f', '\xd0\x9c\xd0\xb8\xd1\x82\xd1\x81\xd1\x83\xd0\xb1\xd0\xb8\xd1\x81\xd0\xb8 \xd0\xbb\xd0\xb0\xd0\xbd\xd1\x81\xd0\xb5\xd1\x80', '\xd0\xa4\xd0\xbe\xd1\x80\xd0\xb4 \xd0\xbc\xd0\xbe\xd0\xbd\xd0\xb4\xd0\xb5\xd0\xbe', '\xd0\x9d\xd0\xb8\xd1\x81\xd1\x81\xd0\xb0\xd0\xbd \xd0\xb0\xd0\xbb\xd1\x8c\xd0\xbc\xd0\xb5\xd1\x80\xd0\xb0', '\xd0\xa4\xd0\xbe\xd0\xbb\xd1\x8c\xd0\xba\xd1\x81\xd0\xb2\xd0\xb0\xd0\xb3\xd0\xb5\xd0\xbd \xd0\xbf\xd0\xb0\xd1\x81\xd1\x81\xd0\xb0\xd1\x82', '\xd0\x9e\xd0\xbf\xd0\xb5\xd0\xbb\xd1\x8c \xd0\xb0\xd1\x81\xd1\x82\xd1\x80\xd0\xb0', '\xd0\x9e\xd0\xbf\xd0\xb5\xd0\xbb\xd1\x8c \xd0\xb2\xd0\xb5\xd0\xba\xd1\x82\xd1\x80\xd0\xb0', '\xd0\xa4\xd0\xbe\xd1\x80\xd0\xb4 \xd1\x84\xd0\xbe\xd0\xba\xd1\x83\xd1\x81']

index = 0
for i in a:
    print ("%s;%s"%(i.decode("utf-8"),l[index]) )
    index+=1

chart = StackedHorizontalBarChart(400, 700, x_range=(0, max(l) ) )
chart.set_bar_width( 3 )
chart.set_colours(['8159F7', ])
chart.add_data( l )
chart.set_title( "Razbor by models" )
chart.set_legend( ['',] )

a.reverse()
chart.set_axis_labels('y', a )
chart.annotated_data()
chart.download( "razbors_By_models_car.png")
Пример #21
0
def __bar_graphic__(data,
                    legends,
                    axis_labels,
                    size,
                    steps,
                    type=StackedVerticalBarChart,
                    multiline=False):

    if multiline:
        max_values = []
        min_values = []
        for row in data:
            max_values.append(max(row))
            min_values.append(min(row))
        max_value = max(max_values)
        min_value = min(min_values)
    else:
        max_value = max(data)
        min_value = min(data)

    step = ((max_value * 1.05) - (min_value * 0.95)) / steps
    left_axis = range(int(min_value * 0.95), int(max_value * 1.05), int(step))
    left_axis[0] = ''

    if type == StackedHorizontalBarChart:
        graph = StackedHorizontalBarChart(size[0],
                                          size[1],
                                          x_range=(0, max_value * 1.05))
        graph.set_axis_labels(Axis.BOTTOM, left_axis)
        graph.set_axis_labels(Axis.LEFT, axis_labels)
    elif type == StackedVerticalBarChart:
        graph = StackedVerticalBarChart(size[0],
                                        size[1],
                                        y_range=(0, max_value * 1.05))
        graph.set_axis_labels(Axis.LEFT, left_axis)
        graph.set_axis_labels(Axis.BOTTOM, axis_labels)
    elif type == GroupedHorizontalBarChart:
        graph = GroupedHorizontalBarChart(size[0],
                                          size[1],
                                          x_range=(0, max_value * 1.05))
        graph.set_axis_labels(Axis.BOTTOM, left_axis)
        graph.set_axis_labels(Axis.LEFT, axis_labels)
        graph.set_bar_spacing(5)
    elif type == GroupedVerticalBarChart:
        graph = GroupedVerticalBarChart(size[0],
                                        size[1],
                                        y_range=(0, max_value * 1.05))
        graph.set_axis_labels(Axis.LEFT, left_axis)
        graph.set_axis_labels(Axis.BOTTOM, axis_labels)
        graph.set_bar_spacing(5)
    else:
        pass  #raise exception

    if multiline:
        for fila in data:
            graph.add_data(fila)
    else:
        graph.add_data(data)

    graph.set_colours(
        ['FFBC13', '22A410', 'E6EC23', '2B2133', 'BD0915', '3D43BD'])
    graph.set_bar_width(40)
    graph.set_legend(legends)
    graph.set_legend_position('b')

    return graph