예제 #1
0
def statistics():
    """ Page display data visualization about statistics for the recipes """

    # Count how many recipes have each meal time to send to the pie chart
    breakfast = mongo.db.recipes.find({'meal_time': 'breakfast'}).count()
    lunch = mongo.db.recipes.find({'meal_time': 'lunch'}).count()
    dinner = mongo.db.recipes.find({'meal_time': 'dinner'}).count()

    # Build pie chart
    pie_chart = Pie()
    pie_chart.title = 'Meal Times'
    pie_chart.add('Breakfast', breakfast)
    pie_chart.add('Lunch', lunch)
    pie_chart.add('Dinner', dinner)
    pie_chart = pie_chart.render_data_uri()

    # Count how many recipes have each training type to send to line chart
    endurance = mongo.db.recipes.find({'training_type': 'endurance'}).count()
    speed = mongo.db.recipes.find({'training_type': 'speed'}).count()
    strength = mongo.db.recipes.find({'training_type': 'strength'}).count()
    power = mongo.db.recipes.find({'training_type': 'power'}).count()

    # Build line chart
    line_chart = Bar()
    line_chart.title = 'Training Types'
    line_chart.add('Endurance', [{'value': endurance, 'label': 'Endurance'}])
    line_chart.add('Strength', [{'value': strength, 'label': 'Strength'}])
    line_chart.add('Power', [{'value': power, 'label': 'Power'}])
    line_chart.add('Speed', [{'value': speed, 'label': 'Speed'}])
    line_chart = line_chart.render_data_uri()

    return render_template('statists.html',
                           title='Statistics',
                           pie_chart=pie_chart,
                           line_chart=line_chart)
예제 #2
0
def dashboard():
    #Getting all projects
    projects = Project.select()
    #Creating a pie chart
    pie_chart = Pie()
    #adding title to pie chart
    pie_chart.title = 'Project Type'
    #instatiating two variables internal and external
    internal = 0
    external = 0
    for project in projects:
        if (project.type == 'Internal'):
            internal += 1
        else:
            external += 1

    pie_chart.add('Internal', internal)
    pie_chart.add('External', external)

    pie_chart.render()
    chart = pie_chart.render_data_uri()

    return render_template('index.html',
                           projects_to_send=projects,
                           chart=chart)
예제 #3
0
파일: test_pie.py 프로젝트: young-0/pygal
def test_donut():
    chart = Pie(inner_radius=.3, pretty_print=True)
    chart.title = 'Browser usage in February 2012 (in %)'
    chart.add('IE', 19.5)
    chart.add('Firefox', 36.6)
    chart.add('Chrome', 36.3)
    chart.add('Safari', 4.5)
    chart.add('Opera', 2.3)
    assert chart.render()
예제 #4
0
def test_donut():
    chart = Pie(inner_radius=0.3, pretty_print=True)
    chart.title = "Browser usage in February 2012 (in %)"
    chart.add("IE", 19.5)
    chart.add("Firefox", 36.6)
    chart.add("Chrome", 36.3)
    chart.add("Safari", 4.5)
    chart.add("Opera", 2.3)
    assert chart.render()
예제 #5
0
def test_donut():
    chart = Pie(inner_radius=.3, pretty_print=True)
    chart.title = 'Browser usage in February 2012 (in %)'
    chart.add('IE', 19.5)
    chart.add('Firefox', 36.6)
    chart.add('Chrome', 36.3)
    chart.add('Safari', 4.5)
    chart.add('Opera', 2.3)
    assert chart.render()
예제 #6
0
파일: test_table.py 프로젝트: young-0/pygal
def test_pie_table():
    chart = Pie(inner_radius=.3, pretty_print=True)
    chart.title = 'Browser usage in February 2012 (in %)'
    chart.add('IE', 19.5)
    chart.add('Firefox', 36.6)
    chart.add('Chrome', 36.3)
    chart.add('Safari', 4.5)
    chart.add('Opera', 2.3)
    q = pq(chart.render_table())
    assert len(q('table')) == 1
예제 #7
0
def test_multiseries_donut():
    # this just demos that the multiseries pie does not respect
    # the inner_radius
    chart = Pie(inner_radius=0.3, pretty_print=True)
    chart.title = "Browser usage by version in February 2012 (in %)"
    chart.add("IE", [5.7, 10.2, 2.6, 1])
    chart.add("Firefox", [0.6, 16.8, 7.4, 2.2, 1.2, 1, 1, 1.1, 4.3, 1])
    chart.add("Chrome", [0.3, 0.9, 17.1, 15.3, 0.6, 0.5, 1.6])
    chart.add("Safari", [4.4, 0.1])
    chart.add("Opera", [0.1, 1.6, 0.1, 0.5])
    assert chart.render()
예제 #8
0
def test_multiseries_donut():
    # this just demos that the multiseries pie does not respect
    # the inner_radius
    chart = Pie(inner_radius=.3, pretty_print=True)
    chart.title = 'Browser usage by version in February 2012 (in %)'
    chart.add('IE', [5.7, 10.2, 2.6, 1])
    chart.add('Firefox', [.6, 16.8, 7.4, 2.2, 1.2, 1, 1, 1.1, 4.3, 1])
    chart.add('Chrome', [.3, .9, 17.1, 15.3, .6, .5, 1.6])
    chart.add('Safari', [4.4, .1])
    chart.add('Opera', [.1, 1.6, .1, .5])
    assert chart.render()
예제 #9
0
파일: test_pie.py 프로젝트: young-0/pygal
def test_multiseries_donut():
    # this just demos that the multiseries pie does not respect
    # the inner_radius
    chart = Pie(inner_radius=.3, pretty_print=True)
    chart.title = 'Browser usage by version in February 2012 (in %)'
    chart.add('IE', [5.7, 10.2, 2.6, 1])
    chart.add('Firefox', [.6, 16.8, 7.4, 2.2, 1.2, 1, 1, 1.1, 4.3, 1])
    chart.add('Chrome', [.3, .9, 17.1, 15.3, .6, .5, 1.6])
    chart.add('Safari', [4.4, .1])
    chart.add('Opera', [.1, 1.6, .1, .5])
    assert chart.render()
예제 #10
0
파일: test_donut.py 프로젝트: cleder/pygal
def test_donut():
    file_name = '/tmp/test_graph-%s.svg' % uuid.uuid4()
    if os.path.exists(file_name):
        os.remove(file_name)
    chart = Pie(inner_radius=.3, pretty_print=True)
    chart.title = 'Browser usage in February 2012 (in %)'
    chart.add('IE', 19.5)
    chart.add('Firefox', 36.6)
    chart.add('Chrome', 36.3)
    chart.add('Safari', 4.5)
    chart.add('Opera', 2.3)
    chart.render_to_file(file_name)
    with open(file_name) as f:
        assert 'pygal' in f.read()
    os.remove(file_name)
예제 #11
0
파일: test_donut.py 프로젝트: cleder/pygal
def test_multiseries_donut():
    #this just demos that the multiseries pie does not respect the inner_radius
    file_name = '/tmp/test_graph-%s.svg' % uuid.uuid4()
    if os.path.exists(file_name):
        os.remove(file_name)
    chart = Pie(inner_radius=.3, pretty_print=True)
    chart.title = 'Browser usage by version in February 2012 (in %)'
    chart.add('IE', [5.7, 10.2, 2.6, 1])
    chart.add('Firefox', [.6, 16.8, 7.4, 2.2, 1.2, 1, 1, 1.1, 4.3, 1])
    chart.add('Chrome', [.3, .9, 17.1, 15.3, .6, .5, 1.6])
    chart.add('Safari', [4.4, .1])
    chart.add('Opera', [.1, 1.6, .1, .5])
    chart.render_to_file(file_name)
    with open(file_name) as f:
        assert 'pygal' in f.read()
    os.remove(file_name)
예제 #12
0
 def lapspercar_svg(self, curr_url=None):
     if not config.config.HTTP_CONFIG.enable_svg_generation:
         return ""
     stats = self.lastStat
     pie_chart = Pie(pygalConfig)
     pie_chart.title = 'Car usage (% laps driven)'
     tl = stats['numLaps']
     lapsPerTrack = sorted(stats['lapsPerCar'].items(),
                           key=lambda x: x[1],
                           reverse=True)
     valueToItem = {}
     for t, nl in lapsPerTrack:
         v = nl * 100 / tl
         while v in valueToItem:
             v -= 1e-9
         valueToItem[v] = t
         pie_chart.add(t, v)
     pie_chart.value_formatter = lambda x, valueToItem=valueToItem: "%s: %.1f%%" % (
         valueToItem.get(x, '?'), x)
     return pie_chart.render()
예제 #13
0
 def lapspercombo_svg(self, curr_url=None):
     if not config.config.HTTP_CONFIG.enable_svg_generation:
         return ""
     stats = self.lastStat
     pie_chart = Pie(pygalConfig)
     pie_chart.title = 'Combo usage (% laps driven)'
     tl = stats['numLaps']
     lapsPerCombo = sorted(stats['lapsPerCombo'].items(),
                           key=lambda x: x[1]['lapCount'],
                           reverse=True)
     valueToItem = {}
     for t, info in lapsPerCombo:
         nl = info['lapCount']
         name = "+".join(info['cars']) + '@' + info['track']
         v = nl * 100 / tl
         while v in valueToItem:
             v -= 1e-9
         valueToItem[v] = name
         pie_chart.add(name, v)
     pie_chart.value_formatter = lambda x, valueToItem=valueToItem: "%s: %.1f%%" % (
         valueToItem.get(x, '?'), x)
     return pie_chart.render()
예제 #14
0
파일: app.py 프로젝트: fwawira/projectflask
def dashboard():
    projects = Project.select()
    pie_chart = Pie()
    pie_chart.title = 'Project Type comparison'
    Internal = 0
    External = 0
    for project in projects:
        if (project.type == 'Internal'):
            Internal += 1
        else:
            External += 1
    pie_chart.add('External', External)
    pie_chart.add('Internal', Internal)
    # pie_chart.add('Chrome', 36.3)
    # pie_chart.add('Safari', 4.5)
    # pie_chart.add('Opera', 2.3)
    chart = pie_chart.render_data_uri()
    projects = Project.select()

    return render_template('index.html',
                           projects_to_send=projects,
                           chart=chart)
예제 #15
0
def pie_route():
    projects = Project.select()
    pie_chart = Pie()
    pie_chart.title = 'Browser usage in February 2012 (in %)'

    # instatiating two variables internal and external
    internal = 0
    external = 0

    for project in projects:
        if (project.type == 'internal'):
            internal += 1
        else:
            external += 1
    pie_chart.add('internal', internal)
    pie_chart.add('external', external)

    pie_chart.render()
    chart = pie_chart.render_data_uri()

    return render_template('index.html',
                           projects_to_send=projects,
                           chart=chart)
예제 #16
0
 def _render_pie(self, values, labels, title, filename):
     pie_chart = Pie(config=self.pygal_config)
     pie_chart.title = title
     for label, val in zip(labels, values):
         pie_chart.add(label, val)
     pie_chart.render_to_file(filename)
예제 #17
0
from pygal import Pie

pie_chart = Pie()
pie_chart.title = 'Browser usage in February 2012 (in %)'
pie_chart.add('IE', 19.5)
pie_chart.add('Firefox', 36.6)
pie_chart.add('Chrome', 36.3)
pie_chart.add('Safari', 4.5)
pie_chart.add('Opera', 2.3)
pie_chart.render()