Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -12,29 +12,37 @@ def get_com_price() -> Any:
|
|
12 |
retries = 5
|
13 |
for i in range(0, retries):
|
14 |
try:
|
15 |
-
|
|
|
|
|
16 |
except Exception as e:
|
17 |
-
print(e)
|
18 |
if i == retries - 1:
|
19 |
raise
|
20 |
time.sleep(retries)
|
21 |
-
raise RuntimeError()
|
22 |
|
23 |
def get_leaderboard_data():
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
scores
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
leaderboard_data
|
36 |
-
|
37 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
38 |
|
39 |
with gr.Blocks() as demo:
|
40 |
gr.Markdown("# Commune Leaderboard")
|
|
|
12 |
retries = 5
|
13 |
for i in range(0, retries):
|
14 |
try:
|
15 |
+
price = float(requests.get("https://api.mexc.com/api/v3/avgPrice?symbol=COMAIUSDT").json()["price"])
|
16 |
+
print(f"Fetched COM price: {price}")
|
17 |
+
return price
|
18 |
except Exception as e:
|
19 |
+
print(f"Error fetching COM price: {e}")
|
20 |
if i == retries - 1:
|
21 |
raise
|
22 |
time.sleep(retries)
|
23 |
+
raise RuntimeError("Failed to fetch COM price")
|
24 |
|
25 |
def get_leaderboard_data():
|
26 |
+
try:
|
27 |
+
com_price = get_com_price()
|
28 |
+
blocks_in_day = 10_800
|
29 |
+
client = CommuneClient(node_url)
|
30 |
+
#emission = client.query("Emission", params=[netuid])
|
31 |
+
emission = [99999999, 99999, 99999999999999999, 11122]
|
32 |
+
scores = {}
|
33 |
+
for uid, emi in enumerate(emission):
|
34 |
+
scores[uid] = ((emi / 10**11) * blocks_in_day) * com_price
|
35 |
+
|
36 |
+
sorted_scores = sorted(scores.items(), key=lambda x: x[1], reverse=True)
|
37 |
+
leaderboard_data = []
|
38 |
+
for rank, (uid, score) in enumerate(sorted_scores, start=1):
|
39 |
+
leaderboard_data.append({"rank": rank, "uid": uid, "score": score})
|
40 |
+
|
41 |
+
print(f"Leaderboard data: {leaderboard_data}")
|
42 |
+
return leaderboard_data
|
43 |
+
except Exception as e:
|
44 |
+
print(f"Error fetching leaderboard data: {e}")
|
45 |
+
return []
|
46 |
|
47 |
with gr.Blocks() as demo:
|
48 |
gr.Markdown("# Commune Leaderboard")
|