Пример #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 bar_route():
    projects = Project.select()
    bar_chart = Bar()
    bar_chart.title = 'Bar graphs (in %)'

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

    for project in projects:
        if (project.type == 'title'):
            title += 1
        else:
            amount += 1
    bar_chart.add('title', title)
    bar_chart.add('amount', amount)

    bar_chart.render()
    chart = bar_chart.render_data_uri()

    return render_template('index.html',
                           projects_to_send=projects,
                           chart=chart)