Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhances root list-delegates #49

Merged
merged 2 commits into from
Sep 4, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions bittensor_cli/src/bittensor/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -757,3 +757,30 @@ def render_tree(
f.write(rendered)
if show:
webbrowser.open(f"file://{output_file}")


def group_vpermits(registrations):
if not registrations:
return ""

ranges = []

# Seting both start and end to the first number in the list
start = end = registrations[0]

# Iterate the list, adding None at the end to handle the last range
for num in registrations[1:] + [None]:
# If the current number is not consecutive with the previous one
if num != end + 1:
# If start and end are the same, it's a single number
if start == end:
ranges.append(str(start))

# If start and end are different, it's a range
else:
ranges.append(f"{start}-{end}")

start = num # Set the start of the new range to the current number
end = num # Update the end to the current number

return ", ".join(ranges)
40 changes: 22 additions & 18 deletions bittensor_cli/src/commands/root.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
render_table,
ss58_to_vec_u8,
update_metadata_table,
group_vpermits,
)

# helpers
Expand Down Expand Up @@ -1494,29 +1495,24 @@ async def list_delegates(subtensor: SubtensorInterface):
console.print(
":warning:[yellow]Could not get delegate info from chain.[/yellow]"
)

table_width = console.width - 10
table = Table(
Column(
"[white]INDEX",
str(len(delegates)),
footer_style="overline white",
style="bold white",
),
Column(
"[white]DELEGATE",
style="bold bright_cyan",
no_wrap=True,
justify="left",
max_width=20,
),
Column(
"[white]SS58",
str(len(delegates)),
footer_style="overline white",
style="bright_magenta",
),
Column(
"[white]NOMINATORS", justify="center", style="dark_sea_green", no_wrap=True
"[white]SS58", str(len(delegates)), style="bright_magenta", max_width=48
),
Column("[white]NOMINATORS", justify="center", style="gold1", no_wrap=True),
Column(
"[white]DELEGATE STAKE(\u03c4)",
justify="right",
Expand All @@ -1530,18 +1526,26 @@ async def list_delegates(subtensor: SubtensorInterface):
no_wrap=True,
),
Column("[white]CHANGE/(4h)", style="grey0", justify="center"),
Column("[white]VPERMIT", justify="right", no_wrap=False),
Column("[white]TAKE", style="white", no_wrap=True),
Column(
"[white]NOMINATOR/(24h)/k\u03c4", style="rgb(42,161,152)", justify="center"
"[white]NOMINATOR/(24h)/k\u03c4",
style="dark_olive_green3",
justify="center",
),
Column("[white]DELEGATE/(24h)", style="rgb(42,161,152)", justify="center"),
Column("[white]Desc", style="rgb(50,163,219)"),
Column("[white]DELEGATE/(24h)", style="dark_olive_green3", justify="center"),
Column(
"[white]VPERMIT",
justify="center",
no_wrap=False,
max_width=20,
style="dark_sea_green",
),
Column("[white]Desc", style="rgb(50,163,219)", max_width=30),
title="[underline dark_orange]Root Delegates\n",
show_footer=True,
width=None,
width=table_width,
pad_edge=False,
box=None,
box=box.SIMPLE,
expand=True,
)

Expand Down Expand Up @@ -1596,7 +1600,7 @@ async def list_delegates(subtensor: SubtensorInterface):
# DELEGATE
Text(delegate_name, style=f"link {delegate_url}"),
# SS58
f"{delegate.hotkey_ss58:8.8}...",
f"{delegate.hotkey_ss58}",
# NOMINATORS
str(len([nom for nom in delegate.nominators if nom[1].rao > 0])),
# DELEGATE STAKE
Expand All @@ -1605,14 +1609,14 @@ async def list_delegates(subtensor: SubtensorInterface):
f"{delegate.total_stake!s:13.13}",
# CHANGE/(4h)
rate_change_in_stake_str,
# VPERMIT
str(delegate.registrations),
# TAKE
f"{delegate.take * 100:.1f}%",
# NOMINATOR/(24h)/k
f"{Balance.from_tao(delegate.total_daily_return.tao * (1000 / (0.001 + delegate.total_stake.tao)))!s:6.6}",
# DELEGATE/(24h)
f"{Balance.from_tao(delegate.total_daily_return.tao * 0.18) !s:6.6}",
# VPERMIT
str(group_vpermits(delegate.registrations)),
# Desc
str(delegate_description),
end_section=True,
Expand Down
Loading