Пример #1
0
def home():
    departments = DepartmentModel.fetch_all()
    all_employees = EmployeesModel.fetch_all()
    male = 0
    female = 0
    others = 0
    for each in all_employees:
        if each.gender == 'm':
            male += 1
        elif each.gender == 'f':
            female += 1
        else:
            others += 1
    pie_chart = pygal.Pie()
    pie_chart.title = 'Comparing Company Employees by Gender'
    pie_chart.add('Male', male)
    pie_chart.add('Female', female)
    pie_chart.add('Others', others)
    graph = pie_chart.render_data_uri()

    line_chart = pygal.Bar()
    line_chart.title = 'Salary cost per Department'
    for each_dept in departments:
        line_chart.add(each_dept.name,
                       DepartmentModel.fetch_total_payroll_by_id(each_dept.id))
    bar_graph = line_chart.render_data_uri()

    # print(graph)
    # print(departments)
    # print(departments)
    return render_template('index.html',
                           idara=departments,
                           graph=graph,
                           bar_graph=bar_graph)
Пример #2
0
def home():
    departments = DepartmentModel.fetch_all()

    #creating a pie chart in the home page
    all_employees = EmployeesModel.fetch_all()
    male = 0
    female = 0
    others = 0

    for each in all_employees:
        if each.gender == 'male':
            male += 1
        elif each.gender == 'female':
            female += 1
        else:
            others += 1

    pie_chart = pygal.Pie() # instantiating the pie class
    pie_chart.title = 'Analysing Company Employees By Gender'
    pie_chart.add('Male', male)
    pie_chart.add('Female', female)
    pie_chart.add('Others', others)
    chart=pie_chart.render_data_uri()

    # creating a  bar graph in the home page
    line_chart = pygal.Bar() # instantiating the bar graph class
    line_chart.title = 'Salary Cost Per Department'

    #loop over departments
    for each_dept in departments:
        line_chart.add(each_dept.name, DepartmentModel.fetch_total_payroll_by_id(each_dept.id))
    bar_graph = line_chart.render_data_uri()

    return render_template('index.html',idara = departments, chart=chart, bar_graph=bar_graph)