def _recurse(dir_path, fn=None): """ Recursively searches directories to parse replay files """ if dir_path.is_file(): try: replay = parse_replay(dir_path, local=True, network=False) except Exception: ERRORS[traceback.format_exc()] += 1 return [fn(replay) if fn else replay] results = [] for obj_path in dir_path.iterdir(): if obj_path.is_file(): try: replay = parse_replay(obj_path, local=True, network=False) except Exception: ERRORS[traceback.format_exc()] += 1 continue results.append(fn(replay) if fn else replay) elif obj_path.is_dir(): results.extend(_recurse(obj_path, fn)) return results
def _recurse(dir_path, fn=None): """ Recursively searches directories to parse replay files """ if dir_path.is_file(): try: replay = parse_replay(dir_path, local=True, network=False) logger.info(f'Parsed replay: {dir_path.name}') return [fn(replay) if fn else replay] except Exception: ERRORS[traceback.format_exc()] += 1 logger.error( f'An error occured during parsing: {traceback.format_exc()}') return [] results = [] logger.info(f'In directory: {dir_path.name}') for obj_path in dir_path.iterdir(): if obj_path.is_file(): try: replay = parse_replay(obj_path, local=True, network=False) logger.info(f'Parsed replay: {obj_path.name}') except Exception: ERRORS[traceback.format_exc()] += 1 logger.error( f'An error occured during parsing: {traceback.format_exc()}' ) continue results.append(fn(replay) if fn else replay) elif obj_path.is_dir(): logger.info(f'Found new directory: {obj_path.name}') results.extend(_recurse(obj_path, fn)) return results
def recurse(dir_path): if dir_path.is_file(): handle_replay(parse_replay(dir_path, local=True, network=False)) return for obj_path in dir_path.iterdir(): if obj_path.is_file(): handle_replay(parse_replay(obj_path, local=True, network=False)) elif obj_path.is_dir(): recurse(obj_path)
def recurse(dir_path, fn): """ Recursively searches directories to parse replay files """ for obj_path in dir_path.iterdir(): if obj_path.is_file(): try: replay = parse_replay(obj_path, local=True, network=False) print('Parsed Replay') except Exception: errors[traceback.format_exc()] += 1 continue fn(replay) elif obj_path.is_dir(): recurse(obj_path, fn)
def handle_replay(path, player_names, identifiers): parsed_ticks = {} replay = parse_replay(path, local=True, creep=False) for player in replay.players.values(): tick_times = { 'economy': [], 'army': [], 'infra': [], } # remove last selection since it technically has no end selections = player.selections[:-1] selections.sort(key=lambda x: x['start']) # list of selections in ~7sec intervals throughout the game ticks = [[]] # current tick tick = 1 for s in selections: # as long as the selection ends before the end of the tick # we count it as part of the tick # tick * TICK_SIZE = upper gameloop limit for the current tick if s['end'] <= tick * TICK_SIZE: # add to current tick ticks[tick - 1].append(s) else: # create a new tick ticks.append([s]) tick += 1 for count, t in enumerate(ticks): all_times = [] selection_times = { 'economy': [], 'army': [], 'infra': [], } # iterating through all selections in the current tick for s in t: # if there are any objects of a group (economy/army/infra) in a selection # it counts for that groups. multiple groups can be counted in a single selection seen_group = set() diff = s['end'] - s['start'] all_times.append(diff) # check the selection for each group # if we haven't already counted it for a group, record the selection length for obj in s['selection']: if (obj.name in command_buildings or GameObj.WORKER in obj.type): if 'economy' not in seen_group: selection_times['economy'].append(diff) seen_group.add('economy') elif (GameObj.BUILDING in obj.type or obj.name == 'Queen' or obj.name == 'Larva'): if 'infra' not in seen_group: selection_times['infra'].append(diff) seen_group.add('infra') elif GameObj.UNIT in obj.type: if 'army' not in seen_group: selection_times['army'].append(diff) seen_group.add('army') # print(f'@{(count + 1) * 7}s, {round(sum(all_times) / 22.4, 2)}s') total_percentage = 0 selection_percentages = {} # iterate through all selection times for all groups for n, v in selection_times.items(): # if no selections for a particular group, skip it if not v: continue # total selection time in seconds for the current group vt = sum(v) / 22.4 # total selection time in seconds all_sec = sum(all_times) / 22.4 # percentage of time the current group was selected percent = (vt / all_sec) * 100 total_percentage += percent selection_percentages[n] = percent for n, v in selection_percentages.items(): tick_times[n].append({ 'tick': (count + 1) * TICK_SIZE, 'percent': round(v, 1), }) # print(n.capitalize()) # print(f'Selection Time: {vt}s ({round(percent, 2)}') parsed_ticks[PlayerTuple(player.name.lower(), player.race.lower())] = tick_times return parsed_ticks
def load_replay_file(path_to_replay: str): """ Loads the replay file defined by path_to_replay.""" deltatick = DELTA_SECOND * TICKS_PER_SECOND return parse_replay(path_to_replay, local=True, tick=deltatick)
for f in replays.iterdir(): if f.is_file(): total_files += 1 else: non_files += 1 print(f'{total_files} files, {non_files} other') replay_data = [] exceptions = [] for count, replay in enumerate(replays.iterdir()): print(f'At {count + 1}/{total_files + non_files} object in directory') if replay.is_file(): print(f'Found file: {replay.name}') try: players, timeline, engagements, summary, meta = parse_replay(replay.resolve(), local=True) replay_data.append([ players[1], players[2], { 'name': players[meta['winner']].name, 'race': players[meta['winner']].race, }, ]) print('Successfully parsed replay file\n') except Exception as e: exceptions.append({ 'file': replay.name, 'exception': traceback.format_exc() }) print(f'An error occured during parsing: {e}\n')
def load_replay_file(path_to_replay: str, delta_second: int): """ Loads the replay file defined by path_to_replay.""" deltatick = delta_second * TICKS_PER_SECOND return parse_replay(path_to_replay, local=True, tick=deltatick)