bulubula commited on
Commit
dbccbb1
·
1 Parent(s): 5e40351
Files changed (2) hide show
  1. app.py +18 -17
  2. utils.py +11 -5
app.py CHANGED
@@ -3,7 +3,6 @@ import wandb
3
  import pandas as pd
4
  import os
5
  import time
6
- import pytz
7
  import datetime
8
  from typing import Dict, Any
9
  from utils import fetch_competition_summary, fetch_models_evaluation, highlight_score_column, get_competitions
@@ -36,23 +35,23 @@ def update_leader_info(
36
  competition: str,
37
  best_model: Dict[str, Any]
38
  ) -> Dict[str, Any]:
39
- start_date = best_model["Created At"]
40
- current_date = datetime.datetime.now(pytz.utc)
41
- days_on_top = (current_date - start_date).days
42
-
43
  if leader_info.get(competition) is None:
44
  leader_info[competition] = {
45
  "Miner hotkey": best_model["Miner hotkey"],
46
- "Date": start_date,
47
- "Days on Top": days_on_top,
48
  }
49
  else:
50
  if leader_info[competition]["Miner hotkey"] == best_model["Miner hotkey"]:
51
- leader_info[competition]["Days on Top"] += days_on_top
 
 
 
 
52
  else:
53
  leader_info[competition]["Miner hotkey"] = best_model["Miner hotkey"]
54
- leader_info[competition]["Date"] = start_date
55
- leader_info[competition]["Days on Top"] = days_on_top
56
  return leader_info[competition]
57
 
58
  @st.cache_data()
@@ -60,7 +59,8 @@ def load_competition_data(last_update_time=None):
60
  competition_summaries = {}
61
  model_evaluations = {}
62
  competitions = get_competitions(CONFIG_URL)
63
- for competition in competitions:
 
64
  competition_summaries[competition] = fetch_competition_summary(wandb_api, ENTITY, competition)
65
  model_evaluations[competition] = fetch_models_evaluation(wandb_api, ENTITY, competition)
66
 
@@ -83,7 +83,8 @@ def main():
83
  if st.session_state.last_update_time is None or (time.time() - st.session_state.last_update_time > UPDATE_INTERVAL):
84
  competition_summaries, model_evaluations, st.session_state.last_update_time = load_competition_data(st.session_state.last_update_time)
85
 
86
- for competition in competitions:
 
87
  if not competition_summaries[competition].empty:
88
  # get all winning hotkeys and number of wins
89
  winning_hotkeys = competition_summaries[competition]["Winning Hotkey"].value_counts()
@@ -106,7 +107,7 @@ def main():
106
  st.session_state.leader_info[competition] = {
107
  "Miner hotkey": "N/A",
108
  "Date": "N/A",
109
- "Days on Top": "N/A"
110
  }
111
  else:
112
  competition_summaries, model_evaluations, _ = load_competition_data(st.session_state.last_update_time)
@@ -116,8 +117,8 @@ def main():
116
  st.write("#### Select a competition to view more details and rankings.")
117
 
118
  # Create a header for the table
119
- cols = st.columns([1, 3, 2, 2, 3, 1])
120
- headers = ["Index", "Competition Name", "Date", "Miner hotkey", "Days on Top"]
121
  for col, header in zip(cols, headers):
122
  col.write(header)
123
 
@@ -126,14 +127,14 @@ def main():
126
 
127
  leader_info = st.session_state.get("leader_info", {}).get(competition, {})
128
 
129
- cols = st.columns([1, 3, 2, 2, 3, 1])
130
  cols[0].write(index)
131
 
132
  if cols[1].button(competition):
133
  st.session_state.selected_competition = competition
134
  cols[2].write(leader_info.get("Date", "N/A"))
135
  cols[3].write(leader_info.get("Miner hotkey", "N/A"))
136
- cols[4].write(leader_info.get("Days on Top", "N/A"))
137
  if st.session_state.selected_competition:
138
  competition_name = st.session_state.selected_competition
139
 
 
3
  import pandas as pd
4
  import os
5
  import time
 
6
  import datetime
7
  from typing import Dict, Any
8
  from utils import fetch_competition_summary, fetch_models_evaluation, highlight_score_column, get_competitions
 
35
  competition: str,
36
  best_model: Dict[str, Any]
37
  ) -> Dict[str, Any]:
 
 
 
 
38
  if leader_info.get(competition) is None:
39
  leader_info[competition] = {
40
  "Miner hotkey": best_model["Miner hotkey"],
41
+ "Date": time.strftime("%Y-%m-%d"),
42
+ # "Days on Top": 1
43
  }
44
  else:
45
  if leader_info[competition]["Miner hotkey"] == best_model["Miner hotkey"]:
46
+ # count the number of days on top
47
+ start_date = datetime.datetime.strptime(leader_info[competition]["Date"], "%Y-%m-%d")
48
+ current_date = datetime.datetime.now()
49
+ days_on_top = (current_date - start_date).days
50
+ # leader_info[competition]["Days on Top"] = days_on_top + 1
51
  else:
52
  leader_info[competition]["Miner hotkey"] = best_model["Miner hotkey"]
53
+ leader_info[competition]["Date"] = time.strftime("%Y-%m-%d")
54
+ # leader_info[competition]["Days on Top"] = 1
55
  return leader_info[competition]
56
 
57
  @st.cache_data()
 
59
  competition_summaries = {}
60
  model_evaluations = {}
61
  competitions = get_competitions(CONFIG_URL)
62
+ for competition_info in competitions:
63
+ competition = competition_info[0]
64
  competition_summaries[competition] = fetch_competition_summary(wandb_api, ENTITY, competition)
65
  model_evaluations[competition] = fetch_models_evaluation(wandb_api, ENTITY, competition)
66
 
 
83
  if st.session_state.last_update_time is None or (time.time() - st.session_state.last_update_time > UPDATE_INTERVAL):
84
  competition_summaries, model_evaluations, st.session_state.last_update_time = load_competition_data(st.session_state.last_update_time)
85
 
86
+ for competition_info in competitions:
87
+ competition = competition_info[0]
88
  if not competition_summaries[competition].empty:
89
  # get all winning hotkeys and number of wins
90
  winning_hotkeys = competition_summaries[competition]["Winning Hotkey"].value_counts()
 
107
  st.session_state.leader_info[competition] = {
108
  "Miner hotkey": "N/A",
109
  "Date": "N/A",
110
+ # "Days on Top": "N/A"
111
  }
112
  else:
113
  competition_summaries, model_evaluations, _ = load_competition_data(st.session_state.last_update_time)
 
117
  st.write("#### Select a competition to view more details and rankings.")
118
 
119
  # Create a header for the table
120
+ cols = st.columns([1, 3, 2, 2, 3])
121
+ headers = ["Index", "Competition Name", "Date", "Miner hotkey"]
122
  for col, header in zip(cols, headers):
123
  col.write(header)
124
 
 
127
 
128
  leader_info = st.session_state.get("leader_info", {}).get(competition, {})
129
 
130
+ cols = st.columns([1, 3, 2, 2, 3])
131
  cols[0].write(index)
132
 
133
  if cols[1].button(competition):
134
  st.session_state.selected_competition = competition
135
  cols[2].write(leader_info.get("Date", "N/A"))
136
  cols[3].write(leader_info.get("Miner hotkey", "N/A"))
137
+ # cols[4].write(leader_info.get("Days on Top", "N/A"))
138
  if st.session_state.selected_competition:
139
  competition_name = st.session_state.selected_competition
140
 
utils.py CHANGED
@@ -8,16 +8,22 @@ import requests
8
 
9
  def get_competitions(CONFIG_URL):
10
  """
11
- Get competition names from the config URL.
12
  """
13
- competition_names = []
14
  try:
15
  config = requests.get(CONFIG_URL).json()
16
  for competition in config:
17
- competition_names.append(competition["competition_id"])
 
 
 
 
 
18
  except Exception as e:
19
- st.write(f"Error loading competition names: {str(e)}")
20
- return competition_names
 
21
 
22
 
23
  def fetch_competition_summary(api, entity, project):
 
8
 
9
  def get_competitions(CONFIG_URL):
10
  """
11
+ Get competition names and their evaluation times from the config URL.
12
  """
13
+ competitions = []
14
  try:
15
  config = requests.get(CONFIG_URL).json()
16
  for competition in config:
17
+ # Extract competition name and evaluation times
18
+ competition_name = competition["competition_id"]
19
+ evaluation_times = competition.get("evaluation_times", [])
20
+
21
+ # Store competition name and evaluation times as a tuple
22
+ competitions.append((competition_name, evaluation_times))
23
  except Exception as e:
24
+ print(f"Error loading competition data: {str(e)}")
25
+
26
+ return competitions
27
 
28
 
29
  def fetch_competition_summary(api, entity, project):