Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/source/cli.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand Down
2 changes: 2 additions & 0 deletions docs/source/workflow.rst
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ To report on the analysis for game that's been loaded and analysed, use the foll
run.sh --black --reference "<unique-game-reference>" --engine <engine-name>
run.sh --summary --reference "<unique-game-reference>" --engine <engine-name>
run.sh --winchance --reference "<unique-game-reference>" --engine <engine-name>
run.sh --info --reference "<unique-game-reference>"

Where:

Expand All @@ -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
--------------------------
Expand Down
11 changes: 8 additions & 3 deletions src/chess_analyser/cli/dispatcher.py
Original file line number Diff line number Diff line change
@@ -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


Expand All @@ -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")
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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):
"""
Expand Down
1 change: 1 addition & 0 deletions src/chess_analyser/constants/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
OPT_WIN_CHANCE = "winchance"
OPT_EXPORT = "export"
OPT_PLAYERS = "players"
OPT_INFO = "info"

OPT_ENGINE = "engine"
OPT_PGN = "pgn"
Expand Down
2 changes: 1 addition & 1 deletion src/chess_analyser/pgn/pgn_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 "*"
Expand Down
3 changes: 2 additions & 1 deletion src/chess_analyser/reporting/__init__.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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",
Expand Down
13 changes: 13 additions & 0 deletions src/chess_analyser/reporting/console_reports.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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)
2 changes: 1 addition & 1 deletion src/chess_analyser/reporting/document.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 6 additions & 2 deletions src/chess_analyser/reporting/game_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []

Expand All @@ -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])
Expand Down
2 changes: 1 addition & 1 deletion src/chess_analyser/reporting/spreadsheet.py
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down