mrfakename commited on
Commit
7128513
·
verified ·
1 Parent(s): c4f7417

Update app/leaderboard.py

Browse files
Files changed (1) hide show
  1. app/leaderboard.py +9 -9
app/leaderboard.py CHANGED
@@ -42,15 +42,15 @@ def get_leaderboard(reveal_prelim = False, hide_battle_votes = False):
42
  for j in range(len(df)):
43
  if i != j:
44
  try:
45
- expected_a = 1 / (1 + 10 ** ((df['score'][j] - df['score'][i]) / 400))
46
- expected_b = 1 / (1 + 10 ** ((df['score'][i] - df['score'][j]) / 400))
47
- actual_a = df['upvote'][i] / df['votes'][i] if df['votes'][i] > 0 else 0.5
48
- actual_b = df['upvote'][j] / df['votes'][j] if df['votes'][j] > 0 else 0.5
49
- df.at[i, 'score'] += 32 * (actual_a - expected_a)
50
- df.at[j, 'score'] += 32 * (actual_b - expected_b)
51
- except:
52
- print(f'Error in ELO calculation for {df["name"][i]} and {df["name"][j]}')
53
- pass
54
  df['score'] = round(df['score'])
55
  ## ELO SCORE
56
  df = df.sort_values(by='score', ascending=False)
 
42
  for j in range(len(df)):
43
  if i != j:
44
  try:
45
+ expected_a = 1 / (1 + 10 ** ((df['score'].iloc[j] - df['score'].iloc[i]) / 400))
46
+ expected_b = 1 / (1 + 10 ** ((df['score'].iloc[i] - df['score'].iloc[j]) / 400))
47
+ actual_a = df['upvote'].iloc[i] / df['votes'].iloc[i] if df['votes'].iloc[i] > 0 else 0.5
48
+ actual_b = df['upvote'].iloc[j] / df['votes'].iloc[j] if df['votes'].iloc[j] > 0 else 0.5
49
+ df.iloc[i, df.columns.get_loc('score')] += 32 * (actual_a - expected_a)
50
+ df.iloc[j, df.columns.get_loc('score')] += 32 * (actual_b - expected_b)
51
+ except Exception as e:
52
+ print(f"Error in ELO calculation for rows {i} and {j}: {str(e)}")
53
+ continue
54
  df['score'] = round(df['score'])
55
  ## ELO SCORE
56
  df = df.sort_values(by='score', ascending=False)