From 999954cc8d663a28b3058a9e588abcf97127d788 Mon Sep 17 00:00:00 2001 From: Sander Land Date: Mon, 21 Dec 2020 11:48:06 +0100 Subject: [PATCH] fix cache --- katrain/__main__.py | 5 +++++ katrain/core/game.py | 10 ++++++---- katrain/core/game_node.py | 1 + katrain/gui/popups.py | 4 ++-- 4 files changed, 14 insertions(+), 6 deletions(-) diff --git a/katrain/__main__.py b/katrain/__main__.py index a49b68e..2efd271 100644 --- a/katrain/__main__.py +++ b/katrain/__main__.py @@ -707,6 +707,11 @@ def run_app(): print(f"Exception {inst.__class__}: {inst.args}\n{trace}") return ExceptionManager.PASS + import yappi + + yappi.set_clock_type("cpu") + yappi.start() + ExceptionManager.add_handler(CrashHandler()) app = KaTrainApp() signal.signal(signal.SIGINT, app.signal_handler) diff --git a/katrain/core/game.py b/katrain/core/game.py index dcf8401..e71662f 100644 --- a/katrain/core/game.py +++ b/katrain/core/game.py @@ -396,7 +396,7 @@ class Game: + f"\ncaptures: {self.prisoner_count}" ) - def generate_filename(self): + def update_root_properties(self): def player_name(player_info): if player_info.name and player_info.player_type == PLAYER_HUMAN: return player_info.name @@ -413,8 +413,10 @@ class Game: x_properties[bw + "R"] = rank_label(player_info.calculated_rank) if "+" in str(self.end_result): x_properties["RE"] = self.end_result - x_properties["KTV"] = ANALYSIS_FORMAT_VERSION self.root.properties = {**root_properties, **{k: [v] for k, v in x_properties.items()}} + + def generate_filename(self): + self.update_root_properties() player_names = { bw: re.sub(r"[\u200b\u3164'<>:\"/\\|?*]", "", self.root.get_property("P" + bw, bw)) for bw in "BW" } @@ -422,14 +424,14 @@ class Game: return f"{base_game_name} {self.game_id}.sgf" def write_sgf( - self, filename: str = None, trainer_config: Optional[Dict] = None, + self, filename: str, trainer_config: Optional[Dict] = None, ): if trainer_config is None: trainer_config = self.katrain.config("trainer", {}) save_feedback = trainer_config.get("save_feedback", False) eval_thresholds = trainer_config["eval_thresholds"] save_analysis = trainer_config.get("save_analysis", False) - + self.update_root_properties() show_dots_for = { bw: trainer_config.get("eval_show_ai", True) or self.katrain.players_info[bw].human for bw in "BW" } diff --git a/katrain/core/game_node.py b/katrain/core/game_node.py index 148b337..0896f3a 100644 --- a/katrain/core/game_node.py +++ b/katrain/core/game_node.py @@ -141,6 +141,7 @@ class GameNode(SGFNode): ] properties["CA"] = ["UTF-8"] properties["AP"] = [f"{PROGRAM_NAME}:{VERSION}"] + properties["KTV"] = [ANALYSIS_FORMAT_VERSION] if self.shortcut_from: properties["KTSF"] = [id(self.shortcut_from)] elif "KTSF" in properties: diff --git a/katrain/gui/popups.py b/katrain/gui/popups.py index b2436e5..324b3b1 100644 --- a/katrain/gui/popups.py +++ b/katrain/gui/popups.py @@ -29,7 +29,7 @@ from katrain.core.constants import ( OUTPUT_ERROR, OUTPUT_INFO, STATUS_INFO, - DATA_FOLDER, + DATA_FOLDER, SGF_INTERNAL_COMMENTS_MARKER, ) from katrain.core.engine import KataGoEngine from katrain.core.lang import i18n, rank_label @@ -267,7 +267,7 @@ class NewGamePopup(QuickConfigGui): def update_from_current_game(self, *args): for bw in "BW": name = self.katrain.game.root.get_property("P" + bw, None) - if name: + if name and SGF_INTERNAL_COMMENTS_MARKER not in name: self.player_name[bw].text = name rules = self.normalized_rules() self.km.text = str(self.katrain.game.root.komi)