def test_get_penalty_name(self):
     self.__set_penalty_consts()
     # Successful
     self.assertEqual(
             get_penalty_name(self.penalty_splits[0][0]),
             "Getting in the way (15 yards)"
             )
     self.assertEqual(
             get_penalty_name(self.penalty_splits[1][0]),
             "Too many ghosts on the field"
             )
     self.assertEqual(
             get_penalty_name(self.penalty_splits[2][0]),
             "Being a Fascist"
             )
     self.assertEqual(get_penalty_name(self.penalty_splits[2][1]),
             "Taking Bribes"
             )
     self.assertEqual(get_penalty_name(self.penalty_splits[3][0]),
             "Illegal Formation"
             )
     self.assertEqual(get_penalty_name(self.penalty_splits[4][0]),
             "Offensive Beach Storming"
             )
     self.assertEqual(get_penalty_name(self.penalty_splits[5][0]),
             "Illegal Contact"
             )
     self.assertEqual(get_penalty_name(self.penalty_splits[7][0]),
             "Illegal Fog"
             )
Example #2
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
Example #3
0
 def test_get_penalty_name(self):
     self.__set_penalty_consts()
     # Successful
     self.assertEqual(get_penalty_name(self.penalty_splits[0][0]),
                      "Getting in the way (15 yards)")
     self.assertEqual(get_penalty_name(self.penalty_splits[1][0]),
                      "Too many ghosts on the field")
     self.assertEqual(get_penalty_name(self.penalty_splits[2][0]),
                      "Being a Fascist")
     self.assertEqual(get_penalty_name(self.penalty_splits[2][1]),
                      "Taking Bribes")
     self.assertEqual(get_penalty_name(self.penalty_splits[3][0]),
                      "Illegal Formation")
     self.assertEqual(get_penalty_name(self.penalty_splits[4][0]),
                      "Offensive Beach Storming")
     self.assertEqual(get_penalty_name(self.penalty_splits[5][0]),
                      "Illegal Contact")
     self.assertEqual(get_penalty_name(self.penalty_splits[7][0]),
                      "Illegal Fog")