emsesc commited on
Commit
b4d92e4
Β·
1 Parent(s): 2811ff1

modify leaderboards

Browse files
Files changed (1) hide show
  1. graphs/leaderboard.py +19 -14
graphs/leaderboard.py CHANGED
@@ -3,7 +3,7 @@ from dash import html
3
 
4
  def create_leaderboard(filtered_df, country_df, developer_df, model_df, start_time=None, end_time=None, top_n=10):
5
  country_icon_map = {
6
- "United States of America": "πŸ‡ΊπŸ‡Έ",
7
  "China": "πŸ‡¨πŸ‡³",
8
  "Germany": "πŸ‡©πŸ‡ͺ",
9
  "France": "πŸ‡«πŸ‡·",
@@ -88,17 +88,22 @@ def create_leaderboard(filtered_df, country_df, developer_df, model_df, start_ti
88
  chips = []
89
  # Countries
90
  for c in meta.get("country", []):
 
 
91
  chips.append((country_icon_map.get(c, ""), c))
92
  # Author
93
  for a in meta.get("author", []):
94
- chips.append((company_icon_map.get(a, ""), a))
 
 
 
 
 
 
95
  # Downloads
96
  for d in meta.get("downloads", []):
97
  if pd.notna(d): # Check if d is not NaN
98
  chips.append(("⬇️", f"{int(d):,}"))
99
- # Org or User
100
- for o in meta.get("org_or_user", []):
101
- chips.append(("🏒" if o == "org" else "πŸ‘€", "Org" if o == "org" else "User"))
102
  return chips
103
 
104
  # Apply metadata builder to top dataframe
@@ -142,7 +147,7 @@ def create_leaderboard(filtered_df, country_df, developer_df, model_df, start_ti
142
  "borderRadius": "12px",
143
  "margin": "2px",
144
  "display": "inline-flex",
145
- "alignItems": "center",
146
  "fontSize": "14px"
147
  })
148
  )
@@ -150,7 +155,7 @@ def create_leaderboard(filtered_df, country_df, developer_df, model_df, start_ti
150
  chips.append(chip(f"{icon} {name}", chip_color))
151
  return html.Div(
152
  chips,
153
- style={"display": "flex", "flexWrap": "wrap", "justifyContent": "center"}
154
  )
155
 
156
  # Progress bar for % of total
@@ -194,19 +199,19 @@ def create_leaderboard(filtered_df, country_df, developer_df, model_df, start_ti
194
  # Table renderer
195
  def render_table(df, title, chip_color="#F0F0F0", bar_color="#4CAF50"):
196
  return html.Div([
197
- html.H4(title, style={"textAlign": "center", "marginBottom": "10px", "fontSize": "20px"}),
198
  html.Table([
199
  html.Thead(html.Tr([
200
- html.Th("Rank", style={"backgroundColor": "#F0F0F0"}),
201
- html.Th("Name", style={"backgroundColor": "#F0F0F0"}),
202
- html.Th("Metadata", style={"backgroundColor": "#F0F0F0"}),
203
- html.Th("% of Total", style={"backgroundColor": "#F0F0F0"})
204
  ])),
205
  html.Tbody([
206
  html.Tr([
207
  html.Td(idx+1, style={"textAlign": "center"}),
208
- html.Td(row["Name"], style={"textAlign": "center"}),
209
- html.Td(render_chips(row["Metadata"], chip_color), style={"textAlign": "center"}),
210
  html.Td(progress_bar(row["% of total"], bar_color), style={"textAlign": "center"})
211
  ]) for idx, row in df.iterrows()
212
  ])
 
3
 
4
  def create_leaderboard(filtered_df, country_df, developer_df, model_df, start_time=None, end_time=None, top_n=10):
5
  country_icon_map = {
6
+ "USA": "πŸ‡ΊπŸ‡Έ",
7
  "China": "πŸ‡¨πŸ‡³",
8
  "Germany": "πŸ‡©πŸ‡ͺ",
9
  "France": "πŸ‡«πŸ‡·",
 
88
  chips = []
89
  # Countries
90
  for c in meta.get("country", []):
91
+ if c == "United States of America":
92
+ c = "USA"
93
  chips.append((country_icon_map.get(c, ""), c))
94
  # Author
95
  for a in meta.get("author", []):
96
+ icon = company_icon_map.get(a, "")
97
+ if icon == "":
98
+ if meta.get("org_or_user", ["user"])[0] == "org":
99
+ icon = "🏒"
100
+ else:
101
+ icon = "πŸ‘€"
102
+ chips.append((icon, a))
103
  # Downloads
104
  for d in meta.get("downloads", []):
105
  if pd.notna(d): # Check if d is not NaN
106
  chips.append(("⬇️", f"{int(d):,}"))
 
 
 
107
  return chips
108
 
109
  # Apply metadata builder to top dataframe
 
147
  "borderRadius": "12px",
148
  "margin": "2px",
149
  "display": "inline-flex",
150
+ "alignItems": "left",
151
  "fontSize": "14px"
152
  })
153
  )
 
155
  chips.append(chip(f"{icon} {name}", chip_color))
156
  return html.Div(
157
  chips,
158
+ style={"display": "flex", "flexWrap": "wrap", "justifyContent": "left"}
159
  )
160
 
161
  # Progress bar for % of total
 
199
  # Table renderer
200
  def render_table(df, title, chip_color="#F0F0F0", bar_color="#4CAF50"):
201
  return html.Div([
202
+ html.H4(title, style={"textAlign": "left", "marginBottom": "10px", "fontSize": "20px"}),
203
  html.Table([
204
  html.Thead(html.Tr([
205
+ html.Th("Rank", style={"backgroundColor": "#F0F0F0", "textAlign": "left"}),
206
+ html.Th("Name", style={"backgroundColor": "#F0F0F0", "textAlign": "left"}),
207
+ html.Th("Metadata", style={"backgroundColor": "#F0F0F0", "textAlign": "left", "marginRight": "10px"}),
208
+ html.Th("% of Total", style={"backgroundColor": "#F0F0F0", "textAlign": "left"})
209
  ])),
210
  html.Tbody([
211
  html.Tr([
212
  html.Td(idx+1, style={"textAlign": "center"}),
213
+ html.Td(row["Name"], style={"textAlign": "left"}),
214
+ html.Td(render_chips(row["Metadata"], chip_color)),
215
  html.Td(progress_bar(row["% of total"], bar_color), style={"textAlign": "center"})
216
  ]) for idx, row in df.iterrows()
217
  ])