ouhenio commited on
Commit
2b70f36
·
verified ·
1 Parent(s): 1596d90

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +62 -3
app.py CHANGED
@@ -221,6 +221,59 @@ def get_estereotipos_data(username_mapping):
221
 
222
  return result
223
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
224
  @lru_cache(maxsize=32)
225
  def get_user_contributions_cached(cache_buster: int):
226
  return consolidate_all_data()
@@ -231,8 +284,9 @@ def consolidate_all_data():
231
  blend_es_data, username_mapping = get_blend_es_data()
232
  include_data = get_include_data(username_mapping)
233
  estereotipos_data = get_estereotipos_data(username_mapping)
 
234
 
235
- all_user_ids = set(blend_es_data.keys()) | set(include_data.keys()) | set(estereotipos_data.keys())
236
 
237
  rows = []
238
  for user_id in all_user_ids:
@@ -245,6 +299,7 @@ def consolidate_all_data():
245
 
246
  include_value = include_data.get(user_id, 0)
247
  estereotipos_value = estereotipos_data.get(user_id, 0)
 
248
 
249
  if isinstance(user_id, str):
250
  if user_id.startswith("discord_"):
@@ -253,13 +308,17 @@ def consolidate_all_data():
253
  elif user_id.startswith("estereotipos_"):
254
  username = user_id.replace("estereotipos_", "")
255
  blend_es_value = 0
 
 
 
256
 
257
  row = {
258
  "Username": username,
259
- "Total": blend_es_value + include_value + estereotipos_value,
260
  "Blend-es": blend_es_value,
261
  "INCLUDE": include_value,
262
- "Estereotipos": estereotipos_value
 
263
  }
264
  rows.append(row)
265
 
 
221
 
222
  return result
223
 
224
+ def get_arena_data(username_mapping):
225
+ result = defaultdict(int)
226
+ try:
227
+ mail_to_discord = {}
228
+ if os.path.exists("mail_to_username.csv"):
229
+ mapping_df = pd.read_csv("mail_to_username.csv")
230
+ if "gmail" in mapping_df.columns and "discord" in mapping_df.columns:
231
+ for _, row in mapping_df.iterrows():
232
+ mail = row["gmail"]
233
+ discord = row["discord"]
234
+ if pd.notna(mail) and pd.notna(discord):
235
+ mail_to_discord[mail.lower()] = discord.lower()
236
+
237
+ if os.path.exists("arena.json"):
238
+ import json
239
+ with open("arena.json", "r", encoding="utf-8") as f:
240
+ arena_data = json.load(f)
241
+
242
+ mail_counts = defaultdict(int)
243
+
244
+ for country, conversations in arena_data.items():
245
+ for conversation in conversations:
246
+ if "username" in conversation:
247
+ mail = conversation["username"]
248
+ if mail:
249
+ mail_counts[mail.lower()] += 1
250
+
251
+ reverse_mapping = {}
252
+ for user_id, username in username_mapping.items():
253
+ reverse_mapping[username.lower()] = user_id
254
+
255
+ for mail, count in mail_counts.items():
256
+ discord_name = mail_to_discord.get(mail, "")
257
+ if discord_name:
258
+ matched = False
259
+ for argilla_name in reverse_mapping:
260
+ if discord_name in argilla_name or argilla_name in discord_name:
261
+ user_id = reverse_mapping[argilla_name]
262
+ result[user_id] += count
263
+ matched = True
264
+ break
265
+
266
+ if not matched:
267
+ result[f"arena_{discord_name}"] = count
268
+ else:
269
+ # Use just the username portion of the email (before the @)
270
+ username_part = mail.split('@')[0] if '@' in mail else mail
271
+ result[f"arena_{username_part}"] = count
272
+ except Exception as e:
273
+ print(f"Error loading arena data: {e}")
274
+
275
+ return result
276
+
277
  @lru_cache(maxsize=32)
278
  def get_user_contributions_cached(cache_buster: int):
279
  return consolidate_all_data()
 
284
  blend_es_data, username_mapping = get_blend_es_data()
285
  include_data = get_include_data(username_mapping)
286
  estereotipos_data = get_estereotipos_data(username_mapping)
287
+ arena_data = get_arena_data(username_mapping)
288
 
289
+ all_user_ids = set(blend_es_data.keys()) | set(include_data.keys()) | set(estereotipos_data.keys()) | set(arena_data.keys())
290
 
291
  rows = []
292
  for user_id in all_user_ids:
 
299
 
300
  include_value = include_data.get(user_id, 0)
301
  estereotipos_value = estereotipos_data.get(user_id, 0)
302
+ arena_value = arena_data.get(user_id, 0)
303
 
304
  if isinstance(user_id, str):
305
  if user_id.startswith("discord_"):
 
308
  elif user_id.startswith("estereotipos_"):
309
  username = user_id.replace("estereotipos_", "")
310
  blend_es_value = 0
311
+ elif user_id.startswith("arena_"):
312
+ username = user_id.replace("arena_", "")
313
+ blend_es_value = 0
314
 
315
  row = {
316
  "Username": username,
317
+ "Total": blend_es_value + include_value + estereotipos_value + arena_value,
318
  "Blend-es": blend_es_value,
319
  "INCLUDE": include_value,
320
+ "Estereotipos": estereotipos_value,
321
+ "Arena": arena_value
322
  }
323
  rows.append(row)
324