Spaces:
Runtime error
Runtime error
Commit
·
94af53a
1
Parent(s):
f8d385e
create leaderboard equipos
Browse files- app.py +101 -0
- leaderboard_equipos.csv +13 -0
app.py
CHANGED
@@ -15,7 +15,9 @@ load_dotenv()
|
|
15 |
# Constants
|
16 |
DATA_DIR = "data"
|
17 |
PARTICIPANTS_CSV = os.path.join(DATA_DIR, "participants.csv")
|
|
|
18 |
LEADERBOARD_PERSONAL_CSV = "leaderboard_personal.csv"
|
|
|
19 |
|
20 |
# Column mappings for participants info
|
21 |
COLUMN_MAP = {
|
@@ -25,6 +27,16 @@ COLUMN_MAP = {
|
|
25 |
"contact_email": "Email de contacto",
|
26 |
}
|
27 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
28 |
# Initialize Argilla client
|
29 |
try:
|
30 |
client = rg.Argilla(
|
@@ -127,6 +139,90 @@ def get_participant_info():
|
|
127 |
return {}
|
128 |
|
129 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
130 |
def get_blend_es_data():
|
131 |
"""Get blend-es data from Argilla."""
|
132 |
if not client:
|
@@ -349,6 +445,11 @@ def consolidate_all_data():
|
|
349 |
full_df.sort_values("Arena", ascending=False, inplace=True)
|
350 |
full_df.to_csv(LEADERBOARD_PERSONAL_CSV, index=False, encoding="utf-8")
|
351 |
|
|
|
|
|
|
|
|
|
|
|
352 |
# Return display dataframe for UI
|
353 |
display_df = pd.DataFrame(display_rows)
|
354 |
if not display_df.empty:
|
|
|
15 |
# Constants
|
16 |
DATA_DIR = "data"
|
17 |
PARTICIPANTS_CSV = os.path.join(DATA_DIR, "participants.csv")
|
18 |
+
EQUIPOS_CSV = os.path.join(DATA_DIR, "equipos.csv")
|
19 |
LEADERBOARD_PERSONAL_CSV = "leaderboard_personal.csv"
|
20 |
+
LEADERBOARD_EQUIPOS_CSV = "leaderboard_equipos.csv"
|
21 |
|
22 |
# Column mappings for participants info
|
23 |
COLUMN_MAP = {
|
|
|
27 |
"contact_email": "Email de contacto",
|
28 |
}
|
29 |
|
30 |
+
# Column mappings for teams info
|
31 |
+
TEAM_COLUMNS = {
|
32 |
+
"team_name": "Nombre del equipo",
|
33 |
+
"email_1": "Email 1",
|
34 |
+
"email_2": "Email 2",
|
35 |
+
"email_3": "Email 3",
|
36 |
+
"email_4": "Email 4",
|
37 |
+
"email_5": "Email 5",
|
38 |
+
}
|
39 |
+
|
40 |
# Initialize Argilla client
|
41 |
try:
|
42 |
client = rg.Argilla(
|
|
|
139 |
return {}
|
140 |
|
141 |
|
142 |
+
def get_team_leaderboard(personal_leaderboard_df):
|
143 |
+
"""Calculate team leaderboard based on personal scores."""
|
144 |
+
if not os.path.exists(EQUIPOS_CSV):
|
145 |
+
return pd.DataFrame()
|
146 |
+
|
147 |
+
try:
|
148 |
+
teams_df = pd.read_csv(EQUIPOS_CSV)
|
149 |
+
team_leaderboard = []
|
150 |
+
|
151 |
+
for _, team_row in teams_df.iterrows():
|
152 |
+
team_name = team_row.get(TEAM_COLUMNS["team_name"], "")
|
153 |
+
if not team_name:
|
154 |
+
continue
|
155 |
+
|
156 |
+
# Get team member emails
|
157 |
+
team_emails = []
|
158 |
+
for i in range(1, 6):
|
159 |
+
email_col = TEAM_COLUMNS[f"email_{i}"]
|
160 |
+
email = team_row.get(email_col, "")
|
161 |
+
if pd.notna(email) and email.strip():
|
162 |
+
team_emails.append(email.lower())
|
163 |
+
|
164 |
+
if not team_emails:
|
165 |
+
continue
|
166 |
+
|
167 |
+
# Map emails to Discord usernames and get scores
|
168 |
+
discord_usernames = []
|
169 |
+
team_scores = {"arena": 0, "blend_es": 0, "estereotipos": 0, "include": 0}
|
170 |
+
|
171 |
+
for email in team_emails:
|
172 |
+
# Get Discord username from email
|
173 |
+
discord_username = get_discord_username(email)
|
174 |
+
discord_usernames.append(discord_username)
|
175 |
+
|
176 |
+
# Find this user in the personal leaderboard
|
177 |
+
user_scores = personal_leaderboard_df[
|
178 |
+
personal_leaderboard_df["Username"].str.lower()
|
179 |
+
== discord_username.lower()
|
180 |
+
]
|
181 |
+
|
182 |
+
if not user_scores.empty:
|
183 |
+
team_scores["arena"] += user_scores.iloc[0]["Arena"]
|
184 |
+
team_scores["blend_es"] += user_scores.iloc[0]["Blend-ES"]
|
185 |
+
team_scores["estereotipos"] += user_scores.iloc[0]["Estereotipos"]
|
186 |
+
team_scores["include"] += user_scores.iloc[0]["INCLUDE"]
|
187 |
+
|
188 |
+
# Pad Discord usernames list to 5 elements
|
189 |
+
while len(discord_usernames) < 5:
|
190 |
+
discord_usernames.append("")
|
191 |
+
|
192 |
+
# Create team row
|
193 |
+
team_row_data = {
|
194 |
+
"team_name": team_name,
|
195 |
+
"discord_1": discord_usernames[0],
|
196 |
+
"discord_2": discord_usernames[1],
|
197 |
+
"discord_3": discord_usernames[2],
|
198 |
+
"discord_4": discord_usernames[3],
|
199 |
+
"discord_5": discord_usernames[4],
|
200 |
+
"total_arena": team_scores["arena"],
|
201 |
+
"ptos_arena": 0, # Set to 0 for now as requested
|
202 |
+
"total_blend_es": team_scores["blend_es"],
|
203 |
+
"ptos_blend_es": 0, # Set to 0 for now as requested
|
204 |
+
"total_estereotipos": team_scores["estereotipos"],
|
205 |
+
"ptos_estereotipos": 0, # Set to 0 for now as requested
|
206 |
+
"total_include": team_scores["include"],
|
207 |
+
"ptos_include": 0, # Set to 0 for now as requested
|
208 |
+
"ptos_total": 0, # Set to 0 for now as requested
|
209 |
+
}
|
210 |
+
|
211 |
+
team_leaderboard.append(team_row_data)
|
212 |
+
|
213 |
+
# Create DataFrame and sort by total_arena
|
214 |
+
if team_leaderboard:
|
215 |
+
team_df = pd.DataFrame(team_leaderboard)
|
216 |
+
team_df.sort_values("total_arena", ascending=False, inplace=True)
|
217 |
+
return team_df
|
218 |
+
else:
|
219 |
+
return pd.DataFrame()
|
220 |
+
|
221 |
+
except Exception as e:
|
222 |
+
print(f"Error calculating team leaderboard: {e}")
|
223 |
+
return pd.DataFrame()
|
224 |
+
|
225 |
+
|
226 |
def get_blend_es_data():
|
227 |
"""Get blend-es data from Argilla."""
|
228 |
if not client:
|
|
|
445 |
full_df.sort_values("Arena", ascending=False, inplace=True)
|
446 |
full_df.to_csv(LEADERBOARD_PERSONAL_CSV, index=False, encoding="utf-8")
|
447 |
|
448 |
+
# Generate and save team leaderboard
|
449 |
+
team_df = get_team_leaderboard(full_df)
|
450 |
+
if not team_df.empty:
|
451 |
+
team_df.to_csv(LEADERBOARD_EQUIPOS_CSV, index=False, encoding="utf-8")
|
452 |
+
|
453 |
# Return display dataframe for UI
|
454 |
display_df = pd.DataFrame(display_rows)
|
455 |
if not display_df.empty:
|
leaderboard_equipos.csv
ADDED
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
+
Cresia,roverico,cresia.aillm,roverico,,,280,0,0,0,0,0,608,0,0
|
3 |
+
TralaleloTralala-MemeAlign,andres_seba,andres_seba,peroloso,,,240,0,0,0,0,0,880,0,0
|
4 |
+
IberoTales,mcdaqc,,,,,118,0,0,0,0,0,449,0,0
|
5 |
+
SabiduriaPopular Castellana,alvaro8gb,enrique.solera.navarro,angustias22,comasberto,,105,0,0,0,0,0,2,0,0
|
6 |
+
Think Paraguayo,enpaiva93,luceldasilva,edmenciab,,,93,0,0,0,0,0,505,0,0
|
7 |
+
HoCV-COL,dreamripper1,,,,,83,0,0,0,0,0,987,0,0
|
8 |
+
Refranero Afro-Cubano,rasel3132,bel21093,,,,0,0,0,0,0,0,0,0,0
|
9 |
+
Comida Colombia + Ecuador,pablo.ce,pablo.ce,magodyboy,nestoralarcon.ed,diegomarquez2008,0,0,0,0,0,0,5660,0,0
|
10 |
+
Equipo LeIA,susanazhou,cosntanzapjeldres,,,,0,0,0,0,0,0,560,0,0
|
11 |
+
PeruWhisper,vandread13,vandread13,,,,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
|
13 |
+
MP,rvk6212,,,,,0,0,0,0,0,0,0,0,0
|