def parse(self, best_counters=False): """ Use the spawningtool parser for `.sc2replay` file. :param file: :return: replay """ prod = [] max_prod = [] counter = [] n_counter = [] for file in self.files: try: replay = parser.parse_replay(file) if best_counters: p, mp, c, nc = self.most_produced_counter(replay) prod.append(p) max_prod.append(mp) counter.append(c) n_counter.append(nc) else: df1 = self.extract_units(replay, 1) df2 = self.extract_units(replay, 2) self.df = pd.concat([self.df, df1, df2], sort=True) except: pass if best_counters: self.df = pd.DataFrame({ 'most_produced': prod, 'n_produced': max_prod, 'best_counter': counter, 'counter_prod': n_counter }) else: self.df.reset_index(inplace=True, drop=True) return self.df
def main(): """ Execute spawningtool """ parser = argparse.ArgumentParser() parser.add_argument("replay_file", help=".SC2Replay file to load") parser.add_argument("--cutoff-time", help="Game time at which to stop displaying events") parser.add_argument("--cache-dir", help="Directory to cache results in") parser.add_argument("--map-details", help="Include map details and positions", action="store_true") args = parser.parse_args() try: result = parse_replay( args.replay_file, cutoff_time=args.cutoff_time, cache_dir=args.cache_dir, include_map_details=bool(args.map_details), ) except CutoffTimeError as error: print error.message except ReplayFormatError as error: print error.message print error.parsed_data else: print_results(result)
def main(): """ Execute spawningtool """ parser = argparse.ArgumentParser() parser.add_argument('replay_file', help='.SC2Replay file to load') parser.add_argument( '--cutoff-time', help='Game time at which to stop displaying events' ) parser.add_argument( '--cache-dir', help='Directory to cache results in' ) parser.add_argument( '--map-details', help='Include map details and positions', action="store_true" ) args = parser.parse_args() try: result = parse_replay( args.replay_file, cutoff_time=args.cutoff_time, cache_dir=args.cache_dir, include_map_details=bool(args.map_details)) except CutoffTimeError as error: print(error.message) except ReplayFormatError as error: print(error.message) print(error.parsed_data) else: print_results(result)
def parse_replay_files(self): replay_files = glob.glob('./replay_data/**/*.SC2Replay') replays = [sc2parser.parse_replay(file) for file in replay_files] with open("./resources/replay_data.pkl", "wb") as file: pickle.dump(replays, file) return replays
def map_replays(filenames, map_fn, results, update_fn, cache_dir=None, **kwargs): for filename in filenames: filename = filename.rstrip('\n') replay = parse_replay(filename, cache_dir=cache_dir) map_fn(replay, results, update_fn, **kwargs)
def main(): """ Execute spawningtool """ parser = argparse.ArgumentParser() parser.add_argument('replay_file', help='.SC2Replay file to load') parser.add_argument( '--cutoff-time', help='Game time at which to stop displaying events' ) args = parser.parse_args() try: result = parse_replay(args.replay_file, cutoff_time=args.cutoff_time) except CutoffTimeError as error: print error.message except ReplayFormatError as error: print error.message print error.parsed_data else: print_results(result)
def main(): """ Execute spawningtool """ parser = argparse.ArgumentParser() parser.add_argument('replay_file', help='.SC2Replay file to load') parser.add_argument('--cutoff-time', help='Game time at which to stop displaying events') parser.add_argument('--cache-dir', help='Directory to cache results in') parser.add_argument('--map-details', help='Include map details and positions', action="store_true") # print arguments parser.add_argument('--build', help='Print out the build orders', action="store_true") parser.add_argument('--units-lost', help='Print out the units lost', action="store_true") parser.add_argument('--abilities', help='Print out the abilities', action="store_true") parser.add_argument('--workers', help='Print out the workers in the build', action="store_true") args = parser.parse_args() try: result = parse_replay(args.replay_file, cutoff_time=args.cutoff_time, cache_dir=args.cache_dir, include_map_details=bool(args.map_details)) except CutoffTimeError as error: print(error.message) except ReplayFormatError as error: print(error.message) print(error.parsed_data) else: print_results(result, args)