File size: 1,701 Bytes
6c858ba
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
import pandas as pd

from chain_data import WEIGHTS_BY_MINER, INCENTIVES, sync_metagraph


def get_color_by_weight(weight: float) -> str:
    if weight < 0.001:
        return "gray"
    elif weight < 0.3:
        r = int(255)
        g = int((weight / 0.3) * 165)
        return f"rgb({r}, {g}, 0)"
    elif weight < 0.8:
        progress = (weight - 0.3) / 0.5
        r = int(255 - (progress * 255))
        g = int(165 + (progress * 90))
        return f"rgb({r}, {g}, 0)"
    else:
        progress = (weight - 0.8) / 0.2
        g = int(255 - ((1 - progress) * 50))
        return f"rgb(0, {g}, 0)"

def create_weights() -> gr.Dataframe:
    data: list[list] = []
    sync_metagraph()

    headers = ["Miner UID", "Incentive"]
    datatype = ["number", "markdown"]

    validator_uids = set()
    for validator_weights in WEIGHTS_BY_MINER:
        for validator_uid, _ in validator_weights:
            validator_uids.add(validator_uid)

    for validator_uid in sorted(validator_uids):
        headers.append(str(validator_uid))
        datatype.append("markdown")

    for miner_uid, validator_weights in enumerate(WEIGHTS_BY_MINER):
        incentive = INCENTIVES[miner_uid]
        row = [miner_uid, f"<span style='color: {get_color_by_weight(incentive)}'>{incentive:.{3}f}</span>"]
        for _, weight in validator_weights:
            row.append(f"<span style='color: {get_color_by_weight(weight)}'>{weight:.{3}f}</span>")
        data.append(row)

    data.sort(key=lambda val: float(val[1].split(">")[1].split("<")[0]), reverse=True)

    return gr.Dataframe(
        pd.DataFrame(data, columns=headers),
        datatype=datatype,
        interactive=False,
    )