FIT9136 Algorithm and Programming Foundation in Python
FIT9136 Algorithm and Programming Foundation in Python
FIT9136 Algorithm and Programming Foundation in Python
programming foundation in
Python
Assignment 3
Lecturer in Charge: Shirin Ghaffarian Maghool
May 2022
Table of Contents
1. Key Information 3
1.1. Do and Do NOT 4
1.2. Documentation 4
1.3. Submission 4
2. Getting help 6
2.1. English language skills 6
2.2. Study skills 6
2.3. Things are tough right now 6
2.4. Things in the unit don’t make sense 6
2.5. I don’t know what I need 6
3. Key tasks 7
3.1. Overview 7
3.2. Website business logic description 8
3.2 Task 1 - design classes 16
3.2.1 User class 16
3.2.2 Admin class 18
3.2.3 Instructor class 19
3.2.4 Student class 21
3.2.5 Course class 21
3.3. Task 2 - Index, user register, login and logout 25
3.4. Task 3 - Students page 26
3.5. Task 4 - Courses page 27
3.6. Task 5 - Instructors page 28
Important Notes: 29
1. Key Information
Your task It is an Individual assignment, where you will write a code for a simple
emulation of a data analysis website.
Late ● 10% deduction per calendar day or part thereof for up to one
Penalties week
● Submissions more than 7 calendar days after the due date will
receive a mark of zero (0) and no assessment feedback will be
provided.
1.2. Documentation
Commenting your code is essential as part of the assessment criteria (refer to
Marking 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.
1.3. Submission
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:
● 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
● 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.
https://www.monash.edu/rlo/research-writing-assignments/referencing-and-academic-integrit
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).
3
eg: original mark was 70/100, submitting 2 days late results in 50/100 (10 marks off). This
includes weekends
1.4. Deliverables
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.
● All files in the “controller” folder include course_controller.py,
index_controller.py, instructor_controller.py and user_controller.py.
● Several files in the “templates” folder include 00login.html, 00register.html,
10student_list.html and 11student_info.html.
● All files need to be compressed into a zip file. The final submission file name is
{your_student_id}.zip.
● Marks will be deducted for any of these requirements that are not strictly
complied with.
2. Getting help
3.1. Overview
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)
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.
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.
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.
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.
Figure 3.3 Student login page
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.
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.
Figure 3.5 Admin login page
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.
Figure 3.6 Register page
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].
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.
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.
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.
Figure 3.10 Instructors page
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.
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).
If you login as a student, you can only see the MyInfo page.
2. __str__()->str.
Return string format example:
“uid;;;username;;;password;;;register_time;;;role”
3. authenticate_user()->bool.
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 return True, otherwise return
False.
4. check_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.
5. generate_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.
6. 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.
7. register_user()->bool.
Four positional arguments - username, password, email, register_time, role.
8. date_conversion()-> 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
timestamp 1637549590753 will be converted to str
“2021-11-22_13:53:10.753” and returned. The time should be GMT+11
Melbourne timezone.
3. register_admin() no return.
This method will create a new admin account and write this account into the
user.txt file.
2. __str__()->str.
Return string format example:
Example 1 (registered manually, so display_name=””, job_title=””,
course_id_list=[]):
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.
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:
“{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.
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.
5. generate_instructor_figure1()->str
Generate a graph that shows the top 10 instructors who teach the most
courses.(any chart)
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.
2. __str__()->str.
Return string format example:
3. 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.
4. get_student_by_id()->Student object
One positional argument id. This method returns a student object by retrieving
the id from the user.txt file.
5. delete_student_by_id()->bool
One positional argument id. This method deletes a student item from the
user.txt file based on the given id.
2. __str__()->str.
Return format:
{category_title};;;{subcategory_id};;;{subcategory_title};;;{subcategory_url};;;{c
ourse_id};;;{course_title};;;{course_url};;;{num_of_subscribers};;;{avg_rating};;;
{num_of_reviews}
3. 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.
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
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}”.
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.
5. generate_page_num_list()->list of 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.
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].
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.
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.
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.
7. delete_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
method returns whether the deletion is successful or not. If the course_id
cannot be found in the course.txt file, return False.
8. get_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.
9. get_courses_by_instructor_id()->tuple
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.
10. generate_course_figure1()->str
Generate a graph to show the top 10 subcategories with the most subscribers.
(any chart)
11.generate_course_figure2()->str
Generate a graph to show the top 10 courses that have lowest avg rating and
over 50000 reviews.(any chart)
12. generate_course_figure3()->str
Generate a graph to show the all the courses avg rating distribution that has
subscribers between 100000 and 10000 (scatter chart)
13. generate_course_figure4()->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")
14. generate_course_figure5()->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
Generate a graph to show the top 10 subcategories with the least courses (any
chart)
In all the graphs, if the course title is too long, you need to extract the first 3 words.
All the generate_course_figure{1-6} methods are required to return a string
explanation about your understanding of this figure.
6. generate_user(login_user_str) in user_controller.
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
method.
9. templates/01register.html page
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.
4. templates/10student_list.html page
Create a table to show the information of users. For each user item, provide a
details button and a delete button. 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.
5. 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.
Important Notes:
● If any exception/error happens when running your program, you will lose
50% marks.
● Please refer to the _demo_{data}.txt file to see the correct data format
● Your program should also work if you change all the data file paths to demo
data file paths.