def load_analysis(self): if not self.analysis_from_sgf: return False try: szx, szy = self.root.board_size board_squares = szx * szy version = self.root.get_property("KTV", ANALYSIS_FORMAT_VERSION) if version > ANALYSIS_FORMAT_VERSION: raise ValueError( f"Can not decode analysis data with version {version}, please update {PROGRAM_NAME}" ) ownership_data, policy_data, main_data, *_ = [ gzip.decompress(base64.standard_b64decode(data)) for data in self.analysis_from_sgf ] self.analysis = { **json.loads(main_data), "policy": unpack_floats(policy_data, board_squares + 1), "ownership": unpack_floats(ownership_data, board_squares), } return True except Exception as e: print(f"Error in loading analysis: {e}") return False
def analysis_loads(property_array, board_squares, version): if version > ANALYSIS_FORMAT_VERSION: raise ValueError( f"Can not decode analysis data with version {version}, please update {PROGRAM_NAME}" ) ownership_data, policy_data, main_data, *_ = [ gzip.decompress(base64.standard_b64decode(data)) for data in property_array ] return { **json.loads(main_data), "policy": unpack_floats(policy_data, board_squares + 1), "ownership": unpack_floats(ownership_data, board_squares), }