Esempio n. 1
0
def get_project_list():
    project_type = request.args.get('project_type')

    db = DatabaseHelper()
    result = db.get_project_list(project_type)

    return api_helper.return_response(result)
Esempio n. 2
0
    def analyze_project_ar(self, year=None):
        connect = DatabaseHelper()
        data = connect.get_activity_ar(year)
        if data['value']:
            data = pd.DataFrame(data['value'])

            project = analyze_helper.set_fullname(connect.get_project_list())
            project = project[project['project_type'] == 1]
            project.drop(columns=['project_type'], inplace=True)
            project_dict = analyze_helper.set_dict(project.index,
                                                   project.project_name)

            # get_branch=connect.get_department(None)
            # branch=[]
            # for i in get_branch['value']:
            #     for index in range(len(i['branch'])):
            #         branch.append(i['branch'][index])
            # branch_data = analyze_helper.set_branch(branch)
            # branch_data.drop(columns=['amount_student'],inplace=True)
            # branch_dict = analyze_helper.set_dict(branch_data.index, branch_data.branch_name)

            get_branch = connect.get_department_ds()
            get_branch = pd.DataFrame(get_branch['value'])

            branch_data = get_branch[['branch_id', 'branch_name']]
            branch_data = branch_data.set_index('branch_id')
            branch_dict = analyze_helper.set_dict(branch_data.index,
                                                  branch_data.branch_name)

            list_project = project.index.tolist()
            project_set = []
            i = 0
            for pindex in list_project:
                df = data[data['project_id'] == pindex]
                name_project = project_dict[pindex]

                if not df.empty:
                    analyze_by_activity = df.groupby(['branch_name']).size()
                    # analyze_by_activity = analyze_helper.set_fullname_index(branch_dict, analyze_by_activity)

                    analyze_by_activity_gpax = df.groupby(['branch_name'
                                                           ])['gpax'].mean()
                    # analyze_by_activity_gpax = analyze_helper.set_fullname_index(branch_dict, analyze_by_activity_gpax)
                    analyze_by_activity_gpax = analyze_by_activity_gpax.round(
                        2)

                    list_pr = {
                        'project_name':
                        name_project,
                        'analyze_by_activity':
                        analyze_by_activity.to_dict(),
                        'analyze_by_activity_gpax':
                        analyze_by_activity_gpax.to_dict()
                    }

                    project_set.append(list_pr)

                else:

                    list_branch = branch_data.branch_name.tolist()
                    df_empty = pd.DataFrame(list_branch,
                                            columns=['branch_name'])
                    df_empty['value'] = 0
                    df_empty.set_index('branch_name', inplace=True)
                    list_pr = {
                        'project_name': name_project,
                        'analyze_by_activity': df_empty.value.to_dict(),
                        'analyze_by_activity_gpax': df_empty.value.to_dict()
                    }
                    project_set.append(list_pr)
                i = i + 1

            value = {
                'project_set': project_set,
            }

            response = True
            message = "Analyze Successfully"
        else:
            value = {}
            response = False
            message = "Don't have Data"

        return inner_res_helper.make_inner_response(response=response,
                                                    message=message,
                                                    value=value)