Spaces:
Configuration error
Configuration error
Commit
·
471a6f6
1
Parent(s):
bfcbeb2
add validator side, update graph
Browse files- app.py +64 -6
- weights.py +47 -0
app.py
CHANGED
@@ -6,6 +6,7 @@ import subnet_util
|
|
6 |
import datetime
|
7 |
import typing
|
8 |
import indexing_util
|
|
|
9 |
from io import BytesIO
|
10 |
FONT = """<link href="https://fonts.cdnfonts.com/css/intersect-c-brk" rel="stylesheet">"""
|
11 |
TITLE_FONT = """<link href="https://fonts.cdnfonts.com/css/promova" rel="stylesheet">"""
|
@@ -49,6 +50,11 @@ hotkey_indexing_data = indexing_util.get_all(indexing_util.hotkey_indexing)
|
|
49 |
hotkey_df = pd.DataFrame(hotkey_indexing_data, columns=['Hotkey', 'Value'])
|
50 |
hotkey_df['Hotkey'] = hotkey_df['Hotkey'].str.decode('utf-8')
|
51 |
hotkey_df['Value'] = hotkey_df['Value'].astype(int)
|
|
|
|
|
|
|
|
|
|
|
52 |
|
53 |
hotkey_daily_indexing_data = indexing_util.get_all(indexing_util.hotkey_daily_indexing)
|
54 |
hotkey_daily_df = pd.DataFrame(hotkey_daily_indexing_data, columns=['Hotkey_Date', 'Value'])
|
@@ -59,12 +65,13 @@ hotkey_daily_df_['Value'] = hotkey_daily_df['Value'].astype(int)
|
|
59 |
|
60 |
dalily_df_max = daily_df['Value'].max()
|
61 |
hotkey_df_max = hotkey_df['Value'].max()
|
|
|
62 |
|
63 |
-
print(hotkey_daily_df_)
|
64 |
-
|
65 |
-
|
66 |
|
67 |
|
|
|
|
|
68 |
|
69 |
|
70 |
def leaderboard_data(
|
@@ -74,7 +81,7 @@ def leaderboard_data(
|
|
74 |
):
|
75 |
value = [
|
76 |
[
|
77 |
-
c.hotkey[0:8],
|
78 |
c.uid,
|
79 |
c.url,
|
80 |
c.block,
|
@@ -84,6 +91,20 @@ def leaderboard_data(
|
|
84 |
]
|
85 |
return value
|
86 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
87 |
with demo:
|
88 |
gr.HTML(FONT)
|
89 |
gr.HTML(TITLE_FONT)
|
@@ -98,10 +119,11 @@ with demo:
|
|
98 |
gr.HTML(f"<h2 align = 'center' style = 'font-size: 25px' >Current Size of Text Dataset: <span style = 'font-size: 30px; color: green;'>{twitter_text_num_rows}</span></h2>")
|
99 |
with gr.Column(scale=1):
|
100 |
gr.HTML(f"<h2 align = 'center' style = 'font-size: 25px' >Current Size of Image Dataset: <span style = 'font-size: 30px; color: green;'>{twitter_image_num_rows}</span></h2>")
|
|
|
101 |
with gr.Accordion("Subnet Stats"):
|
102 |
gr.HTML(f"""<h2 align = 'center' class="promova" style = 'font-size: 35px;' > Miner Stats</h2>""")
|
103 |
|
104 |
-
gr.
|
105 |
daily_df,
|
106 |
x="Date",
|
107 |
y="Value",
|
@@ -144,7 +166,7 @@ with demo:
|
|
144 |
title="Daily scraped data amount of each Miner",
|
145 |
# color="Date",
|
146 |
# tooltip=["Hotkey"],
|
147 |
-
y_lim=[0,
|
148 |
x_title="Date",
|
149 |
y_title="Amount of data scraped",
|
150 |
height=500,
|
@@ -155,6 +177,7 @@ with demo:
|
|
155 |
color_legend_position="top",
|
156 |
# elem_classes="daily_scraped_data",
|
157 |
)
|
|
|
158 |
with gr.Tab(label="Miners Data"):
|
159 |
class_denominator = sum(
|
160 |
miners_data[i].incentive #TODO: emssion to incentive
|
@@ -180,6 +203,7 @@ with demo:
|
|
180 |
# miner_table = gr.components.Dataframe(
|
181 |
# value=miners_data
|
182 |
# )
|
|
|
183 |
with gr.Accordion("Miner stats"):
|
184 |
gr.HTML(
|
185 |
f"""<h3>{last_refresh.strftime("refreshed at %H:%M on %Y-%m-%d")}</h3>"""
|
@@ -208,5 +232,39 @@ with demo:
|
|
208 |
interactive=False,
|
209 |
visible=True,
|
210 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
211 |
)
|
212 |
demo.launch()
|
|
|
6 |
import datetime
|
7 |
import typing
|
8 |
import indexing_util
|
9 |
+
import weights
|
10 |
from io import BytesIO
|
11 |
FONT = """<link href="https://fonts.cdnfonts.com/css/intersect-c-brk" rel="stylesheet">"""
|
12 |
TITLE_FONT = """<link href="https://fonts.cdnfonts.com/css/promova" rel="stylesheet">"""
|
|
|
50 |
hotkey_df = pd.DataFrame(hotkey_indexing_data, columns=['Hotkey', 'Value'])
|
51 |
hotkey_df['Hotkey'] = hotkey_df['Hotkey'].str.decode('utf-8')
|
52 |
hotkey_df['Value'] = hotkey_df['Value'].astype(int)
|
53 |
+
# Filter hotkey_df to only show value is over than 1000
|
54 |
+
hotkey_df = hotkey_df[hotkey_df['Value'] > 1000]
|
55 |
+
# Sort hotkey_df by Value
|
56 |
+
hotkey_df = hotkey_df.sort_values(by='Value', ascending=False)
|
57 |
+
|
58 |
|
59 |
hotkey_daily_indexing_data = indexing_util.get_all(indexing_util.hotkey_daily_indexing)
|
60 |
hotkey_daily_df = pd.DataFrame(hotkey_daily_indexing_data, columns=['Hotkey_Date', 'Value'])
|
|
|
65 |
|
66 |
dalily_df_max = daily_df['Value'].max()
|
67 |
hotkey_df_max = hotkey_df['Value'].max()
|
68 |
+
hotkey_daily_df_max = hotkey_daily_df_['Value'].max()
|
69 |
|
70 |
+
# print(hotkey_daily_df_)
|
|
|
|
|
71 |
|
72 |
|
73 |
+
weight_list, miners = weights.validator_info()
|
74 |
+
print(weight_list)
|
75 |
|
76 |
|
77 |
def leaderboard_data(
|
|
|
81 |
):
|
82 |
value = [
|
83 |
[
|
84 |
+
c.hotkey[0:8] + "...",
|
85 |
c.uid,
|
86 |
c.url,
|
87 |
c.block,
|
|
|
91 |
]
|
92 |
return value
|
93 |
|
94 |
+
def validator_data():
|
95 |
+
value = [
|
96 |
+
[
|
97 |
+
c['uid'],
|
98 |
+
"{:,}".format(c['validator_stake']) + " τ",
|
99 |
+
c['vtrust'],
|
100 |
+
] + [
|
101 |
+
c ['miners_weight'].get(miner[0], 0)
|
102 |
+
for miner in miners
|
103 |
+
]
|
104 |
+
for c in weight_list
|
105 |
+
]
|
106 |
+
return value
|
107 |
+
|
108 |
with demo:
|
109 |
gr.HTML(FONT)
|
110 |
gr.HTML(TITLE_FONT)
|
|
|
119 |
gr.HTML(f"<h2 align = 'center' style = 'font-size: 25px' >Current Size of Text Dataset: <span style = 'font-size: 30px; color: green;'>{twitter_text_num_rows}</span></h2>")
|
120 |
with gr.Column(scale=1):
|
121 |
gr.HTML(f"<h2 align = 'center' style = 'font-size: 25px' >Current Size of Image Dataset: <span style = 'font-size: 30px; color: green;'>{twitter_image_num_rows}</span></h2>")
|
122 |
+
gr.HTML("<br/>")
|
123 |
with gr.Accordion("Subnet Stats"):
|
124 |
gr.HTML(f"""<h2 align = 'center' class="promova" style = 'font-size: 35px;' > Miner Stats</h2>""")
|
125 |
|
126 |
+
gr.LinePlot(
|
127 |
daily_df,
|
128 |
x="Date",
|
129 |
y="Value",
|
|
|
166 |
title="Daily scraped data amount of each Miner",
|
167 |
# color="Date",
|
168 |
# tooltip=["Hotkey"],
|
169 |
+
y_lim=[0, hotkey_daily_df_max * 1.5],
|
170 |
x_title="Date",
|
171 |
y_title="Amount of data scraped",
|
172 |
height=500,
|
|
|
177 |
color_legend_position="top",
|
178 |
# elem_classes="daily_scraped_data",
|
179 |
)
|
180 |
+
gr.HTML("<br/>")
|
181 |
with gr.Tab(label="Miners Data"):
|
182 |
class_denominator = sum(
|
183 |
miners_data[i].incentive #TODO: emssion to incentive
|
|
|
203 |
# miner_table = gr.components.Dataframe(
|
204 |
# value=miners_data
|
205 |
# )
|
206 |
+
gr.HTML("<br/>")
|
207 |
with gr.Accordion("Miner stats"):
|
208 |
gr.HTML(
|
209 |
f"""<h3>{last_refresh.strftime("refreshed at %H:%M on %Y-%m-%d")}</h3>"""
|
|
|
232 |
interactive=False,
|
233 |
visible=True,
|
234 |
|
235 |
+
)
|
236 |
+
gr.HTML("<br/>")
|
237 |
+
with gr.Accordion("Validator stats"):
|
238 |
+
gr.HTML(
|
239 |
+
f"""<h3>{last_refresh.strftime("refreshed at %H:%M on %Y-%m-%d")}</h3>"""
|
240 |
+
)
|
241 |
+
# with gr.Tabs():
|
242 |
+
# for entry in miners_data:
|
243 |
+
# name = f"uid={entry.uid} : commit={entry.commit[0:8]} : url={entry.url}"
|
244 |
+
# with gr.Tab(name):
|
245 |
+
# gr.Chatbot()
|
246 |
+
leaderboard_table = gr.components.Dataframe(
|
247 |
+
value=validator_data(),
|
248 |
+
headers = [
|
249 |
+
"UID",
|
250 |
+
"Stake",
|
251 |
+
"V-Trust"
|
252 |
+
] + [
|
253 |
+
f"Miner-{miner[0]} (Incentive: {miner[1]})"
|
254 |
+
for miner in miners
|
255 |
+
],
|
256 |
+
datatype=[
|
257 |
+
"number",
|
258 |
+
"number",
|
259 |
+
"number"
|
260 |
+
|
261 |
+
] + [
|
262 |
+
"number"
|
263 |
+
for miner in miners
|
264 |
+
],
|
265 |
+
elem_id="leaderboard_table",
|
266 |
+
interactive=False,
|
267 |
+
visible=True,
|
268 |
+
|
269 |
)
|
270 |
demo.launch()
|
weights.py
ADDED
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import bittensor as bt
|
2 |
+
import json
|
3 |
+
subtensor = bt.subtensor(network = "ws://127.0.0.1:9944")
|
4 |
+
bt.logging.info("Connected to subtensor")
|
5 |
+
|
6 |
+
|
7 |
+
|
8 |
+
# stake = subtensor.get_stake(hotkey_ss58="")
|
9 |
+
def get_miner_uids(metagraph: bt.metagraph) -> list:
|
10 |
+
miner_uids = []
|
11 |
+
for i, axon in enumerate(metagraph.axons):
|
12 |
+
v_trust = metagraph.validator_trust[i].item()
|
13 |
+
|
14 |
+
if v_trust > 0.0:
|
15 |
+
continue
|
16 |
+
miner_uids.append((i, metagraph.incentive[i].item()))
|
17 |
+
# sort miner_uids by incentive
|
18 |
+
miner_uids = sorted(miner_uids, key=lambda x: x[1], reverse=True)
|
19 |
+
|
20 |
+
return miner_uids
|
21 |
+
|
22 |
+
|
23 |
+
def validator_info():
|
24 |
+
metagraph = subtensor.metagraph(netuid = 10)
|
25 |
+
all_weights = subtensor.weights(netuid=10)
|
26 |
+
axons = metagraph.axons
|
27 |
+
weight_list = []
|
28 |
+
for validator_uid, weights in all_weights:
|
29 |
+
total_weight = sum([weight for validator_uid, weight in weights])
|
30 |
+
validator_stake = metagraph.stake[validator_uid].item()
|
31 |
+
vtrust = metagraph.validator_trust[validator_uid].item()
|
32 |
+
temp_list = {}
|
33 |
+
for miner_uid, weight in weights:
|
34 |
+
# temp_list.append((miner_uid, weight/total_weight * validator_stake))
|
35 |
+
temp_list[miner_uid] = weight/total_weight
|
36 |
+
weight_list.append({'uid': validator_uid, 'miners_weight': temp_list, 'validator_stake': int(validator_stake), 'vtrust': vtrust})
|
37 |
+
# weight_list[validator_uid] = {'miners_weight': temp_list, 'validator_stake': validator_stake, 'vtrust': vtrust}
|
38 |
+
# Sort weight_list by validator_stake
|
39 |
+
weight_list = sorted(weight_list, key=lambda x: x['validator_stake'], reverse=True)
|
40 |
+
bt.logging.info(f"weights:{weight_list}")
|
41 |
+
miners = get_miner_uids(metagraph)
|
42 |
+
return weight_list, miners
|
43 |
+
|
44 |
+
# print(miners_sorted_by_incentive)
|
45 |
+
|
46 |
+
|
47 |
+
|