程序代写案例-FIT9136

欢迎使用51辅导,51作业君孵化低价透明的学长辅导平台,服务保持优质,平均费用压低50%以上! 51fudao.top




















FIT9136 Algorithm and

programming foundation
in Python
Python 中 fit9136算法及
编程基础



Assignment 3
作业 3


Lecturer in Charge: Shirin Ghaffarian Maghool
负责人: Shirin Ghaffarian Maghool
















May 2022
2022年 5月
Table of Contents
目录




1. Key Information
1. 主要资料 3
1.1. Do and Do NOT
1.1做与不做 4
1.2. Documentation
1.2文档 4
1.3. Submission
1.3递交申请 4

2. Getting help
2、寻求帮助 6
2.1.
2.1.
English language skills
英语语言技能 6
2.2.
2.2.
Study skills
学习技能 6
2.3.
2.3.
Things are tough right now
现在的情况很艰难 6
2.4.
2.4.
Things in the unit don’t make sense
单位里的事情没有任何意义 6
2.5. I don’t know what I need
2.5我不知道我需要什么 6

3. Key tasks
关键任务 7
3.1.
3.1.
Overview
概述 7
3.2.
3.2.
Website business logic description
网站业务逻辑描述 8
3.2 Task 1 - design classes
3.2 task1- 设计类 16

3.2.1
3.2.1
User class
用户类 16

3.2.2
3.2.2
Admin class
管理类 18

3.2.3
3.2.3
Instructor class
教练课程 19

3.2.4
3.2.4
Student class
学生班 21

3.2.5
3.2.5
Course class
课程类 21
3.3.
3.3.
Task
2
任务
2
- Index, user register, login and logout
ー索引、用户登记、登入及注销 25
3.4. Task - Students page 26
3.4. 3
任务
3
- 学生网页
3.5.
3.5.
Task
4
任务
4
- Courses page
ー课程网页 27
3.6.
3.6.
Task
5
任务
5
- Instructors page
- 教练网页 28
Important Notes:
重要提示: 29
1. Key Information
1. 主要资料

Purpose
目的
This assessment is related to the following learning objectives (LO):
这项评估与下列学习目标有关:


● LO4: Investigate useful Python packages for scientific computing
● LO4: 为科学计算调查有用的 Python 软件包



and data analysis
和数据分析


LO5: Experiment with basic data manipulation, analysis, and
LO5: 基本数据操作,分析和实验



visualisation technique to formulate business insight
形成商业洞察力的可视化技术


L07: Build a basic web application based on Python web
L07: 基于 Python web 构建一个基本的 web 应用程序


frameworks
框架



Your task
你的任务
It is an Individual assignment, where you will write a code for a simple
它是一个单独的赋值,在这里您将为一个简单的


emulation of a data analysis website.
模拟数据分析网站。



Value
价值
35% of your total marks for the unit
单位总分的 35%



Due Date
预产期
[Friday 10th Jun 2022, week 14] 4:30 pm
2022年 6月 10日,星期五,第 14周



Submission
提交
● Via Moodle Assignment Submission.
●通过 Moodle 提交作业。


● Turnitin will be used for similarity checking of all submissions.
* Turnitin 将用于对所有提交的材料进行相似性检查。



Assessment
评估
See Moodle Assessment page
参见 Moodle 评估页面

Criteria
标准



Late
迟到了 ●
10% deduction per calendar day or part thereof for up to one
每个日历日或其中一部分扣除 10% ,最多一天

Penalties
惩罚

week



Submissions more than 7 calendar days after the due date will
在截止日期后超过 7个日历日提交的作品将


receive a mark of zero (0) and no assessment feedback will be
评分为零(0) ,并且没有评估反馈


provided.
提供。



Support
支持
See Moodle Assessment page
参见 Moodle 评估页面

Resources

参考资料


Feedback
反馈
Feedback will be provided on student work via:
对学生作业的反馈将通过以下方式提供:


general cohort performance
一般队列表现


specific student feedback ten working days post submission
提交后 10个工作日的具体学生反馈



1.1. Do and Do NOT
1.1做与不做

Do

Do NOT
不要


Maintain academic integrity1
维护学术诚信
● Leave your assignment in draft mode
●让你的作业处于草稿模式

● Get support early from this unit and other
尽早得到本单位和其他单位的支持
● Submit late (10% daily penalty applies)3
●逾期递交(每日罚款 10%)3


● Submission is not accepted after 7 days of
●七天后不接受递交申请


services in the university
在大学提供的服务

Apply for special consideration for
申请特殊照顾
the due date, unless you have special
预产期,除非你有特殊的


extensions2
延期 2
consideration.
考虑。




1.2. Documentation
1.2文档

Commenting your code is essential as part of the assessment criteria (refer to
Marking Rubrics).
作为评估标准的一部分,注释代码是必不可少的(请参阅标记 Rubrics)。

You should also include comments at the beginning of your program file, which
specify your name, your Student ID, the start date and the last modified date of the
program, as well as with a high-level description of the program. In-line comments
within the program are also part of the required documentation.
您还应该在程序文件的开头包括注释,其中指定您的姓名、学生 ID、开始日期
和程序的最后修改日期,以及程序的高级描述。程序中的行内注释也是所需文
档的一部分。



1.3. Submission
1.3递交申请

Your have to submit your assignment via the assignment submission link (i.e.,
“Assignment 2 Submission”) on the Moodle site by the deadline specified in Section 1,
i.e. 10th Jun 2022 (Friday) by 4:30 pm:
你必须在第 1 节指定的截止日期,即 2022 年 6 月 10 日(星期五)下午 4 时 30 分
前,透过 Moodle 网站上的作业提交链接(即「作业 2提交」)递交作业:

● There will be NO hard copy submission required for this assignment.
这项作业不需要提交硬拷贝。

● You are required to submit your assignment as a .zip file named with your
Student ID. For example, if your Student ID is 12345678, you would submit a
zipped file named 12345678.zip
你被要求提交你的作业作为。以你的学生证命名的 zip 文件。例如,如果你
的学生 ID 是 12345678,你会提交一个名为 12345678的压缩文件。Zip

● Do not include any unnecessary file in this folder
不要在此文件夹中包含任何不必要的文件

● Note that marks will be deducted if this requirement is not strictly complied
with.
注意,如果不严格遵守这个要求,标记将被扣除。

● No submission accepted via email.
不接受以电邮方式递交的意见书。





1

https://www.monash.edu/rlo/research-writing-assignments/referencing-and-academic-
integrit y/academic-integrity
Https://www.monash.edu/rlo/research-writing-assignments/reference-and-academic-integrity
y/academic-integrity
2 https://www.monash.edu/exams/changes/special-consideration (All the Special Consideration
should be applied no later than two University working days after the due date of the affected assessment).
Https://www.monash.edu/exams/changes/Special-Consideration (所有特殊考虑应在受影响评估
到期日后不迟于两个大学工作日内适用)。
3 eg: original mark was 70/100, submitting 2 days late results in 50/100 (10 marks off). This
includes weekends
例如: 原始分数为 70/100,提交 2天后的结果为 50/100(10分)。这包括周末
1.4. Deliverables
1.4交付成果

Your submission should contain the following documents:
你提交的文件应包括以下文件:

● All files in the “model” folder include course.py, user.py, user_admin.py,
user_instructor.py and user_student.py.
“ model”文件夹中的所有文件包括 course.py、 user.py、 user _ admin.py、
user _ instructor.py 和 user _ student.py。

● All files in the “controller” folder include course_controller.py,
index_controller.py, instructor_controller.py and user_controller.py.
控制器文件夹中的所有文件包括 course _ controller.py,index _ controller.py,
instructor _ controller.py 和 user _ controller.py。

● Several files in the “templates” folder include 00login.html, 00register.html,
10student_list.html and 11student_info.html.
“ templates”文件夹中的几个文件包括 00login.html、00register.html、
10student _ list.html 和 11student _ info.html。

● All files need to be compressed into a zip file. The final submission file name is
{your_student_id}.zip.
所有的文件都需要压缩成一个 zip 文件,最终的提交文件名是{ your _ student
_ id } . zip。

● Marks will be deducted for any of these requirements that are not strictly
complied with.
任何未能严格遵守上述规定的商标将会被扣除。
2. Getting help
2、寻求帮助


2.1. English language skills
2.1英语语言能力

if you don’t feel confident with your English.
如果你对自己的英语不自信。

● Talk to English Connect: https://www.monash.edu/english-connect
Talk to English Connect: https://www.monash.edu/English-Connect



2.2. Study skills
2.2学习技能

If you feel like you just don’t have enough time to do everything you need to, maybe
you just need a new approach
如果你觉得你没有足够的时间去做所有你需要做的事情,也许你只是需要一个
新的方法

● Talk to a learning skills advisor:
https://www.monash.edu/library/skills/contacts
向学习技能顾问咨询:
https://www.monash.edu/library/skills/contacts



2.3. Things are tough right now
2.3. 现在情况很艰难

Everyone needs to talk to someone at some point in their life, no judgement here.
每个人都需要在他们生命中的某个时刻和某个人交谈,这里没有评判。

● Talk to a counsellor:
https://www.monash.edu/health/counselling/appointments
(friendly, approachable, confidential, free)
咨询顾问:
https://www.monash.edu/health/counselling/appointments
(友好、平易近人、保密、免费)



2.4. Things in the unit don’t make sense
2.4单位里的事情没有意义

Even if you’re not quite sure what to ask about, if you’re not sure you won’t be alone,
it’s always better to ask.
即使你不确定该问些什么,如果你不确定你不会孤单,最好还是问问。

● Ask in Ed: https://edstem.org/au/courses/7429/discussion/
在教育部提问: https://edstem.org/au/courses/7429/discussion/

● Attend a consultation:
https://lms.monash.edu/course/view.php?id=135703§ion=21
参加咨询: https://lms.monash.edu/course/view.php? id = 135703 &
section = 21


2.5. I don’t know what I need
2.5我不知道我需要什么

Everyone at Monash University is here to help you. If things are tough now they
won’t magically get better by themselves. Even if you don’t exactly know, come and
talk with us and we’ll figure it out. We can either help you ourselves or at least point
you in the right direction.
蒙纳士大学的每个人都会来帮助你。如果事情现在很艰难,他们不会自己奇迹
般地好起来。即使你不是很清楚,过来和我们谈谈,我们会解决的。我们可以
自己帮你,或者至少给你指明正确的方向。
3. Key tasks
关键任务

This assignment is a data analysis website. You are required to analyse the given data
in folder data/source_course_files. This project is based on Python Flask Framework
and you need to complete the files inside the controller folder named
这个作业是一个数据分析网站。你需要分析文件夹数据/源 _ 课程 _ 文件中给定
的数据。这个项目基于 Python Flask Framework,你需要完成控制器文件夹中的
文件

course_controller.py, index_controller.py, instructor_controller.py and
Course _ controller.py,index _ controller.py,instructor _ controller.py 和

user_controller.py,
user_instructor.py
templates folder
User _
controller.py ,
user _
instructor.py 模板
文件夹

model folder named course.py, user.py, user_admin.py, and
user_student.py and several html pages (views) in the called
00login.html, 00register.html, 10student_list.html and
名为 course.py、 user.py、 user _ admin.py 和 user _
student.py 的模型文件夹以及名为 00login. html、00register.
html、10student _ list. html 和 user _ student.py 的几个 html
页面(视图)

11student_info.html.
11student _ info.html.

This is an individual assignment and must be your own work.
这是个人作业,必须是你自己的作品。

You can use any libraries except the time-related libraries or functions in this
assignment.
除了与时间相关的库或此任务中的函数外,您可以使用任何库。

In the provided project-> lib folder, there are a few methods and variables in the
helper.py file that can be imported and used in your tasks. For example, if you need
to access the course.txt data file, you can add “from lib.helper import
course_data_path” in your file. All the path variables in the helper.py should not be
changed. Any unexpected changes may cause the website to not run,which will lead
to mark penalties.
在提供的 project-> lib 文件夹中,helper.py 文件中有一些方法和变量可以导入并
用于任务中。例如,如果你需要访问 course.txt 数据文件,你可以在你的文件中
添加“ from lib.helper import course _ data _ path”。Py 中的所有路径变量都不应
该被改变。任何意外的更改都可能导致网站无法运行,这将导致标记处罚。

3.1. Overview
3.1概览

1. Data explanation In the data folder, the source_course_file folder contains all
the data files we need to use in this assignment. The course.txt and user.txt
files are used to save all the course and user data. The example of course and
user data can be found in _demo_course.txt and _demo_user.txt files.
(course.txt and user.txt files are provided but empty)
数据说明在数据文件夹中,source _ course _ file 文件夹包含了我们在这个作
业中需要使用的所有数据文件。Course.txt 和 user.txt 文件用于保存所有
的课程和用户数据。课程和用户数据的例子可以在 _ demo _ course.txt 和
_ demo _ user.txt 文件中找到。(course.txt 和 user.txt 文件是空的)

2. Folder structure
文件夹结构





















The image above shows a folder structure of this assignment. Running the
main.py file can start this web application. The template file has some
incomplete code which will generate errors. It is better to finish some tasks
before starting to run the web application.
上面的图片显示了这个任务的文件夹结构。运行 main.py 文件可以启动这
个 web 应用程序。模板文件中有一些不完整的代码会产生错误。最好在
开始运行 web 应用程序之前完成一些任务。

3. Start the assignment
开始布置作业

Step1. Create a new project in Pycharm and copy all the files into this project.
Step2. Open requirements.txt file and you can see the image below.
Step1第一步。在 Pycharm 中创建一个新项目,并将所有文件复制到该
项目中。第二步。打开 requirements.txt 文件,您可以看到下面的图片。











Step3. Click install requirements.
Step3。单击安装要求。

After the instalment of all libraries, you can start to work on this assignment.
在完成所有库的安装之后,你就可以开始完成这项任务了。

( Feel free to use the `pip install -r requirements.txt` if you can understand
this command)
如果您能理解这个命令,请随意使用‘ pip install-r requirements.txt’)

3.2. Website business logic description
3.2网站业务逻辑描述

1. Index page - Index page is the homepage of your web application. To launch
the application you must run the main.py file, and use the
link:http://localhost:5000/ in the browser.
索引页面-索引页面是您的 web 应用程序的主页。要启动应用程序,你必须
运行 main.py 文件,并在浏览器中使用链接: http://localhost: 5000/。
















Figure 3.1 Index page no login
图 3.1 Index 页面没有登录

2. Login page - Login page allows the user to login into the web application
which requires them to input username and password. There are three
different kinds of users, i.e., Admin, Instructor, and student. Each kind of user
will see different contents from the home (index) pages after login.
登录页面-登录页面允许用户登录到 web 应用程序,要求他们输入用户名和
密码。有三种不同类型的用户,即 Admin,Instructor 和 student。每种类
型的用户在登录后都会看到来自主页(索引)的不同内容。





























Figure 3.2 Login page
图 3.2登录页面


For example, when a student logs in, the index (home) page looks like the
figure 3.3. Students can only check their own information and logout.
例如,当学生登录时,索引(主页)页面如图 3.3所示。学生只能检查自己
的信息并注销。















Figure 3.3 Student login page
图 3.3 Student 登录页面


For example, when the instructor logs in, the index (home) page looks like the
figure 3.4. Instructors can only see the courses they teach and logout.
例如,当指导员登录时,索引(主页)页面如图 3.4 所示。教师只能看到他
们教授的课程并注销。



















Figure 3.4 Instructor login page
图 3.4 Instructor 登录页面

For example, when admin logs in, the index (home) page looks like the figure
3.5. There is a reset database button which can remove all the content in the
course.txt and user.txt files.
例如,当管理员登录时,索引(主页)页面如图 3.5 所示。有一个重置数据
库按钮可以删除 course.txt 和 user.txt 文件中的所有内容。
























Figure 3.5 Admin login page
图 3.5 Admin 登录页面

4. Register page - Register page allows users to register them into the web
application, in the case they do not have an account. It is required to enter
username, password, email address and role when registering a user. And a
register timestamp(unix epoch time) will be generated automatically. All these
five values will be sent to the application’s backend to store the values in the
user.txt file.
Register page-Register 页面允许用户在没有帐户的情况下将其注册到 web 应
用程序中。注册用户时需要输入用户名、密码、电子邮件地址和角色。
注册时间戳(unix 纪元时间)将自动生成。所有这五个值都会被发送到应用
程序的后端,以便在 user.txt 文件中存储这些值。



































Figure 3.6 Register page
图 3.6 Register 页面


5. Courses page - After a user logs in as admin, they can see the similar page as
in figure3.7. In this page, the total number of courses and 20 course objects
will be displayed. All the course objects can be returned based on the page
number. By default, the page number is 1. Each page has a maximum of 20
courses. At the bottom of the webpage, a page number list is shown. By
default, the page number list is always be [1,2,3,4,5,6,7,8,9].
Courses 页面——当用户以管理员身份登录后,他们可以看到类似的页面,如
图 3.7 所示。在这个页面中,将显示课程总数和 20 个课程对象。所有的
课程对象都可以根据页码返回。默认情况下,页码是 1。每个页面最多有
20 个课程。在网页的底部,显示了一个页码列表。默认情况下,页码列
表总是[1,2,3,4,5,6,7,8,9]。


Two buttons are placed below the total number of courses, which are the
Process Course Data button and the Course Analysis Figure button. The
Process Course Data button will retrieve all the data from given course data
files(this process may take some time). The Course Analysis Figure button will
generate 6 figures and the explanations of each figure. All the figures are
saved into lib.helper.figure_save_path and all the explanations(i.e., the trend
of the figure) about each figure will be displayed in a new webpage.
在课程总数下面有两个按钮,分别是 Process Course Data 按钮和 Course
Analysis Figure 按钮。Process Course Data 按钮将从给定的课程数据文件中
检索所有数据(这个过程可能需要一些时间)。Course Analysis Figure 按钮将
生成 6 个数字和每个数字的解释。所有数据都保存在 lib.helper.figure _
save _ path 中,关于每个数据的所有解释(即数据的趋势)将显示在一个新
的网页中。
For each item of course, there will be a Details button and a Delete button.
Details button will take you to the course details page. The Delete button will
remove selected data from the course.txt file and user.txt file.
当然,对于每个项目,都会有一个详细信息按钮和一个删除按钮。Details
按钮会带你进入课程详细信息页面。Delete 按钮将从 course.txt 文件和
user.txt 文件中删除选定的数据。



































Figure 3.7 Course list page
图 3.7课程列表页



























Figure 3.8 Course details page
图 3.8课程详情页面
If you login as an instructor, the courses page will show the courses this
instructor teaches.
如果你以教师身份登录,课程页面会显示这位教师教授的课程。


























Figure 3.9 Courses page when login as instructor
图 3.9作为讲师登录时的课程页面

If you login as a student, there is no courses page available.
如果你以学生身份登录,没有可用的课程页面。


6. Instructors page - In this page, the total number of instructors will be
displayed. Because each instructor can teach more than one course, the total
number of instructors is less than the total number of courses. All the
instructor objects can be returned based on the page number. By default, the
page number is 1. Each page has a maximum of 20 instructors. At the bottom
of the webpage, a page number list is shown. For each instructor, we can see
all the courses this instructor teaches by clicking the Teach Courses button.
导师页面-在这个页面中,将显示导师的总数。因为每个讲师可以教授一门以
上的课程,所以讲师的总数少于课程的总数。所有的指导者对象都可以
根据页码返回。默认情况下,页码是 1。每个页面最多有 20 个讲师。在
网页的底部,会显示一个页码列表。对于每个讲师,我们可以通过点击
Teach Courses 按钮来查看讲师讲授的所有课程。


There are two buttons below the total number, that are Process Instructor
Data button and Instructor Analysis Figure button. The Process Instructor will
extract all the instructor information from the given data files and store
instructors info into the user.txt file. This method may take a while to finish.
The Instructor Analysis Figure button has similar functionality as the course
analysis button.
下面有两个按钮,分别是 Process Instructor Data 按钮和 Instructor Analysis
Figure 按钮。Process Instructor 将从给定的数据文件中提取所有的指导者
信息,并将指导者信息存储到 user.txt 文件中。这个方法可能需要一段时
间才能完成。Instructor Analysis Figure 按钮和 course Analysis 按钮功能相
似。
































Figure 3.10 Instructors page
图 3.10教师页面

7. Students page. In this page, the total number of students and a list of students
will be displayed. Students’ info are not extracted from the files but registered
manually in the register page.
学生页面。在此页面中,将显示学生总数和学生列表。学生的信息不是从文
件中提取出来的,而是在注册页面手动注册的。




















Figure 3.11 students page
图 3.11学生页面

Admin can click the details button to see students’ details and click the delete
button to remove this student (the student info will be deleted from the
user.txt file).
Admin 可以单击 details 按钮查看学生的详细信息,并单击 delete 按钮删
除该学生(学生信息将从 user.txt 文件中删除)。
If you login as a student, you can only see the MyInfo page.
如果您以学生身份登录,您只能看到 MyInfo 页面。

















Figure 3.12 Myinfo page when login as a student
图 3.12学生登录时的 Myinfo 页面





3.2 Task 1 - design classes
3.2 task1- 设计类

You are required to implement the User class, Admin class, Instructor class, Student
class, and Course class in the user.py, user_admin.py, user_instructor.py,
user_student.py and course.py files respectively. The Admin, Instructor and Student
class should inherit from the User class. The methods of each class are described
below. The path in the helper.py file is valid for the Flask application. If you hope to
perform a local test, you need to change the path. But, remember to change it back
when you submit your files as your tutor will mark your work based on the
submission files. The helper.py file is not submitted.
您需要在 User.py、 User _ Admin.py、 User _ Instructor.py、 User _ Student.py 和
Course.py 文件中分别实现 User 类、 Admin 类、 Instructor 类、 Student 类和
Course 类。Admin、 Instructor 和 Student 类应该继承自 User 类。每个类的方法
如下所述。Py 文件中的路径对于 Flask 应用是有效的。如果你希望执行一个本地
测试,你需要改变路径。但是,当你提交你的文件时,记得要改回来,因为你
的导师会根据提交的文件标记你的作业。没有提交 helper.py 文件。

3.2.1 User class
3.2.1用户类

1. constructor.
构造函数。

Five positional arguments: uid(int, default value is -1), username(str, default
value is “”), password(str, default value is “”), register_time(str, default value
is “yyyy-MM-dd_HH:mm:ss.SSS”), role(str, default value is “”). The role can
only be value “admin”, “instructor” and “student”.
五个位置参数: uid (int,缺省值为 -1) ,username (str,缺省值为“”) ,
password (str,缺省值为“”) ,register _ time (str,缺省值为“ yyyy-MM-dd
_ hh: mm: ss.SSS”) ,role (str,缺省值为“”)。角色只能是值“ admin”,
“ instructor”和“ student”。

2. __str__()->str.
_ _ str _ _ ()-> str.

Return string format example:
“uid;;;username;;;password;;;register_time;;;role”
返回字符串格式示例: “ uid; ; username; ;
password; ; register _ time; ; ; role”

3. authenticate_user()->(bool, str).
Authenticate _ user ()-> (bool,str).
Two positional arguments - username and password. This method is used to
check whether username and password can be matched with users saved in
user.txt data file. If matched, this method will retrieve the user information
from user.txt file and return a tuple (True, user_info_string), otherwise return
(False, “”).
两个位置参数-用户名和密码。这个方法用来检查用户名和密码是否与保
存在 user.txt 数据文件中的用户匹配。如果匹配,该方法将从 user.txt 文
件检索用户信息,并返回一个 tuple (True,user _ info _ string) ,否则返回
(False,“”)。

4. check_username_exist()->bool.
选择 _username _ exist ()-> bool。

One positional argument - username. This method is to check whether the
given username exists in the user.txt data file. If it exists, return True,
otherwise return False.
一个位置参数-用户名。这个方法是检查给定的用户名是否存在于 user.txt
数据文件中。如果存在,返回 True,否则返回 False。

5. generate_unique_user_id()->str.
生成 _ unique _ user _ id ()-> str。

This method is used to generate and return a 6 digit unique user id which is
not in the user.txt file.
此方法用于生成并返回一个不在 user.txt 文件中的 6位唯一用户 id。


6. encrypt_password()->str.
Encrypt _ password ()-> str.

One positional argument - password. For a given password, you are required
to encrypt the string. You can reuse the encryption method in A1/A2 here.
一个位置参数-密码。对于给定的密码,需要对字符串进行加密。你可以
在这里重用 A1/a2中的加密方法。

7. register_user()->bool.
Register _ user ()-> bool.

Five positional arguments - username, password, email, register_time, role.
The validation can happen in this function or before calling this function.
五个位置参数-用户名,密码,电子邮件,寄存器 _ 时间,角色。验证可
以在这个函数中或者在调用这个函数之前进行。


o If the username exists in the user.txt file, return False.
如果 user.txt 文件中存在用户名,返回 False。

o A unique user id is required when registering a new user.
注册新用户时需要一个唯一的用户 id。

o If the user registers successfully, return True.
如果用户注册成功,返回 True。

o Register_time will be a unix epoch timestamp (milli seconds) which
needs to be converted using date_conversion() method.
Register _ time 将是一个 unix 历史时间戳(毫秒) ,需要使用 date _
conversion ()方法进行转换。

o The new user needs to be written into the user.txt file. All the
attributes are separated by three semicolons - “;;;”. The registration of
different roles could generate different strings.
新用户需要写入 user.txt 文件。所有的属性都由三个分号分隔-“ ;。不
同角色的注册可以生成不同的字符串。

The format example 1:
格式示例 1:




The format example 2:
格式示例 2:

(username: test_instructor, password: test_instructor)
(用户名: test _ instructor,密码: test _ instructor)

The 9 semi-colons here indicate there are no values for
display_name(str, default value is “”), job_title(str, default value is “”)
and course_id_list(list, default value is []).
这里的 9个分号表示 display _ name (str,默认值为“”)、 job _ title
(str,默认值为“”)和 course _ id _ list (list,默认值为[])没有值。








8. date_conversion()-> str.
日期 _ 转换()-> str。

One positional argument - register_time. The given register_time will be a
unix epoch timestamp (milli seconds) and it needs to be converted to format
“year-month-day_hour:minute:second.milliseconds”. For example, a
一个位置参数-register _ time。给定的 register _ time 将是 unix 历史时间戳
( 毫 秒 ) , 需 要 将 其 转 换 为 “ year-month-day _ hour: minute:
second.milliseconds”格式。例如,a

timestamp 1637549590753 will be converted to str “2021-11-
22_13:53:10.753” and returned. The time should be GMT+11 Melbourne
timezone.
时间戳 1637549590753将被转换为 str“2021-11-22 _ 13:53:10.753”并返回。
时间应该是 GMT + 11墨尔本时区。


Refer this link https://www.unixtimestamp.com/index.php to check how to
convert unix epoch time to human readable format. A method called
get_day_from_timestamp(timestamp) is provided in the lib.helper file. By
using this method, you can convert the timestamp to the day of month. You
can import and use this method in the user.py file. It is not allowed to use any
time-related libraries or functions here. You are required to implement the
conversion by yourself. Because we use some approximate values like 1 month
(30.44 days) = 2629743 seconds, the boundary cases can be ignored like 1st
Mar. Only make sure most of the results are correct. If you hope to try to
generate a very accurate result, it is great (no extra mark allocated). The final
readable time would be GMT +11.
参考这个链接 https://www.unixtimestamp.com/index.php 来检查如何将
unix 纪元时间转换为人类可读的格式。Lib.helper 文件中提供了一个名为
get _ day _ from _ timestamp (timestamp)的方法。通过使用这个方法,你
可以将时间戳转换成月份。你可以在 user.py 文件中导入并使用这个方法。
这里不允许使用任何与时间相关的库或函数。你需要自己完成转换。因
为我们使用了一些近似值,比如 1个月(30.44天) = 2629743秒,所以边界
情况可以像 3 月 1 日那样被忽略。只要确保大部分结果是正确的。如果
你希望得到一个非常准确的结果,那就太好了(没有额外的分数)。最终的
可读时间是 GMT + 11。

9. validate_username()-> bool.
验证 _ username ()-> bool。

One positional argument - username. The username can only be letters or
underscore. If not, return False.
一个位置参数-用户名。用户名只能是字母或下划线。如果不是,返回
False。

10. validate_password()-> bool.
验证 _ password ()-> bool。

One positional argument - password. The length of password must be greater
than or equal to 8. If not, return False.
一个位置参数-password。密码长度必须大于或等于 8。如果不是,返回
False。

11. validate_email()-> bool.
验证 _ email ()-> bool。

One positional argument - email. Use regex expressions to check whether the
email address is valid or not. The email should end with “.com”, contain “@”,
and have length greater than 8. If not, return False.
一个位置论点-电子邮件。使用正则表达式来检查邮件地址是否有效。电
子邮件应该以“。Com”,包含“@”,长度大于 8。如果不是,返回 False。

12. clear_user_data() no return.
清除 _ user _ data ()不返回。

This method will remove all the data in the user.txt file.
这个方法将删除 user.txt 文件中的所有数据。
13. Class variable current_login_user.
Class 变量 current _ login _ user。

Default value is None. This variable is used to save the user object(Could be
Admin, Instructor or Student object) after login. If the user is not logged in,
the web application will redirect the web page to the index page.
默认值为 None。这个变量用于在登录后保存用户对象(可以是 Admin、
Instructor 或 Student 对象)。如果用户没有登录,web 应用程序会将网页
重定向到索引页面。

3.2.2 Admin class
3.2.2管理类

1. constructor.
构造函数。

This method has five positional arguments: uid(int, default value is -1),
username(str, default value is “”), password(str, default value is “”),
register_time(str, default value is “yyyy-MM-dd_HH:mm:ss.SSS”) and role(str,
default value is “admin”). Admin account does not have an email address
attribute.
此方法有五个位置参数: uid (int,默认值为 -1)、 username (str,默认值为
“”)、 password (str,默认值为“”)、 register _ time (str,默认值为“ yyyy-
MM-dd _ hh: mm: ss.SSS”)和 role (str,默认值为“ admin”)。Admin 帐户没
有 email 地址属性。

2. __str__()->str.
_ _ str _ _ ()-> str.
Return string format example:
返回字符串格式示例:




3. register_admin() no return.
Register _ admin ()不返回。

This method will create a new admin account and write this account into the
user.txt file. This method does not need to call the register method
implemented in the User class. And, no validation required for the admin
account. The default username and password can be any value predefined by
yourself. For example, username=”admin”, password=”admin”. Admin
account cannot be registered via frontend webpages.
此方法将创建一个新的管理员帐户,并将该帐户写入 user.txt 文件。这个
方法不需要调用在 User 类中实现的 register 方法。并且,管理员帐户不需
要验证。默认的用户名和密码可以是任何你自己预定义的值。例如,
username = “ admin”,password = “ admin”。Admin 帐户不能通过前端网
页注册。




3.2.3 Instructor class
3.2.3教练课程

1. constructor.
构造函数。

This method has 9 positional arguments: uid(int, default value is -1),
username(str, default value is “”), password(str, default value is “”),
register_time(str, default value is “yyyy-MM-dd_HH:mm:ss.SSS”), role(str,
default value is “instructor”), email(str, default value is “”), display_name(str,
default value is “”), job_title(str, default value is “”) and course_id_list(list,
default value is []).
此方法有 9个位置参数: uid (int,默认值为 -1)、 username (str,默认值为
“”)、 password (str,默认值为“”)、 register _ time (str,默认值为“ yyyy-
MM-dd _ hh: mm: ss.SSS”)、 role (str,默认值为“ instructor”)、 email (str,
默认值为“”)、 display _ name (str,默认值为“”)、 job _ title (str,默认值为
“”)和 course _ id _ list (list,默认值为[])。

2. __str__()->str.
_ _ str _ _ ()-> str.
Return string format example:
返回字符串格式示例:
Example 1 (registered manually, so display_name=””, job_title=””,
course_id_list=[]):
示例 1(手动注册,因此显示 _name =””,job _ title =””,course _ id _ list =
[]) :






Example 2 (extracted from files):
示例 2(从文件中提取) :











3. get_instructors() no return.
得到指导员,没有回报。

This method will extract instructor information from the given course data
files. Similar to the process of retrieving course data, but this method focuses
on the instructor data of each course. In each course item, there could be
multiple instructors. There is no need to perform registration validation for
each instructor’s info in this method. All the null value in json str should be
saved as None or string “null”. All the empty string value “” should be saved as
same empty string “”.
这个方法将从给定的课程数据文件中提取讲师信息。类似于检索课程数
据的过程,但是这种方法关注的是每门课程的讲师数据。在每个课程项
目中,可能有多个讲师。在这个方法中,不需要对每个讲师的信息进行
注册验证。Json str 中的所有 null 值都应该保存为 None 或字符串“ null”。
所有的空字符串值“”都应该保存为相同的空字符串“”。


After retrieving the required data, you need to write the info into user.txt file
to save all the instructor data. Each attribute needs to be separated by “;;;”.
The required attributes and data format is:
在检索所需的数据之后,需要将信息写入 user.txt 文件以保存所有指导者
数据。每个属性需要用“ ;。所需的属性和数据格式是:

“{instructor_id};;;{username};;;{password};;;{register_time};;;{role};;;{email};;;{
“{ instructor _ id } ; ; { username } ; ; { password } ; ; { register _ time } ; ; ;
{ role } ; ; { email } ; ;

instructor_display_name};;;{instructor_job_title};;;{course_id_list}”. The
username is generated by converting the display name to lowercase and
replacing the whitespace to underscore. The password uses the instructor_id
value directly. The email address is generated by combining the username and
the “@gmail.com”. All the course ids in the course_id_list will be connected to
using two “-” marks. The format is “course_id--course_id--course_id”. If an
instructor is already in the user.txt file, only update the course_id_list which
saves the course this instructor teaches. The register_time uses the default
value.
{ instructor _ display _ name } ; { instructor _ job _ title } ; ; { course _ id _
list }”。用户名是通过将显示名称转换为小写并将空格替换为下划线来生
成的。密码直接使用 instructor _ id 值。邮箱地址是由用户名和“@gmail.
com”组合而成的。在课程 _ id _ 列表中的所有课程 id 都将使用两个“-”标
记连接。格式是“ course _ id —— course _ id —— course _ id”。如果一个讲
师已经在 user.txt 文件中,只需更新 course _ id _ list 就可以保存这个讲师
讲授的课程。Register _ time 使用默认值。


The auto-generated instructor accounts are different from the manually
registered instructor account. Manually registered instructor accounts do not
have any course_id_list. And, the display name and job title are empty.
自动生成的指导者帐户不同于手动注册的指导者帐户。手动注册的教师
帐户没有任何课程 id 列表。而且,显示名称和作业名称都是空的。
However, these accounts should have the same format in user.txt as the
但是,这些帐户在 user.txt 中的格式应该与

auto-generated accounts.
自动生成的帐户。

For example:
例如:










4. get_instructors_by_page()->tuple
通过页面()-> 元组获取指导者

One positional argument: page. This method reads the user.txt file to retrieve
all the instructor information. With all the instructor information and the
current page number, a list of Instructor objects and the total pages will be
generated. Each page has at most 20 instructors. A tuple contains the list of
instructors, total page number and the total number of instructors will be
returned.
一个位置参数: page。这个方法读取 user.txt 文件来检索所有的指导者信
息。有了所有的指导者信息和当前的页码,将生成一个指导者对象列表
和总页面。每个页面最多有 20 个指导者。一个元组包含了指导者的列表,
总页码和指导者的总数将被返回。

5. generate_instructor_figure1()->str
生成 _ instructor _ figure1()-> str

Generate a graph that shows the top 10 instructors who teach the most
courses.(any chart)
生成一个图表,显示教授最多课程的前 10名教师。(任何图表)


In all the graphs, if the instructor display name is too long, you need to extract
the first 3 words. The generate_instructor_figure1() method is required to
return a string explanation about your understanding of this figure. All the
graphs use the instructor title, course title, category title or subcategory title
as x-axis labels.
在所有的图表中,如果教师显示的名字太长,你需要提取前三个字。需
要使用 generate _ instructor _ figure1()方法来返回一个关于你对这个图的
理解的字符串解释。所有的图形都使用教师标题、课程标题、类别标题
或子类别标题作为 x 轴标签。



3.2.4 Student class
3.2.4学生班

1. constructor.
构造函数。

Six positional arguments: uid(int, default value is -1), username(str, default
value is “”), password(str, default value is “”), register_time(str, default value
is “yyyy-MM-dd_HH:mm:ss.SSS”), role(str, default value is “student”),
email(str, default value is “”)
六个位置参数: uid (int,默认值为 -1) ,username (str,默认值为“”) ,
password (str,默认值为“”) ,register _ time (str,默认值为“ yyyy-MM-dd
_ hh: mm: ss.SSS”) ,role (str,默认值为“ student”) ,email (str,默认值为
“”)

2. __str__()->str.
_ _ str _ _ ()-> str.
Return string format example:
返回字符串格式示例:





3. get_students_by_page()->tuple.
Get _ students _ by _ page ()-> tuple.

One positional argument: page. This method reads the user.txt file to retrieve
all the student information. With all the student information and the current
page number, a list of Student objects and the total pages will be generated.
Each page has at most 20 students. A tuple contains the list of students, total
page number and the total number of students will be returned.
一个位置参数: page。这个方法读取 user.txt 文件来检索所有的学生信息。
有了所有的学生信息和当前的页码,就会生成一个 Student 对象列表和所
有的页面。每个页面最多有 20 个学生。一个元组包含学生列表,总页数
和返回的学生总数。

4. get_student_by_id()->Student object
Get _ Student _ by _ id ()-> Student 对象

One positional argument id. This method returns a student object by
retrieving the id from the user.txt file.
这个方法通过从 user.txt 文件中检索 id 来返回一个学生对象。


5. delete_student_by_id()->bool
删除 _ student _ by _ id ()-> bool

One positional argument id. This method deletes a student item from the
user.txt file based on the given id.
这个方法根据给定的 id 从 user.txt 文件中删除一个学生项。

3.2.5 Course class
3.2.5课程类

1. constructor.
构造函数。

Eleven positional arguments: category_title(str, default value is “”),
subcategory_id(int, default value is -1), subcategory_title(str, default value is
“”), subcategory_description(str, default value is “”), subcategory_url(str,
default value is “”), course_id(int, default value is -1), course_title(str, default
value is “”), course_url(str, default value is “”), num_of_subscribers(int,
default value is 0), avg_rating(float, default value is 0.0) and
num_of_reviews(int, default value is 0).
十一个位置参数: category _ title (str,缺省值为“”) ,subcategory _ id (int,
缺省值为 -1) ,subcategory _ title (str,缺省值为“”) ,subcategory _
description (str,缺省值为“”) ,subcategory _ url (str,缺省值为“”) ,course
_ id (int,缺省值为 -1) ,course _ title (str,缺省值为“”) ,course _ url (str,
缺省值为“”) ,num _ of _ subscribers (int,缺省值为 0) ,avg _ rating (float,
缺省值为 0.0)和 num _ of _ reviews (int,缺省值为 0)。


2. __str__()->str.
Return format:
返回格式:

{category_title};;;{subcategory_id};;;{subcategory_title};;;{subcategory_descrip
tion};;;{subcategory_url};;;{course_id};;;{course_title};;;{course_url};;;{num_of
_subscribers};;;{avg_rating};;;{num_of_reviews}
{ category _ title } ; { subcategory _ id } ; { subcategory _ title } ; { subcategory _
description } ; { subcategory _ url } ; { course _ id } ; { course _ title } ; ; { course _
url } ; ; { num_of_subscribers } ; { avg _ rating } ; { num_of_reviews }

Return string format example:
返回字符串格式示例:










3. get_courses() no return.
Get _ courses () no return.

This method will extract course information from the given course data files.
In the source_course_files folder, there are 4 categories of courses. In each
category folder, there are some subcategories. Inside each subcategory folder,
you can find the course json files. You need to retrieve the category_title from
the 4 category folder names and other course info from the json files. In each
json file, there is another category name which is also acceptable for
category_title value like the image below.
该方法将从给定的课程数据文件中提取课程信息。在 source _ course _
files 文件夹中,有 4个类别的课程。在每个分类文件夹中,都有一些子分
类。在每个子类别文件夹中,你可以找到课程 json 文件。你需要从 4 个
目录文件夹中检索目录 _ title,从 json 文件中检索其他课程信息。在每个
json 文件中,都有另外一个类别名称,对于类别 _ title 值也是可以接受的,
如下图所示。



















All the null value in json str should be saved as None or string “null”. All the
empty string value “” should be saved as same empty string “”.
Json str 中的所有空值都应该保存为 None 或字符串“ null”。所有的空字符
串值“”都应该保存为相同的空字符串“”。


After retrieving the required data, you need to write the info into course.txt
file to save all the course data. All the data need to be separated by “;;;”. The
在检索所需的数据之后,您需要将该信息写入 course.txt 文件以保存所有
的课程数据。所有的数据需要用“ ; ;”分隔。这个

required attributes and data format is:
“{category_title};;;{subcategory_id};;;{subcategory_title};;;{subcategory_descri
ption};;;{subcategory_url};;;{course_id};;;{course_title};;;{course_url};;;{num_o
f_subscribers};;;{avg_rating};;;{num_of_reviews}”.
所需的属性和数据格式是: “{ category _ title } ; ; { subcategory _ id } ; ;
{ subcategory _ title } ; ; { subcategory _ description } ; ; { subcategory _
url } ; ; ; { course _ id } ; ; ; { course _ title } ; ; ; { course _ url } ; ; { num _ f _
subscriber } ; ; { avg _ rating } ; ; { num _ of _ reviews }”。

4. clear_course_data() no return.
清除航线数据()不返回。

This method will remove all the content in the course.txt file. After calling this
method, the course.txt file will become an empty file.
这个方法将删除 course.txt 文件中的所有内容。在调用这个方法之后,
course.txt 文件将变成一个空文件。
5. generate_page_num_list()->list of int.
生成 _ page _ num _ list ()-> int 列表。

Two positional arguments: page and total_pages. This method uses the
current page number and total pages to generate a list of integers as viewable
page numbers. For example, the image below shows a default page number
list [1,2,3,4,5,6,7,8,9] when the current page number is 1.
两个位置参数: page 和 total _ pages。这个方法使用当前页码和总页码生
成一个整数列表作为可视页码。例如,下图显示了当前页码为 1 时的默
认页码列表[1,2,3,4,5,6,7,8,9]。





If the current page number is less than or equal to 5, the generated page
number list is always [1,2,3,4,5,6,7,8,9]. If the current page number is greater
than 5 and less than total pages minus 4, the page number list will be integers
from current page number minus 4 until current page number plus 4. For
example, in the image below, the current page is 8 and the number list
becomes [4,5,6,7,8,9,10,11,12].
如果当前页码小于或等于 5,则生成的页码列表总是[1,2,3,4,5,6,7,8,9]。
如果当前页码大于 5,小于总页码减 4,则页码列表将是从当前页码减 4
到当前页码加 4 的整数。例如,在下面的图像中,当前页面是 8,数字列
表变成[4,5,6,7,8,9,10,11,12]。





If the current page is greater than or equal to total pages minus 4, the list of
numbers changes to range between total pages minus 8 until total pages.
如果当前页面大于或等于总页数减 4,则数字列表的范围从总页数减 8到
总页数不等。


6. get_courses_by_page()->tuple
按页面()-> 元组获取课程

One positional argument: page. The return value is a tuple that contains a list
of Course objects, total pages of courses and the total number of courses. This
method reads the course.txt file to retrieve all the course information. With
all the course information and the current page number, a list of Course
objects will be generated, the total pages and the total number of courses will
be returned. Each page has at most 20 courses.
一个位置参数: page。返回值是一个元组,它包含了 Course 对象的列表、
总的课程页面和总的课程数。这个方法读取 course.txt 文件来检索所有的
课程信息。根据所有课程信息和当前页码,将生成一个 Course 对象列表,
返回总页数和课程总数。每个页面最多有 20个课程。


For example, if there are 100 courses info in the course.txt file and the current
page number is 2, then the 21-40 lines course info will be converted to a list
with 20 Course objects. The total page number is 5.
例如,如果 Course.txt 文件中有 100 个课程信息,当前页码为 2,那么
21-40行的课程信息将被转换为包含 20个 Course 对象的列表。总页码是
5。

7. delete_course_by_id()->bool
删除 _ course _ by _ id ()-> bool

One positional argument: course_id. The method reads course info from the
course.txt file and deletes the course information belongs to that course_id.
Meanwhile, if an instructor in the user.txt file teaches this course, the course
id should also be removed from the instructor’s course_id_list. Finally, this
一个位置参数: course _ id。该方法从 course.txt 文件中读取课程信息,并
删除属于该课程 _id 的课程信息。同时,如果 user.txt 文件中的讲师教授
这门课程,那么课程 id 也应该从讲师的 course _ id _ list 中删除。最后,
这个

method returns whether the deletion is successful or not. If the course_id
cannot be found in the course.txt file, return False.
方法返回删除是否成功。如果在 course.txt 文件中找不到 course _ id,返
回 False。

8. get_course_by_course_id()->tuple
通过 _ course _ id ()-> 元组获取 _ course _ by _ course _ id ()-> tuple

One positional argument: course_id. You are required to find the course by
given course_id and convert the info to a Course object. Then, using the
retrieved course info to get the num_of_subscribers, avg_rating and
num_of_reviews. Based on these three numbers, generate a comment for this
course. If the num_of_subscribers greater than 100000 and avg_rating greater
than 4.5 and num_of_reviews greater than 10000, the comment should be
“Top Courses”. If the num_of_subscribers greater than 50000 and avg_rating
greater than 4.0 and num_of_reviews greater than 5000, the comment should
be “Popular Courses”. If the num_of_subscribers greater than 10000 and
avg_rating greater than 3.5 and num_of_reviews greater than 1000, the
comment should be “Good Courses”. The other courses are “General Courses”.
The Course object and comment will be returned as a tuple.
一个位置参数: course _ id。你需要通过给定的 Course _ id 来查找课程,并
将信息转换为 Course 对象。然后,使用检索到的课程信息得到订阅者的
数量,平均评分和评论的数量。基于这三个数字,生成本课程的评论。
如果订阅者的数量大于 100000,平均评分大于 4.5,评论的数量大于
10000,注释应该是“顶级课程”。如果订阅者的数量大于 50000,平均评
分大于 4.0,评论的数量大于 5000,注释应该是“热门课程”。如果订阅者
的数量大于 10000,平均评分大于 3.5,评论的数量大于 1000,那么评论
应该是“ Good Courses”。其他课程是“通用课程”。Course 对象和注释将作
为一个元组返回。

9. get_courses_by_instructor_id()->tuple
通过 _ instructor _ id ()-> tuple 获得 _ courses _

One positional argument: instructor_id. This method reads the user.txt file
and course.txt file to find all the course information the specified instructor
teaches. If this instructor teaches more than 20 courses, only 20 courses will
be returned with the total number of courses this instructor teaches (do not
need to sort, just use the default order and get the first 20). Otherwise, all the
courses and the total number will be returned. The return type is a tuple that
contains a list of course objects and the total number of courses teached by
this instructor.
一个位置参数: instructor _ id。这个方法读取 user.txt 文件和 course.txt 文
件来查找指定教师教授的所有课程信息。如果这位教师教授的课程超过
20 门,那么只有 20 门课程会返回这位教师教授的课程总数(不需要排序,
只需使用默认顺序,得到前 20 门)。否则,所有的课程和总数将被返回。
返回类型是一个元组,它包含了一系列的课程对象和这个讲师教授的课
程总数。

10. generate_course_figure1()->str
生成 _ course _ figure 1()-> str

Generate a graph to show the top 10 subcategories with the most subscribers.
(any chart)
生成一个图表来显示最多订阅者的前 10个子类别。(任意图表)


11. generate_course_figure2()->str
生成 _ course _ figure 2()-> str

Generate a graph to show the top 10 courses that have lowest avg rating and
over 50000 reviews.(any chart)
生成一个图表,显示平均分最低的前 10门课程和超过 50000个评论。(任
意图表)

12. generate_course_figure3()->str
生成 _ course _ figure 3()-> str

Generate a graph to show the all the courses avg rating distribution that has
subscribers between 100000 and 10000 (scatter chart)
生成一个图表,显示所有的课程平均评分分布在 100000和 10000之间(散
点图)
13. generate_course_figure4()->str
生成 _ course _ figure 4()-> str

Generate a graph to show the number of courses for all categories and sort in
ascending order (pie chart, offsetting the second largest number of course
with "explode")
生成一个图表,显示所有类别的课程数量,并按升序排序 (饼图,用
“ explode”抵消第二大课程数量)

14. generate_course_figure5()->str
生成 _ course _ figure 5()-> str

Generate a graph to show how many courses have reviews and how many
courses do not have reviews.(bar chart)
生成一个图表来显示有多少课程有评论,有多少课程没有评论。(条形图)

15. generate_course_figure6()->str
生成 _ course _ figure 6()-> str

Generate a graph to show the top 10 subcategories with the least courses
(any chart)
生成一个图表,显示最少课程的前 10个子类别(任意图表)


In all the graphs, if the course title is too long, you need to extract the first 3 words. If
the Course title is "Welcome to introduction to Python", using "Welcome to
introduction" is enough. If you have extra time, you can also extract the key word
like "introduction to Python". But, this may require a complex process as your
program may need to understand the sentence. All the generate_course_figure{1-6}
methods are required to return a string explanation about your understanding of this
figure. All the graphs use the instructor title, course title, category title or
subcategory title as x-axis labels.
在所有的图表中,如果课程标题太长,你需要提取前三个字。如果课程标题是
“ Welcome to introduction to Python”,使用“ Welcome to introduction”就足够了。
如果你有额外的时间,你也可以提取一些关键词,比如“ Python 入门”。但是,
这可能需要一个复杂的过程,因为你的程序可能需要理解这个句子。所有的
generate _ course _ figure {1-6}方法都需要返回一个关于你对这个图的理解的字
符串解释。所有的图都使用教师标题、课程标题、类别标题或子类别标题作为 x
轴标签。

3.3. Task 2 - Index, user register, login and logout
3.3任务 2-索引,用户注册,登录和注销

This part will call the methods implemented in previously designed classes. In the
lib/helper.py file, there are two functions called render_result() and
render_err_result(), which can be used to return result success or failure for POST
methods.
本部分将调用在先前设计的类中实现的方法。在 lib/helper.py 文件中,有两个名
为 render _ result ()和 render _ err _ result ()的函数,它们可用于返回 POST 方法
的结果成功或失败。

1. index() in index_controller. GET request, route is “/”.
Index _ controller 中的 index ()。 GET 请求,路由是“/”。

There is only one method in the index_controller which is the index page of this
web application. In this method, it is required to check the class variable
User.current_login_user to see if there is any logged user. If there exists a logged
user, pass the current_login_user’s role to context[‘current_user_role’].
Otherwise, do nothing. Next, create an admin account and register it manually.
索引控制器中只有一个方法,那就是这个 web 应用程序的索引页面。在这个
方法中,需要检查类变量 User.current _ login _ user,看看是否有登录的用户。
如果存在一个登录用户,将当前 _ login _ user 的角色传递给上下文[‘ current
_ user _ role’]。否则,什么都不做。下一步,创建一个管理员帐户并手动注
册。

Finally, render the “01index.html”. Admin account should be generated every
time in the index_controller/index() method. But, you need to handle the
最后,渲染“01index”。Html”。Admin 帐户应该每次在 index _
controller/index ()方法中生成。但是,你需要处理
duplicates. If an admin account already exists with the same username and
password in the user.txt file, do not overwrite it.
复制品。如果一个管理员帐户在 user.txt 文件中已经有相同的用户名和密码,不要
覆盖它。

2. login() in user_controller. GET request, route is
“/login”. Return the “00login.html” page.
Login ()在 user _ controller。 GET 请求中,路由为
“/login”。返回“00login. html”页面。

3. login_post() in user_controller. POST request, route is “/login”.
在 user _ controller 中的 login _ POST ()。 POST 请求,路由是“/login”。

Get “username”, “password” values from the request.values. Use the user
validation methods to check the username and password. If all valid, call the
authentication method. If username and password belong to a valid user,
return the string info of this user. Then, generate a corresponding user object
using the generate_user() method and assign this user to the
User.current_login_user class variable.
从 request.values 获取“ username”,“ password”值。使用用户验证方法检
查用户名和密码。如果都有效,调用身份验证方法。如果用户名和密码
属于一个有效用户,返回该用户的字符串信息。然后,使用 generate _
user ()方法生成一个对应的用户对象,并将该用户赋值给 User.current _
login _ user 类变量。

4. templates/00login.html page
Templates/00login. html 页面

Create two input boxes here for users to input username and password. The
type of username input is text and the type of password input is password.
Write your code within the student code comment area.
在这里创建两个输入框供用户输入用户名和密码。用户名输入的类型是
文本,密码输入的类型是密码。在学生代码注释区域写你的代码。

5. logout() in user_controller. GET request, route is “/logout”.
GET 请求,路由为“/logout”。

Reset the User.current_login_user to None and return the “01index.html”
page.
重置 User.current _ login _ user 为 None 并返回“01index. html”页面。
6. generate_user(login_user_str) in user_controller.
在 user _ controller 中生成 _ user (login _ user _ str)。

This method is defined and used only in user_controller for login_post()
method. Because after login, it is required to generate a user object(could be
Admin, Instructor or Student). Since using child class in parent class will cause
exceptions, the User.authenticate_user() method cannot return an
Admin/Instructor/Student object directly. So,you need to return a user string
in User.authenticate_user() and convert the user string to an object in this
这个方法被定义并且只在 user _ controller for login _ post ()方法中使用。
因为在登录之后,需要生成一个用户对象(可以是 Admin,Instructor 或
Student)。因为在父类中使用子类会导致异常,User.authenticate _ user ()
方法不能直接返回 Admin/Instructor/Student 对象。所以,你需要在
User.authenticate _ user ()中返回一个用户字符串,然后把这个用户字符串
转换成

generate_user() method. The return object could be
Admin()/Instructor()/Student().
方法。返回对象可以是 Admin ()/Instructor ()/Student ()。


7. register() in user_controller. GET request, route is
“/register”. Return the “00register.html” page.
Register ()在 user _ controller 中。 GET 请求,路由是
“/register”。返回“00register. html”页面。

8. register_post() in user_controller. POST request, route is “/register”.
在 user _ controller 中 register _ POST ()。 POST 请求,路由是“/register”。

Get “username”, “password”, “email”, “register_time”, “role” values from the
request.values. Use the user validation methods to check the username,
password and email. If all valid, register this user. Otherwise, return
render_err_result(msg=”proper message for users”).
从 request.values 获取“ username”、“ password”、“ email”、“ register _
time”、“ role”值。使用用户验证方法检查用户名、密码和电子邮件。如
果都有效,注册这个用户。否则,返回 render _ err _ result (msg =
“ proper message for users”)。

9. templates/01register.html page
模板/01register. html 页面

Create three input boxes for the user to input username, password and email.
The type of username and email input are text and the type of password input
is password. Write your code within the student code comment area.
创建三个输入框供用户输入用户名、密码和电子邮件。用户名和电子邮
件输入的类型是文本,密码输入的类型是密码。在学生代码注释区域写
你的代码。

3.4. Task 3 - Students page
3.4. 任务三-学生专页

1. student_list() in user_controller. GET request, route is “/student-list”.
在 user _ controller 中的 student _ list ()。 GET 请求,路由是“/student-list”。

Try to write this method by referring to the instructor_list and course_list.
Make sure the context dict has “context['one_page_user_list']”,
“context['total_pages']”, “context['page_num_list']”,
“context['current_page']”, “context['total_num']”,
“context["current_user_role"]” has values as the web pages need to show
these values and may cause errors if these values are not exist.
尝试参考讲师列表和课程列表来编写这个方法。确保上下文 dict 具有
“ context [‘ one _ page _ user _ list’]”、“ context [‘ total _ pages’]”、“ context
[‘ page _ num _ list’]”、“ context [‘ current _ page’]”、“ context [‘ total _
num’]”、“ context [‘ current _ user _ role’]”具有值,因为网页需要显示这些
值,如果这些值不存在,可能会导致错误。

2. student_info() in user_controller. GET request, route is “/student-info”.
GET 请求中的 student _ info () ,路由为“/student-info”。

Find a student based on the “id” attribute in the request.values. If not exist,
return a new student and set all instance variables with default values. Make
sure the “context["current_user_role"]” has values.
根据 request.values 中的“ id”属性查找学生。如果不存在,返回一个新学
生,并设置所有实例变量的默认值。确保“ context [“ current _ user _ role”]”
有值。


3. student_delete() in user_controller. GET request, route is “/student-delete”.
Delete student according to the “id” attribute in the request.values. This
method will return “redirect(url_for(user_page.student_list))” if successful.
Otherwise, return “redirect(url_for(index_page.index))”.
User _ controller 中的 student _ delete ()。GET 请求,路由是“/student-
delete”。根据 request.values 中的“ id”属性删除学生。这个方法将返回
“ redirect (url _ for (user _ page。如果成功,则返回。否则,返回
“ redirect (url _ for (index _ page。索引)。

4. templates/10student_list.html page
Templates/10student _ list.html page

Create a table to show the information of users. Each row of table need to show
one student info and a details button/link and a delete button/link. The href of
the details button is “/user/student-info?id={{user.uid}}” and the href of the
delete button is “/user/student-delete?id={{user.uid}}”. Write your code within
the given table tag. For example, 创建一个表格来显示用户信息。每一行表格需要显示一个学生信息和一个详
细信息按钮 /链接和一个删除按钮 /链接。详细信息按钮的 href 是
“/user/student-info?Id = { user.uid }}”,删除按钮的 href 是“/user/student-
delete?Id = { user.uid }”。在给定的表格标签中编写代码。例如,< a href =
“ ... { user.uid }”class = “ btn

btn-primary”>Details
, danger”>Delete. When clicking Details link, you will go to
Btn-primary”> Details ,< a href =”... { user.uid }”class =”btn btn-
danger”> Delete

student_info page. When clicking Delete link, you will delete one student item.
当点击 Delete 链接时,你将删除一个学生项目。

If you do not use class attribute here in the HTML tag , it is also correct.
如果在 HTML 标记 < a > 中没有使用 class 属性,也是正确的。


5. templates/11student_info.html page
Templates/11student _ info. html page

Create a page to have a header print out “Student Info” and all the
information of a student below the header. Write your code within the given
div tag.
创建一个页面,让页眉打印出“ Student Info”以及页眉下方学生的所有信
息。在给定的 div 标签中编写代码。

3.5. Task 4 - Courses page
3.5任务 4-Courses 页面

1. course_list() in course_controller. GET request, route is “/course-list”.
在 course _ controller. GET 请求中,路由为“/course-list”。

In this method, some code is already provided. Add more code to make the
method run. If the user is not logged in, should not allow access to the courses
and redirect the page to “index_page.index”. If there exists a logged user, get
the expected course list and page number list. Make sure the
“context["current_user_role"]” has values.
在这个方法中,已经提供了一些代码。添加更多的代码使方法运行。如
果用户没有登录,不应该允许访问课程,并将页面重定向到“ index _ page。
索引。如果有登录用户,获取预期的课程列表和页码列表。确保“ context
[“ current _ user _ role”]”有值。

For Mac users, if you meet the “Method not allowed” error in pages, try to
refresh the page. If the result can show properly, there should be no errors in
your backend logic and you can ignore this error.
对于 Mac 用户,如果你在页面中遇到“ Method not allowed”错误,尝试刷
新页面。如果结果显示正确,后端逻辑应该没有错误,你可以忽略这个
错误。




















2. reset_database() in course_controller. POST request, route is “/reset-
database”.
2. reset _ database () in course _ controller。 POST 请求,路由是“/reset-
database”。

This method simply removes all the content in the user.txt and course.txt files
by calling methods in User and Course class. After finish, return a success
message. If an error happens, return the render_err_result(msg=”exception
happened”) method result. Use try except block in this method to handle
exceptions.
此方法只是通过调用 User 和 Course 类中的方法来删除 User.txt 和
Course.txt 文件中的所有内容。完成后,返回一条成功消息。如果发生错
误,返回 render _ err _ result (msg = “ exception happened”)方法结果。在
此方法中使用 try except 块来处理异常。
3.6. Task 5 - Instructors page
任务 5-教练页面

1. Instructor_list() in instructor_controller. Get request, route is “/instructor-list”.
In this method, some code is already provided. Add more code to make the
method run. If the user is not logged in, should not allow access to the
instructors and redirect the page to “index_page.index”. If there exists a
logged user, get the expected instructor list and page number list. Make sure
the “context["current_user_role"]” has values.
Instructor _ controller 中的 Instructor _ list ()。Get 请求,路由是“/instructor-
list”。在这个方法中,已经提供了一些代码。添加更多的代码使方法运行。
如果用户没有登录,不应该允许访问指导者,并将页面重定向到“ index _
page”。索引。如果有登录用户,获取预期的指导者列表和页码列表。确
保“ context [“ current _ user _ role”]”有值。

For Mac users, if you meet the “Method not allowed” error in pages, try to
refresh the page. If the result can show properly, there should be no errors in
your backend logic and you can ignore this error.
对于 Mac 用户,如果你在页面中遇到“ Method not allowed”错误,尝试刷
新页面。如果结果显示正确,后端逻辑应该没有错误,你可以忽略这个
错误。




















2. teach_courses() in instructor_controller. GET request, route is “/teach-
courses”.
在指导员控制器中教课程。 GET 请求,路径是“/教课程”。

In this method , some code is already provided. Add more code to make the
method run. If the user is not logged in, should not allow access to the teach
courses and redirect the page to “index_page.index”. If there exists an “id”
attribute in the request.values, assign this value to the instructor_id. If there is
no “id” attribute in the request.values, use the current logged user’s id as the
instructor_id. Then, you can get the teach courses list. Make sure the
“context["current_user_role"]” has values.
在这个方法中,已经提供了一些代码。添加更多的代码使方法运行。如
果用户没有登录,不应该允许访问授课课程并将页面重定向到“ index _
page”。索引。如果 request.values 中存在“ id”属性,则将该值赋给
instructor _ id。如果 request.values 中没有“ id”属性,使用当前登录的用户
id 作为 instructor _ id。然后,你就可以得到授课课程列表。确保“ context
[“ current _ user _ role”]”有值。

Important Notes:
重要提示:

● If any exception/error happens when running your program, you will lose 50%
marks.
如果在运行程序时发生任何异常/错误,您将损失 50% 的分数。

● Please refer to the _demo_{data}.txt file to see the correct data format
请参考 _ demo _ { data } . txt 文件以查看正确的数据格式

● Your program should also work if you change all the data file paths to demo
data file paths.
如果你将所有的数据文件路径更改为演示文件路径,你的程序也应该可以工
作。


欢迎咨询51作业君
51作业君

Email:51zuoyejun

@gmail.com

添加客服微信: abby12468