Due: Friday, October 28, 11:00 AM
It's advising time! Time to start thinking about classes for the Spring! It can be tough to search through the course listings to find the classes you want. So let's write a program to help you out! The problem here that since registration for the Spring hasn't started yet, the data is kinda boring... so were are going to use data from a snapshot for registration for this semester - Fall 2016 - taken during August.
Write a library called
lous_list.py that will contain two methods that will aid students in finding information about classes.
These methods will all need to read from our online custom Lou's List interface. For example, if you want to see all the courses in the CS department, can go to:
and you'll see many lines like this:
CS;1110;002;Introduction to Programming;Ahmed Ibrahim;Lecture;3;true;false;true;false;true;1100;1150;Rice Hall 130;146;150;38.031639;-78.510811
Viewing the page "normally", it all runs together. You should view the source of the page to get a better view. (Chrome: View->Developer->View Source and Firefox: Tools->Web Developer->Page Source).
By replacing the text after the last
/ with any department at UVa, you can see their classes! For example,
BIOL will load all Biology classes.
For each line on the page, the fields are (in order):
- Dept ID (0)
- Course Number (1)
- Section (2)
- Course Title (3)
- Instructor (4)
- Type of class (5)
- Hours (6)
- Monday (7)
- Tuesday (8)
- Wednesday (9)
- Thursday (10)
- Friday (11)
- Start Time (12)
- End Time (13)
- Location (14)
- Enrollment (15)
- Allowable Enrollment (16)
- Latitude (17)
- Longitude (18)
Start and end times are expressed in the CSV as a 3- or 4-character string representing a 24-hour clock so, e.g., CS 1112 starts at 1400 and ends at 1515, for a duration of 75 minutes and CS 2150 section 105 starts at 1330 and ends at 1515 for a duration of 105 minutes.
Some sections have a listed start and end time of -1, meaning they do not have a fixed schedule.
You must do this POTD by writing these two functions:
instructors(department): Returns a sorted list containing each instructor listed in Lou's List for the given department. Do not count the same instructor twice. For example,
Mark Sherriff is listed as instructor for around 19 courses for the CS department but should only appear in the resulting list once.
To test this function, you should create a separate testing file, just as you did for previous POTDs. If you invoke
instructors("EAST") you should get back a list with three elements: ['Charles Laughlin', 'Jack Chen', 'Staff']. Note that the order does matter here. If you invoke
instructors("URDU") you should get back a list with two element: ['Griffith Chaussee', 'Mehr Farooqi'].
class_search(dept_name, has_seats_available=True, level=None, not_before=None, not_after=None): Returns a list of lists which contains all the information for all the classes that meet the provided criteria.
By default, if you invoke
class_search("CS"), the function should return a list containing all of the information from all of the CS courses in which there are seats available (Enrollment < Allowable Enrollment). If you invoke
class_search("CS", False), then all classes should be displayed, regardless of enrollment. As you add the optional parameters, you can adjust the search even more, as explained below:
- has_seats_available - If set to
True, the function will check to ensure that Enrollment is not greater than or equal to Allowable Enrollment (i.e. there are seats actually available for a student to take). If set to
Falsethen it doesn't matter if there are seats available or not and current enrollment should be ignored when determining if the class should be returned or not.
- level - Given a 4-digit level value, the function should only include classes that are at that level. For example, saying level=2000 should limit the list to only courses whose first digit is 2.
- not_before - Tells the function to exclude all classes that start before (but not at) that time. For example, if you say not_before=1000, then the function should exclude 9:00 and 9:30 classes, but still include 10:00 classes.
- not_after - Tells the function to exclude all classes that start after (but not at) that time. For example, if you say not_after=1400, then the function should exclude classes that start at 3:00, but not 2:00.
For example, if you invoke
class_search("CS", level=1000, not_before=1600) it should return (example formatted to make it easier to read):
[ ['CS', '1110', '106', 'Introduction to Programming', 'Mark Sherriff', 'Laboratory', '0', 'false', 'false', 'false', 'true', 'false', '1700', '1815', 'Olsson Hall 001', '45', '46', '38.032079', '-78.510755'], ['CS', '1110', '107', 'Introduction to Programming', 'Mark Sherriff', 'Laboratory', '0', 'false', 'false', 'false', 'true', 'false', '1830', '1945', 'Olsson Hall 001', '44', '46', '38.032079', '-78.510755'], ['CS', '1110', '108', 'Introduction to Programming', 'Mark Sherriff', 'Laboratory', '0', 'false', 'false', 'false', 'true', 'false', '2000', '2115', 'Olsson Hall 001', '27', '46', '38.032079', '-78.510755'], ['CS', '1113', '', 'Introduction to Programming', 'Ahmed Ibrahim', '', '3', 'false', 'false', 'false', 'true', 'false', '1700', '1815', 'Rice Hall 130', '48', '60', '38.031639', '-78.510811'], ['CS', '1113', '', 'Introduction to Programming', 'Kevin Sullivan', '', '3', 'false', 'false', 'false', 'true', 'false', '1830', '1945', 'Rice Hall 130', '43', '58', '38.031639', '-78.510811'] ]
Suggested Algorithms: Unlike the previous POTD, you don't necessarily need to create a separate function to read the website data (although you can if you want). And you don't have to load all of the data into a data structure. Consider including the code to read the website at the top of each of these methods and then doing your work inside the loop in which you read each line from the website.
You cannot use Beautiful Soup or any other HTML parser - the grading system will not recognize the library and you'll get a weird header error. You must use
urllib to pull down the CSV.
Submission: Please submit one .py file named
lous_list.py to the POTD submission system at https://archimedes.cs.virginia.edu/cs1110/. DO NOT submit any testing files. We only want your
NOTE: Make sure to remove all
print() statements from your code before submitting. We will not run any tests on any file that still has
print() statements in the code!