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.
- 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.
Please download the Assignment 3 files and extract the zip archive.
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.
- 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 functions, you can run this program to interactively test your code using different profiles.
- Checker: a3_checker.py
We have provided a checker program that you should use to check your code. See below for more information about a3_checker.py.
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:
- 1 line containing the person’s name
- then 0 or more lines containing the names of this person’s clubs (one club per line)
- and finally 0 or more lines containing the names of this person’s friends (one friend per line)
The profile file format adheres to the following rules:
- There is exactly one blank line between profiles.
- Club names do not contain commas.
- All lines that contain a person’s name are in the following format:
- You may assume that no person has a comma as part of their 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.
The starter zip file contains an example profile file named profiles.txt.
You are required to:
- write six required functions in club_functions.py and helper functions as appropriate (see marking scheme)
- write unittest s for two of the required functions ( get_average_club_count and get_last_to_first ).
In the functions below, where alphabetical order is specified, you should use the uppercase names like ‘DJ Tanner’ would come before mixed-case names like ‘Danny Tanner’
Write (and submit) unittest test files for functions get_average_club_count and get_last_to_first 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 assertAlmostEqual method, as we have done in the starter code.
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.
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.
To run the checker, open a3_checker.py and run it. Note: the checker file should be in the same directory as your club_functions.py , as provided in the starter code zip file. Be sure to scroll up to the top and read all messages.
- 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
- 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.