Spaces:
Running on CPU Upgrade

lunarflu HF Staff commited on
Commit
5599f57
Β·
verified Β·
1 Parent(s): a987f79
Files changed (1) hide show
  1. app.py +24 -24
app.py CHANGED
@@ -263,29 +263,29 @@ async def add_exp(member_id):
263
  new_xp = int(old_xp) + XP_PER_MESSAGE
264
 
265
  # ----------------------------------------------------
266
- total_xp = global_df.loc[index, 'total_exp']
267
  hub_xp = global_df.loc[index, 'hub_exp']
268
 
269
- total_xp = str(total_xp)
270
  hub_xp = str(hub_xp)
271
 
272
- if total_xp.startswith("L") and total_xp.endswith("L"):
273
- total_xp = total_xp[1:-1]
274
  if hub_xp.startswith("L") and hub_xp.endswith("L"):
275
  hub_xp = hub_xp[1:-1]
276
 
277
- old_total_xp = int(total_xp)
278
 
279
  # check if hub exp not empty
280
  if hub_xp.strip():
281
- total_xp = int(new_xp) + int(hub_xp)
282
  else:
283
- total_xp = int(new_xp)
284
 
285
  # ----------------------------------------------------
286
 
287
  # total v
288
- current_level = calculate_level(total_xp)
289
 
290
  # convert back to string + google sheet proofing
291
  new_xp = str(new_xp)
@@ -294,13 +294,13 @@ async def add_exp(member_id):
294
  global_df.loc[index, 'discord_exp'] = new_xp # do not change column name
295
 
296
  # after
297
- if not total_xp.startswith("L") and not total_xp.endswith("L"):
298
- total_xp = f"L" + str(total_xp) + f"L"
299
 
300
  # add back to dataframe in memory after checking redundantly;
301
- if total_xp.startswith("L") and total_xp.endswith("L"):
302
  print("test5")
303
- global_df.loc[index, 'total_exp'] = total_xp # do not change column name
304
  print(f"Record for {member} updated from {old_total_xp} to {global_df.loc[index, 'total_exp']} (+{XP_PER_MESSAGE}) ")
305
 
306
  # level up
@@ -320,12 +320,12 @@ async def add_exp(member_id):
320
  # do calculations
321
  copy_df = global_df.copy()
322
  copy_df['discord_user_id'] = copy_df['discord_user_id'].str.strip('L').astype(str)
323
- copy_df['total_xp'] = copy_df['total_xp'].str.strip('L').astype(int)
324
  row = copy_df[copy_df['discord_user_id'] == str(member_id)]
325
  print(f"Row found for {member_id}!")
326
- target_exp = row['total_xp'].values[0]
327
- rank = (copy_df['total_xp'] > target_exp).sum() + 1
328
- print(f"The rank for discord_id {member_id} based on total_xp is: {rank}")
329
  except Exception as e:
330
  print(f"Discord ID {member_id} not found in the DataFrame.")
331
  rank = "πŸ€—"
@@ -337,14 +337,14 @@ async def add_exp(member_id):
337
 
338
 
339
  # L12345L -> `12345` -> 12345
340
- total_xp = total_xp[1:-1]
341
- total_xp = int(total_xp)
342
 
343
- if total_xp % 10 == 0: # staggers messages so we don't send one every time exp is earned
344
  # claim exp (-30 for level 3, but +100 as bonus exp. This scales infinitely until the member verifies,
345
  # so they can continue earning exp, it just won't translate to levels and the leaderboard.
346
  # This way they can claim at any time and get a big boost in levels!
347
- claim_exp = total_xp + 70
348
 
349
  # send embed
350
  embed = Embed(color=Color.red())
@@ -484,11 +484,11 @@ async def remove_huggingfolks():
484
 
485
  # drop first column (discord id -> this is so we can display the important stuff in the leaderboard)
486
  community_global_df.drop(community_global_df.columns[0], axis=1, inplace=True)
487
- community_global_df['total_xp'] = community_global_df['total_xp'].str.strip('L').astype(int)
488
- community_global_df['total_xp'] = pd.to_numeric(community_global_df['total_xp'])
489
- community_global_df = community_global_df.nlargest(len(community_global_df), 'total_xp')
490
 
491
- top_30_exp = community_global_df.nlargest(30, 'total_xp')
492
 
493
  top_30_exp['D'] = ['πŸ₯‡','πŸ₯ˆ','πŸ₯‰','','','','','','','','','','','','','','','','','','','','','','','','','','','']
494
  top_30_rows = top_30_exp.values.tolist()
 
263
  new_xp = int(old_xp) + XP_PER_MESSAGE
264
 
265
  # ----------------------------------------------------
266
+ total_exp = global_df.loc[index, 'total_exp']
267
  hub_xp = global_df.loc[index, 'hub_exp']
268
 
269
+ total_exp = str(total_exp)
270
  hub_xp = str(hub_xp)
271
 
272
+ if total_exp.startswith("L") and total_exp.endswith("L"):
273
+ total_exp = total_exp[1:-1]
274
  if hub_xp.startswith("L") and hub_xp.endswith("L"):
275
  hub_xp = hub_xp[1:-1]
276
 
277
+ old_total_xp = int(total_exp)
278
 
279
  # check if hub exp not empty
280
  if hub_xp.strip():
281
+ total_exp = int(new_xp) + int(hub_xp)
282
  else:
283
+ total_exp = int(new_xp)
284
 
285
  # ----------------------------------------------------
286
 
287
  # total v
288
+ current_level = calculate_level(total_exp)
289
 
290
  # convert back to string + google sheet proofing
291
  new_xp = str(new_xp)
 
294
  global_df.loc[index, 'discord_exp'] = new_xp # do not change column name
295
 
296
  # after
297
+ if not total_exp.startswith("L") and not total_exp.endswith("L"):
298
+ total_exp = f"L" + str(total_exp) + f"L"
299
 
300
  # add back to dataframe in memory after checking redundantly;
301
+ if total_exp.startswith("L") and total_exp.endswith("L"):
302
  print("test5")
303
+ global_df.loc[index, 'total_exp'] = total_exp # do not change column name
304
  print(f"Record for {member} updated from {old_total_xp} to {global_df.loc[index, 'total_exp']} (+{XP_PER_MESSAGE}) ")
305
 
306
  # level up
 
320
  # do calculations
321
  copy_df = global_df.copy()
322
  copy_df['discord_user_id'] = copy_df['discord_user_id'].str.strip('L').astype(str)
323
+ copy_df['total_exp'] = copy_df['total_exp'].str.strip('L').astype(int)
324
  row = copy_df[copy_df['discord_user_id'] == str(member_id)]
325
  print(f"Row found for {member_id}!")
326
+ target_exp = row['total_exp'].values[0]
327
+ rank = (copy_df['total_exp'] > target_exp).sum() + 1
328
+ print(f"The rank for discord_id {member_id} based on total_exp is: {rank}")
329
  except Exception as e:
330
  print(f"Discord ID {member_id} not found in the DataFrame.")
331
  rank = "πŸ€—"
 
337
 
338
 
339
  # L12345L -> `12345` -> 12345
340
+ total_exp = total_exp[1:-1]
341
+ total_exp = int(total_exp)
342
 
343
+ if total_exp % 10 == 0: # staggers messages so we don't send one every time exp is earned
344
  # claim exp (-30 for level 3, but +100 as bonus exp. This scales infinitely until the member verifies,
345
  # so they can continue earning exp, it just won't translate to levels and the leaderboard.
346
  # This way they can claim at any time and get a big boost in levels!
347
+ claim_exp = total_exp + 70
348
 
349
  # send embed
350
  embed = Embed(color=Color.red())
 
484
 
485
  # drop first column (discord id -> this is so we can display the important stuff in the leaderboard)
486
  community_global_df.drop(community_global_df.columns[0], axis=1, inplace=True)
487
+ community_global_df['total_exp'] = community_global_df['total_exp'].str.strip('L').astype(int)
488
+ community_global_df['total_exp'] = pd.to_numeric(community_global_df['total_exp'])
489
+ community_global_df = community_global_df.nlargest(len(community_global_df), 'total_exp')
490
 
491
+ top_30_exp = community_global_df.nlargest(30, 'total_exp')
492
 
493
  top_30_exp['D'] = ['πŸ₯‡','πŸ₯ˆ','πŸ₯‰','','','','','','','','','','','','','','','','','','','','','','','','','','','']
494
  top_30_rows = top_30_exp.values.tolist()