File size: 2,386 Bytes
6c858ba
 
 
b190717
 
6c858ba
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b190717
 
 
 
 
 
 
 
 
 
 
 
 
 
6c858ba
 
 
 
 
 
b190717
 
6c858ba
b190717
6c858ba
 
 
 
 
 
 
b190717
f6f4fa7
 
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import gradio as gr
import pandas as pd

from chain_data import WEIGHTS_BY_MINER, INCENTIVES, sync_metagraph, Weight
from wandb_data import Uid, get_current_runs


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 get_active_weights() -> list[list[tuple[Uid, Weight]]]:
    runs = get_current_runs()
    weights: list[list[tuple[Uid, Weight]]] = []

    for miner_uid, validator_weights in enumerate(WEIGHTS_BY_MINER):
        new_weights: list[tuple[Uid, Weight]] = []
        for validator_uid, weight in validator_weights:
            if validator_uid in [run.uid for run in runs]:
                new_weights.append((validator_uid, weight))
        weights.append(new_weights)

    return weights

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

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

    weights = WEIGHTS_BY_MINER if include_inactive else get_active_weights()

    validator_uids = set()
    for validator_weights in weights:
        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):
        if miner_uid not in INCENTIVES:
            break
        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,
    )