src.modules.backend.stats_manager

Module for managing game statistics and history.

Classes

StatsManager([history_file, event_bus])

Handles game statistics and history storage/retrieval.

class src.modules.backend.stats_manager.StatsManager(history_file='game_history.json', event_bus=None)[source]

Handles game statistics and history storage/retrieval.

__init__(history_file='game_history.json', event_bus=None)[source]
notify(event)[source]

Called when a relevant event occurs.

Parameters:

event – The event that occurred

save_history()[source]

Save game history to file.

Return type:

None

get_stats()[source]

Calculate and return current statistics dynamically from game history.

Return type:

Dict[str, Any]

get_history(limit=None)[source]

Get game history, optionally limited to the most recent games.

Return type:

List[Dict[str, Any]]

get_game_by_id(game_id)[source]

Get a specific game by its ID.

Parameters:

game_id (str) – The unique ID of the game to retrieve

Return type:

Optional[Dict[str, Any]]

Returns:

The game record if found, None otherwise

search_games(game_id=None, won=None, target_word=None, max_attempts=None)[source]

Search for games matching specific criteria.

Parameters:
  • game_id (Optional[str]) – Filter by game ID (exact match)

  • won (Optional[bool]) – Filter by game outcome (won/lost)

  • target_word (Optional[str]) – Filter by target word

  • max_attempts (Optional[int]) – Return only games with attempts <= this value

Return type:

List[Dict[str, Any]]

Returns:

List of matching game records

clear_all_history()[source]

Clear all game history and reset to blank.

Returns:

True if successful, False if there was an error

Return type:

bool

get_history_count()[source]

Get the total number of games in history.

Return type:

int

has_history()[source]

Check if there is any game history.

Return type:

bool