Hello, if you have any need, please feel free to consult us, this is my wechat: wx91due
COMP9311 25T1: Project 1
Deadline: Friday 20:59:59 April 4th (Sydney Time)
Aims
- Reading and understanding a moderately large relational schema (MyMyUNSW).
- Implementing SQL queries and views to satisfy requests for information.
- Implementing PL/pgSQL functions to aid in satisfying requests for information.
- The goal is to build some useful data access operations on the MyMyUNSW database. The data may contain some data inconsistencies; however, they won’t affect your answers to the project.
Background
UNSW has spent a considerable amount of money ($80M+) on the MyUNSW/NSS system, and it handles much of the educational administration plausibly well. Most people gripe about the quality of the MyUNSW interface, but the system does allow you to carry out most basic enrolment tasks online.
Despite its successes, MyUNSW/NSS still has several deficiencies, including:
- No waiting lists for course or class enrolment.
- No representation for degree program structures.
- Poor integration with the UNSW Online Handbook.
The second point prevents MyUNSW/NSS from being used for three important operations that would be extremely helpful to students in managing their enrolment:
- Finding out how far they have progressed through their degree program, and what remains to be completed.
- Checking what are their enrolment options for next semester (e.g., get a list of available courses).COMP9311 (25T1)
- Determining when they have completed all the requirements of their degree program and are eligible to graduate.
NSS contains data about students, courses, classes, pre-requisites, quotas, etc. but does not contain any representation of UNSW's degree program structures. Without such information in the NSS database, it is not possible to do any of the above three. So, in 2007 the COMP9311 class devised a data model that could represent program requirements and rules for UNSW degrees. This was built on top of an existing schema that represented all the core NSS data (students, staff, courses, classes, etc.). The enhanced data model was named the MyMyUNSW schema.
The MyMyUNSW database includes information that encompasses the functionality of NSS, the UNSW Online Handbook, and the CATS (room allocation) database. The MyMyUNSW data model, schema and database are described in a separate document.
How to do this project:
- Read this specification carefully and completely.
- Familiarize with the database schema (description, SQL schema, summary).
- Make a private directory for this project and put a copy of the proj1.sql template there.
- You must use the create statements in proj1.sql when defining your solutions.
- Look at the expected outputs in the qX_expected tables loaded as part of the check.sql file.
- Solve each of the problems in ‘tasks’ section and put your completed solutions into proj1.sql.
- Check that your solution is correct by verifying against the example outputs and by using the check_qX() functions (following the ‘AutoTest Checking’ section).
- Test that your proj1.sql file will load without error into a database containing just the original MyMyUNSW data.
- Double-check that your proj1.sql file loads in a single pass into a database containing just the original MyMyUNSW data.
- Submit the project via moodle.
- For each question, you must output result within 120 seconds on vxdb01 server.
- Hardcode is strictly forbidden.
Setting Up
If you've already set up PLpgSQL in your template1 database, you will get one error message as the database starts to load:
psql:mymyunsw.dump:NN: ERROR: language "plpgsql" already exist.
Apart from possible messages relating to plpgsql, you should get no error messages.
- If you leave your project until the last minute, loading the database on vxdb01 will be considerably slower, thus delaying your work even more.
- The solution: at least load the database Right Now, even if you don't start using it for a while.
- Note that the mymyunsw.dump file is 50MB in size; copying it under your home directory or your ‘/localstorage’ directory is not a good idea.
- If you have other large databases under your PostgreSQL server on vxdb01 or if you have large files under your ‘/localstorage/YOU/’ directory, it is possible that you will exhaust your vxdb01 disk quota. Regardless, it is certain that you will not be able to store two copies of the MyMyUNSW database under your vxdb01 server.
- The solution: remove any existing databases before loading your MyMyUNSW database.
The only error messages produced by these commands should be those noted above. If you omit any of the steps, then things will not work as planned.
Important Advice Before You Start
Tip: study the schema of each table to see how tables are related and try write some queries to explore/ understand what each table is storing.
Read these before you start on the exercises:
- The marks reflect the relative difficulty/length of each question.
- Work on the project on the supplied proj1.sql template file.
- Make sure that your queries work on any instance of the MyMyUNSW schema; don't customize them to work just on this database; we may test them on a different database instance.
- Do not assume that any query will return just a single result; even if it phrased as "most" or "biggest", there may be two or more equally "big" instances in the database.
- When queries ask for people's names, use the Person.name field; it's there precisely to produce displayable names.
- When queries ask for student ID, use the People.unswid field; the People.id field is an internal numeric key and of no interest to anyone outside the database.
- Unless specifically mentioned in the exercise, the order of tuples in the result does not matter; it can always be adjusted using order by. In fact, our check.sql will order your results automatically for comparison.
- The precise formatting of fields within a result tuple does matter, e.g., if you convert a number to a string using to_char it may no longer match a numeric field containing the same value, even though the two fields may look similar.
- We advise developing queries in stages; make sure that any sub-queries or sub joins that you're using works correctly before using them in the query for the final view/function
- You may define as many additional views as you need, provided that (a) the definitions in proj1.sql are preserved, (b) you follow the requirements in each question on what you are allowed to define.
- If you meet with error saying something like “cannot change name of view column”, you can drop the view you just created by using command “drop view VIEWNAME cascade;” then create your new view again.
Tasks
Question 1 (3 marks)
- subject_code should be taken from Subjects.code field.
- ‘School’ type refers to the Orgunit_types.name field that contains ‘School’.
- The organization’s name refers to the orgunits.longname field.
- Level-5 refers to the subject_code formatted as ‘XXXX5***’, where ‘X’ represents a letter and ‘*’ represents a number.
Question 2 (3 marks)
- course_id refers to the Courses.id field.
- Lecture and Laboratory refer to the Class_types.name field.
- Lecture room refers to the Class.room field.
- Professor denotes the ‘Prof’ in People.title.
Question 3 (4 marks)
- unsw_id should be taken from people.unswid field.
- The stream types 'Major', 'Minor', and 'Honours' are identified using the refer to stream_types.description field.
Question 4 (5 marks)
Note: Round avg_mark to the nearest 0.01 in numeric type (i.e., 85.014 ≈ 85.01, 85.016 ≈ 85.02, 85 ≈85.00).
- course_id should be taken from Courses.id.
- Faculty refers to the organization units where their Orgunit_types.name is ‘Faculty’.
- A student is considered to have passed if their course mark ≥ 50.
- The ‘master students’ refers to the degree_types.name containing the word ‘Master’.
- The ‘year’ refers to the ‘semesters.year’ field.
Question 5 (5 marks)
Show the highest mark achieved by any student in the course. And the given names of the students who achieved this highest mark. If multiple students share the highest mark, their given names are concatenated in order, separated by "; " (e.g., "Jack; Michele").
- The given name refers to the People.given field.
Question 6 (5 marks)
- subject_id should be taken from subjects.id field.
- The ‘year’ refers to the ‘semesters.year’ field.
- room_id should be taken from rooms.id field.
Question 7 (6 marks)
- student_id should be taken from people.unswid field.
- orgunit_id refers to orgunits.id field.
- program_id refers to programs.id field.
- Assuming students can register at most 1 program in each semester.
- A student will pass the course and earn the UOC if she/he receives the mark ≥ 50.
- The student is valid for graduation if the total UOC earned in the program (hint: subjects.uoc) is no less than the required UOC of the program (refer to programs.uoc).
- If a student has enrolled in several different programs, you need to calculate the UOC separately according to different programs. A course is considered part of a program if the student enrolls in both the course and the program during the same semester.
- For each student, the duration of one program is the number of days between the earliest date (hint: Semesters.starting) and the latest date (hint: Semesters.ending) among all his or her course enrollments for that program, regardless of whether the course was passed.
- In the same program, a student may register for the same subject multiple times (multiple courses) because of possible retakes after failing. When determining program completion, only subjects with marks ≥ 50 are counted, but when calculating the duration, all enrollment records are included. We assume each subject has only one record with a mark over 50. If multiple courses share the same subject code with a pass, you can treat them as distinct subjects. For example, some research courses (for instance, honours thesis A/B/C) must be enrolled in multiple times but share the same subject code.
Question 8 (6 marks)
For each such staff member, the view also returns the student ID (student_id) of those who enrolled in courses where the mentioned staff served but may not as a course convenor, along with the number of times (teach_times) the student enrolled in those courses across their entire enrollment history.
- A person is employed as a course convenor for a course if her/his staff_roles.name is ‘Course Convenor’ in course_staff.
- ‘Above distinction’ means that Course_enrolments.mark is ≥ 75.
- We only consider the no-null mark in the ‘Above distinction’ rate calculation.
- student_id should be taken from people.unswid field.
- staff_id should be taken from People.unswid field.
- The Rank()function in PostgreSQL will be able to do this for you to generate the ranking column.
Question 9 (6 marks)
Define a PL/pgSQL function Q9(unswsid integer) This function takes a student's unswid as input and returns the given name of the student's favorite teacher—defined as the course convenor whose courses the student has enrolled in the most times (Note: different with Q8).
Additionally, the function returns: 1) The number of times the student has enrolled in courses convened by this teacher. 2) The rank of the student based on how many times they have enrolled in the teacher’s courses compared to other students.
- An unswid should be taken from People.unswid field.
- A person is employed as a course convenor for a course if her/his staff_roles.name is ‘Course Convenor’ in course_staff.
- Only courses where the student has received a non-null mark are considered.
- The teacher’s given name should be retrieved from ’people.given’.
- The student's unswid should be taken from ’people.unswid’.
- The Rank()function in PostgreSQL will be able to do this for you to generate the ranking column.
- Teacher name: the given name of the teacher refer to ’people.given’.
- Enrolled times: The number of times the student enrolled in courses convened by this teacher.
- Rank: the register rank should be an integer. If she/he ranked 2nd in the ranking, the result is 2.
Special output:
- If the student has not finished any required course with a valid mark, return a line in the format of ‘WARNING: Invalid Student Input [X]’, where ‘X’ denotes the provided unswid.
Question 10 (7 marks)
- An unswid should be taken from People.unswid field.
- Unlike to the Question 7, in this question, a student passes a course if she/he obtains a grade in setpass = {SY, PT, PC, PS, CR,DN, HD,A, B, C, XE, T, PE, RC,RS} refers to course_enrolments.grade.
- All the grades in setpass ∩ setsy = {SY, XE, T, PE} or in setpass ∩ (course mark = null), means the courses the student passed but won’t be included in WAM calculation.
- All the grade not in setpass, excluding the course mark = null, means a fail.
- If a student has enrolled in several different programs, you need to calculate the WAM separately according to different programs. A course is considered part of a program if the student enrolls in both the course and the program during the same semester. Assuming students can register at most 1 program in each semester.
Where: M = mark received in a course,U = units of credit for a course.
The WAM is calculated as: [(80×6)+(81×6)+ (82×6)+(83×3)+(84×3)]/(6 + 6 + 6 + 3 + 3) = 81.625 ≈ 81.63 .
Each line of output (in text type) should contain the following three elements concatenated with a space:
- Unswid: a unswid of student which is taken from People.unswid field.
- Program name: a program name which is taken from programs.name field.
- WAM: the WAM result and round it to the nearest 0.01. Use the same rule as Q4.
- If the student has enrolled in one program, but she/he did not register for any course or all the courses registered are not included in WAM calculation for that program, i.e., the divisor is zero, return ‘No WAM Available’ in the WAM section of the return line.
- If the student has not enrolled in any programs (cannot find any programs for the student), return a line in the format of ‘WARNING: Invalid Student Input [X]’, where ‘X’ denotes the provided unswid.
AutoTest Checking
1. You must ensure that your submitted proj1.sql file will be loaded and run correctly (i.e., it has no syntax errors, and it contains all your view definitions in the correct order).
b. For all the submission files, you must make sure there is no error occurring when using the autotest provided above. If we need to manually fix problems in your proj1.sql file to test it (e.g., change the order of some definitions), you will be fined half of the mark as penalty for each problem.
2. In addition, write queries that are reasonably efficient.
3. The submission file should contain answers to all the exercises for this project. It should be completely self-contained and able to load in a single pass, so that it can beauto-tested as follows:
Project Submission
- You are required to submit an electronic version of your answers via Moodle.
- We only accept the .sql format. Please name your files in the following formatto submit: proj1_zID.sql (e.g., proj1_z5000000.sql).
- Only the Latest Submission is marked. The Latest Submission after thedeadline will result in a late penalty.
- In case the system is not working properly, please ensure to take these steps: keepa copy of your submitted file on the CSE server without any post-deadlinemodifications. If you're uncertain about how to do this, refer to the guidelines provided on Taggi.
- If you have problems relating to your submission, please email to [email protected].
- If there are issues with Moodle, send your assignment to the above email with thesubject title “<zid> COMP9311 Proj1 Submission”.
- 5% of the total mark (50 marks) will be deducted for each additional day.
- Submissions that are more than five days late will not be marked.
The work you submit must be your own work. Submission of work partially or completelyderived from any other person or jointly written with any other person is not permitted.
All submissions will be checked for plagiarism. The university regards plagiarism as a form of academic misconduct and has very strict rules. Not knowing the rules will not be considered a valid excuse when you are caught.
- For UNSW policies, penalties, and information to help avoid plagiarism, please see: https://student.unsw.edu.au/plagiarism.
- For guidelines in the online ELISE tutorials for all new UNSW students: https://subjectguides.library.unsw.edu.au/elise/plagiarism.