예제 #1
0
    def test_neutral(self):
        # This test uses GetGame to return two `ELOKnownGame` instances and
        # two `ELONeutralKnownGame` instances, checking their margins
        team_a = ELO("NE", 1744)
        team_b = ELO("DET", 1540)

        logging.info(
            "Assuming NE {1744} vs DET {1540} at NE ending 34-26; delta = 269")
        self.assertEqual(
            GetGame(team_a, team_b, 34, 26).ELOMargin(), 269,
            "Expected ELO Margin 65 + 1744 - 1540 = 269")

        logging.info(
            "Assuming NE {1744} vs DET {1540} at DET ending 34-26; delta = 139"
        )
        self.assertEqual(
            GetGame(team_b, team_a, 26, 34).ELOMargin(), -139,
            "Expected ELO Margin 65 + 1540 - 1744 = -139")

        logging.info(
            "Assuming NE {1744} vs DET {1540} at a neutral site ending 34-26; delta = 204"
        )
        self.assertEqual(
            GetGame(ELO("*NE", team_a.elo), team_b, 34, 26).ELOMargin(), 204,
            "Expected ELO Margin 1744 - 1540 = 204")
        self.assertEqual(
            GetGame(ELO("*DET", team_b.elo), team_a, 34, 26).ELOMargin(), -204,
            "Expected ELO Margin 1540 - 1744 = - 204")
예제 #2
0
 def test_raises(self):
     game = ELOKnownGame(ELO('ATL', 1541, 6, 1), ELO('TB', 1351, 2, 4), 20,
                         23)
     game.winner = 'HOU'
     with self.assertRaises(AttributeError):
         # This should fail upon trying to access `self.winner.name`
         game.loser  # Statement does have effect since this is a property it is a function call
     game.winner = ELO('HOU', 1450, 3, 5)
     with self.assertRaises(KeyError):
         # This should fail as the temporary dictionary only stores ATL and TB, not HOU
         game.loser
     with self.assertRaises(ValueError):
         # This has a sanity check to ensure the winner is either home or away
         game.UpdateTeams()
예제 #3
0
    def FromJSON(cls, json_file):
        """

        :param json_file:
        :return:
        """
        if not json_file.endswith('.json'):
            json_file += '.json'
        with open(json_file) as f:
            data = json.load(f)
        for team, val in data.items():
            if isinstance(val, ELO):
                continue
            if isinstance(val, int):
                data[team] = ELO(team, val)
            elif isinstance(val, List[int]):
                data[team] = ELO(team, *val)
        return cls(data)
예제 #4
0
 def test_Week08_TBatATL(self):
     logging.info("Testing TB @ ATL Week 8 2015")
     logging.info("Favored: Home; Winner: Home")
     data = {
         'home': ELO('ATL', 1541, 6, 1),
         'away': ELO('TB', 1351, 2, 4),
         'winner': ELO('TB', 1376, 3, 4),
         'loser': ELO('ATL', 1516, 6, 2),
         'home_points': 20,
         'away_points': 23,
         'spread': 3,
         'home_win_min': 0.812,
         'home_win_max': 0.813,
         'away_win_min': 0.187,
         'away_win_max': 0.188,
         'elo_points': 25
     }
     game = self.run_game(data)
     self.assertLess(
         game.winner, game.loser,
         f"Expected {game.winner} to be less than {game.loser}")
     logging.info("Test Passed")
예제 #5
0
 def test_Week11_GBatMIN(self):
     # Home team favored and lost
     logging.info("Testing GB @ MIN Week 11 2015")
     logging.info("Favored: Home; Winner: Away")
     data = {
         'home': ELO('MIN', 1586, 7, 2),
         'away': ELO('GB', 1619, 6, 3),
         'winner': ELO('GB', 1650, 7, 3),
         'loser': ELO('MIN', 1555, 7, 3),
         'home_points': 13,
         'away_points': 30,
         'spread': 17,
         'home_win_min': 0.54,
         'home_win_max': 0.56,
         'away_win_min': 0.44,
         'away_win_max': 0.46,
         'elo_points': 31
     }
     game = self.run_game(data)
     self.assertLess(
         game.loser, game.winner,
         f"Expected {game.loser} to be less than {game.winner}")
     logging.info("Test Passed")
예제 #6
0
 def test_Week17_NEatMIA(self):
     # Away team favored but lost
     logging.info("Testing NE @ MIA Week 17 2015")
     logging.info("Favored: Away; Winner: Home")
     data = {
         'home': ELO('MIA', 1361, 5, 10),
         'away': ELO('NE', 1689, 12, 3),
         'winner': ELO('MIA', 1407, 6, 10),
         'loser': ELO('NE', 1643, 12, 4),
         'home_points': 20,
         'away_points': 10,
         'spread': 10,
         'home_win_min': 0.180,
         'home_win_max': 0.181,
         'away_win_min': 0.819,
         'away_win_max': 0.820,
         'elo_points': 46
     }
     game = self.run_game(data)
     self.assertLess(
         game.winner, game.loser,
         f"Expected {game.winner} to be less than {game.loser}")
     logging.info("Test Passed")
예제 #7
0
 def test_Week14_SEAatBAL(self):
     # Away team favored and won
     logging.info("Testing SEA @ BAL Week 14 2015")
     logging.info("Favored: Away; Winner: Away")
     data = {
         'home': ELO('BAL', 1491, 4, 8),
         'away': ELO('SEA', 1676, 7, 5),
         'winner': ELO('SEA', 1697, 8, 5),
         'loser': ELO('BAL', 1470, 4, 9),
         'home_points': 6,
         'away_points': 35,
         'spread': 29,
         'home_win_min': 0.332,
         'home_win_max': 0.334,
         'away_win_min': 0.666,
         'away_win_max': 0.667,
         'elo_points': 21
     }
     game = self.run_game(data)
     self.assertLess(
         game.loser, game.winner,
         f"Expected {game.loser} to be less than {game.winner}")
     logging.info("Test Passed")
예제 #8
0
 def ToELO(self) -> ELO:
     return ELO(*self.data)