afght12 commited on
Commit
fd8c150
1 Parent(s): 0587701

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -17
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
- return float(requests.get("https://api.mexc.com/api/v3/avgPrice?symbol=COMAIUSDT").json()["price"])
 
 
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
- com_price = get_com_price()
25
- blocks_in_day = 10_800
26
- client = CommuneClient(node_url)
27
- emission = client.query("Emission", params=[netuid])
28
- scores = {}
29
- for uid, emi in enumerate(emission):
30
- scores[uid] = ((emi / 10**11) * blocks_in_day) * com_price
31
-
32
- sorted_scores = sorted(scores.items(), key=lambda x: x[1], reverse=True)
33
- leaderboard_data = []
34
- for rank, (uid, score) in enumerate(sorted_scores, start=1):
35
- leaderboard_data.append({"rank": rank, "uid": uid, "score": score})
36
-
37
- return leaderboard_data
 
 
 
 
 
 
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")