mariagrandury commited on
Commit
377b868
·
1 Parent(s): d70837b

create challenge leaderboards as csv and md

Browse files
app.py CHANGED
@@ -1,52 +1,25 @@
1
- import json
2
- import os
3
  import time
4
- from collections import defaultdict
5
- from functools import lru_cache
6
 
7
- import argilla as rg
8
  import gradio as gr
9
  import pandas as pd
10
  from dotenv import load_dotenv
11
  from fastapi import FastAPI
12
 
13
- from calculate_personal_scores import calculate_personal_scores
14
- from calculate_team_scores import calculate_team_scores
15
-
16
  load_dotenv()
17
 
18
- # FastAPI app
19
  app = FastAPI()
20
 
21
- # Global variables for caching
22
- last_update_time = 0
23
- cached_data = None
24
 
25
 
26
  def create_leaderboard_ui():
27
  """Create the leaderboard UI with caching."""
28
- global cached_data, last_update_time
29
- current_time = time.time()
30
-
31
- if cached_data is not None and current_time - last_update_time < 300:
32
- df = cached_data
33
- else:
34
- print("Recalculating scores...")
35
- df = calculate_personal_scores()
36
- cached_data = df
37
- last_update_time = current_time
38
- calculate_team_scores()
39
-
40
- if not df.empty:
41
- df = df.reset_index(drop=True)
42
- df.index = df.index + 1
43
- df = df.rename_axis("Rank").reset_index()
44
 
 
45
  df_html = df.to_html(classes="leaderboard-table", border=0, index=False)
46
 
47
  return f"""
48
  <div style="margin: 20px 0;">
49
- <p>Última Actualización: {time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(last_update_time))}</p>
50
  <style>
51
  .leaderboard-table {{
52
  width: 100%;
@@ -112,21 +85,10 @@ def create_leaderboard_ui():
112
  """
113
 
114
 
115
- def refresh_data():
116
- """Refresh the leaderboard data."""
117
- global cached_data, last_update_time
118
- cached_data = None
119
- last_update_time = 0
120
- return create_leaderboard_ui()
121
-
122
-
123
- # Gradio interface
124
  with gr.Blocks(theme=gr.themes.Default()) as demo:
125
  with gr.Column(scale=1):
126
  gr.Markdown("# 🏆 Leaderboard Personal Retos Hackathon 2025")
127
  leaderboard_html = gr.HTML(create_leaderboard_ui)
128
- refresh_btn = gr.Button("🔄 Actualizar Datos", variant="primary")
129
- refresh_btn.click(fn=refresh_data, outputs=leaderboard_html)
130
 
131
  gr.mount_gradio_app(app, demo, path="/")
132
 
 
 
 
1
  import time
 
 
2
 
 
3
  import gradio as gr
4
  import pandas as pd
5
  from dotenv import load_dotenv
6
  from fastapi import FastAPI
7
 
 
 
 
8
  load_dotenv()
9
 
 
10
  app = FastAPI()
11
 
12
+ LEADERBOARD_PATH = "leaderboard_personal.csv"
 
 
13
 
14
 
15
  def create_leaderboard_ui():
16
  """Create the leaderboard UI with caching."""
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
17
 
18
+ df = pd.read_csv(LEADERBOARD_PATH)
19
  df_html = df.to_html(classes="leaderboard-table", border=0, index=False)
20
 
21
  return f"""
22
  <div style="margin: 20px 0;">
 
23
  <style>
24
  .leaderboard-table {{
25
  width: 100%;
 
85
  """
86
 
87
 
 
 
 
 
 
 
 
 
 
88
  with gr.Blocks(theme=gr.themes.Default()) as demo:
89
  with gr.Column(scale=1):
90
  gr.Markdown("# 🏆 Leaderboard Personal Retos Hackathon 2025")
91
  leaderboard_html = gr.HTML(create_leaderboard_ui)
 
 
92
 
93
  gr.mount_gradio_app(app, demo, path="/")
94
 
calculate_personal_scores.py CHANGED
@@ -261,6 +261,77 @@ def get_arena_data():
261
  return []
262
 
263
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
264
  def calculate_personal_scores():
265
  """Consolidate all data sources and create leaderboard."""
266
  # Collect all data
@@ -366,6 +437,10 @@ def calculate_personal_scores():
366
  os.path.join(LEADERBOARD_PERSONAL_CSV), index=False, encoding="utf-8"
367
  )
368
 
 
 
 
 
369
  return display_df
370
 
371
 
 
261
  return []
262
 
263
 
264
+ def create_challenge_leaderboards(display_df):
265
+ """Create individual CSV files for each challenge."""
266
+
267
+ # Create leaderboards directory if it doesn't exist
268
+ import os
269
+
270
+ leaderboards_dir = "leaderboards"
271
+ os.makedirs(leaderboards_dir, exist_ok=True)
272
+
273
+ for challenge in ["Arena", "Blend-ES", "Estereotipos", "INCLUDE"]:
274
+ if challenge in display_df.columns:
275
+ # Create challenge-specific dataframe with only username and challenge score
276
+ challenge_df = display_df[["Username", challenge]].copy()
277
+
278
+ # Sort by score (descending) and then by username (ascending) for ties
279
+ challenge_df = challenge_df.sort_values(
280
+ [challenge, "Username"], ascending=[False, True]
281
+ )
282
+
283
+ # Generate filenames in leaderboards directory
284
+ clean_challenge = challenge.replace(" ", "_").replace("-", "_")
285
+ csv_filename = os.path.join(
286
+ leaderboards_dir, f"leaderboard_{clean_challenge.lower()}.csv"
287
+ )
288
+ txt_filename = os.path.join(
289
+ leaderboards_dir, f"leaderboard_{clean_challenge.lower()}.txt"
290
+ )
291
+
292
+ # Save to CSV (include all participants)
293
+ challenge_df.to_csv(csv_filename, index=False, encoding="utf-8")
294
+ print(f"Created {csv_filename} with {len(challenge_df)} participants")
295
+
296
+ # Save to TXT as markdown table (exclude users with 0 scores)
297
+ with open(txt_filename, "w", encoding="utf-8") as f:
298
+ f.write(f"# {challenge} Leaderboard\n\n")
299
+ f.write("| Puesto | Discord ID | Puntuación |\n")
300
+ f.write("|------|----------|-------|\n")
301
+
302
+ rank = 1
303
+ for _, row in challenge_df.iterrows():
304
+ username = row["Username"]
305
+ score = row[challenge]
306
+
307
+ # Skip users with 0 scores
308
+ if score == 0:
309
+ continue
310
+
311
+ # Use medal emojis for top 3 ranks
312
+ if rank == 1:
313
+ rank_display = "🥇"
314
+ elif rank == 2:
315
+ rank_display = "🥈"
316
+ elif rank == 3:
317
+ rank_display = "🥉"
318
+ else:
319
+ rank_display = str(rank)
320
+
321
+ f.write(f"| {rank_display} | {username} | {score} |\n")
322
+ rank += 1
323
+
324
+ print(
325
+ f"Created {txt_filename} with markdown table format (excluding 0 scores)"
326
+ )
327
+
328
+ # Show top 5 scores
329
+ print(f"Top 5 {challenge} scores:")
330
+ for i, (_, row) in enumerate(challenge_df.head().iterrows(), 1):
331
+ print(f" {i}. {row['Username']}: {row[challenge]}")
332
+ print()
333
+
334
+
335
  def calculate_personal_scores():
336
  """Consolidate all data sources and create leaderboard."""
337
  # Collect all data
 
437
  os.path.join(LEADERBOARD_PERSONAL_CSV), index=False, encoding="utf-8"
438
  )
439
 
440
+ # Create individual challenge leaderboards
441
+ print("\nCreating individual challenge leaderboards...")
442
+ create_challenge_leaderboards(display_df)
443
+
444
  return display_df
445
 
446
 
leaderboard_equipos.csv DELETED
@@ -1,13 +0,0 @@
1
- team_name,discord_1,discord_2,discord_3,discord_4,discord_5,total_arena,ptos_arena,total_blend_es,ptos_blend_es,total_estereotipos,ptos_estereotipos,total_include,ptos_include,ptos_total
2
- TralaleloTralala-MemeAlign,andres_seba,peroloso,,,,120,1.2,0,0.0,70,0.7,370,1.0,2.9
3
- HoCV-COL,dreamripper1,,,,,83,0.83,0,0.0,85,0.85,902,1.0,2.6799999999999997
4
- Cresia,roverico,cresia.aillm,alberto.medina,,,140,1.4,0,0.0,1,0.01,303,1.0,2.41
5
- IberoTales,mcdaqc,,,,,118,1.18,0,0.0,2,0.02,449,1.0,2.2
6
- Think Paraguayo,enpaiva93,luceldasilva,edmenciab,,,93,0.93,0,0.0,3,0.03,502,1.0,1.96
7
- SabiduriaPopular Castellana,alvaro8gb,enrique.solera.navarro,angustias22,comasberto,,105,1.05,0,0.0,2,0.02,0,0.0,1.07
8
- Comida Colombia + Ecuador,pablo.ce,magodyboybusiness,nestoralarcon.ed,oddyec,,0,0.0,0,0.0,0,0.0,2830,1.0,1.0
9
- Equipo LeIA,susanazhou,cosntanzapjeldres,,,,0,0.0,0,0.0,0,0.0,560,1.0,1.0
10
- Refranero Afro-Cubano,rasel3132,bel21093,,,,0,0.0,0,0.0,0,0.0,0,0.0,0.0
11
- PeruWhisper,vandread13,,,,,0,0.0,0,0.0,0,0.0,0,0.0,0.0
12
- Falsos_Amigos,yeisonm3011,erick bustamante,dinho9779,,,0,0.0,0,0.0,0,0.0,0,0.0,0.0
13
- MP,rvk6212,,,,,0,0.0,0,0.0,0,0.0,0,0.0,0.0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
leaderboards/leaderboard_arena.csv ADDED
@@ -0,0 +1,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ Username,Arena
2
+ roverico,140
3
+ steminism,133
4
+ andres_seba,120
5
+ mcdaqc,118
6
+ dreamripper1,83
7
+ bea esparcia,80
8
+ angustias22,63
9
+ henry mantilla,58
10
+ fabianpp,50
11
+ alvaro8gb,42
12
+ enpaiva93,40
13
+ ghuerta170,35
14
+ edmenciab,30
15
+ luceldasilva,23
16
+ adriszmar,22
17
+ danielcavilla,19
18
+ helenpy,19
19
+ gonzalo_40146,8
20
+ gfuentes2000,1
21
+ gonzalo.fuentes,1
22
+ agumeister,0
23
+ alebravo,0
24
+ alexis_castillo,0
25
+ amayuelas,0
26
+ arri98,0
27
+ bel21093_72376,0
28
+ clauvallory,0
29
+ conilinguist,0
30
+ dramos7,0
31
+ elena w.,0
32
+ freddyalfonsoboulton,0
33
+ godswrath97,0
34
+ gonznm,0
35
+ gpalomeque,0
36
+ guidoivetta ,0
37
+ henrymantilla,0
38
+ jedzill4,0
39
+ jorge-neo,0
40
+ jorge.vallego,0
41
+ jorgeav,0
42
+ lucase#5596,0
43
+ maria isabel ll,0
44
+ mgomez8540,0
45
+ neovalleltd,0
46
+ oscarcumbicus,0
47
+ pablo.ce,0
48
+ rasel,0
49
+ reewos,0
50
+ susanazhou,0
51
+ valaery,0
52
+ xat.,0
53
+ yee51,0
leaderboards/leaderboard_arena.txt ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Arena Leaderboard
2
+
3
+ | Puesto | Discord ID | Puntuación |
4
+ |------|----------|-------|
5
+ | 🥇 | roverico | 140 |
6
+ | 🥈 | steminism | 133 |
7
+ | 🥉 | andres_seba | 120 |
8
+ | 4 | mcdaqc | 118 |
9
+ | 5 | dreamripper1 | 83 |
10
+ | 6 | bea esparcia | 80 |
11
+ | 7 | angustias22 | 63 |
12
+ | 8 | henry mantilla | 58 |
13
+ | 9 | fabianpp | 50 |
14
+ | 10 | alvaro8gb | 42 |
15
+ | 11 | enpaiva93 | 40 |
16
+ | 12 | ghuerta170 | 35 |
17
+ | 13 | edmenciab | 30 |
18
+ | 14 | luceldasilva | 23 |
19
+ | 15 | adriszmar | 22 |
20
+ | 16 | danielcavilla | 19 |
21
+ | 17 | helenpy | 19 |
22
+ | 18 | gonzalo_40146 | 8 |
23
+ | 19 | gfuentes2000 | 1 |
24
+ | 20 | gonzalo.fuentes | 1 |
leaderboards/leaderboard_blend_es.csv ADDED
@@ -0,0 +1,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ Username,Blend-ES
2
+ adriszmar,0
3
+ agumeister,0
4
+ alebravo,0
5
+ alexis_castillo,0
6
+ alvaro8gb,0
7
+ amayuelas,0
8
+ andres_seba,0
9
+ angustias22,0
10
+ arri98,0
11
+ bea esparcia,0
12
+ bel21093_72376,0
13
+ clauvallory,0
14
+ conilinguist,0
15
+ danielcavilla,0
16
+ dramos7,0
17
+ dreamripper1,0
18
+ edmenciab,0
19
+ elena w.,0
20
+ enpaiva93,0
21
+ fabianpp,0
22
+ freddyalfonsoboulton,0
23
+ gfuentes2000,0
24
+ ghuerta170,0
25
+ godswrath97,0
26
+ gonzalo.fuentes,0
27
+ gonzalo_40146,0
28
+ gonznm,0
29
+ gpalomeque,0
30
+ guidoivetta ,0
31
+ helenpy,0
32
+ henry mantilla,0
33
+ henrymantilla,0
34
+ jedzill4,0
35
+ jorge-neo,0
36
+ jorge.vallego,0
37
+ jorgeav,0
38
+ lucase#5596,0
39
+ luceldasilva,0
40
+ maria isabel ll,0
41
+ mcdaqc,0
42
+ mgomez8540,0
43
+ neovalleltd,0
44
+ oscarcumbicus,0
45
+ pablo.ce,0
46
+ rasel,0
47
+ reewos,0
48
+ roverico,0
49
+ steminism,0
50
+ susanazhou,0
51
+ valaery,0
52
+ xat.,0
53
+ yee51,0
leaderboards/leaderboard_blend_es.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ # Blend-ES Leaderboard
2
+
3
+ | Puesto | Discord ID | Puntuación |
4
+ |------|----------|-------|
leaderboards/leaderboard_estereotipos.csv ADDED
@@ -0,0 +1,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ Username,Estereotipos
2
+ bea esparcia,126
3
+ neovalleltd,122
4
+ dreamripper1,85
5
+ andres_seba,70
6
+ alexis_castillo,68
7
+ elena w.,57
8
+ alebravo,30
9
+ jedzill4,27
10
+ gonznm,24
11
+ agumeister,21
12
+ adriszmar,20
13
+ jorge.vallego,14
14
+ jorgeav,13
15
+ maria isabel ll,12
16
+ clauvallory,5
17
+ dramos7,5
18
+ enpaiva93,3
19
+ lucase#5596,3
20
+ alvaro8gb,2
21
+ mcdaqc,2
22
+ xat.,2
23
+ freddyalfonsoboulton,1
24
+ roverico,1
25
+ valaery,1
26
+ yee51,1
27
+ amayuelas,0
28
+ angustias22,0
29
+ arri98,0
30
+ bel21093_72376,0
31
+ conilinguist,0
32
+ danielcavilla,0
33
+ edmenciab,0
34
+ fabianpp,0
35
+ gfuentes2000,0
36
+ ghuerta170,0
37
+ godswrath97,0
38
+ gonzalo.fuentes,0
39
+ gonzalo_40146,0
40
+ gpalomeque,0
41
+ guidoivetta ,0
42
+ helenpy,0
43
+ henry mantilla,0
44
+ henrymantilla,0
45
+ jorge-neo,0
46
+ luceldasilva,0
47
+ mgomez8540,0
48
+ oscarcumbicus,0
49
+ pablo.ce,0
50
+ rasel,0
51
+ reewos,0
52
+ steminism,0
53
+ susanazhou,0
leaderboards/leaderboard_estereotipos.txt ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Estereotipos Leaderboard
2
+
3
+ | Puesto | Discord ID | Puntuación |
4
+ |------|----------|-------|
5
+ | 🥇 | bea esparcia | 126 |
6
+ | 🥈 | neovalleltd | 122 |
7
+ | 🥉 | dreamripper1 | 85 |
8
+ | 4 | andres_seba | 70 |
9
+ | 5 | alexis_castillo | 68 |
10
+ | 6 | elena w. | 57 |
11
+ | 7 | alebravo | 30 |
12
+ | 8 | jedzill4 | 27 |
13
+ | 9 | gonznm | 24 |
14
+ | 10 | agumeister | 21 |
15
+ | 11 | adriszmar | 20 |
16
+ | 12 | jorge.vallego | 14 |
17
+ | 13 | jorgeav | 13 |
18
+ | 14 | maria isabel ll | 12 |
19
+ | 15 | clauvallory | 5 |
20
+ | 16 | dramos7 | 5 |
21
+ | 17 | enpaiva93 | 3 |
22
+ | 18 | lucase#5596 | 3 |
23
+ | 19 | alvaro8gb | 2 |
24
+ | 20 | mcdaqc | 2 |
25
+ | 21 | xat. | 2 |
26
+ | 22 | freddyalfonsoboulton | 1 |
27
+ | 23 | roverico | 1 |
28
+ | 24 | valaery | 1 |
29
+ | 25 | yee51 | 1 |
leaderboards/leaderboard_include.csv ADDED
@@ -0,0 +1,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ Username,INCLUDE
2
+ pablo.ce,2830
3
+ amayuelas,2300
4
+ oscarcumbicus,1280
5
+ jorge-neo,927
6
+ dreamripper1,902
7
+ reewos,608
8
+ arri98,598
9
+ steminism,577
10
+ godswrath97,561
11
+ susanazhou,560
12
+ enpaiva93,502
13
+ mcdaqc,449
14
+ guidoivetta ,393
15
+ fabianpp,372
16
+ andres_seba,370
17
+ ghuerta170,353
18
+ mgomez8540,348
19
+ roverico,303
20
+ henrymantilla,302
21
+ bel21093_72376,300
22
+ conilinguist,300
23
+ rasel,300
24
+ adriszmar,227
25
+ gpalomeque,120
26
+ agumeister,0
27
+ alebravo,0
28
+ alexis_castillo,0
29
+ alvaro8gb,0
30
+ angustias22,0
31
+ bea esparcia,0
32
+ clauvallory,0
33
+ danielcavilla,0
34
+ dramos7,0
35
+ edmenciab,0
36
+ elena w.,0
37
+ freddyalfonsoboulton,0
38
+ gfuentes2000,0
39
+ gonzalo.fuentes,0
40
+ gonzalo_40146,0
41
+ gonznm,0
42
+ helenpy,0
43
+ henry mantilla,0
44
+ jedzill4,0
45
+ jorge.vallego,0
46
+ jorgeav,0
47
+ lucase#5596,0
48
+ luceldasilva,0
49
+ maria isabel ll,0
50
+ neovalleltd,0
51
+ valaery,0
52
+ xat.,0
53
+ yee51,0
leaderboards/leaderboard_include.txt ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # INCLUDE Leaderboard
2
+
3
+ | Puesto | Discord ID | Puntuación |
4
+ |------|----------|-------|
5
+ | 🥇 | pablo.ce | 2830 |
6
+ | 🥈 | amayuelas | 2300 |
7
+ | 🥉 | oscarcumbicus | 1280 |
8
+ | 4 | jorge-neo | 927 |
9
+ | 5 | dreamripper1 | 902 |
10
+ | 6 | reewos | 608 |
11
+ | 7 | arri98 | 598 |
12
+ | 8 | steminism | 577 |
13
+ | 9 | godswrath97 | 561 |
14
+ | 10 | susanazhou | 560 |
15
+ | 11 | enpaiva93 | 502 |
16
+ | 12 | mcdaqc | 449 |
17
+ | 13 | guidoivetta | 393 |
18
+ | 14 | fabianpp | 372 |
19
+ | 15 | andres_seba | 370 |
20
+ | 16 | ghuerta170 | 353 |
21
+ | 17 | mgomez8540 | 348 |
22
+ | 18 | roverico | 303 |
23
+ | 19 | henrymantilla | 302 |
24
+ | 20 | bel21093_72376 | 300 |
25
+ | 21 | conilinguist | 300 |
26
+ | 22 | rasel | 300 |
27
+ | 23 | adriszmar | 227 |
28
+ | 24 | gpalomeque | 120 |