Introduction to Computer Science
CompSci 101 : Spring 2014

Basketball Statistics

March madness is upon us! So let's look at some statistics from Sports Reference of the past few seasons and ask some questions about the players. The data file contains tab separated values on each line and includes a header row describing the meaning of each of the 15 integer stats about the player for a single season. The meaning of the abbreviations in the column headers are given here.

Start by snarfing the code from the class website. Alternatively, you can browse code here. This code, developed during class, reads in the given data, calculating career stats for each player by summing each column, and printing out the players in a variety of sorting orders.

Understanding the Code

The given function, loadData, converts the lines of data in the file into a dictionary in which the keys are a string, the player's name, and the values are a dictionary representing the player's stats. This dictionary has keys that are a string, the name of the stat from the header row in the data file, and the values are an int, the career value of that stat for the player. It represents a career stat because it is the sum of all occurrences of that stat for that player in the data file. This allows you determine a player's total number of rebounds using the following code:

def totalRebounds (stats):
"""
return ORB + DRB (both offensive and defensive rebounds)
"""
return stats['ORB'] + stats['DRB']

 

Working with the Code

In this part, complete the follwing functions that each take a single parameter: a dictionary whose keys are strings, representing the names of the stats given in the file's header row for a single player, and whose values are ints, representing the values of the corresponding stat; and return a number (either int of float), the result of the calculation for that player.

  1. Use the following formula to calculate a player's totalPoints:
    FT + 3 * 3P + 2 * (FG - 3P)     # number of 1, 2, and 3 points shots made
    

  2. Use the following formula to calculate a player's minutesPerGame:
    MP / G     # total minutes played per all games played
    

  3. Use the following formula to calculate a player's freeThrowPercent (don 't forget to check for players that made no free throw attempts).
    FT / FTA     # those made out of the total attempted
    

  4. Use the following formula to calculate a player's pointsPerMinute:
  5. totalPoints / MP   # total points scored per all minutes played
    

  6. Use the following formula to calculate a player's effectiveFieldGoalPercent:
    (FG + 0.5 * 3P) / FGA
    

    Effective Field Goal Percentage adjusts for the fact that a 3-point field goal is worth one more point than a 2-point field goal. For example, suppose Player A goes 4 for 10 with 2 threes, while Player B goes 5 for 10 with 0 threes. Each player would have 10 points from field goals, and thus would have the same effective field goal percentage (50%).

  7. Use the following formula to calculate a player's gameScore:
    totalPoints + 0.4 * FG - 0.7 * FGA - 0.4*(FTA - FT) + 0.7 * ORB + 
    0.3 * DRB + STL + 0.7 * AST + 0.7 * BLK - 0.4 * PF - TOV) / G
    

    Game Score was created by John Hollinger to give a rough measure of a player's productivity for a single game. The scale is similar to that of points scored (40 is an outstanding performance, 10 is an average performance, etc.).