def getContacts(client): data = client.listFriends() table = Table(show_footer=False) table.add_column("Name", no_wrap=True) table.add_column("JID", no_wrap=True) table.add_column("Subscription", no_wrap=True) table.add_column("Status", no_wrap=True) table.add_column("Extra", no_wrap=True) table.title = ( "[not italic]:girl_light_skin_tone: Users In Rooster [not italic]:boy_light_skin_tone:" ) for row in data: table.add_row(*row) table.columns[4].header_style = "bold red" table.columns[3].header_style = "bold green" table.columns[2].header_style = "bold blue" table.columns[1].header_style = "red" table.columns[0].header_style = "cyan" table.row_styles = ["none", "dim"] table.border_style = "bright_yellow" for x in [ box.SQUARE, box.MINIMAL, box.SIMPLE, box.SIMPLE_HEAD, ]: table.box = x console.print(table, justify="left")
def getInfoUser(client): questions = [{ 'type': 'input', 'message': 'Enter username to get info', 'name': 'username' }] answers = prompt(questions, style=custom_style_2) data = client.getUserInfo(answers['username']) table = Table(show_footer=False) table.add_column("Email", no_wrap=True) table.add_column("JID", no_wrap=True) table.add_column("Username", no_wrap=True) table.add_column("Name", no_wrap=True) table.title = ( "[not italic]:girl_light_skin_tone: Username Information [not italic]:boy_light_skin_tone:" ) for row in data: table.add_row(*row) table.columns[3].header_style = "bold red" table.columns[2].header_style = "bold green" table.columns[1].header_style = "bold blue" table.columns[0].header_style = "cyan" table.row_styles = ["none", "dim"] table.border_style = "bright_yellow" for x in [ box.SQUARE, box.MINIMAL, box.SIMPLE, box.SIMPLE_HEAD, ]: table.box = x console.print(table, justify="left")
def weights(self): r""" Prints an weights to screen. """ console = bittensor.__console__ subtensor = bittensor.subtensor( config = self.config ) metagraph = bittensor.metagraph( subtensor = subtensor ) wallet = bittensor.wallet( config = self.config ) with console.status(":satellite: Syncing with chain: [white]{}[/white] ...".format(self.config.subtensor.network)): metagraph.load() metagraph.sync() metagraph.save() table = Table() rows = [] table.add_column("[bold white]uid", style='white', no_wrap=False) for uid in metagraph.uids.tolist(): table.add_column("[bold white]{}".format(uid), style='white', no_wrap=False) if self.config.all_weights: rows.append(["[bold white]{}".format(uid) ] + ['{:.3f}'.format(v) for v in metagraph.W[uid].tolist()]) else: if metagraph.coldkeys[uid] == wallet.coldkeypub.ss58_address: if not self.config.all_hotkeys: if metagraph.hotkeys[uid] == wallet.hotkey.ss58_address: rows.append(["[bold white]{}".format(uid) ] + ['{:.3f}'.format(v) for v in metagraph.W[uid].tolist()]) else: rows.append(["[bold white]{}".format(uid) ] + ['{:.3f}'.format(v) for v in metagraph.W[uid].tolist()]) for row in rows: table.add_row(*row) table.box = None table.pad_edge = False table.width = None with console.pager(): console.print(table)
def stagers_table(): """ Generate a new stagers table. :return: A newly defined stagers table """ _stagers_table = Table(style=TABLE_STYLE) _stagers_table.box = box.MINIMAL _stagers_table.add_column('Name', justify='center') _stagers_table.add_column('Delivery', justify='center') return _stagers_table
def agents_table(): """ Generate a new connections table. :return: A newly defined connections table """ _connections_table = Table(style=TABLE_STYLE) _connections_table.box = box.MINIMAL _connections_table.add_column('Name', justify='center') _connections_table.add_column('Check In Delta', justify='center') _connections_table.add_column('Username', justify='center') _connections_table.add_column('Hostname', justify='center') _connections_table.add_column('PID', justify='center') _connections_table.add_column('Integrity', justify='center') return _connections_table
def quick_table(self, title: str, header: List[str], rows: List[List[str]], verbose: bool = False) -> None: if verbose and not self.verbose: return table = Table(title=title) table.box = box.SIMPLE_HEAD for i in header: table.add_column(i) for row in rows: table.add_row(*[str(cell) for cell in row]) self.__out__(table)
def output_rich(data: Dataset, formatter, cache_disabled): console.record = True table = Table( show_header=True, header_style="bold blue", row_styles=[Style(), Style(color=Color.from_ansi(252))], show_footer=True, footer_style="bold blue", ) table.box = box.MINIMAL rows = list(data.get_rows_list(formatter)) for col in data.output_columns: table.add_column(col, footer="" if len(rows) < 15 else col) for row in rows: table.add_row(*row) console.print(table) console.rule("Information") if len(data.output_columns) < len(data.available_columns): console.print( "[green]More columns available:[/green]", ", ".join(sorted(data.available_columns - set(data.output_columns))), ) console.print("[green]Sorted by:[/green]", ", ".join(data.sort)) if data.where is None: console.print( f"[green]All available rows ({table.row_count}) are shown.[/green]" ) else: console.print( "[green]Filter active:[/green]", f"`[blue]{data.where}[/blue]`", f"→ {table.row_count} rows of {data.original_row_count} available rows shown.", ) if not cache_disabled: console.print( "[green]Caching enabled. To disable, use[/green] --no-cache")
table.border_style = color with beat(10): console.print(table, justify="center") for box in [ box.ASCII, box.ASCII2, box.DOUBLE, box.DOUBLE_EDGE, box.HEAVY_EDGE, box.MINIMAL_HEAVY_HEAD, box.MINIMAL_DOUBLE_HEAD, box.SIMPLE, box.SIMPLE_HEAD, ]: table.box = box with beat(20): console.print(table, justify="center") original_width = Measurement.get(console, table).maximum for width in range(original_width, console.width, 2): table.width = width with beat(2): console.print(table, justify="center") for width in range(console.width, original_width, -2): table.width = width with beat(2): console.print(table, justify="center")
def generate_table(): nonlocal config nonlocal manager nonlocal subtensor nonlocal dendrite nonlocal meta total_stake = 0.0 total_incentive = 0.0 total_rank = 0.0 total_success = 0 total_time = 0.0 # Fill row. def get_row(droplet): nonlocal total_stake nonlocal total_incentive nonlocal total_rank nonlocal total_time nonlocal total_success nonlocal config if droplet.name not in config.names: return # Setup asyncio loop. connection = connection_for_droplet(droplet) # Get connection string can_connect_bool = can_connect(connection) connect_str = '[bold green] YES' if can_connect( connection) else '[bold red] NO' # get hotkey if can_connect_bool: try: hotkey = get_hotkey(connection) hotkey_str = hotkey if hotkey != None else '[yellow] None' except Exception as e: hotkey_str = '[yellow] None' logger.error('{}: Failed to pull hotkey error = {}', droplet.name, e) else: hotkey_str = '[yellow] None' # get coldkey if can_connect_bool: try: coldkeypub = get_coldkeypub(connection) coldkeypub_str = coldkeypub if coldkeypub != None else '[yellow] None' except Exception as e: coldkeypub_str = '[yellow] None' logger.error('{}: Failed to pull coldkey error = {}', droplet.name, e) else: coldkeypub_str = '[yellow] None' # get branch if can_connect_bool: try: branch = get_branch(connection) branch_str = branch if branch != None else '[yellow] None' except Exception as e: branch_str = '[yellow] None' logger.error('{}: Failed to pull branch error = {}', droplet.name, e) else: branch_str = '[yellow] None' # get install status if can_connect_bool and branch != None: try: installed = is_installed(connection) is_installed_str = '[bold green] Yes' if installed else '[bold red] No' except Exception as e: installed = False is_installed_str = '[bold red] No' logger.error( '{}: Failed to pull install status error = {}', droplet.name, e) else: installed = False is_installed_str = '[bold red] No' # get miner status if can_connect_bool and installed: try: is_running = is_miner_running(connection) is_running_str = '[bold green] Yes' if is_running else '[bold red] No' except Exception as e: is_running = False is_running_str = '[bold red] No' logger.error( '{}: Failed to pull running status: error = {}', droplet.name, e) else: is_running = False is_running_str = '[bold red] No' # get is_subscribed try: uid = meta.hotkeys.index(hotkey) is_subscribed = True is_subscribed_str = '[bold green] Yes' except: is_subscribed = False is_subscribed_str = '[bold red] No' # get subscription status. if is_subscribed: stake = meta.S[uid].item() rank = meta.R[uid].item() incentive = meta.I[uid].item() lastemit = int(meta.block - meta.lastemit[uid]) lastemit = "[bold green]" + str( lastemit) if lastemit < 3000 else "[bold red]" + str( lastemit) address = str(meta.addresses[uid]) neuron = meta.neuron_endpoints[uid] total_stake += stake total_rank += rank total_incentive += incentive * 14400 uid_str = str(uid) stake_str = '[green]\u03C4{:.5}'.format(stake) rank_str = '[green]\u03C4{:.5}'.format(rank) incentive_str = '[green]\u03C4{:.5}'.format(incentive * 14400) lastemit_str = str(lastemit) address_str = str(address) else: uid_str = '[dim yellow] None' stake_str = '[dim yellow] None' rank_str = '[dim yellow] None' incentive_str = '[dim yellow] None' lastemit_str = '[dim yellow] None' address_str = '[dim yellow] None' # Make query and get response. if installed and is_running and is_subscribed and wallet.has_hotkey and neuron != None: start_time = time.time() result, code = dendrite.forward_text( neurons=[neuron], x=[torch.zeros((1, 1), dtype=torch.int64)]) end_time = time.time() code_to_string = bittensor.utils.codes.code_to_string( code.item()) code_color = bittensor.utils.codes.code_to_color(code.item()) code_str = '[' + str(code_color) + ']' + code_to_string query_time_str = '[' + str( code_color) + ']' + "" + '{:.3}'.format(end_time - start_time) + "s" if code.item() == 0: total_success += 1 total_time += end_time - start_time else: code_str = '[dim yellow] N/A' query_time_str = '[dim yellow] N/A' row = [ str(droplet.name), str(droplet.ip_address), str(droplet.region['name']), str(droplet.size_slug), str(connect_str), branch_str, is_installed_str, is_running_str, is_subscribed_str, address_str, uid_str, stake_str, rank_str, incentive_str, lastemit_str, query_time_str, code_str, hotkey_str, coldkeypub_str ] return row # Get latest droplets. droplets = manager.get_all_droplets(tag_name=[TAG]) if config.names == None: config.names = [droplet.name for droplet in droplets] subtensor.connect() meta.load() meta.sync(subtensor=subtensor, force=config.force) meta.save() TABLE_DATA = [] with ThreadPoolExecutor(max_workers=MAX_THREADS) as executor: if config.live: TABLE_DATA = list(executor.map(get_row, droplets)) else: TABLE_DATA = list( tqdm(executor.map(get_row, droplets), total=len(droplets))) TABLE_DATA = [row for row in TABLE_DATA if row != None] TABLE_DATA.sort(key=lambda TABLE_DATA: TABLE_DATA[0]) total_stake_str = '\u03C4{:.7}'.format(total_stake) total_rank_str = '\u03C4{:.7}'.format(total_rank) total_incentive_str = '\u03C4{:.7}'.format(total_incentive) total_time_str = '{:.3}s'.format( total_time / len(config.names)) if total_time != 0 else '0.0s' total_success_str = '[bold green]' + str( total_success) + '/[bold red]' + str( len(config.names) - total_success) console = Console() table = Table(show_footer=False) table.title = ("[bold white]Miners") table.add_column("[overline white]NAME", str(len(config.names)), footer_style="overline white", style='white') table.add_column("[overline white]IP", style='blue') table.add_column("[overline white]LOC", style='yellow') table.add_column("[overline white]SIZE", style='green') table.add_column("[overline white]CONN", style='green') table.add_column("[overline white]BRNCH", style='bold purple') table.add_column("[overline white]INSTL") table.add_column("[overline white]RNG") table.add_column("[overline white]SUBD") table.add_column("[overline white]ADDR", style='blue') table.add_column("[overline white]UID", style='yellow') table.add_column("[overline white]STAKE(\u03C4)", total_stake_str, footer_style="overline white", justify='right', style='green', no_wrap=True) table.add_column("[overline white]RANK(\u03C4)", total_rank_str, footer_style="overline white", justify='right', style='green', no_wrap=True) table.add_column("[overline white]INCN(\u03C4/d)", total_incentive_str, footer_style="overline white", justify='right', style='green', no_wrap=True) table.add_column("[overline white]LEmit", justify='right', no_wrap=True) table.add_column("[overline white]Qry(sec)", total_time_str, footer_style="overline white", justify='right', no_wrap=True) table.add_column("[overline white]Qry(code)", total_success_str, footer_style="overline white", justify='right', no_wrap=True) table.add_column("[overline white]HOT", style='bold blue', no_wrap=False) table.add_column("[overline white]COLD", style='blue', no_wrap=False) table.show_footer = True console.clear() for row in TABLE_DATA: table.add_row(*row) table.box = None table.pad_edge = False table.width = None table = Align.center(table) return table
core_client = client.CoreV1Api( api_client=config.new_client_from_config(context=chosen_context)) w = watch.Watch() console = Console() table = Table(show_footer=False, show_header=True, expand=True) table.row_styles = ["none", "dim"] table.add_column("created on", style="cyan", header_style="bold cyan") table.add_column("context", style="blue", header_style="bold blue") table.add_column("namespace", style="blue", header_style="bold blue") table.add_column("name", style="magenta", header_style="bold magenta") table.add_column("kind") table.add_column("reason", style="green", header_style="bold green") table.add_column("type", style="green", header_style="bold green") table.add_column("message") table_centered = Columns((table, ), align="center", expand=True) table.box = box.SIMPLE console.clear() with Live(table_centered, console=console, refresh_per_second=10, vertical_overflow="visible"): try: for event in w.stream( core_client.list_event_for_all_namespaces, _request_timeout=300): action = list(event.values())[0] metadata = event['object'].metadata creation_timestamp = metadata.creation_timestamp creation_ts_human = creation_timestamp.strftime( "%Y.%m.%d %H:%M:%S") namespace = metadata.namespace
table.columns[4].footer_style = "bright_blue" with beat(10): table.row_styles = ["none", "dim"] with beat(10): table.border_style = "bright_yellow" for box_style in [ box.SQUARE, box.MINIMAL, box.SIMPLE, box.SIMPLE_HEAD, ]: with beat(10): table.box = box_style with beat(10): table.pad_edge = False original_width = console.measure(table).maximum for width in range(original_width, console.width, 2): with beat(1): table.width = width for width in range(console.width, original_width, -2): with beat(1): table.width = width for width in range(original_width, 90, -2):
def overview(self): r""" Prints an overview for the wallet's colkey. """ console = bittensor.__console__ wallet = bittensor.wallet( config = self.config ) subtensor = bittensor.subtensor( config = self.config ) all_hotkeys = CLI._get_hotkey_wallets_for_wallet( wallet ) neurons = [] block = subtensor.block with console.status(":satellite: Syncing with chain: [white]{}[/white] ...".format(self.config.subtensor.network)): for wallet in tqdm(all_hotkeys): nn = subtensor.neuron_for_pubkey( wallet.hotkey.ss58_address ) if not nn.is_null: neurons.append( nn ) balance = subtensor.get_balance( wallet.coldkeypub.ss58_address ) TABLE_DATA = [] total_stake = 0.0 total_rank = 0.0 total_trust = 0.0 total_consensus = 0.0 total_incentive = 0.0 total_dividends = 0.0 total_emission = 0 for nn, hotwallet in tqdm(list(zip(neurons,all_hotkeys))): uid = nn.uid active = nn.active stake = nn.stake rank = nn.rank trust = nn.trust consensus = nn.consensus incentive = nn.incentive dividends = nn.dividends emission = int(nn.emission * 1000000000) last_update = int(block - nn.last_update) row = [ hotwallet.hotkey_str, str(uid), str(active), '{:.5f}'.format(stake), '{:.5f}'.format(rank), '{:.5f}'.format(trust), '{:.5f}'.format(consensus), '{:.5f}'.format(incentive), '{:.5f}'.format(dividends), '{}'.format(emission), str(last_update), bittensor.utils.networking.int_to_ip( nn.ip) + ':' + str(nn.port) if nn.port != 0 else '[yellow]none[/yellow]', nn.hotkey ] total_stake += stake total_rank += rank total_trust += trust total_consensus += consensus total_incentive += incentive total_dividends += dividends total_emission += emission TABLE_DATA.append(row) total_neurons = len(neurons) table = Table(show_footer=False) table.title = ( "[white]Wallet - {}:{}".format(self.config.wallet.name, wallet.coldkeypub.ss58_address) ) table.add_column("[overline white]HOTKEY", str(total_neurons), footer_style = "overline white", style='bold white') table.add_column("[overline white]UID", str(total_neurons), footer_style = "overline white", style='yellow') table.add_column("[overline white]ACTIVE", justify='right', style='green', no_wrap=True) table.add_column("[overline white]STAKE(\u03C4)", '\u03C4{:.5f}'.format(total_stake), footer_style = "overline white", justify='right', style='green', no_wrap=True) table.add_column("[overline white]RANK", '{:.5f}'.format(total_rank), footer_style = "overline white", justify='right', style='green', no_wrap=True) table.add_column("[overline white]TRUST", '{:.5f}'.format(total_trust), footer_style = "overline white", justify='right', style='green', no_wrap=True) table.add_column("[overline white]CONSENSUS", '{:.5f}'.format(total_consensus), footer_style = "overline white", justify='right', style='green', no_wrap=True) table.add_column("[overline white]INCENTIVE", '{:.5f}'.format(total_incentive), footer_style = "overline white", justify='right', style='green', no_wrap=True) table.add_column("[overline white]DIVIDENDS", '{:.5f}'.format(total_dividends), footer_style = "overline white", justify='right', style='green', no_wrap=True) table.add_column("[overline white]EMISSION(\u03C1)", '\u03C1{}'.format(int(total_emission)), footer_style = "overline white", justify='right', style='green', no_wrap=True) table.add_column("[overline white]UPDATED", justify='right', no_wrap=True) table.add_column("[overline white]AXON", justify='left', style='dim blue', no_wrap=True) table.add_column("[overline white]HOTKEY", style='dim blue', no_wrap=False) table.show_footer = True table.caption = "[white]Wallet balance: [green]\u03C4" + str(balance.tao) console.clear() for row in TABLE_DATA: table.add_row(*row) table.box = None table.pad_edge = False table.width = None console.print(table)
def metagraph(self): r""" Prints an entire metagraph. """ console = bittensor.__console__ subtensor = bittensor.subtensor( config = self.config ) metagraph = bittensor.metagraph( subtensor = subtensor ) console.print(":satellite: Syncing with chain: [white]{}[/white] ...".format(self.config.subtensor.network)) metagraph.sync() metagraph.save() issuance = subtensor.total_issuance difficulty = subtensor.difficulty TABLE_DATA = [] total_stake = 0.0 total_rank = 0.0 total_trust = 0.0 total_consensus = 0.0 total_incentive = 0.0 total_dividends = 0.0 total_emission = 0 for uid in metagraph.uids: ep = metagraph.endpoint_objs[uid] row = [ str(ep.uid), '{:.5f}'.format( metagraph.stake[uid]), '{:.5f}'.format( metagraph.ranks[uid]), '{:.5f}'.format( metagraph.trust[uid]), '{:.5f}'.format( metagraph.consensus[uid]), '{:.5f}'.format( metagraph.incentive[uid]), '{:.5f}'.format( metagraph.dividends[uid]), '{}'.format( int(metagraph.emission[uid] * 1000000000)), str((metagraph.block.item() - metagraph.last_update[uid].item())), str( metagraph.active[uid].item() ), ep.ip + ':' + str(ep.port) if ep.is_serving else '[yellow]none[/yellow]', ep.hotkey[:10], ep.coldkey[:10] ] total_stake += metagraph.stake[uid] total_rank += metagraph.ranks[uid] total_trust += metagraph.trust[uid] total_consensus += metagraph.consensus[uid] total_incentive += metagraph.incentive[uid] total_dividends += metagraph.dividends[uid] total_emission += int(metagraph.emission[uid] * 1000000000) TABLE_DATA.append(row) total_neurons = len(metagraph.uids) table = Table(show_footer=False) table.title = ( "[white]Metagraph: name: {}, block: {}, N: {}/{}, tau: {}/block, stake: {}, issuance: {}, difficulty: {}".format(subtensor.network, metagraph.block.item(), sum(metagraph.active.tolist()), metagraph.n.item(), bittensor.Balance.from_tao(metagraph.tau.item()), bittensor.Balance.from_tao(total_stake), issuance, difficulty ) ) table.add_column("[overline white]UID", str(total_neurons), footer_style = "overline white", style='yellow') table.add_column("[overline white]STAKE(\u03C4)", '\u03C4{:.5f}'.format(total_stake), footer_style = "overline white", justify='right', style='green', no_wrap=True) table.add_column("[overline white]RANK", '{:.5f}'.format(total_rank), footer_style = "overline white", justify='right', style='green', no_wrap=True) table.add_column("[overline white]TRUST", '{:.5f}'.format(total_trust), footer_style = "overline white", justify='right', style='green', no_wrap=True) table.add_column("[overline white]CONSENSUS", '{:.5f}'.format(total_consensus), footer_style = "overline white", justify='right', style='green', no_wrap=True) table.add_column("[overline white]INCENTIVE", '{:.5f}'.format(total_incentive), footer_style = "overline white", justify='right', style='green', no_wrap=True) table.add_column("[overline white]DIVIDENDS", '{:.5f}'.format(total_dividends), footer_style = "overline white", justify='right', style='green', no_wrap=True) table.add_column("[overline white]EMISSION(\u03C1)", '\u03C1{}'.format(int(total_emission)), footer_style = "overline white", justify='right', style='green', no_wrap=True) table.add_column("[overline white]UPDATED", justify='right', no_wrap=True) table.add_column("[overline white]ACTIVE", justify='right', style='green', no_wrap=True) table.add_column("[overline white]AXON", justify='left', style='dim blue', no_wrap=True) table.add_column("[overline white]HOTKEY", style='dim blue', no_wrap=False) table.add_column("[overline white]COLDKEY", style='dim purple', no_wrap=False) table.show_footer = True for row in TABLE_DATA: table.add_row(*row) table.box = None table.pad_edge = False table.width = None console.print(table)