Xiangiqgame
AI engine for Xiangqi
Loading...
Searching...
No Matches
game_output_generator.py
Go to the documentation of this file.
1"""
2Contains the GameOutputGenerator class.
3"""
4
5from pathlib import Path
6
7from xiangqipy.game_summary import GameSummary
8from xiangqipy.game_summary_io import export_game_summary
9from xiangqipy.game_summary_plot_manager import GameSummaryPlotManager
10
11
13 """
14 Outputs GameSummary to .json file, and saves plots to a .png file.
15 """
16
18 self,
19 game_summary: GameSummary,
20 output_dir_suffix: str = None,
21 custom_output_root: Path = None,
22 # game_collection_id: str = None,
23 ):
24 self.game_summary = game_summary
25 self.output_dir_suffix = output_dir_suffix
26 self.custom_output_root = custom_output_root
28 # self.game_collection_id = game_collection_id
29
30 def create_output_dir(self) -> Path:
31
32 output_dir_name = self.game_summary.game_id
33 if self.output_dir_suffix:
34 output_dir_name += f"-{self.output_dir_suffix}"
35
36 if self.custom_output_root:
37 output_root = self.custom_output_root
38 else:
39 output_root = (
40 Path(__file__).parent.parent.parent / "data" / "game_summaries"
41 )
42
43 game_output_dir_name = self.game_summary.game_id
44 if self.output_dir_suffix:
45 game_output_dir_name += f"-{self.output_dir_suffix}"
46
47 game_output_dir = output_root / game_output_dir_name
48 game_output_dir.mkdir(parents=True, exist_ok=True)
49
50 return game_output_dir
51
52 def generate_output(self):
53 # output_dir = self.create_output_dir()
54 plot_manager = GameSummaryPlotManager(game_summary=self.game_summary)
55 plot_manager.plot(show_plot=False)
56
57 game_summary_path = self.output_dir / f"{self.game_summary.game_id}.json"
58 export_game_summary(
59 game_summary=self.game_summary, path=game_summary_path
60 )
61
62 plot_manager.save_figure(
63 path=self.output_dir / f"{self.game_summary.game_id}.png"
64 )
Outputs GameSummary to .json file, and saves plots to a .png file.
def __init__(self, GameSummary game_summary, str output_dir_suffix=None, Path custom_output_root=None)
Manages the layout and file output of a figure containing multiple plots of data from a GameSummary.
Contains functions for importing / exporting a GameSummary from / to .json file.
Contains the GameSummaryPlotManager class.
GameSummary class and its component classes.
Definition: game_summary.py:1