CSC108H Assignment 3, Summer 2011

Due Monday, July 25, 11:55 pm

Introduction

The purpose of this assignment is to give you more practice writing functions and programs in Python, and in particular writing code with dictionaries and files.\

You should spend at least one hour reading through this handout to make sure you understand what is required, so that you don't waste your time going in circles, or worse yet, hand in something you think is correct and find out later that you misunderstood the specifications. Highlight the handout, scribble on it, and find all the things you're not sure about as soon as possible.

It is probably worth spending at least a day thinking about the assignment before writing code of any sort. Try to think through potential problems to catch them before they appear. This will save hours of frustrating debugging time.

Hockey Statistics

During a hockey game, statistics are often recorded indicating the performance of the players. These are compiled for analysis, which is used to evaluate players.

We will be taking some very basic stats, and then writing code that generates some more advanced stats and returns some information about them. This will mainly involve dictionary manipulation. Here is a basic guide to advanced hockey stats if you're interested. We won't be dealing with most of these because it's hard to find the raw data to generate them, but it is interesting to read about.

The stats we consider

The raw stats we will get are Player Names, Teams, Games Played, Goals Scored, Powerplay goals scored, Time on Ice, and Powerplay Time on Ice. We will be getting a season's worth of these stats. When we store these stats, they should all be stored as strings, but as strings without the " character. A complete description of the stats follows:

From these stats we will want to compute a number of advanced stats. If you read the link above, we don't have the raw data to computer some of the more advanced and interesting stats, but the ones we may need to compute are here:

Data Source

We will be providing data for you in the form of .csv (comma separated value) files. We will be using US-stlye csv files. You may obtain some here. In the .csv file, the first line of the file will contain column headings that contain all of the basic stat headings listed above. Each column is separated by a , and text fields are indicated by quotation marks. There is no guaranteed order to which stat falls under which heading. While the files we give you have only one team per file, this is also not guaranteed. Subsequent lines contain the data for one player, whose name and team and stats are in the appropriate column.

Note that throughout one run of your program, we may load multiple .csv files.

Your Task

You are to write code that takes csv files and then updates a dictionary of players with the stats contained in that csv file. Your code should also be able to generate advanced statistics, and furthermore it should be able to sort players by statistics.

Note that in this assignment you will be modifying a global variable. You are allowed to create other global variables, if you find it useful. You are to download assignment3.py and complete the code stubs, according to the docstrings. You will also need to define helper functions that are not in the assignment, but the functions given should give you some idea of how to proceed.

Additional requirements

How to tackle this assignment

While this assignment is much more reasonable than assignment 2, you'll still need a good strategy for how to tackle it. Here is our suggestion. First download the code from assignment3.py.

Principles:

Advice:

This program can be broken down into several separate aspects. Some of these follow:
  1. Read this handout thoroughly and carefully, making sure you understand everything in it, particularly how the advanced statistics are calculated. Read the code stubs to make sense of the following advice.
  2. You need to write your own code to open files, but only add_file_info should do so.
  3. You should start by writing code to add the basic stats to player_stats.
  4. Note that get_col_names, toi_in_games, and add_player are all helper functions for this basic task.
  5. Then try and write code that will update player_stats with the advanced statistics.
  6. Finally, write code to return ordered lists of players.
  7. Make sure to test the code as you're writing each small bit, so that you can ferret out problems early.
  8. The shell can be useful for testing half-written functions.

Marking

These are the aspects of your work that we will focus on in the marking:

Submitting your assignment

You must hand in your work electronically, using the MarkUs system. Log in to it here, using your cdf login and password.

To declare your partnership, one of you needs to invite the other to be a partner, and then they need to accept the invitation. To invite a partner, navigate to the Assignment 2 page, find "Group Information", and click on "Invite". You will be prompted for the other student's cdf user name; enter it. To accept an invitation, find "Group Information" on the Assignment 2 page, find the invitation listed there, and click on "Join". Note that, when working in a pair, only one person should submit the assignment.

To submit your work, again navigate to the Assignment 2 page, then click on the "Submissions" tab near the top. Click "Add a New File" and either type a file name or use the "Browse" button to choose one. Then click "Submit".

For this assignment, hand in just one file:

Once you have submitted, be sure to check that you have submitted the correct version; new or missing files will not be accepted after the due date. Remember that spelling of filenames, including case, counts. If your file is not named exactly as above, your code will receive zero for correctness.