def test_convert_quarter(self):
     # Successful
     self.assertEqual(convert_quarter("1"), 1)
     self.assertEqual(convert_quarter("2"), 2)
     self.assertEqual(convert_quarter("3"), 3)
     self.assertEqual(convert_quarter("4"), 4)
     self.assertEqual(convert_quarter("OT"), 5)
     # Failure
     self.assertRaises(ValueError, convert_quarter, "0")
     self.assertRaises(ValueError, convert_quarter, "5")
     self.assertRaises(ValueError, convert_quarter, "Five")
Ejemplo n.º 2
0
 def test_convert_quarter(self):
     # Successful
     self.assertEqual(convert_quarter("1"), 1)
     self.assertEqual(convert_quarter("2"), 2)
     self.assertEqual(convert_quarter("3"), 3)
     self.assertEqual(convert_quarter("4"), 4)
     self.assertEqual(convert_quarter("OT"), 5)
     # Failure
     self.assertRaises(ValueError, convert_quarter, "0")
     self.assertRaises(ValueError, convert_quarter, "5")
     self.assertRaises(ValueError, convert_quarter, "Five")
Ejemplo n.º 3
0
    def __set_state(self, cols):
        """ Takes a list of columns from an HTML table and sets the "state"
        dictionary for the play.

        returns:
            A state dictionary with the following fields:
                {"offense": "home", "down": 2, "yards to first down": 10,
                "yards to goal": 36, "time": 398}
        """
        state = {}

        # Down
        down = convert_int(cols[2].get_text(strip=True))
        if down is not None:
            state["down"] = down

        # Quarter (Used to set the time, also set in the __parse_play())
        if self.current_play_info["quarter"] < 5:
            quarter = convert_quarter(cols[0].get_text(strip=True))
            self.current_play_info["quarter"] = quarter
        else:
            quarter = self.current_play_info["quarter"]

        # Time
        time_string = cols[1].get_text(strip=True)
        time = convert_game_clock(time_string, quarter)
        if time is not None:
            self.current_play_info["time"] = time
        else:
            time = self.last_play_info["time"]
        state["time"] = time

        # Yards to go
        ytfd = convert_int(cols[3].get_text(strip=True))
        if ytfd is not None:
            state["yards to first down"] = ytfd

        # Offense
        state["offense"] = self.current_play_info["offense"]

        # Yards to goal
        offense = state["offense"]
        if offense == "home":
            team_code = self.home
        else:
            team_code = self.away
        ytg = convert_field_position(cols[4].get_text(strip=True), team_code)
        if ytg is not None:
            state["yards to goal"] = ytg

        return state