MySQL student performance management system

 

Chapter 1 Overall System Design

    1.   Project Background and Significance

Every school needs to conduct statistical analysis of test scores at the end of the term, and these tasks must be completed within one week after the test. If the statistical work of a large amount of performance data is done manually, it will be time-consuming, labor-intensive, and error-prone. With the rapid development of random computer technology and the rapid popularization of computers in daily management applications, it is imperative to use computers to manage student performance. Therefore, it is necessary to develop a fully functional, safe, reliable, fast and convenient grade management system that meets the needs of the school for grade entry, query, and modification.

    1.   System design content

1.2.1 System design purpose

   Develop a student performance management system that is easy to operate, friendly in interface, flexible and practical, safe and reliable. The development of the system is aimed at teachers and student services. It can improve the efficiency of statistical analysis of students' grades, reduce the burden of educational administrators on student performance management and statistics, and improve the school's standardized management of student performance.

The grade system can collect and organize students' grades in a timely manner, so that relevant departments of the school can obtain reliable student grade information in a timely manner, which is convenient for management. It is convenient for teachers to record and count the grades of students in the classes they lead, improve work efficiency, reduce burdens, and improve teaching quality. Realize the fast and convenient processing of a large amount of grade data information, and complete the processing requirements of grade entry, modification, deletion, query, etc. It is convenient for students to check their grades in various subjects.

1.2.2 System overview

    This system enables students to select courses online and check their grades. Using the method of python+flask+mysql, without server deployment, it can be tested and run on a single machine

The front-end borrows from the front-end page template found on the Internet, and modifies it on this basis. The main technology is html+css+js. The front-end and back-end are developed separately, and tools such as postman are used for interface testing. 

1.2.3 System function requirements

  1. The system is divided into three types of users: administrators, teachers, and students, and different users have different permissions.
  2. Students can log in to check their personal information, check their grades and change their passwords.
  3. Teachers can log in to view personal information, manage courses, collect student performance statistics, and modify login passwords.
  4. Administrators can add, delete, modify and check information on students, teachers, courses, majors, and major course selection information. 
    1.   development environment
  1. Windows10 operating system
  2. PyCharm Community Edition 2022.1.1
  3. MySQL 8.0


Chapter 2 Demand Analysis

2.1 System business requirements 

This system will develop a student performance management system. By surveying students' learning situation, teachers teach

According to the situation, the students' grades are analyzed, and it is determined that the student's grades management system mainly has three types of user roles: students,

teachers, administrators. Their respective main information processing needs are as follows: 

admin user

  1. Add, delete, modify and check the teacher's information. Teacher information includes teacher number, name, gender, and year of birth.
  2. Maintain the basic information of students, realize the addition, deletion, modification, and query of students' personal information. Student information includes student number, name, gender, year of birth, place of origin, year of admission, major number and name.
  3. Maintain the basic information of courses, realize the addition, deletion, modification and query of course information,

Course information includes course number, course name, credits, academic year, semester, teacher number and name.

  1. Manage professional information to realize the addition, deletion, modification, and query of majors, where majors include major number, major name, and number of students.
  2. Maintain the basic information of major course selection, realize the addition, deletion, modification, and query of course selection information. Course selection information includes major number, major name, course number, and course name.

Student user:

  1. Inquire about personal information.  
  2. Students can view their selected course information and grade information of previously selected courses.
  3. Students can query the teachers corresponding to the courses.
  4. Change login password

Teacher user:

  1. Inquire about personal information.  
  2. View information about the courses taught and the students who have taken the courses.
  3. Modify student grades and view course statistics.

2.2 System data requirements

The main data sources involved in the system include student data, teacher data, and administrator data, and various forms such as course information table, professional information table, and professional course selection table are generated. Combined with business processing requirements, the system data flow diagram is shown in the figure.

 

Figure 2-1 Entity description

Figure 2-2 Data flow description

 

Chapter 3 Outline Design

3.1 Functional structure design

According to the business requirements and data requirements obtained from the requirements analysis, the functional structure diagram of the system can be defined, as shown in Figure 3-1.

 

Figure 3-1 Functional Structure of Student Performance Management System

The detailed functions of each module are as follows:

3.1.1 Student Module

  1. Students pass their own student number, and the initial password is the student number;
  2. Check the course information of each subject, the teacher of the course, and check the grades of the course;
  3. Personal password modification: modify the current password and two new passwords after input verification;

3.1.2 Teacher Module

(1) The teacher logs in through the teacher number, and the initial password is the teacher number;

(2) Curriculum management: Teachers record and modify the grades of the taught courses, and count the number of students in different grades;

(3) To modify the personal account password, the previous password and two new passwords are input and verified to modify the password;

3.1.3 Administrator module

  • Administrator login, user name is admin, password is asdfg13579;
  • View student information, and add, modify, and delete it;
  • View teacher information, and add, modify, and delete it;
  • View course information, and add, modify, and delete it;
  • View professional information, and add, modify and delete it;
  • Check the major course selection information, and add, modify, and delete it;

3.2 Database conceptual structure design

3.2.1 Conceptual structure

The application requirements obtained in the requirement analysis stage should first be abstracted into the structure of the information world, so that these requirements can be better and more accurately realized with a certain DBMS.

Main features of the conceptual structure:

  1. Can truly and fully reflect the display world, including the connection between things and things, and satisfy users

The processing requirements for data are just a model of the real world;

  1. It is easy to understand, so that it can be used to exchange ideas with users who are not familiar with computers, and the active participation of users

And is the key to the success of database design.

  1. Easy to change, when the application environment and application requirements change, it is easy to modify and expand the conceptual model;
  2. Easy to convert to various data models such as relational, network, and hierarchical;

The conceptual structure is the common basis of various data models. It is more independent of the machine and more abstract than the data model, so it is more stable.

3.2.2 Conceptual structure design of student performance management system

Now further analyze the requirements of the designed system, and generate the ER model of the conceptual structure design. Since the system is not complex, a top-down design approach can be used. The key to top-down design is to identify the core activities of the system. The so-called core activity means that other activities in the system must revolve around this activity, or are closely related to this activity. Once the core activities are identified, the system has room to expand.

3.2.3 ER model

The system mainly involves three entities: students, teachers, and administrators. Students and teachers establish contact through teaching. One student learns multiple courses, and one teacher can teach multiple students; administrators establish contacts with students and teachers through management; There are entities such as courses, majors, major course selection, and grades; analyze and define the attributes of each entity, and establish the ER diagram of the entity connection model as shown below.

 

Figure 3-4 ER Diagram of Student Performance Management System

3.3 Database logical structure design

Relationship schema:

Transform the conceptual model of the database into the following basic relational schemas. The attributes are marked as primary keys, and those marked as foreign keys;          

Student ( student number ,name, gender, year of birth, place of birth, year of enrollment, major number ,password)

Teacher ( teacher number , name, gender, year of birth, password)

Course ( Course ID , Course Name, Academic Year, Semester, Credits, Faculty ID )

Major ( professional number , professional name)

Course selection by students ( student number, course number , grades)

Major course selection ( professional code, course code )

Administrator ( username , password)

3.4 Database physical design

3.4.1 Database table structure

The database includes 5 relational tables, of which Table 3-5 ~ 3-10 shows the table structure.

  1. student student table:

field

describe

Value description

Remark

student_id

student number, primary key

char(10), number

primary key

student_name

student name

varchar(20), Chinese

not null

sex

gender

char(2), male|female

birth_year

year of birth

char(4), number

province

Home province

varchar(20), Chinese

enter_year

Start year

char(4), number

not null

major_id

Specialty Number, Foreign Key

char(3), number

foreign key, not null

password

encrypted password

varchar(128)

not null

Table 3-5 Student table structure

  1. teacher teacher table:

field

describe

Value description

Remark

teacher_id

teacher number

char(5), number

primary key

teacher_name

teacher name

varchar(20), Chinese

 not null

sex

gender

char(2), male|female

birth_year

year of birth

char(4), number

password

encrypted password

varchar(128)

not null

Table 3-6 Teacher table structure

    (3) course schedule

field

describe

Value description

Remark

course_id

Course No

char(5), number

primary key

course_name

Course Title

varchar(20), Chinese

 not null

year

year of establishment

char(4), number

 not null

semester

open semester

char(2), Autumn|Spring

 not null

teacher_id

teacher number

char(5), number

foreign key, not null

credit

credit

tiny int,unsigned,0~10

 not null

Table 3-7 Curriculum structure

(4) student_course student course selection table

field

describe

Value description

Remark

student_id

student number

char(10) , number

joint primary key, foreign key

course_id

Course No

char(5) , number

joint primary key, foreign key

grade

score

tiny int,unsigned,0~100

Table 3-8 Course Selection Table Structure

  1. major_course major course selection table

field

describe

Value description

Remark

major_id

professional number

char(3), number

joint primary key, foreign key

course_id

Course No

char(5), number

joint primary key, foreign key

Table 3-9 Structure of major course selection table

(6) admin administrator table

field

describe

Value description

Remark

admin_name

username

char(15)

primary key

password

password

char(128)

not null

Table 3-10 Administrator table structure

3.4.2 Database table creation code

1. Create a database

create database grade_manage_system;

2. Enter the database

use grade_manage_system

3. Create a student table

create table student

(

student_id char(10) primary key,

student_name varchar(20) not null,

sex char(2),

birth_year char(4),

 province varchar(20),

enter_year char(4) not null,

major_id char(3) not null,

 password varchar(128) not null

);

4. Create teacher table

create table teacher

(

teacher_id char(5) primary key,

teacher_name varchar(20) not null,

 sex char(2),

 birth_year char(4),

password varchar(128) not null

);

5. Create a class schedule

create table course

(

course_id char(5) primary key,

 course_name varchar(20) not null,

 year char(4) not null,

 semester char(2) not null,

 teacher_id char(5) not null,

 credit tinyint unsigned not null

);

6. Create a professional table

create table major

(

major_id char(3) primary key,

 major_name varchar(20) not null unique

);

7. Create a professional course selection list

create table major_course

(

major_id char(3),

 course_id char(5)

);

8. Create a student course selection report card

create table student_course

(

student_id char(10),

 course_id char(5),

 grade tinyint unsigned

);
  1. Create admin table
create table admin

(

admin_name char(15) primary key,

 password varchar(128) not null

);

Chapter 4 System Implementation

4.1   Interface design

The student performance management system page is made by the Python programming flask library. The page is mainly divided into four modules, namely: login page module, student user module, teacher user module and administrator user module. The landing page is made of html+css+js technology, and is interfaced by using tools such as postman. And there are several small modules under the other three modules, each containing several pages. The detailed interface design is as follows.

4.1.1 Login page design

The student performance management system is to log in by selecting the login identity and entering the account password. The administrator uses admin as the user name, and the password is a fixed value, which cannot be modified. The teacher uses the teacher number as the user name, and the default password is the teacher number, which can be modified. The student uses the student number as the user name, and the password defaults to the student number, which can be modified. The login interface is as follows:

 

4.1.2 Student Module

4.1.3 Teacher Module

4.1.4 Administrator module

The administrator logs in with the username admin and the password asdfg13579,

After the administrator logs in successfully, there are several functional interfaces for viewing all student information, adding students, viewing all teacher information, adding teachers, viewing all course information, adding courses, viewing all major information, adding majors, viewing major course selection information, and adding major course selection

4.2 Main functions and program codes

4.2.1 数据库搭建

学生成绩管理系统的实现,共需要在 MySQL 上创建一个数据库,七个表,分别

是学生表(student)、教师表(teacher)、课程表(course)、专业表

(major)、管理员表(admin)、学生选课表(student_course)、专业选课表(major_course)。

1创建并使用数据库

create database grade_manage_system;//

use grade_manage_system

2创建专业表

create table major(major_id char(3) primary key, major_name varchar(20) not null unique);//

3创建学生表

create table student(

student_id char(10) primary key, student_name varchar(20) not null,

 sex char(2), 

            birth_year char(4), province varchar(20), enter_year char(4) not null, 

            major_id char(3) not null, password varchar(128) not null);//

alter table student add foreign key (major_id) references major (major_id) on delete cascade;//

4创建教师表

create table teacher(

teacher_id char(5) primary key, teacher_name varchar(20) not null, 

sex char(2), 

            birth_year char(4), password varchar(128) not null);//

5创建课程表

create table course(

course_id char(5) primary key, course_name varchar(20) not null, 

            year char(4) not null, semester char(2) not null, 

teacher_id char(5) not null, 

            credit tinyint unsigned not null);//

alter table course add foreign key (teacher_id) references teacher (teacher_id) on delete cascade;//

6创建专业选课表

create table major_course(

major_id char(3), course_id char(5));//

alter table major_course add primary key (major_id, course_id);//

alter table major_course add foreign key (major_id) references major (major_id)

on delete cascade;//

alter table major_course add foreign key (course_id) references course (course_id) on delete cascade;//

7创建学生选课表

create table student_course(

student_id char(10), course_id char(5), grade tinyint unsigned);//

alter table student_course add primary key (student_id, course_id);//

8创建添加专业选课

create trigger trigger_insert_1 after insert on major_course for each row

begin

    insert into student_course (

        select student_id, new.course_id, null

        from student

        where major_id = new.major_id

    );

end//

9创建删除专业选课

create trigger trigger_delete_1 after delete on major_course for each row

begin

    delete from student_course

    where student_id in (

        select student_id

        from student

        where major_id = old.major_id

    ) and course_id = old.course_id;

end//

10创建添加学生

create trigger trigger_insert_2 after insert on student for each row

begin

    insert into student_course (

        select new.student_id, course_id, null

        from major_course

        where major_id = new.major_id

    );

end//

11创建删除学生

create trigger tigger_delete_2 after delete on student for each row

begin

    delete from student_course

    where course_id in (

        select course_id

        from major_course

        where major_id = old.major_id

    ) and student_id = old.student_id;

end//



delimiter ;

4.2.2 数据库的连接

功能:使得数据库与客户端进行数据传输

代码:

  1. if __name__ == '__main__':  
        app.config['DEBUG'] = True  
        app.config['SECRET_KEY'] = '123456'  
        app.config['DATABASE_USER'] = 'root'  
        app.config['DATABASE_PASSWORD'] = '1234 
     

4.2.3 登录模块

功能:验证账号密码和对应的权限,以及跳转进入对应主页面

代码

  1. from flask import Flask  
    from flask_login import LoginManager  
    from app.models.session import LoginChecker  
    from werkzeug.utils import redirect  
    from flask_login import login_required  
      
    login_manager = LoginManager()  
     
     
    @login_manager.user_loader  
    def load_user(user_id):  
        if 'student' in user_id:  
            return LoginChecker('load', 'student', user_id[7:], 'default')  
        if 'teacher' in user_id:  
            return LoginChecker('load', 'teacher', user_id[7:], 'default')  
        if 'admin' in user_id:  
            return LoginChecker('load', 'admin', user_id[5:], 'default')  
        return None  
      
      
    app = Flask(__name__)  
    login_manager.init_app(app)  
    from app.web.student import web  
    app.register_blueprint(web)  
     
     
    @app.route('/')  
    def bare():  
        return redirect('/static/Login.html')  
     
     
    @app.route('/static/Login.html')  
    def html_login():  
        return app.send_static_file('Login.html')  
     
     
    @app.route('/static/Student_Info.html')  
    @login_required  
    def html_student_info():  
        return app.send_static_file('Student_Info.html')  
     
     
    @app.route('/static/Student_Scores.html')  
    @login_required  
    def html_student_scores():  
        return app.send_static_file('Student_Scores.html')  
     
     
    @app.route('/static/Student_ChangePassword.html')  
    @login_required  
    def html_student_change_password():  
        return app.send_static_file('Student_ChangePassword.html')  
     
     
    @app.route('/static/Teacher_Info.html')  
    @login_required  
    def html_teacher_info():  
        return app.send_static_file('Teacher_Info.html')  
     
     
    @app.route('/static/Teacher_Courses.html')  
    @login_required  
    def html_teacher_courses():  
        return app.send_static_file('Teacher_Courses.html')  
     
     
    @app.route('/static/Teacher_CourseInfo.html')  
    @login_required  
    def html_course_info():  
        return app.send_static_file('Teacher_CourseInfo.html')  
     
     
    @app.route('/static/Teacher_ChangePassword.html')  
    @login_required  
    def html_teacher_change_password():  
        return app.send_static_file('Teacher_ChangePassword.html')  
     
     
    @app.route('/static/Teacher_Statistics.html')  
    @login_required  
    def html_teacher_statistics():  
        return app.send_static_file('Teacher_Statistics.html')  

4.2.4 学生菜单模块

功能:在学生页面进行不同功能页面的切换

各个功能代码如下:

  1. 学生登录菜单
  1. from app.models.general import connect_to_sql  
      
      
    class StudentReader:  
        def __init__(self, student_id):  
            self.data = read_base_information(student_id)  
            if self.data.get('error'):  
                return  
            self.data = dict(self.data, **read_total_credits(student_id))  
            if self.data.get('error'):  
                return  
            self.data = dict(self.data, **read_number_of_courses(student_id))  
            if self.data.get('error'):  
                return  
            self.data = dict(self.data, **read_average_grade(student_id))  
      
      
    class StudentCoursesReader:  
        def __init__(self, student_id):  
            self.data = read_selected_courses(student_id)  

  1. 学生查看个人信息
  1. def read_base_information(student_id):  
        connection = connect_to_sql()  
        data = {}  
        try:  
            with connection.cursor() as cursor:  
                # 查询学生基本信息  
                sql = 'select student_id, student_name, sex, birth_year, province, enter_year, major_name, s.major_id ' \  
                      'from student as s, major as m ' \  
                      'where s.student_id = %s and s.major_id = m.major_id;' % student_id  
                cursor.execute(sql)  
                result = cursor.fetchone()  
                if result:  
                    data['student_id'] = result[0]  
                    data['student_name'] = result[1]  
                    data['sex'] = result[2]  
                    data['birth_year'] = result[3]  
                    data['province'] = result[4]  
                    data['enter_year'] = result[5]  
                    data['major_name'] = result[6]  
                    data['major_id'] = result[7]  
                else:  
                    data['error'] = 'student id ' + student_id + ' not found in database'  
        except Exception as e:  
            data['error'] = str(e)  
        finally:  
            connection.close()  
        return data  

  1. 学生查看课程信息及成绩
  1. def read_total_credits(student_id):  
        connection = connect_to_sql()  
        data = {}  
        try:  
            with connection.cursor() as cursor:  
                sql = 'select if(sum(credit) is null, 0, sum(credit)) from student as s, course as c, student_course as sc ' \  
                      'where s.student_id = %s and s.student_id = sc.student_id ' \  
                      'and c.course_id = sc.course_id and grade >= 60;' % student_id  
                cursor.execute(sql)  
                result = cursor.fetchone()  
                if result:  
                    data['credits'] = int(result[0])  
                else:  
                    data['credits'] = 0  
        except Exception as e:  
            data['error'] = str(e)  
        finally:  
            connection.close()  
        return data  
      
      
    def read_number_of_courses(student_id):  
        connection = connect_to_sql()  
        data = {}  
        try:  
            with connection.cursor() as cursor:  
                sql = 'select count(course_id) from student_course ' \  
                      'where student_id = %s;' % student_id  
                cursor.execute(sql)  
                result = cursor.fetchone()  
                if result:  
                    data['number_of_courses'] = int(result[0])  
                else:  
                    data['number_of_courses'] = 0  
        except Exception as e:  
            data['error'] = str(e)  
        finally:  
            connection.close()  
        return data  
      
      
    def read_average_grade(student_id):  
        connection = connect_to_sql()  
        data = {}  
        try:  
            with connection.cursor() as cursor:  
                sql = 'select credit, grade from student_course as sc, course as c ' \  
                      'where sc.student_id = %s and sc.course_id = c.course_id ' \  
                      'and grade is not null;' % student_id  
                cursor.execute(sql)  
                result = cursor.fetchall()  
                if result:  
                    total_credit = 0  
                    total_grade = 0  
                    for row in result:  
                        total_credit += row[0]  
                        total_grade += row[0] * row[1]  
                    data['average_grade'] = round(float(1.0*total_grade/total_credit), 2)  
                else:  
                    data['average_grade'] = 0  
        except Exception as e:  
            data['error'] = str(e)  
        finally:  
            connection.close()  
        return data  
      
      
    def read_selected_courses(student_id):  
        connection = connect_to_sql()  
        data = {}  
        try:  
            with connection.cursor() as cursor:  
                sql = 'select c.course_id, c.course_name, c.year, c.semester, t.teacher_name, c.credit, sc.grade ' \  
                      'from course as c, student_course as sc, teacher as t ' \  
                      'where sc.student_id = %s and sc.course_id = c.course_id ' \  
                      'and t.teacher_id = c.teacher_id;' % student_id  
                cursor.execute(sql)  
                result = cursor.fetchall()  
                data['courses'] = []  
                for row in result:  
                    tmp = {'course_id': row[0], 'course_name': row[1], 'year': row[2], 'semester': row[3],  
                           'teacher_name': row[4], 'credit': row[5], 'grade': row[6]}  
                    data['courses'].append(tmp)  
        except Exception as e:  
            data['error'] = str(e)  
        finally:  
            connection.close()  
        return data  

4.2.5 教师菜单模块

功能:在教师页面进行不同功能页面的切换

  1. 教师登录页面
  1. from app.models.general import connect_to_sql  
      
      
    class TeacherReader:  
        def __init__(self, teacher_id):  
            self.data = read_base_information(teacher_id)  
            if self.data.get('error'):  
                return  
            self.data = dict(self.data, **read_number_of_courses(teacher_id))  
      
      
    class TeacherCoursesReader:  
        def __init__(self, teacher_id):  
            self.data = read_taught_courses(teacher_id)  
      
      
    class TeacherCourseStudentReader:  
        def __init__(self, course_id):  
            self.data = read_selected_students(course_id)  
      
      
    class TeacherGradeUpdater:  
        def __init__(self, course_id, student_id, grade):  
            self.data = update_student_grade(course_id, student_id, grade)  
      
      
    class CourseStatisticReader:  
        def __init__(self, course_id):  
            self.data = read_course_statistic(course_id)  

  1. 教师查看个人信息
  1. def read_number_of_courses(teacher_id):  
        connection = connect_to_sql()  
        data = {}  
        try:  
            with connection.cursor() as cursor:  
                # 查询教师所授课程数量  
                sql = 'select count(course_id) from course ' \  
                      'where teacher_id = %s;' % teacher_id  
                cursor.execute(sql)  
                result = cursor.fetchone()  
                if result:  
                    data['number_of_courses'] = int(result[0])  
                else:  
                    data['number_of_courses'] = 0  
        except Exception as e:  
            data['error'] = str(e)  
        finally:  
            connection.close()  
        return data  

(3)教师查看授课信息

  1. def read_taught_courses(teacher_id):  
        connection = connect_to_sql()  
        data = {}  
        try:  
            with connection.cursor() as cursor:  
                # 查询教师授课列表  
                sql = 'select course_id, course_name, year, semester, credit ' \  
                      'from course ' \  
                      'where teacher_id = %s ' % teacher_id  
                cursor.execute(sql)  
                result = cursor.fetchall()  
                data['courses'] = []  
                if result:  
                    for row in result:  
                        tmp = {'course_id': row[0], 'course_name': row[1], 'year': row[2], 'semester': row[3],  
                               'credit': row[4]}  
                        data['courses'].append(tmp)  
        except Exception as e:  
            data['error'] = str(e)  
        finally:  
            connection.close()  
        return data  

(4)教师查看选课学生

  1. def read_selected_students(course_id):  
        connection = connect_to_sql()  
        data = {}  
        try:  
            with connection.cursor() as cursor:  
                # 查询选课学生列表  
                sql = 'select s.student_id, s.student_name, s.sex, m.major_name, sc.grade ' \  
                      'from student_course as sc, student as s, major as m ' \  
                      'where sc.student_id = s.student_id and s.major_id = m.major_id ' \  
                      'and course_id = %s ' % course_id  
                cursor.execute(sql)  
                result = cursor.fetchall()  
                data['students'] = []  
                if result:  
                    for row in result:  
                        tmp = {'student_id': row[0], 'student_name': row[1], 'sex': row[2], 'major_name': row[3],  
                               'grade': row[4]}  
                        data['students'].append(tmp)  
        except Exception as e:  
            data['error'] = str(e)  
        finally:  
            connection.close()  
        return data  

(5)教师查看课程统计信息

  1. def read_course_statistic(course_id):  
        connection = connect_to_sql()  
        data = {}  
        try:  
            with connection.cursor() as cursor:  
                # 查询某课程统计信息  
                sql = 'select ' \  
                      'count(case when grade between 0 and 59 then grade end) as \'0-59\',' \  
                      'count(case when grade between 60 and 69 then grade end) as \'60-69\',' \  
                      'count(case when grade between 70 and 79 then grade end) as \'70-79\',' \  
                      'count(case when grade between 80 and 89 then grade end) as \'80-89\',' \  
                      'count(case when grade between 90 and 100 then grade end) as \'90-100\' ' \  
                      'from student_course ' \  
                      'where course_id = %s;' % course_id  
                cursor.execute(sql)  
                result = cursor.fetchone()  
                if result:  
                    data['0-59'] = int(result[0])  
                    data['60-69'] = int(result[1])  
                    data['70-79'] = int(result[2])  
                    data['80-89'] = int(result[3])  
                    data['90-100'] = int(result[4])  
                else:  
                    data['error'] = 'course_id ' + course_id + ' not found in database'  
        except Exception as e:  
            data['error'] = str(e)  
        finally:  
            connection.close()  
        return data  

(6)教师修改学生成绩

  1. def update_student_grade(course_id, student_id, grade):  
        connection = connect_to_sql()  
        data = {}  
        try:  
            with connection.cursor() as cursor:  
                # 更新学生某课程成绩  
                sql = 'update student_course ' \  
                      'set grade = %s ' \  
                      'where course_id = \'%s\' and student_id = \'%s\';' % (grade, course_id, student_id)  
                cursor.execute(sql)  
                connection.commit()  
        except Exception as e:  
            data['error'] = str(e)  
            connection.rollback()  
        finally:  
            connection.close()  
        return data  

4.2.6 管理员模块

功能:在管理员页面进行不同功能页面的切换

  1. 管理员管理学生模块
  1. 管理学生菜单
  1. from app.models.general import connect_to_sql  
    from app.models.student import StudentReader  
    from werkzeug.security import generate_password_hash  
      
      
    class StudentListReader:  
        def __init__(self):  
            data = read_student_id_list()  
            if data.get('error'):  
                return  
            student_id_list = data['student_id']  
            self.data = {'students': []}  
            for student_id in student_id_list:  
                tmp = StudentReader(student_id)  
                if tmp.data.get('error'):  
                    self.data['error'] = tmp.data['error']  
                    return  
                self.data['students'].append(tmp.data)  
      
      
    class StudentUpdater:  
        def __init__(self, student_id, student_name, sex, birth_year, province, enter_year, major_id):  
            self.data = update_student(student_id, student_name, sex, birth_year, province, enter_year, major_id)  
      
      
    class StudentInserter:  
        def __init__(self, student_name, sex, birth_year, province, enter_year, major_id):  
            self.data = insert_student(student_name, sex, birth_year, province, enter_year, major_id)  
      
      
    class StudentDeleter:  
        def __init__(self, student_id):  
            self.data = delete_student(student_id)  

  1. 删除学生信息
  1. def delete_student(student_id):  
        connection = connect_to_sql()  
        data = {}  
        try:  
            with connection.cursor() as cursor:  
                sql = 'delete from student where student_id = \'%s\'; ' % student_id  
                cursor.execute(sql)  
                connection.commit()  
        except Exception as e:  
            data['error'] = str(e)  
            connection.rollback()  
        finally:  
            connection.close()  
        return data  

  1. 添加学生信息
  1. def insert_student(student_name, sex, birth_year, province, enter_year, major_id):  
        connection = connect_to_sql()  
        data = {}  
        try:  
            with connection.cursor() as cursor:  
                student_id = get_new_student_id(enter_year, major_id)  
                password = generate_password_hash(student_id['student_id'])  
                sql = 'insert into student values ' \  
                      '(\'%s\', \'%s\', \'%s\', \'%s\', \'%s\', \'%s\', \'%s\', \'%s\'); ' \  
                      % (student_id['student_id'], student_name, sex, birth_year, province, enter_year, major_id, password)  
                cursor.execute(sql)  
                connection.commit()  
        except Exception as e:  
            data['error'] = str(e)  
            connection.rollback()  
        finally:  
            connection.close()  
        return data  

  1. 查看学生信息表
  1. def read_student_id_list():  
        connection = connect_to_sql()  
        data = {}  
        try:  
            with connection.cursor() as cursor:  
                sql = 'select student_id from student order by student_id;'  
                cursor.execute(sql)  
                data['student_id'] = cursor.fetchall()  
        except Exception as e:  
            data['error'] = str(e)  
        finally:  
            connection.close()  
        return data  

  1. 修改学生信息
  1. def update_student(student_id, student_name, sex, birth_year, province, enter_year, major_id):  
        connection = connect_to_sql()  
        data = {}  
        try:  
            with connection.cursor() as cursor:  
                sql = 'update student set student_name = \'%s\', sex = \'%s\', birth_year = \'%s\', ' \  
                      'province = \'%s\', enter_year = \'%s\', major_id = \'%s\' where student_id = \'%s\'; ' % \  
                      (student_name, sex, birth_year, province, enter_year, major_id, student_id)  
                cursor.execute(sql)  
                connection.commit()  
        except Exception as e:  
            data['error'] = str(e)  
            connection.rollback()  
        finally:  
            connection.close()  
        return data  

  1. 管理员管理教师模块
  1. 管理教师菜单
  1. from werkzeug.security import generate_password_hash  
      
    from app.models.general import connect_to_sql  
      
      
    class TeacherListReader:  
        def __init__(self):  
            self.data = read_teacher_list()  
      
      
    class TeacherIdReader:  
        def __init__(self):  
            self.data = read_teacher_id()  
      
      
    class TeacherUpdater:  
        def __init__(self, teacher_id, teacher_name, sex, birth_year):  
            self.data = update_teacher(teacher_id, teacher_name, sex, birth_year)  
      
      
    class TeacherInserter:  
        def __init__(self, teacher_name, sex, birth_year):  
            self.data = insert_teacher(teacher_name, sex, birth_year)  
      
      
    class TeacherDeleter:  
        def __init__(self, teacher_id):  
            self.data = delete_teacher(teacher_id)  

  1. 查看教师信息
  1. def read_teacher_list():  
        connection = connect_to_sql()  
        data = {}  
        try:  
            with connection.cursor() as cursor:  
                sql = 'select t.teacher_id, teacher_name, sex, birth_year, count(course_id) as number_of_courses ' \  
                      'from teacher as t left outer join course as c ' \  
                      'on c.teacher_id = t.teacher_id ' \  
                      'group by t.teacher_id ' \  
                      'order by t.teacher_id;'  
                cursor.execute(sql)  
                result = cursor.fetchall()  
                data['teachers'] = []  
                for row in result:  
                    tmp = {'teacher_id': row[0], 'teacher_name': row[1], 'sex': row[2],  
                           'birth_year': row[3], 'number_of_courses': row[4]}  
                    data['teachers'].append(tmp)  
        except Exception as e:  
            data['error'] = str(e)  
        finally:  
            connection.close()  
        return data  

  1. 删除教师信息
  1. def delete_teacher(teacher_id):  
        connection = connect_to_sql()  
        data = {}  
        try:  
            with connection.cursor() as cursor:  
                sql = 'delete from teacher where teacher_id = \'%s\'; ' % teacher_id  
                cursor.execute(sql)  
                connection.commit()  
        except Exception as e:  
            data['error'] = str(e)  
            connection.rollback()  
        finally:  
            connection.close()  
        return data  

  1. 添加教师信息
  1. def insert_teacher(teacher_name, sex, birth_year):  
        connection = connect_to_sql()  
        data = {}  
        try:  
            with connection.cursor() as cursor:  
                teacher_id = get_new_teacher_id()  
                password = generate_password_hash(teacher_id['teacher_id'])  
                if teacher_id.get('error'):  
                    data['error'] = teacher_id['error']  
                    return data  
                sql = 'insert into teacher values(\'%s\', \'%s\', \'%s\', \'%s\', \'%s\');' \  
                      % (teacher_id['teacher_id'], teacher_name, sex, birth_year, password)  
                cursor.execute(sql)  
                connection.commit()  
        except Exception as e:  
            data['error'] = str(e)  
            connection.rollback()  
        finally:  
            connection.close()  
        return data  

  1. 修改教师信息
  1. def update_teacher(teacher_id, teacher_name, sex, birth_year):  
        connection = connect_to_sql()  
        data = {}  
        try:  
            with connection.cursor() as cursor:  
                sql = 'update teacher set teacher_name = \'%s\', sex = \'%s\', birth_year = \'%s\' ' \  
                      'where teacher_id = \'%s\'; ' % \  
                      (teacher_name, sex, birth_year, teacher_id)  
                cursor.execute(sql)  
                connection.commit()  
        except Exception as e:  
            data['error'] = str(e)  
            connection.rollback()  
        finally:  
            connection.close()  
        return data  

  1. 管理员管理课程模块
  1. 管理课程菜单
  1. from app.models.general import connect_to_sql  
      
      
    class CourseReader:  
        def __init__(self):  
            self.data = read_course()  
      
      
    class SingleCourseReader:  
        def __init__(self, course_id):  
            self.data = read_single_course(course_id)  
      
      
    class CourseDeleter:  
        def __init__(self, course_id):  
            self.data = delete_course(course_id)  
      
      
    class CourseInserter:  
        def __init__(self, course_name, year, semester, teacher_id, credit):  
            self.data = insert_course(course_name, year, semester, teacher_id, credit)  
      
      
    class CourseUpdater:  
        def __init__(self, course_id, course_name, year, semester, teacher_id, credit):  
            self.data = update_course(course_id, course_name, year, semester, teacher_id, credit)  
      
      
    class CourseTeacherReader:  
        def __init__(self, course_id):  
            self.data = get_teacher_of_course(course_id)  

  1. 查看课程信息
  1. def read_course():  
        connection = connect_to_sql()  
        data = {}  
        try:  
            with connection.cursor() as cursor:  
                sql = 'select tmp.course_id, tmp.course_name, tmp.year, tmp.semester, tmp.teacher_id, ' \  
                      'tmp.credit, tmp.number_of_students, tmp.average_grade, t.teacher_name from ( ' \  
                      'select c.course_id, course_name, year, semester, teacher_id, credit, count(student_id), avg(grade) ' \  
                      'from course as c left outer join student_course as sc ' \  
                      'on c.course_id = sc.course_id ' \  
                      'group by c.course_id ' \  
                      ') as tmp(course_id, course_name, year, semester, teacher_id, ' \  
                      'credit, number_of_students, average_grade), teacher as t ' \  
                      'where tmp.teacher_id = t.teacher_id ' \  
                      'order by tmp.course_id; '  
                cursor.execute(sql)  
                result = cursor.fetchall()  
                data['courses'] = []  
                for row in result:  
                    average_grade = row[7]  
                    if average_grade is None:  
                        average_grade = 0  
                    tmp = {'course_id': row[0], 'course_name': row[1], 'year': row[2], 'semester': row[3],  
                           'teacher_id': row[4], 'credit': row[5], 'number_of_students': row[6],  
                           'average_grade': round(float(average_grade), 2), 'teacher_name': row[8]}  
                    data['courses'].append(tmp)  
        except Exception as e:  
            data['error'] = str(e)  
        finally:  
            connection.close()  
        return data  

  1. 添加课程信息
  1. def insert_course(course_name, year, semester, teacher_id, credit):  
        connection = connect_to_sql()  
        data = {}  
        try:  
            with connection.cursor() as cursor:  
                course_id = get_new_course_id()  
                if course_id.get('error'):  
                    data['error'] = course_id['error']  
                    return data  
                sql = 'insert into course values(\'%s\', \'%s\', \'%s\', \'%s\', \'%s\', %d);' \  
                      % (course_id['course_id'], course_name, year, semester, teacher_id, credit)  
                cursor.execute(sql)  
                connection.commit()  
        except Exception as e:  
            data['error'] = str(e)  
            connection.rollback()  
        finally:  
            connection.close()  
        return data  

  1. 删除课程信息
  1. def delete_course(course_id):  
        connection = connect_to_sql()  
        data = {}  
        try:  
            with connection.cursor() as cursor:  
                sql = 'delete from course where course_id = \'%s\'; ' % course_id  
                cursor.execute(sql)  
                connection.commit()  
        except Exception as e:  
            data['error'] = str(e)  
        finally:  
            connection.close()  
        return data  

  1. 修改课程信息
  1. def update_course(course_id, course_name, year, semester, teacher_id, credit):  
        connection = connect_to_sql()  
        data = {}  
        try:  
            with connection.cursor() as cursor:  
                sql = 'update course set course_name = \'%s\', year = \'%s\', semester = \'%s\',' \  
                      'teacher_id = \'%s\', credit = %d where course_id = \'%s\';' \  
                      % (course_name, year, semester, teacher_id, credit, course_id)  
                cursor.execute(sql)  
                connection.commit()  
        except Exception as e:  
            data['error'] = str(e)  
            connection.rollback()  
        finally:  
            connection.close()  
        return data  

  1. 管理员管理专业模块
  1. 管理专业菜单
  1. from app.models.general import connect_to_sql  
      
      
    class MajorIdReader:  
        def __init__(self):  
            self.data = read_major_id()  
      
      
    class MajorReader:  
        def __init__(self):  
            self.data = read_major()  
      
      
    class SingleMajorReader:  
        def __init__(self, major_id):  
            self.data = read_single_major(major_id)  
      
      
    class MajorUpdater:  
        def __init__(self, major_id, major_name):  
            self.data = update_major(major_id, major_name)  
      
      
    class MajorInserter:  
        def __init__(self, major_name):  
            self.data = insert_major(major_name)  
      
      
    class MajorDeleter:  
        def __init__(self, major_id):  
            self.data = delete_major(major_id)  

  1. 管理员查看专业
  1. def read_major():  
        connection = connect_to_sql()  
        data = {}  
        try:  
            with connection.cursor() as cursor:  
                sql = 'select m.major_id, major_name, count(student_id) as number_of_students ' \  
                      'from major as m left outer join student as s ' \  
                      'on m.major_id = s.major_id ' \  
                      'group by m.major_id ' \  
                      'order by m.major_id;'  
                cursor.execute(sql)  
                result = cursor.fetchall()  
                data['majors'] = []  
                for row in result:  
                    tmp = {'major_id': row[0], 'major_name': row[1], 'number_of_students': row[2]}  
                    data['majors'].append(tmp)  
        except Exception as e:  
            data['error'] = str(e)  
        finally:  
            connection.close()  
        return data  

  1. 管理员添加专业
  1. def insert_major(major_name):  
        connection = connect_to_sql()  
        data = {}  
        try:  
            with connection.cursor() as cursor:  
                major_id = get_new_major_id()  
                if major_id.get('error'):  
                    data['error'] = major_id['error']  
                    return data  
                sql = 'insert into major values(\'%s\', \'%s\');' % (major_id['major_id'], major_name)  
                cursor.execute(sql)  
                connection.commit()  
        except Exception as e:  
            data['error'] = str(e)  
            connection.rollback()  
        finally:  
            connection.close()  
        return data  

  1. 管理员修改专业
  1. def update_major(major_id, major_name):  
        connection = connect_to_sql()  
        data = {}  
        try:  
            with connection.cursor() as cursor:  
                sql = 'update major set major_name = \'%s\' where major_id = \'%s\';' % (major_name, major_id)  
                cursor.execute(sql)  
                connection.commit()  
        except Exception as e:  
            data['error'] = str(e)  
            connection.rollback()  
        finally:  
            connection.close()  
        return data  

  1. 管理员删除专业
  1. def insert_major_course(major_id, course_id):  
        connection = connect_to_sql()  
        data = {}  
        try:  
            with connection.cursor() as cursor:  
                sql = 'insert into major_course values(\'%s\', \'%s\');' % (major_id, course_id)  
                cursor.execute(sql)  
                """ 
                sql = 'insert into student_course ( select student_id, \'%s\', ' \ 
                      'null from student where major_id = \'%s\');' % (course_id, major_id) 
                cursor.execute(sql) 
                """  
                connection.commit()  
        except Exception as e:  
            data['error'] = str(e)  
            connection.rollback()  
        finally:  
            connection.close()  
        return data  

  1. 管理员管理专业选课
  1. 管理选课菜单
  1. def insert_major_course(major_id, course_id):  
        connection = connect_to_sql()  
        data = {}  
        try:  
            with connection.cursor() as cursor:  
                sql = 'insert into major_course values(\'%s\', \'%s\');' % (major_id, course_id)  
                cursor.execute(sql)  
                """ 
                sql = 'insert into student_course ( select student_id, \'%s\', ' \ 
                      'null from student where major_id = \'%s\');' % (course_id, major_id) 
                cursor.execute(sql) 
                """  
                connection.commit()  
        except Exception as e:  
            data['error'] = str(e)  
            connection.rollback()  
        finally:  
            connection.close()  
        return data  

  1. 管理员添加专业选课
  1. def insert_major_course(major_id, course_id):  
        connection = connect_to_sql()  
        data = {}  
        try:  
            with connection.cursor() as cursor:  
                sql = 'insert into major_course values(\'%s\', \'%s\');' % (major_id, course_id)  
                cursor.execute(sql)  
                """ 
                sql = 'insert into student_course ( select student_id, \'%s\', ' \ 
                      'null from student where major_id = \'%s\');' % (course_id, major_id) 
                cursor.execute(sql) 
                """  
                connection.commit()  
        except Exception as e:  
            data['error'] = str(e)  
            connection.rollback()  
        finally:  
            connection.close()  
        return data  
    

  1. 管理员删除专业选课
  1. def delete_major_course(major_id, course_id):  
        connection = connect_to_sql()  
        data = {}  
        try:  
            with connection.cursor() as cursor:  
                """ 
                sql = 'delete from student_course ' \ 
                      'where student_id in ( ' \ 
                          'select student_id ' \ 
                          'from student ' \ 
                          'where major_id = \'%s\') ' \ 
                      'and course_id = \'%s\'; ' % (major_id, course_id) 
                cursor.execute(sql) 
                """  
                sql = 'delete from major_course ' \  
                      'where major_id = \'%s\' and course_id = \'%s\' ' % (major_id, course_id)  
                cursor.execute(sql)  
                connection.commit()  
        except Exception as e:  
            data['error'] = str(e)  
            connection.rollback()  
        finally:  
            connection.close()  
        return data  

  1. 管理员查看专业选课
  1. def read_major_course():  
        connection = connect_to_sql()  
        data = {}  
        try:  
            with connection.cursor() as cursor:  
                sql = 'select m.major_id, major_name, c.course_id, course_name ' \  
                      'from major_course as mc, major as m, course as c ' \  
                      'where mc.major_id = m.major_id and mc.course_id = c.course_id ' \  
                      'order by m.major_id, c.course_id;'  
                cursor.execute(sql)  
                result = cursor.fetchall()  
                data['major_courses'] = []  
                for row in result:  
                    tmp = {'major_id': row[0], 'major_name': row[1], 'course_id': row[2], 'course_name': row[3]}  
                    data['major_courses'].append(tmp)  
        except Exception as e:  
            data['error'] = str(e)  
        finally:  
            connection.close()  
        return data  

 

第五章 测试与总结

5.1  测试

通过调试,对各个模块的功能进行测试;

5.2  总结

本次实验我是在windows操作系统平台下完成的,应用了MySQL数据库建表,触发,删除插入.......;Python语言中的GUI图形用户界面、通过html+css+js技术进行网站搭建,使用postman等工具进行接口测试,与数据库连接〔jdbc〕等技术。较好的在规定时间内完成了老师安排给我们的任务,实验过程中尽管遇到了不少问题,但最后经过与同伴互相探讨,借阅资料,上网查阅等都使问题得到了解决。总的来说感觉数据库、flask、python语言等编程技术应用起来灵活,容易理解。历尽一个多月课程设计让我对python语言等编程技术产生了浓厚的兴趣,更重要的是增强了我学习的自信心。

我们做的题目是《学生成绩管理系统》按照老师的安排,我们先进行系统需求和系统功能设计,在确定了我们要做的学生成绩管理系统应具有哪些功能后利用visio汇出了管理系统的流程图,并且进一步利用visio的强大功能画出ER图继而生成了物理模型图以及数据库,完成了数据库设计阶段。〔包括需求分析和概要设计〕;在剩下来的几天里我们主要把精力集中在应用程序的调试及课程设计报告的书写上。通过网络、书籍等查找所需的资料。数据库局部的书写〔包括数据库、表、触发器、索引、存储过程等的创立〕以及完成ER图,物理模型图的设计转换局部。

心得与体会:

通过本次课程设计我深切的体会到学习与实践的重要性。第一、在实验的过程中我一边学习一边上机动手操作,才发现自己不懂的太多太多,以前的自己太渺小,我需要不断的在学习中成长。同时也深刻体会到自己需要在动手操作方面努力改良提高。第二、记得老师和学长们总是教导我们要学会请教别人,告诉我们请教别人能在走出社会以后更是显得尤为重要,之前我还有点不以为然,过分的相信自己。通过本次为期一个多月的课程设计我对老师和学长的话坚信不移,最后较好的完成了任务,也从中学到了不少东西。我笃信在以后的学习和成长过程中我会更加注重与他人协作,互助。

参考文献

[1]蒋睿.MySQL数据库安全研究[J].电脑知识与技术,2020,16(09):3-4+21.

[2]王珊.数据库技术与应用[M].北京:清华大学出版社,2005.

[3]贺卉珍.基于配置管理数据库的高可用架构风险发现[J].中国金融电脑

,2020(03):68-74.

[4]郑智方,李彬,刘世坤,李鹏.探究mysql的运用实例-对数据库的宏观把握[J].科技风,2020(06):129.

[5]梁相栋,郭小燕,许亮,郑鑫伟.班级文化信息管理系统的建设与开发[J].甘肃科技,2020,36(04):25-27+39.

[6]杨琳,昌明权.基于MySQL的高校党支部信息管理系统数据库设计[J].电脑知识与技术,2020,16(05):276-277+284.

[7] 洪锦魁 .Python GUI 设计:tkinter 菜鸟编程. 清华大学出版社,2019.

[8] 张晓博.基于 Python 的 SQL Server 海量数据转移的研究与实现[J].铁路计算机应用,2012.

[9]萨师煊 , 王珊 . 数据库系统概论 [M]. 北京 : 高等教育出版社 ,2002.

[10] 乔晶 . 高校学生成绩管理系统设计与实现 [J]. 电脑编程技巧与维护 ,2015(23:59-60.

[11]周文艳.谈学生成绩管理系统中的数据库设计[J].沧州师范专科学校学报, 2006, 6, 22 (2) :65-67

Guess you like

Origin blog.csdn.net/qq_62760217/article/details/127136472