ouhenio commited on
Commit
5fb1bc9
·
verified ·
1 Parent(s): 7a3a0f0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +60 -6
app.py CHANGED
@@ -172,6 +172,53 @@ def get_include_data(username_mapping):
172
 
173
  return result
174
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
175
  @lru_cache(maxsize=32)
176
  def get_user_contributions_cached(cache_buster: int):
177
  return consolidate_all_data()
@@ -181,8 +228,9 @@ def consolidate_all_data():
181
 
182
  blend_es_data, username_mapping = get_blend_es_data()
183
  include_data = get_include_data(username_mapping)
 
184
 
185
- all_user_ids = set(blend_es_data.keys()) | set(include_data.keys())
186
 
187
  rows = []
188
  for user_id in all_user_ids:
@@ -194,16 +242,22 @@ def consolidate_all_data():
194
  username = blend_es_data[user_id]["username"]
195
 
196
  include_value = include_data.get(user_id, 0)
 
197
 
198
- if isinstance(user_id, str) and user_id.startswith("discord_"):
199
- username = user_id.replace("discord_", "")
200
- blend_es_value = 0
 
 
 
 
201
 
202
  row = {
203
  "Username": username,
204
- "Total": blend_es_value + include_value,
205
  "Blend-es": blend_es_value,
206
- "INCLUDE": include_value
 
207
  }
208
  rows.append(row)
209
 
 
172
 
173
  return result
174
 
175
+ def get_estereotipos_data(username_mapping):
176
+ result = defaultdict(int)
177
+ try:
178
+ mail_to_discord = {}
179
+ if os.path.exists("mail_to_username.csv"):
180
+ mapping_df = pd.read_csv("mail_to_username.csv")
181
+ if "gmail" in mapping_df.columns and "discord" in mapping_df.columns:
182
+ for _, row in mapping_df.iterrows():
183
+ mail = row["gmail"]
184
+ discord = row["discord"]
185
+ if pd.notna(mail) and pd.notna(discord):
186
+ mail_to_discord[mail.lower()] = discord.lower()
187
+
188
+ if os.path.exists("token_id_counts.csv"):
189
+ counts_df = pd.read_csv("token_id_counts.csv")
190
+ if "token_id" in counts_df.columns and "count" in counts_df.columns:
191
+ mail_counts = defaultdict(int)
192
+ for _, row in counts_df.iterrows():
193
+ mail = row["token_id"]
194
+ count = row["count"]
195
+ if pd.notna(mail) and pd.notna(count):
196
+ mail_counts[mail.lower()] += int(count)
197
+
198
+ reverse_mapping = {}
199
+ for user_id, username in username_mapping.items():
200
+ reverse_mapping[username.lower()] = user_id
201
+
202
+ for mail, count in mail_counts.items():
203
+ discord_name = mail_to_discord.get(mail, "")
204
+ if discord_name:
205
+ matched = False
206
+ for argilla_name in reverse_mapping:
207
+ if discord_name in argilla_name or argilla_name in discord_name:
208
+ user_id = reverse_mapping[argilla_name]
209
+ result[user_id] += count
210
+ matched = True
211
+ break
212
+
213
+ if not matched:
214
+ result[f"estereotipos_{discord_name}"] = count
215
+ else:
216
+ result[f"estereotipos_{mail}"] = count
217
+ except Exception as e:
218
+ print(f"Error loading estereotipos data: {e}")
219
+
220
+ return result
221
+
222
  @lru_cache(maxsize=32)
223
  def get_user_contributions_cached(cache_buster: int):
224
  return consolidate_all_data()
 
228
 
229
  blend_es_data, username_mapping = get_blend_es_data()
230
  include_data = get_include_data(username_mapping)
231
+ estereotipos_data = get_estereotipos_data(username_mapping)
232
 
233
+ all_user_ids = set(blend_es_data.keys()) | set(include_data.keys()) | set(estereotipos_data.keys())
234
 
235
  rows = []
236
  for user_id in all_user_ids:
 
242
  username = blend_es_data[user_id]["username"]
243
 
244
  include_value = include_data.get(user_id, 0)
245
+ estereotipos_value = estereotipos_data.get(user_id, 0)
246
 
247
+ if isinstance(user_id, str):
248
+ if user_id.startswith("discord_"):
249
+ username = user_id.replace("discord_", "")
250
+ blend_es_value = 0
251
+ elif user_id.startswith("estereotipos_"):
252
+ username = user_id.replace("estereotipos_", "")
253
+ blend_es_value = 0
254
 
255
  row = {
256
  "Username": username,
257
+ "Total": blend_es_value + include_value + estereotipos_value,
258
  "Blend-es": blend_es_value,
259
+ "INCLUDE": include_value,
260
+ "Estereotipos": estereotipos_value
261
  }
262
  rows.append(row)
263