Exemple #1
0
    def __set_penalty(self):
        """ Takes the description of a play from self with a penalty in it and
        sets the "penalty" dictionary for the play.

        returns:
            A penalty dictionary with the following fields:
                "penalty": { "type": "Illegal Use of Hands",
                "on": "home", "player": "Terrence Cody", "yards": -5,
                "no play": True }
        """
        penalties = {
                "penalties": []
                }
        #TODO: What do we do when there are multiple penalties?
        # I think we can get the team the penalty was on by looking at the down
        # marker for the previous play and the current play. However, this
        # doesn't work if we have multiple penalties.
        no_play = False
        for pen_string in split_penalties(self.current_play_info["description"]):
            p = {}
            # Set the name of the penalty
            p["name"] = get_penalty_name(pen_string)
            # Set the yardage
            yards = get_penalty_yards(pen_string)
            if yards:
                p["yards"] = yards
            # Set the offending player
            p["offender"] = get_penalty_player(
                    pen_string,
                    self.home,
                    self.away
                    )
            # Set the team
            p["team"] = get_penalty_team(
                    pen_string,
                    self.current_play_info["offense"],
                    self.home,
                    self.away,
                    self.home_players,
                    self.away_players
                    )
            # Get type info
            p_type = get_penalty_type(pen_string)
            if p_type == "declined":
                p["accepted"] = False
            else:
                p["accepted"] = True
                if p_type == "no play":
                    no_play = True

            # Fill in the full dictionary
            penalties["penalties"].append(p)

        penalties["no play"] = no_play

        return penalties
Exemple #2
0
 def test_get_penalty_yards(self):
     self.__set_penalty_consts()
     # Successful
     self.assertEqual(get_penalty_yards(self.penalty_splits[0][0]), 15)
     self.assertEqual(get_penalty_yards(self.penalty_splits[1][0]), 5)
     self.assertEqual(get_penalty_yards(self.penalty_splits[2][0]), 5)
     self.assertEqual(get_penalty_yards(self.penalty_splits[2][1]), None)
     self.assertEqual(get_penalty_yards(self.penalty_splits[3][0]), None)
     self.assertEqual(get_penalty_yards(self.penalty_splits[4][0]), 100)
     self.assertEqual(get_penalty_yards(self.penalty_splits[5][0]), 137)
     self.assertEqual(get_penalty_yards(self.penalty_splits[7][0]), 1000)
     # Failure
     self.assertRaises(ValueError, get_penalty_yards, "Ten yards")
 def test_get_penalty_yards(self):
     self.__set_penalty_consts()
     # Successful
     self.assertEqual(
             get_penalty_yards(self.penalty_splits[0][0]),
             15
             )
     self.assertEqual(
             get_penalty_yards(self.penalty_splits[1][0]),
             5
             )
     self.assertEqual(
             get_penalty_yards(self.penalty_splits[2][0]),
             5
             )
     self.assertEqual(
             get_penalty_yards(self.penalty_splits[2][1]),
             None
             )
     self.assertEqual(
             get_penalty_yards(self.penalty_splits[3][0]),
             None
             )
     self.assertEqual(
             get_penalty_yards(self.penalty_splits[4][0]),
             100
             )
     self.assertEqual(
             get_penalty_yards(self.penalty_splits[5][0]),
             137
             )
     self.assertEqual(
             get_penalty_yards(self.penalty_splits[7][0]),
             1000
             )
     # Failure
     self.assertRaises(ValueError, get_penalty_yards, "Ten yards")