Example #1
0
    def analyze_by_dept(self, dept):
        value = {}
        connect = DatabaseHelper()
        data = connect.get_all_student(dept)
        if data['value']:
            df = pd.DataFrame(data['value'])

            # get_branch=connect.get_department(dept)
            # if dept:
            #     branch_data = analyze_helper.set_branch(get_branch['value'][0][2])
            # else :
            #     print(get_branch)
            #     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)

            get_branch = connect.get_department_ds()
            get_branch = pd.DataFrame(get_branch['value'])
            if dept:
                get_branch = get_branch[get_branch['dept_id'] == dept]
            branch_data = get_branch[['branch_id', 'branch_name']]
            branch_data = branch_data.set_index('branch_id')

            status_data = analyze_helper.set_fullname(
                connect.get_status_list())
            branch_dic = analyze_helper.set_dict(branch_data.index,
                                                 branch_data.branch_name)
            status_dic = analyze_helper.set_dict(status_data.index,
                                                 status_data.status_title)
            status_by_branch = self.__status_by_branch(
                df, list(branch_data.index.values),
                list(status_data.index.values))
            # print(df)
            status_by_branch_index = analyze_helper.set_fullname_index(
                branch_dic, status_by_branch)
            status_by_branch_finist = analyze_helper.set_fullname_column(
                status_dic, status_by_branch_index)
            status_by_year = self.__count_status(
                df[['student_year', 'education_status']],
                list(status_data.index.values))
            status_by_year_finist = analyze_helper.set_fullname_column(
                status_dic, status_by_year)

            count_by_branch = df.groupby(['branch_id']).size()
            count_by_branch = analyze_helper.check_list(
                branch_data.index, count_by_branch)
            count_by_branch = analyze_helper.set_fullname_index(
                branch_dic, count_by_branch)

            value['dept_name'] = get_branch.iloc[0, 1]
            value['all_stu_dept'] = self.__count_student_dept(df)
            value['branch'] = [count_by_branch.to_dict()]
            value['status_by_year'] = [status_by_year_finist.to_dict('index')]
            value['df_status_by_branch'] = [
                status_by_branch_finist.to_dict('index')
            ]

            response = True
            message = "Analyze Student Successfully"
        else:
            response = False
            message = "Don't have Data"

        return inner_res_helper.make_inner_response(response, message, value)
Example #2
0
    def student_admin(self):
        value = {}
        connect = DatabaseHelper()
        data = connect.get_all_student()
        if data['value']:
            df = pd.DataFrame(data['value'])
            # get_branch=connect.get_department(None)

            # dept_data = pd.io.json.json_normalize(get_branch['value'], 'branch', ['dept_id','dept_name'])

            # department_data = dept_data[['dept_id','dept_name']].set_index('dept_id')
            # department_data.drop_duplicates(inplace=True)

            get_branch = connect.get_department_ds()
            get_branch = pd.DataFrame(get_branch['value'])
            department_data = get_branch[['dept_id', 'dept_name']]
            department_data = department_data.set_index('dept_id')

            status_data = analyze_helper.set_fullname(
                connect.get_status_list())

            status_dic = analyze_helper.set_dict(status_data.index,
                                                 status_data.status_title)

            list_department = department_data.index.unique().tolist()
            analyze_by_dept = []
            for dept in list_department:
                analyze = {}
                df_dept = df[df['dept_id'] == dept]
                department_selector = get_branch[get_branch['dept_id'] == dept]
                branch_data = analyze_helper.set_branch(
                    department_selector[['branch_id', 'branch_name']])
                branch_dic = analyze_helper.set_dict(branch_data.index,
                                                     branch_data.branch_name)

                status_by_branch = self.__status_by_branch(
                    df_dept, list(branch_data.index.values),
                    list(status_data.index.values))
                status_by_branch_index = analyze_helper.set_fullname_index(
                    branch_dic, status_by_branch)
                status_by_branch_finist = analyze_helper.set_fullname_column(
                    status_dic, status_by_branch_index)
                status_by_year = self.__count_status(
                    df_dept[['student_year', 'education_status']],
                    list(status_data.index.values))
                status_by_year_finist = analyze_helper.set_fullname_column(
                    status_dic, status_by_year)

                count_by_branch = df_dept.groupby(['branch_id']).size()
                count_by_branch = analyze_helper.check_list(
                    branch_data.index, count_by_branch)
                count_by_branch = analyze_helper.set_fullname_index(
                    branch_dic, count_by_branch)
                analyze['dept_id'] = dept

                # print(branch_data)
                analyze['branch'] = count_by_branch.to_dict()
                analyze['status_by_year'] = [
                    status_by_year_finist.to_dict('index')
                ]
                analyze['df_status_by_branch'] = [
                    status_by_branch_finist.to_dict('index')
                ]
                analyze_by_dept.append(analyze)

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

        return inner_res_helper.make_inner_response(response, message, value)