def decompile_replay(replay_path, output_path: str = None, overwrite: bool = True, rattletrap_path: str = None): """ Takes a path to the replay and outputs the json of that replay. :param replay_path: Path to a specific replay. :param output_path: The output path of rattletrap. :param overwrite: True if we should recreate the json even if it already exists. :param rattletrap_path: Custom location for rattletrap executable. Path to folder. :return: The json created from rattle trap. """ return run_rattletrap.decompile_replay(replay_path, output_path, overwrite, rattletrap_path)
def analyse_replay(replay: str, output_path: str = None): json_ = None if output_path is not None: output_path_ = Path(output_path) if output_path_.is_file(): with timer('Loading previously decompiled replay'): with output_path_.open("r") as f: json_ = json.load(f) if json_ is None: with timer('Decompiling replay'): json_ = decompile_replay(replay, output_path=output_path) with timer('Parsing json'): json_parser_game = JsonParserGame() json_parser_game.initialize(loaded_json=json_) with timer('Creating protobuf game'): game = create_game(json_parser_game) # print(game) with timer('Creating full pandas DataFrame'): df = create_data_frame(json_parser_game) # print(df.memory_usage()) events = game.events # with timer('Getting old hits'): # # old hits # old_hit_frames = BaseHit.get_hits_from_game(json_parser_game, None, None, df, None) with timer('Getting hits'): # new hits get_hits(events, game, df) with timer('Calculating hit types'): calculate_hit_types(events.hits, game, df) with timer('Calculating pressures'): calculate_pressures(events, game, df) with timer("Calculating stats"): analysis = calculate_stats(events, game, df) return json_parser_game, game, df, events, analysis
def decompile_replay(replay_path, output_path: str = None, overwrite=True): """ Takes a path to the replay and outputs the json of that replay. :param replay_path: Path to a specific replay. :param output_path: The output path of rattletrap. :param overwrite: True if we should recreate the json even if it already exists. :return: The json created from rattle trap. """ binaries = [ f for f in os.listdir(os.path.join(BASE_DIR, 'rattletrap')) if not f.endswith('.py') ] platform = pt.system() if platform == 'Windows': binary = [f for f in binaries if f.endswith('.exe')][0] elif platform == 'Linux': binary = [f for f in binaries if 'linux' in f][0] elif platform == 'Darwin': binary = [f for f in binaries if 'osx' in f][0] else: raise Exception('Unknown platform, unable to process replay file.') return run_rattletrap.decompile_replay(replay_path, output_path)