File size: 10,587 Bytes
f6e1dec
 
 
 
 
 
 
 
471a6f6
f6e1dec
 
 
 
 
b8c0a50
f6e1dec
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1bf4004
 
 
 
 
 
 
 
 
 
f6e1dec
 
 
 
 
 
 
 
 
 
 
471a6f6
 
 
 
 
f6e1dec
 
 
 
 
 
 
 
7d0f2fa
 
471a6f6
7d0f2fa
471a6f6
f6e1dec
 
471a6f6
 
f6e1dec
 
 
 
 
 
 
 
 
471a6f6
f6e1dec
 
 
 
 
 
 
 
 
471a6f6
 
 
 
 
 
 
 
 
 
 
 
 
 
f6e1dec
 
 
 
 
 
 
 
 
 
 
 
 
 
471a6f6
f6e1dec
 
 
471a6f6
aeb7b2b
 
 
 
 
 
 
 
 
 
bfcbeb2
aeb7b2b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
bfcbeb2
aeb7b2b
 
 
 
 
 
f6e1dec
 
 
 
 
 
 
d16810b
471a6f6
f6e1dec
 
 
 
 
d16810b
f6e1dec
 
 
 
471a6f6
f6e1dec
 
 
 
 
 
7895e0a
 
 
 
 
 
 
 
 
3a4bc4d
7895e0a
f6e1dec
 
 
 
 
 
 
 
471a6f6
f6e1dec
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
471a6f6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f6e1dec
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
import gradio as gr
import pandas as pd
import matplotlib.pyplot as plt
from dataset_util import load_data, get_num_rows
import subnet_util
import datetime
import typing
import indexing_util
import weights
from io import BytesIO
FONT = """<link href="https://fonts.cdnfonts.com/css/intersect-c-brk" rel="stylesheet">"""
TITLE_FONT = """<link href="https://fonts.cdnfonts.com/css/promova" rel="stylesheet">"""
TITLE = """ <h1 align = "center" id = "space-title" class = "intersect"> D3 Subnet Leaderboard</h1> """
DESCRIPTION = """<marquee><h3 align= "center"> The D3 Subnet, standing for Decentralized Distributed Data Scraping subnet, plays a crucial role in the advancement of artificial intelligence by ensuring ample training data for all Bittensor AI networks. </h3></marquee>"""
IMAGE = """<a href="https://discord.com/channels/799672011265015819/1161764869280903240" target="_blank"><img src="https://github.com/gitphantomman/d3_subnet/blob/main/docs/d3.png?raw=true" alt="D3 Subnet" style="margin: auto; width: 20%; border: 0;" /></a>"""

last_refresh = None
demo = gr.Blocks(css="""
                 .intersect {font-family: 'Intersect C BRK', sans-serif; font-size:40px} 
                 .promova {font-family: 'Promova', sans-serif; font-size:40px}
                 """)

twitter_text_dataset = load_data("bittensor-dataset/twitter-text-dataset")
twitter_text_num_rows = get_num_rows(twitter_text_dataset)
twitter_image_dataset = load_data("bittensor-dataset/twitter-image-dataset")
twitter_image_num_rows = get_num_rows(twitter_image_dataset)

tao_price = subnet_util.get_tao_price()
(subtensor, metagraph) = subnet_util.get_subtensor_and_metagraph()
last_refresh = datetime.datetime.now()
miners_data = subnet_util.get_subnet_data(subtensor, metagraph)
# url = "http://127.0.0.1:8001/"
# try:
#     response = requests.get(url)
#     response_body = response.json()
#     twitter_text_num_rows = response_body['twitter_text_rows']
#     twitter_image_num_rows = response_body['twitter_image_rows']
# except:
#     twitter_text_num_rows = 0
#     twitter_image_num_rows = 0
#     bt.logging.error("Could not connect to the API")


daily_indexing_data = indexing_util.get_all(indexing_util.daily_indexing)
daily_df = pd.DataFrame(daily_indexing_data, columns=['Date', 'Value'])
daily_df['Date'] = pd.to_datetime(daily_df['Date'].str.decode('utf-8'))
daily_df['Value'] = daily_df['Value'].astype(int)

hotkey_indexing_data = indexing_util.get_all(indexing_util.hotkey_indexing)
hotkey_df = pd.DataFrame(hotkey_indexing_data, columns=['Hotkey', 'Value'])
hotkey_df['Hotkey'] = hotkey_df['Hotkey'].str.decode('utf-8')
hotkey_df['Value'] = hotkey_df['Value'].astype(int)
# Filter hotkey_df to only show value is over than 1000
hotkey_df = hotkey_df[hotkey_df['Value'] > 1000]
# Sort hotkey_df by Value
hotkey_df = hotkey_df.sort_values(by='Value', ascending=False)


hotkey_daily_indexing_data = indexing_util.get_all(indexing_util.hotkey_daily_indexing)
hotkey_daily_df = pd.DataFrame(hotkey_daily_indexing_data, columns=['Hotkey_Date', 'Value'])
hotkey_daily_df_= pd.DataFrame()
hotkey_daily_df_['Hotkey'] = hotkey_daily_df['Hotkey_Date'].str.decode('utf-8').str.split(' ').str[0]
hotkey_daily_df_['Date'] = hotkey_daily_df['Hotkey_Date'].str.decode('utf-8').str.split(' ').str[1]
hotkey_daily_df_['Value'] = hotkey_daily_df['Value'].astype(int)

dalily_df_max = daily_df['Value'].max()
hotkey_df_max = hotkey_df['Value'].max()
hotkey_daily_df_max = hotkey_daily_df_['Value'].max()

# print(hotkey_daily_df_)


weight_list, miners = weights.validator_info()
print(weight_list)


def leaderboard_data(
    # show_stale: bool,
    # scores: typing.Dict[int, typing.Dict[str, typing.Optional[float | str]]],
    # competition_id: str,
):
    value = [
        [
            c.hotkey[0:8] + "...",
            c.uid,
            c.url,
            c.block,
        ]
        for c in miners_data
        # if c.incentive and c.url[0:8] == "https://"
    ]
    return value

def validator_data():
    value = [
        [
            c['uid'],
            "{:,}".format(c['validator_stake']) + " τ",
            c['vtrust'],
        ] + [
            c ['miners_weight'].get(miner[0], 0)
            for miner in miners
        ]
        for c in weight_list
    ]
    return value

with demo:
    gr.HTML(FONT)
    gr.HTML(TITLE_FONT)
    gr.HTML(TITLE)
    gr.HTML(IMAGE)
    gr.HTML(DESCRIPTION)

    with gr.Tabs():
        with gr.Accordion("Dataset Stats"):
            with gr.Row():
                with gr.Column(scale=1):
                    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>")
                with gr.Column(scale=1):
                    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>")
        gr.HTML("<br/>")
        with gr.Accordion("Subnet Stats"):
            gr.HTML(f"""<h2 align = 'center' class="promova" style = 'font-size: 35px;' > Miner Stats</h2>""")
            
            gr.LinePlot(
                daily_df,
                x="Date",
                y="Value",
                title="Daliy scraped data amount",
                # color="Date",
                # tooltip=["Date", "Value"],
                y_lim=[0, dalily_df_max * 1.5],
                x_title="Date",
                y_title="Amount of data scraped",
                height=500,
                width=1000,
                scale=5,
                # color="Value",
                color_legend_position="top",
                # elem_classes="daily_scraped_data",
            )
            gr.BarPlot(
                hotkey_df,
                x="Hotkey",
                y="Value",
                title="Scraped data amount of each Miner",
                # color="Date",
                # tooltip=["Hotkey", "Value"],
                y_lim=[0, hotkey_df_max * 1.5],
                x_title="Date",
                y_title="Amount of data scraped",
                height=500,
                width=1000,
                scale=5,
                # color="Value",
                x_label_angle=-30,
                color_legend_position="top",
                # elem_classes="daily_scraped_data",
            )
            
            gr.ScatterPlot(
                hotkey_daily_df_,
                x="Date",
                y="Value",
                title="Daily scraped data amount of each Miner",
                # color="Date",
                # tooltip=["Hotkey"],
                y_lim=[0, hotkey_daily_df_max * 1.5],
                x_title="Date",
                y_title="Amount of data scraped",
                height=500,
                width=1000,
                scale=5,
                # color="Hotkey",
                x_label_angle=-30,
                color_legend_position="top",
                # elem_classes="daily_scraped_data",
            )
        gr.HTML("<br/>")
        with gr.Tab(label="Miners Data"):
            class_denominator = sum(
                miners_data[i].incentive #TODO: emssion to incentive
                for i in range(0, min(10, len(miners_data)))
                if miners_data[i].incentive
            )
            if class_denominator == 0:
                class_values = {
                    f"(uid={miners_data[i].uid}, hotkey={miners_data[i].hotkey[0:8]}) - {miners_data[i].url} · ${round(miners_data[i].emission * tao_price, 2):,}{round(miners_data[i].emission, 2):,})": miners_data[i].incentive + 1 / (class_denominator + 1)
                    for i in range(0, min(10, len(miners_data)))
                }
            else:
                class_values = {
                    f"(uid={miners_data[i].uid}, hotkey={miners_data[i].hotkey[0:8]}) - {miners_data[i].url} · ${round(miners_data[i].emission * tao_price, 2):,}{round(miners_data[i].emission, 2):,})": miners_data[i].incentive / class_denominator 
                    for i in range(0, min(10, len(miners_data)))
                # if miners_data[i].incentive
                }
            gr.Label(
                label="Top 10 Miners",
                value=class_values,
                num_top_classes=10,
            )
        # miner_table = gr.components.Dataframe(
        #     value=miners_data
        # )
        gr.HTML("<br/>")
        with gr.Accordion("Miner stats"):
            gr.HTML(
                f"""<h3>{last_refresh.strftime("refreshed at %H:%M on %Y-%m-%d")}</h3>"""
            )
            # with gr.Tabs():
            #     for entry in miners_data:
            #         name = f"uid={entry.uid} : commit={entry.commit[0:8]} : url={entry.url}"
            #         with gr.Tab(name):
            #             gr.Chatbot()
            leaderboard_table = gr.components.Dataframe(
                value=leaderboard_data(),
                headers = [
                    "Hotkey",
                    "UID",
                    "Url",
                    "Block",
                ],
                datatype=[
                    "markdown",
                    "number",
                    "markdown",
                    "number",

                ],
                elem_id="leaderboard_table",
                interactive=False,
                visible=True,

            )
        gr.HTML("<br/>")
        with gr.Accordion("Validator stats"):
            gr.HTML(
                f"""<h3>{last_refresh.strftime("refreshed at %H:%M on %Y-%m-%d")}</h3>"""
            )
            # with gr.Tabs():
            #     for entry in miners_data:
            #         name = f"uid={entry.uid} : commit={entry.commit[0:8]} : url={entry.url}"
            #         with gr.Tab(name):
            #             gr.Chatbot()
            leaderboard_table = gr.components.Dataframe(
                value=validator_data(),
                headers = [
                    "UID",
                    "Stake",
                    "V-Trust"
                ] + [
                    f"Miner-{miner[0]} (Incentive: {miner[1]})"
                    for miner in miners
                ],
                datatype=[
                    "number",
                    "number",
                    "number"

                ] + [
                    "number"
                    for miner in miners
                ],
                elem_id="leaderboard_table",
                interactive=False,
                visible=True,

            )
demo.launch()