def redraw(self) -> None: try: for idx, frame_file in enumerate(sorted(find_frames(self.log_dir, self.game_name))): df = pd.read_csv(frame_file) self.line_max[idx].set_xdata(df['frame_count']) self.line_max[idx].set_ydata(df['frame_time_max']) self.line_avg[idx].set_xdata(df['frame_count']) self.line_avg[idx].set_ydata(df['frame_time_avg']) self.ax[idx].set_xlim(0, df['frame_count'].max()) self.figure.canvas.draw() except Exception as e: logger.warning(e)
def frame_files(self) -> List[str]: if self._frame_files is None: self._frame_files = find_frames(self.log_dir, self.game_name) return self._frame_files
def launch_game(players: List[Player], launch_params: Dict[str, Any], show_all: bool, read_overwrite: bool, wait_callback: Callable) -> None: """ :raises DockerException, ContainerException, RealtimeOutedException """ if not players: raise GameException("at least one player must be specified") # todo: this is a quick fix, do it properly later existing_files = itertools.chain( find_logs(launch_params["log_dir"], launch_params["game_name"]), find_replays(launch_params["map_dir"], launch_params["game_name"]), find_results(launch_params["log_dir"], launch_params["game_name"]), find_frames(launch_params["log_dir"], launch_params["game_name"])) for file_ in existing_files: logger.debug(f"removing existing file {file_}") os.remove(file_) for nth_player, player in enumerate(players): launch_image(player, nth_player=nth_player, num_players=len(players), **launch_params) logger.debug("checking if game has launched properly...") time.sleep(1) start_containers = running_containers(launch_params["game_name"]) if len(start_containers) != len(players): raise DockerException( "some containers exited prematurely, please check logs") if not launch_params["headless"]: for index, player in enumerate(players if show_all else players[:1]): port = launch_params["vnc_base_port"] + index host = launch_params["vnc_host"] logger.info( f"launching vnc viewer for {player} on address {host}:{port}") launch_vnc_viewer(host, port) logger.info( "\n" "In headful mode, you must specify and start the game manually.\n" "Select the map, wait for bots to join the game " "and then start the game.") logger.info( f"waiting until game {launch_params['game_name']} is finished...") running_time = time.time() while True: containers = running_containers(launch_params["game_name"]) if len(containers) == 0: # game finished break if len( containers ) >= 2: # update the last time when there were multiple containers running_time = time.time() if len(containers) == 1 and time.time( ) - running_time > MAX_TIME_RUNNING_SINGLE_CONTAINER: raise ContainerException( f"One lingering container has been found after single container " f"timeout ({MAX_TIME_RUNNING_SINGLE_CONTAINER} sec), the game probably crashed." ) logger.debug(f"waiting. {containers}") wait_callback() exit_codes = [container_exit_code(container) for container in containers] # remove containers before throwing exception logger.debug("removing game containers") remove_game_containers(launch_params["game_name"]) if any(exit_code == EXIT_CODE_REALTIME_OUTED for exit_code in exit_codes): raise RealtimeOutedException( f"some of the game containers has realtime outed.") if any(exit_code == 1 for exit_code in exit_codes): raise ContainerException( f"some of the game containers has finished with error exit code.") if read_overwrite: logger.info("overwriting bot files") for nth_player, player in enumerate(players): if isinstance(player, BotPlayer): logger.debug(f"overwriting files for {player}") distutils.dir_util.copy_tree( f"{player.write_dir}/{launch_params['game_name']}_{nth_player}", player.read_dir)