def test_convert_game_clock(self):
     # Successful
     self.assertEqual(convert_game_clock("15:00", 1), 0)
     self.assertEqual(convert_game_clock("15:00", 2), 900)
     self.assertEqual(convert_game_clock("15:00", 5), 3600)
     self.assertEqual(convert_game_clock("0:24", 3), 2676)
     # Failure
     self.assertRaises(ValueError, convert_game_clock, "16:00", 1)
     self.assertRaises(ValueError, convert_game_clock, "14:61", 1)
     self.assertRaises(ValueError, convert_game_clock, "15:01", 1)
     self.assertRaises(ValueError, convert_game_clock, "-10:35", 1)
     self.assertRaises(ValueError, convert_game_clock, "-00:35", 1)
     self.assertRaises(ValueError, convert_game_clock, "00:35", 0)
예제 #2
0
 def test_convert_game_clock(self):
     # Successful
     self.assertEqual(convert_game_clock("15:00", 1), 0)
     self.assertEqual(convert_game_clock("15:00", 2), 900)
     self.assertEqual(convert_game_clock("15:00", 5), 3600)
     self.assertEqual(convert_game_clock("0:24", 3), 2676)
     # Failure
     self.assertRaises(ValueError, convert_game_clock, "16:00", 1)
     self.assertRaises(ValueError, convert_game_clock, "14:61", 1)
     self.assertRaises(ValueError, convert_game_clock, "15:01", 1)
     self.assertRaises(ValueError, convert_game_clock, "-10:35", 1)
     self.assertRaises(ValueError, convert_game_clock, "-00:35", 1)
     self.assertRaises(ValueError, convert_game_clock, "00:35", 0)
예제 #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