CSC108H Assignment 3
Introduction
In this assignment, you will write a club recommendation system for a social network. Based on the scoring system described below, your program will recommend clubs that a person may wish to join.
This handout explains the problem you are to solve, and the tasks you need to complete for the assignment. Please read it carefully.
Goals of this Assignment
- Write function bodies using dictionaries and file reading.
- Write code to mutate lists and dictionaries.
- Use top down design to break a problem down into subtasks and implement helper functions to complete those tasks.
- Write tests to check whether a function is correct.
Files to Download
Please download the Assignment 3 files and extract the zip archive.- Starter code:
- club_functions.py
This file contains the headers for the functions you will need to write for this assignment, and a few completed function docstrings. You will start development here, using the Function Design Recipe process to implement each required function. The functions in this file can call each other, and several of them will also be called by the main program ( club_finder.py ). You can, and should, write some helper functions in this file that are called by your required functions. required functions.
- test_get_average_club_count.py and test_get_last_to_first.py
We are providing the beginning of two unit test files, test_get_average_club_count.py and test_get_last_to_first.py . These files will contain your unit tests for the get_average_club_count and get_last_to_first functions, respectively, that are described below.
- Data: profiles.txt
The profiles.txt file contains social network data. This is sample data, and you should not modify this file. You may
want to create your own data files to supplement this file for testing. See the next section for instructions on how to
interpret this data.
-
Main Program: club_finder.py
The file contains a program that loads some data and then calls some functions that you will implement in club_functions.py . You do not need to modify this file. After you have implemented all of your club_functions.py functions, you can run this program to interactively test your code using different profiles.
We have provided a checker program that you should use to check your code. See below for more information about a3_checker.py .
Data Format
The profile information for people in the social network is stored in a file. Your program will need to read the data from the file and process it.
The file contains 0 or more profiles. Each profile has the following format:
The profile file format adheres to the following rules:
LastName, FirstName(s)
You may assume that no person has a comma as part of their LastName or FirstName(s) . There is one comma in a line containing a person's name.
- Every person has a single (non-empty) last name (not a good assumption in general, but we'll make it for this assignment). A person may have a single (non-empty) first name or more than one word in their first name, separated by spaces.
For example, the following are all valid lines that contain people's names in the profiles file:
-
Mandela, Nelson
- King-Noel, Augusta Ada
- Gandhi, Mohandas K.
Your Tasks
You are required to:1. write six required functions in club_functions.py and helper functions as appropriate (see marking scheme)
2. write unittest s for two of the required functions ( get_average_club_count and get_last_to_first ).
Data structures and ordering
Alphabetical Order
In the functions below, where alphabetical order is specified, you should use the list method sort . As a result, uppercase names like 'DJ Tanner' would come before mixed-case names like 'Danny Tanner' .
Data Structures
A "person to friends" dictionary ( Dict[str, List[str]] ) is our data structure for representing the mapping of people to their friends. -
key: person's name ( str ) in the format:
FirstName(s) LastName
-
value: list of friends' names in FirstName(s) LastName format ( List[str] ), sorted in alphabetical order by
FirstName(s) LastName . Use the list method sort to put the list of friends' names into alphabetical order.
- example: this dictionary represents the "person to friends" data from profiles.txt :
Visually, we can think of this person to friends dictionary as the following network, where an arrow from Jay Pritchett to Gloria Pritchett indicates that Jay Pritchett has a friend named Gloria Pritchett.{'Jay Pritchett': ['Claire Dunphy', 'Gloria Pritchett', 'Manny Delgado'],
'Claire Dunphy': ['Jay Pritchett', 'Mitchell Pritchett', 'Phil Dunphy'],
'Manny Delgado': ['Gloria Pritchett', 'Jay Pritchett', 'Luke Dunphy'],
'Mitchell Pritchett': ['Cameron Tucker', 'Claire Dunphy', 'Luke Dunphy'],
'Alex Dunphy': ['Luke Dunphy'],
'Cameron Tucker': ['Gloria Pritchett', 'Mitchell Pritchett'],
'Haley Gwendolyn Dunphy': ['Dylan D-Money', 'Gilbert D-Cat'],
'Phil Dunphy': ['Claire Dunphy', 'Luke Dunphy'],
'Dylan D-Money': ['Chairman D-Cat', 'Haley Gwendolyn Dunphy'],
'Gloria Pritchett': ['Cameron Tucker', 'Jay Pritchett', 'Manny Delgado'],
'Luke Dunphy': ['Alex Dunphy', 'Manny Delgado', 'Mitchell Pritchett', 'Phil Dunphy']}
A "person to clubs" dictionary ( Dict[str, List[str]] ) is our data structure for representing the mapping of people to the clubs they are members of.
-
key: person's name ( str ) in the format:
FirstName(s) LastName
- value: list of clubs that person is a member of ( List[str] ), sorted in alphabetical order. Use the list method sort to put the club names into alphabetical order.
- example: this dictionary represents the "person to clubs" data from profiles.txt
Visually, we can think of this person to clubs dictionary as the following network, where an arrow from Manny Delgado to Chess Club indicates that Manny Delgado is a member of the Chess Club.{'Claire Dunphy': ['Parent Teacher Association'],
'Manny Delgado': ['Chess Club'],
'Mitchell Pritchett': ['Law Association'],
'Alex Dunphy': ['Chess Club', 'Orchestra'],
'Cameron Tucker': ['Clown School', 'Wizard of Oz Fan Club'],
'Phil Dunphy': ['Real Estate Association'],
'Gloria Pritchett': ['Parent Teacher Association']}
Required Testing ( unittest)
Write (and submit) unittest test files for functions get_average_club_count and get_last_to_first . These tests should be implemented in the appropriately named starter files.
We will evaluate the completeness of your test files by running them against flawed implementations we have written to see how many errors you catch. Avoid redundant tests. The goal is to catch all of our errors without extra, unnecessary tests.
Your unittest testfiles should stand alone: they should require no additional files (like a profile file). Instead, you should define appropriate test values in the file, such as a dictionary that might be generated from reading a profile file, to use for your tests. You may assume that the folder that contains your unittest test files also contains a club_functions.py file.
Recall that floating-point numbers are approximations of real numbers. To compare float s, you should use the assertAlmostEqual method, as we have done in the starter code.
Required Functions
This section contains a table with detailed descriptions of the 6 functions that you must complete. You'll need to add a second example to the docstrings for each function in the starter code.
We provided one helper function in the starter code that you may use. You should follow the approach we've been using on large problems recently and write additional helper functions to break these high-level tasks down. Each helper function must have a clear purpose. Each helper function must have a complete docstring produced by following the Function Design Recipe. You should test your helper functions to make sure they work.
|
|
||||||||||
|
|
||||||||||
|
|
||||||||||
|
|
||||||||||
|
|
|
|
||||||||||
|
|
A3 Checker
We are providing a checker module ( a3_checker.py ) that tests two things:-
whether your code follows the Python Style Guidelines, and
- whether your functions are named correctly, have the correct number of parameters, and return the correct types.
If the checker passes for both style and types:
- Your code follows the style guidelines.
- Your function names, number of parameters, and return types match the assignment specification. This does not mean that your code works correctly in all situations. We will run a different set of tests on your code once you hand it in, so be sure to thoroughly test your code yourself before submitting.
-
It may have failed because your code did not follow the style guidelines. Review the error description(s) and fix the code style. Please see the PyTA documentation (http://www.cs.toronto.edu/~david/pyta/) for more information about errors.
- It may have failed because:
- you are missing one or more function,
- one or more of your functions is misnamed,
- one or more of your functions has the incorrect number or type of parameters, or
- one of more of your function return types does not match the assignment specification.
Read the error message to identify the problematic function, review the function specification in the handout, and fix your code.Make sure the checker passes before submitting.
Running the checker program on Markus
In addition to running the checker program on your own computer, run the checker on MarkUs as well. You will be able to run the checker program on MarkUs once every 12 hours (note: we may have to revert to every 24 hours if MarkUs has any issues handling every 12 hours). This can help to identify issues such as uploading the incorrect file.
First, submit your work on MarkUs. Next, click on the "Automated Testing" tab and then click on "Run Tests". Wait for a minute or so, then refresh the webpage. Once the tests have finished running, you'll see results for the Style Checker and Type Checker components of the checker program (see both the Automated Testing tab and results files under the Submissions tab). Note that these are not actually marks -- just the checker results. If there are errors, edit your code, run the checker program again on your own machine to check that the problems are resolved, resubmit your assignment on MarkUs, and (if time permits) after the 24 hour period has elapsed, rerun the checker on MarkUs.
Testing your Code
It is strongly recommended that you test each function as soon as you write it. As usual, follow the Function Design Recipe (we've provided the function name and types for you) to implement your code. Once you've implemented a function, run it against the examples in your docstrings and the unit tests you've defined.Additional requirements
-
Do not call print , input , or open , except within the if __name__ == '__main__' block.
-
Do not use any break or continue statements.
-
Do not modify or add to the import statements provided in the starter code.
-
Do not add any code outside of a function definition.
-
Do not mutate objects unless specified.
- Do not use Python language features for sorting that we haven’t covered in this course, like the optional parameter key or the function sorted
Marking
These are the aspects of your work that will be marked for Assignment 3: -
Correctness (70%): Your functions should perform as specified. Correctness, as measured by our tests, will count for the largest single portion of your marks. Once your assignment is submitted, we will run additional tests, not provided in the checker. Passing the checker does not mean that your code will earn full marks for correctness.
-
Testing (10%): We will run the unittests that you submit on a series of flawed (incorrect) implementations we have written. Your testing mark will depend on how many of the flawed implementations your unittests catch, whether they successfully pass a working (correct) implementation, and whether your test files contain redundant (unnecessary) tests.
- Coding style (20%):
- Make sure that you follow the Python style guidelines that we have introduced and the Python coding conventions that we have been using throughout the semester. Although we don't provide an exhaustive list of style rules, the checker tests for style are complete, so if your code passes the checker, then it will earn full marks for coding style with two exceptions: docstrings and use of helper functions may be evaluated separately. For each occurrence of a PyTA error (http://www.cs.toronto.edu/~david/pyta/) , a 1 mark (out of 20) deduction will be applied. For example, if a C0301 (line-too-long) error occurs 3 times, then 3 marks will be deducted.
- Your program should be broken down into functions, both to avoid repetitive code and to make the program easier to read. If a function body is more than about 20 statements long, introduce helper functions to do some of the work -- even if they will only be called once.
- All functions, including helper functions, should have complete docstrings including preconditions when you think they are necessary.
- Also, your variable names and names of your helper functions should be meaningful. Your code should be as simple and clear as possible.
No Remark Requests
No remark requests will be accepted. A syntax error could result in a grade of 0 on the assignment. Before the deadline, you are responsible for running your code and the checker program to identify and resolve any errors that will prevent our tests from running.The very last thing you do before submitting should be to run the checker program one last time.
What to Hand In
Otherwise, you could make a small error in your final changes before submitting that causes your code to receive zero for correctness.
2019-11-18
In this assignment, you will write a club recommendation system for a social network.