def test_get_penalty_type(self):
     self.__set_penalty_consts()
     # Successful
     self.assertEqual(get_penalty_type(self.penalty_splits[0][0]), "accepted")
     self.assertEqual(get_penalty_type(self.penalty_splits[1][0]), "no play")
     self.assertEqual(get_penalty_type(self.penalty_splits[2][0]), "accepted")
     self.assertEqual(get_penalty_type(self.penalty_splits[2][1]), "declined")
     self.assertEqual(get_penalty_type(self.penalty_splits[3][0]), "declined")
     self.assertEqual(get_penalty_type(self.penalty_splits[4][0]), "no play")
     self.assertEqual(get_penalty_type(self.penalty_splits[5][0]), "accepted")
     self.assertEqual(get_penalty_type(self.penalty_splits[7][0]), "accepted")
Esempio n. 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
Esempio n. 3
0
 def test_get_penalty_type(self):
     self.__set_penalty_consts()
     # Successful
     self.assertEqual(get_penalty_type(self.penalty_splits[0][0]),
                      "accepted")
     self.assertEqual(get_penalty_type(self.penalty_splits[1][0]),
                      "no play")
     self.assertEqual(get_penalty_type(self.penalty_splits[2][0]),
                      "accepted")
     self.assertEqual(get_penalty_type(self.penalty_splits[2][1]),
                      "declined")
     self.assertEqual(get_penalty_type(self.penalty_splits[3][0]),
                      "declined")
     self.assertEqual(get_penalty_type(self.penalty_splits[4][0]),
                      "no play")
     self.assertEqual(get_penalty_type(self.penalty_splits[5][0]),
                      "accepted")
     self.assertEqual(get_penalty_type(self.penalty_splits[7][0]),
                      "accepted")