diff --git a/docs/source/cli.rst b/docs/source/cli.rst index b90e9aa..f0c1ddb 100644 --- a/docs/source/cli.rst +++ b/docs/source/cli.rst @@ -20,6 +20,8 @@ Command Line Reference +--------------------+----------------+----------------------------------------------------------+ | -wc, --winchance | | Print win chance data for an analysis on the console | +--------------------+----------------+----------------------------------------------------------+ +| -i, --info | | Print a table of game information | ++--------------------+----------------+----------------------------------------------------------+ | -ex, --export | | Export analysis results | +--------------------+----------------+----------------------------------------------------------+ | -pl, --players | | Print a table of players on the console | diff --git a/docs/source/workflow.rst b/docs/source/workflow.rst index aa35841..29e2726 100644 --- a/docs/source/workflow.rst +++ b/docs/source/workflow.rst @@ -61,6 +61,7 @@ To report on the analysis for game that's been loaded and analysed, use the foll run.sh --black --reference "" --engine run.sh --summary --reference "" --engine run.sh --winchance --reference "" --engine + run.sh --info --reference "" Where: @@ -69,6 +70,7 @@ Where: - "--black" tabulates the detailed per-move analysis for black - "--summary" provides a summary consisting of ACPL, accuracy and move annotations (dubious, mistake, blunder) for both players - "--winchance" tabulates the data used to generate a "Win%" chart [#1]_ +- "--info" tabulates the game headers, read from the PGN file Exporting Analysis Results -------------------------- diff --git a/src/chess_analyser/cli/dispatcher.py b/src/chess_analyser/cli/dispatcher.py index 5366985..f892f74 100644 --- a/src/chess_analyser/cli/dispatcher.py +++ b/src/chess_analyser/cli/dispatcher.py @@ -1,10 +1,10 @@ import argparse from ..reporting import tabulate_analysis, tabulate_summary, tabulate_win_chance, \ - write_analysis_spreadsheet, write_analysis_document, tabulate_players + write_analysis_spreadsheet, write_analysis_document, tabulate_players, tabulate_game_info from ..analysis.analysis import analyse_game from ..constants import PROGRAM_NAME, PROGRAM_DESCRIPTION, PROGRAM_VERSION, OPT_LOAD, OPT_ANALYSE, \ - OPT_RESULTS, OPT_WHITE, OPT_BLACK, OPT_SUMMARY, OPT_WIN_CHANCE, OPT_EXPORT, OPT_PLAYERS, OPT_ENGINE, OPT_PGN, \ - OPT_REFERENCE, OPT_VERBOSE, OPT_XLSX, OPT_DOCX + OPT_RESULTS, OPT_WHITE, OPT_BLACK, OPT_SUMMARY, OPT_WIN_CHANCE, OPT_EXPORT, OPT_PLAYERS, OPT_INFO, \ + OPT_ENGINE, OPT_PGN, OPT_REFERENCE, OPT_VERBOSE, OPT_XLSX, OPT_DOCX from ..pgn import import_pgn, export_pgn @@ -29,6 +29,7 @@ def configure_parser(): parser.add_argument("-wc", "--winchance", action="store_true", help="Print win chance data for an analysis on the console") parser.add_argument("-ex", "--export", action="store_true", help="Export analysis results") parser.add_argument("-pl", "--players", action="store_true", help="Print a table of players on the console") + parser.add_argument("-i", "--info", action="store_true", help="Print a table of game information") # Values parser.add_argument("-p", "--pgn", nargs=1, help="Path to PGN file holding the game to analysis") @@ -64,6 +65,7 @@ def parse_command_line(): OPT_WIN_CHANCE: args.winchance, OPT_EXPORT: args.export, OPT_PLAYERS: args.players, + OPT_INFO: args.info, # Values OPT_ENGINE: args.engine[0] if args.engine else None, @@ -98,6 +100,9 @@ def dispatch_report(options): if options[OPT_PLAYERS]: tabulate_players() + if options[OPT_INFO]: + tabulate_game_info(options) + def dispatch_export(options): """ diff --git a/src/chess_analyser/constants/__init__.py b/src/chess_analyser/constants/__init__.py index d6acbfb..0b09429 100644 --- a/src/chess_analyser/constants/__init__.py +++ b/src/chess_analyser/constants/__init__.py @@ -13,6 +13,7 @@ OPT_WIN_CHANCE = "winchance" OPT_EXPORT = "export" OPT_PLAYERS = "players" +OPT_INFO = "info" OPT_ENGINE = "engine" OPT_PGN = "pgn" diff --git a/src/chess_analyser/pgn/pgn_export.py b/src/chess_analyser/pgn/pgn_export.py index 0312b74..6d8f177 100644 --- a/src/chess_analyser/pgn/pgn_export.py +++ b/src/chess_analyser/pgn/pgn_export.py @@ -26,7 +26,7 @@ def export_pgn(options): raise ValueError(f"No moves found for the game with ID {game.id}") # Get the game headers - headers = load_game_information(options[OPT_REFERENCE], options[OPT_ENGINE], True, False) + headers = load_game_information(options[OPT_REFERENCE], True, None) # TODO: There are better ways to get this! result_list = [h[1] for h in headers if h[0] == "Result"] result = result_list[0] if result_list else "*" diff --git a/src/chess_analyser/reporting/__init__.py b/src/chess_analyser/reporting/__init__.py index 3701797..d2c696d 100644 --- a/src/chess_analyser/reporting/__init__.py +++ b/src/chess_analyser/reporting/__init__.py @@ -1,5 +1,5 @@ from .console_reports import print_analysis_table_headers, print_analysis_table_row, tabulate_analysis, tabulate_summary, \ - tabulate_win_chance, tabulate_players + tabulate_win_chance, tabulate_players, tabulate_game_info from .document import write_analysis_document from .images import write_board_position_image, write_win_percent_chart_image from .spreadsheet import write_analysis_spreadsheet @@ -13,6 +13,7 @@ "tabulate_summary", "tabulate_win_chance", "tabulate_players", + "tabulate_game_info", "write_analysis_document", "write_board_position_image", "write_win_percent_chart_image", diff --git a/src/chess_analyser/reporting/console_reports.py b/src/chess_analyser/reporting/console_reports.py index d3a78da..67b8ed9 100644 --- a/src/chess_analyser/reporting/console_reports.py +++ b/src/chess_analyser/reporting/console_reports.py @@ -1,4 +1,5 @@ from .constants import ANALYSIS_HEADERS, SUMMARY_HEADERS, WIN_CHANCE_HEADERS +from .game_info import load_game_information from ..constants import OPT_ENGINE, OPT_REFERENCE, OPT_WHITE, OPT_BLACK, WHITE, BLACK from ..database.logic import load_analysis, get_analysis_engine_id, list_players from ..analysis.calculations import calculate_summary_statistics, calculate_win_chance_chart_data, extract_player_analysis @@ -151,3 +152,15 @@ def tabulate_players(): print_row(player, column_widths) +def tabulate_game_info(options): + # Load the game information + info = load_game_information(options[OPT_REFERENCE], False, None) + + # Write the table headers + column_widths = [20, 60] + headers = ["Item", "Value"] + print_row(headers, column_widths) + + # Write the information + for i in info: + print_row(i, column_widths) diff --git a/src/chess_analyser/reporting/document.py b/src/chess_analyser/reporting/document.py index f5506dc..8507656 100644 --- a/src/chess_analyser/reporting/document.py +++ b/src/chess_analyser/reporting/document.py @@ -120,7 +120,7 @@ def write_analysis_document(options): run.add_picture(board_position_image) # Add the game information - info = load_game_information(options[OPT_REFERENCE], options[OPT_ENGINE], False, True) + info = load_game_information(options[OPT_REFERENCE], False, options[OPT_ENGINE]) if info: document.add_heading(f"Game Information", level=1) add_table_to_analysis_document(document, ["Item", "Value"], info) diff --git a/src/chess_analyser/reporting/game_info.py b/src/chess_analyser/reporting/game_info.py index 379068d..dd4f355 100644 --- a/src/chess_analyser/reporting/game_info.py +++ b/src/chess_analyser/reporting/game_info.py @@ -2,9 +2,13 @@ from ..engines import load_engine_definitions, get_engine_display_name -def load_game_information(identifier, engine, pgn_only, include_engine_name): +def load_game_information(identifier, pgn_only, engine): """ Load the game meta-data for a specified game + + :param identifier: Game identifier - reference or ID + :param pgn_only: Only return headers that are part of the PGN specification + :param engine: Name of the engine - if not None, included in the headers """ headers = [] @@ -15,7 +19,7 @@ def load_game_information(identifier, engine, pgn_only, include_engine_name): game = load_game(identifier) if game.meta_data: # Add the analysis engine to the game information, if required - if include_engine_name: + if engine: load_engine_definitions() engine_display_name = get_engine_display_name(engine) headers.append(["Analysis Engine", engine_display_name]) diff --git a/src/chess_analyser/reporting/spreadsheet.py b/src/chess_analyser/reporting/spreadsheet.py index 690c2a9..2eb5848 100644 --- a/src/chess_analyser/reporting/spreadsheet.py +++ b/src/chess_analyser/reporting/spreadsheet.py @@ -106,7 +106,7 @@ def write_analysis_spreadsheet(options): chart_table = [[i + 1, x] for i, x in enumerate(chart_data)] # Get the game information - info = load_game_information(options[OPT_REFERENCE], options[OPT_ENGINE], False, True) + info = load_game_information(options[OPT_REFERENCE], False, options[OPT_ENGINE]) # Create a new Excel workbook to hold the analysis details workbook = create_workbook(options[OPT_XLSX])