Spaces:
Running
Running
Commit
·
81a9ded
1
Parent(s):
c55570e
use bittensor python api
Browse files
app.py
CHANGED
|
@@ -9,48 +9,45 @@ g_cached_data: pd.DataFrame | None = None
|
|
| 9 |
g_last_fetch_time = 0.0
|
| 10 |
|
| 11 |
|
| 12 |
-
def get_incentive_percent_for_key(key, sn, incentive, substrate) -> tuple[float, int]:
|
| 13 |
-
uid = substrate.query('SubtensorModule', 'Uids', [sn, key])
|
| 14 |
-
if uid and uid.value is not None:
|
| 15 |
-
owner_incentive = int(incentive[uid.value])
|
| 16 |
-
if owner_incentive > 0:
|
| 17 |
-
return (owner_incentive / 65535) * 100, uid.value
|
| 18 |
-
return -1, -1
|
| 19 |
-
|
| 20 |
-
|
| 21 |
def fetch_incentive_data() -> pd.DataFrame:
|
| 22 |
-
print("Starting data fetch...")
|
| 23 |
data = []
|
| 24 |
subtensor = bt.subtensor(network="finney")
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
data.append([sn_link, f"{ck_incentive:.2f}%", ck_uid, "Coldkey", address_link])
|
| 39 |
-
continue
|
| 40 |
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
|
|
|
|
|
|
| 51 |
|
| 52 |
data = [(i+1, *d) for i, d in enumerate(data)]
|
| 53 |
df = pd.DataFrame(data, columns=["#", "Subnet", "Burn", "UID", "Key", "Address"]) # type: ignore
|
|
|
|
| 54 |
return df
|
| 55 |
|
| 56 |
|
|
@@ -59,7 +56,9 @@ def get_cached_data() -> pd.DataFrame:
|
|
| 59 |
if g_cached_data is None or (time.time() - g_last_fetch_time) > 1200: # 20 min
|
| 60 |
g_last_fetch_time = time.time()
|
| 61 |
g_cached_data = fetch_incentive_data()
|
| 62 |
-
|
|
|
|
|
|
|
| 63 |
|
| 64 |
|
| 65 |
with gr.Blocks(title="Bittensor Subnet Incentives") as demo:
|
|
@@ -69,13 +68,12 @@ with gr.Blocks(title="Bittensor Subnet Incentives") as demo:
|
|
| 69 |
This dashboard displays the burn percentage set by subnet owners for miners.
|
| 70 |
"""
|
| 71 |
)
|
| 72 |
-
|
| 73 |
output_df = gr.DataFrame(
|
| 74 |
datatype=["number", "markdown", "str", "number", "str", "markdown"],
|
| 75 |
label="Subnet Burn Data",
|
| 76 |
interactive=False,
|
| 77 |
-
|
| 78 |
-
col_count=(6, "fixed")
|
| 79 |
)
|
| 80 |
-
demo.load(get_cached_data, None, output_df)
|
| 81 |
demo.launch()
|
|
|
|
| 9 |
g_last_fetch_time = 0.0
|
| 10 |
|
| 11 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
def fetch_incentive_data() -> pd.DataFrame:
|
|
|
|
| 13 |
data = []
|
| 14 |
subtensor = bt.subtensor(network="finney")
|
| 15 |
+
print("connected to subtensor")
|
| 16 |
+
subnets = subtensor.all_subnets()
|
| 17 |
+
print("fetched all subnets")
|
| 18 |
+
metagraphs = subtensor.get_all_metagraphs_info()
|
| 19 |
+
print("fetched all metagraphs")
|
| 20 |
+
|
| 21 |
+
assert subnets, "WTF"
|
| 22 |
+
assert metagraphs, "WTF"
|
| 23 |
+
|
| 24 |
+
for sn in range(1, 129):
|
| 25 |
+
subnet = subnets[sn]
|
| 26 |
+
metagraph = metagraphs[sn]
|
| 27 |
+
address_to_uid = {hk: i for i, hk in enumerate(metagraph.hotkeys)}
|
| 28 |
+
addresses = [("coldkey", subnet.owner_coldkey), ("hotkey", subnet.owner_hotkey)]
|
| 29 |
|
| 30 |
+
for key_type, address in addresses:
|
| 31 |
+
uid = address_to_uid.get(address, None)
|
| 32 |
+
if uid is None:
|
| 33 |
+
continue
|
|
|
|
|
|
|
| 34 |
|
| 35 |
+
incentive = metagraph.incentives[uid]
|
| 36 |
+
if incentive <= 0:
|
| 37 |
+
continue
|
| 38 |
+
|
| 39 |
+
data.append([
|
| 40 |
+
f"[{sn}](https://taostats.io/subnets/{sn})",
|
| 41 |
+
f"{incentive*100:.2f}%",
|
| 42 |
+
uid,
|
| 43 |
+
key_type,
|
| 44 |
+
f"[{address}](https://taostats.io/{key_type}/{address})"
|
| 45 |
+
])
|
| 46 |
+
break
|
| 47 |
|
| 48 |
data = [(i+1, *d) for i, d in enumerate(data)]
|
| 49 |
df = pd.DataFrame(data, columns=["#", "Subnet", "Burn", "UID", "Key", "Address"]) # type: ignore
|
| 50 |
+
print(f"{len(data)} subnets burn")
|
| 51 |
return df
|
| 52 |
|
| 53 |
|
|
|
|
| 56 |
if g_cached_data is None or (time.time() - g_last_fetch_time) > 1200: # 20 min
|
| 57 |
g_last_fetch_time = time.time()
|
| 58 |
g_cached_data = fetch_incentive_data()
|
| 59 |
+
|
| 60 |
+
time_str = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(g_last_fetch_time + 1200))
|
| 61 |
+
return time_str, g_cached_data
|
| 62 |
|
| 63 |
|
| 64 |
with gr.Blocks(title="Bittensor Subnet Incentives") as demo:
|
|
|
|
| 68 |
This dashboard displays the burn percentage set by subnet owners for miners.
|
| 69 |
"""
|
| 70 |
)
|
| 71 |
+
next_process_text = gr.Textbox(label="Next refresh time", interactive=False)
|
| 72 |
output_df = gr.DataFrame(
|
| 73 |
datatype=["number", "markdown", "str", "number", "str", "markdown"],
|
| 74 |
label="Subnet Burn Data",
|
| 75 |
interactive=False,
|
| 76 |
+
max_height=1000000
|
|
|
|
| 77 |
)
|
| 78 |
+
demo.load(get_cached_data, None, [next_process_text, output_df])
|
| 79 |
demo.launch()
|