<commit_before>from tabulate import tabulate

class DeckAnalysis(object):
    """Analyze how a specific hero performs.
    """

    def __init__(self, games: list, hero: str):
        """Create a new analysis given a list of games and a hero."""
        self.games = games
        self.hero = hero

        self.wins = 0
        self.losses = 0
        self.opponents = {}
        self.__analyze()

    def __analyze(self):
        """Analyze the game data in the context of the hero."""

        for game in self.games:
            if not self.hero == game.hero:
                continue

            if game.won():
                self.wins += 1
            else:
                self.losses += 1

            # Initialize a dict the first time we encounter a new opponent hero.
            opponent = game.opponent
            self.opponents[opponent] = self.opponents.get(opponent, {'games': 0, 'wins': 0, 'losses': 0})
            self.opponents[opponent]['games'] += 1
            if game.won():
                self.opponents[opponent]['wins'] += 1
            else:
                self.opponents[opponent]['losses'] += 1
                
    def summarize(self):
        """Print a table summarizing the game results."""
        
        # We'll be adding more columns based on the opponent classes we encountered.
        headers = ['games', 'wins', 'losses', 'win %']

        # Add the data for the first columns summarizing all games.
        # Tabulate expects a list of lists, where each list represents a row of data.
        game_count = self.wins + self.losses
        table = [[game_count, self.wins, self.losses, (self.wins / game_count) * 100]]

        for opponent, result in sorted(self.opponents.items(), key=lambda k_v: k_v[1]['games'], reverse=True):
            # Add headers and data for this opponent
            headers.append(opponent + ' games')
            table[-1].append(result['games'])
            headers.append('wins')
            table[-1].append(result['wins'])
            headers.append('losses')
            table[-1].append(result['losses'])
            headers.append('win %')
            table[-1].append((result['wins'] / result['games']) * 100)<commit_msg>Switch the deck analysis display to have a row for each opponent<commit_after>from tabulate import tabulate

class DeckAnalysis(object):
    """Analyze how a specific hero performs.
    """

    def __init__(self, games: list, hero: str):
        """Create a new analysis given a list of games and a hero."""
        self.games = games
        self.hero = hero

        self.wins = 0
        self.losses = 0
        self.opponents = {}
        self.__analyze()

    def __analyze(self):
        """Analyze the game data in the context of the hero."""

        for game in self.games:
            if not self.hero == game.hero:
                continue

            if game.won():
                self.wins += 1
            else:
                self.losses += 1

            # Initialize a dict the first time we encounter a new opponent hero.
            opponent = game.opponent
            self.opponents[opponent] = self.opponents.get(opponent, {'games': 0, 'wins': 0, 'losses': 0})
            self.opponents[opponent]['games'] += 1
            if game.won():
                self.opponents[opponent]['wins'] += 1
            else:
                self.opponents[opponent]['losses'] += 1
                
    def summarize(self):
        """Print a table summarizing the game results."""
        headers = ['opponent', 'games', 'wins', 'losses', 'win %']

        # Add the data for the first columns summarizing all games.
        # Tabulate expects a list of lists, where each list represents a row of data.
        game_count = self.wins + self.losses
        table = [['All', game_count, self.wins, self.losses, (self.wins / game_count) * 100]]

        for opponent, result in sorted(self.opponents.items(), key=lambda k_v: k_v[1]['games'], reverse=True):
            # Add a row for this opponent.
            table.append([opponent, result['games'], result['wins'], result['losses'], (result['wins'] / result['games']) * 100])
{'fraction_non_alphanumeric': 0.12231604342581423, 'fraction_numerical': 0.00916767189384801, 'mean_word_length': 1.989185291997116, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4352725', 'n_tokens_mistral': 1196, 'n_tokens_neox': 1119, 'n_words': 367}