Exemplo n.º 1
0
class Analyzer:
    def __init__(self, games, previous_length):
        self.previous_length = previous_length
        self.data_store = DataStore(previous_length)
        self.games = [Attributes(game) for game in games]

    def run(self):
        games_dict = {}
        for game in self.games:
            away_team = self.data_store.get_data(game.away_team)
            home_team = self.data_store.get_data(game.home_team)
            if not away_team or not home_team:
                self.add_game_data(game)
                continue
            enough_away_stats = len(
                away_team.previous_stats) == self.previous_length
            enough_home_stats = len(
                home_team.previous_stats) == self.previous_length
            enough_previous_stats = enough_away_stats and enough_home_stats
            if not enough_previous_stats:
                self.add_game_data(game)
                continue
            away_pred = predict_score(away_team, home_team)
            home_pred = predict_score(home_team, away_team)
            games_dict[game.id] = (away_pred, home_pred)
        return games_dict

    def add_game_data(self, game):
        self.data_store.add_data(game.away_team)
        self.data_store.add_data(game.home_team)
        for player in game.away_players:
            self.data_store.add_data(player)
        for player in game.home_players:
            self.data_store.add_data(player)