3. Key tasks (100 marks)
This assignment is a simple emulation of data processing. Your application should be able to ask the user to input username, password to login into your system. The system should be able to identify the role of this user and allow corresponding operations.
This is an individual assignment and must be your own work.
The allowed libraries are random, math, os and re. You will not receive marks for the components if you use any other libraries apart from the mentioned library.
Please finish reading the description of all classes before starting the implementation.
3.1. User class
User class handles the fundamental methods of all users. The User class is the parent class of Admin, Instructor and Student classes.
3.1.1 constructor
A user must have id(int, default value -1), username(str, default value “”), password(str, default value “”).
3.1.2 generate_unique_user_id()
This method checks the files user_admin.txt, user_instructor.txt and user_student.txt to generate an unique user id. The return result is a 10 digits integer.
3.1.3 encryption(input_password)
This method encrypts the input_password to a string that is difficult to read by humans. Reuse the encryption algorithm that was in A1 to encode the input password. The encrypted password will be returned and the type is string.
3.1.4 login()
Each user can call the login method to perform authentication. In this login() method, it is required to call the encryption() method defined before to encode the password. The encoded password can be used to compare with the password extracted from files. You are required to to check the user_admin.txt, user_instructor.txt and user_student.txt file according to the username and password and return a tuple which contains the login_result(bool type), login_user_role(str type, the values can only be “Admin”, “Instructor”, “Student”), login_user_info(any type e.g. list or tuple
or str, this value can be used to create different types of user object (Admin, Student or Instructor)).
3.1.5 extract_info()
This method prints out a message “You have no permission to extract information”.
3.1.6 view_courses(args=[])
This method prints out a message “You have no permission to view courses”.
3.1.7 view_users()
This method prints out a message “You have no permission to view users”.
3.1.8 view_reviews(args=[])
This method prints out a message “You have no permission to view reviews”.
3.1.9 remove_data()
This method prints out a message “You have no permission to remove data”.
3.1.10 __str__()
This method returns a formatted user string: “user_id;;;username;;;password”. All the
attributes are concatenated using “;;;”.
3.2. Admin class
Admin class inherits from the User class.
3.2.1 constructor
Admin only have attributes id(int, default value -1), username(str, default value “”) and password(str, default value “”) which can be inherited from the parent class.
3.2.2 register_admin()
This method checks the user_admin.txt file to find out whether the username already exists or not. If not, register this admin. If it exists, do nothing.
3.2.3 extract_course_info()
This method can get course information from the raw_data.txt. The extracted course info should be saved into file following the format below: “course_id;;;course_title;;;image_100x100;;;headline;;;num_of_subscribers;;;avg_rating;;;course_content_length”.
For each line in the raw_data.txt file, you can copy and paste it to Json Parser Online to check the format. Each line contains more than one course. All the corresponding attributes can be found in the text. You can use the library re or str methods to extract the data. The course content length in the text is like “40.5 hours”. Only 40.5 need to be retrieved. The course data will be saved into the course.txt file.
3.2.4 extract_review_info()
This method can get review information from the review_data folder. The extracted review info saving format is “review_id;;;review_content;;;review_rating;;;course_id” The course id can be obtained from each file’s name in the review_data folder.
3.2.5 extract_students_info()
This method can get student information from the review_data folder. Each review string contains one user information. Assume each user only has one review. The attributes of each student are id, username, password, user_title, user_image_50x50, user_initials and review_id. If a student’s id cannot be found in the string, you need to generate it by calling the generate_unique_user_id() method defined in the User class. The username should be generated by converting the user_title to lowercase and replacing all the whitespace to underscore. The password is generated by
converting user_initials to lowercase and combining the user id. The password expression looks like “user_initials + user_id + user_initials”. User_initials can be obtained from the review data. For example, user_id is 12345, user initials is “DE”, the password is “de12345de”. The student info will be written into file=user_student.txt and the format example is “id;;;username;;;password;;;user_title;;;user_image_50x50;;;user_initials;;;review_id”.
3.2.6 extract_instructor_info()
This method extracts information from the raw_data.txt file in the course_data folder. Each course item contains several instructor information. The username is generated by converting the instructor_display_name to lowercase and replacing all the whitespace to underscore. The password uses the instructor id directly. The instructor info saving format example is:
“id;;;username;;;password;;;display_name;;;job_title;;;image_100x100;;;course_id1–course_id2–course_id3–course_id4”.