-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8a3d079
commit 76fd722
Showing
1 changed file
with
22 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,46 @@ | ||
# format.py | ||
# results_formatter.py | ||
from ..state import GameState # Adjust the import according to your project structure | ||
|
||
def results(game_state: GameState) -> str: | ||
""" | ||
Takes a GameState object and formats its contents into plain text, then returns the text content. | ||
Formats the results from a GameState object into a readable string. | ||
Args: | ||
game_state (GameState): The game state object containing all game data. | ||
Returns: | ||
str: The content of the formatted results. | ||
str: A formatted string of the game results. | ||
""" | ||
# Format the results into a plain text string | ||
results_str = "General Game Stats:\n" | ||
results_str = "Game Statistics:\n" | ||
|
||
# Format general game statistics | ||
results_str += "\nGeneral Game Stats:\n" | ||
results_str += f"Total Frames: {len(game_state.frames)}\n" | ||
results_str += f"Number of Possessions: {len(game_state.possessions)}\n" | ||
results_str += f"Number of Shot Attempts: {len(game_state.shot_attempts)}\n\n" | ||
|
||
# Format Player Stats | ||
results_str += "Player Stats:\n" | ||
results_str += f"Number of Shot Attempts: {len(game_state.shot_attempts)}\n" | ||
# Format player statistics | ||
results_str += "\nPlayer Stats:\n" | ||
for player_id, player_state in game_state.players.items(): | ||
results_str += f"Player {player_id}:\n" | ||
results_str += f" Total Frames: {player_state.frames}\n" | ||
results_str += f" Field Goals Attempted: {player_state.field_goals_attempted}\n" | ||
results_str += f" Field Goals Made: {player_state.field_goals}\n" | ||
results_str += f" Points Scored: {player_state.points}\n" | ||
results_str += f" Field Goal Percentage: {player_state.field_goal_percentage}\n" | ||
results_str += f" Passes: {sum(player_state.passes.values())}\n" | ||
results_str += f" Assists: {player_state.assists}\n" | ||
results_str += f" Rebounds: {player_state.rebounds}\n\n" | ||
results_str += f" Field Goal Percentage: {player_state.field_goal_percentage:.2f}\n" | ||
results_str += f" Passes Made: {sum(player_state.passes.values())}\n" | ||
|
||
# Format Team Stats | ||
results_str += "Team Stats:\n" | ||
for team_id, team_state in [('Team 1', game_state.team1), ('Team 2', game_state.team2)]: | ||
# Format team statistics | ||
results_str += "\nTeam Stats:\n" | ||
for team_id, team in [('Team 1', game_state.team1), ('Team 2', game_state.team2)]: | ||
results_str += f"{team_id}:\n" | ||
results_str += f" Shots Attempted: {team_state.shots_attempted}\n" | ||
results_str += f" Shots Made: {team_state.shots_made}\n" | ||
results_str += f" Points: {team_state.points}\n" | ||
results_str += f" Field Goal Percentage: {team_state.field_goal_percentage}\n\n" | ||
results_str += f" Shots Attempted: {team.shots_attempted}\n" | ||
results_str += f" Shots Made: {team.shots_made}\n" | ||
results_str += f" Points: {team.points}\n" | ||
results_str += f" Field Goal Percentage: {team.field_goal_percentage:.2f}\n" | ||
|
||
# Format Ball Stats | ||
results_str += "Ball Stats:\n" | ||
# Format ball statistics | ||
results_str += "\nBall Stats:\n" | ||
results_str += f"Ball Frames: {game_state.ball.frames}\n" | ||
|
||
# Return the results string | ||
return results_str |