rwitz commited on
Commit
e8b47d4
1 Parent(s): 0590b87

Update elo.py

Browse files
Files changed (1) hide show
  1. elo.py +10 -8
elo.py CHANGED
@@ -1,13 +1,15 @@
1
  import pandas as pd
2
 
3
- def update_elo_ratings(ratings_dataset, winner, loser):
4
- # Check if the ratings_dataset is empty
5
- if ratings_dataset is None or ratings_dataset.num_rows == 0:
6
  # Create a blank DataFrame with the required columns
7
  ratings_df = pd.DataFrame(columns=['bot_name', 'elo_rating', 'games_played'])
8
  else:
9
- # Convert the Hugging Face dataset to a pandas DataFrame
10
- ratings_df = pd.DataFrame(ratings_dataset)
 
 
11
 
12
  # Check and add new players if they don't exist in the dataset
13
  for player in [winner, loser]:
@@ -46,7 +48,7 @@ def update_elo_ratings(ratings_dataset, winner, loser):
46
  ratings_df.loc[ratings_df['bot_name'] == winner, 'elo_rating'] = winner_new_rating
47
  ratings_df.loc[ratings_df['bot_name'] == loser, 'elo_rating'] = loser_new_rating
48
 
49
- # Convert the DataFrame back to a Hugging Face dataset
50
- updated_ratings_dataset = Dataset.from_pandas(ratings_df)
51
 
52
- return updated_ratings_dataset
 
1
  import pandas as pd
2
 
3
+ def update_elo_ratings(ratings_dict, winner, loser):
4
+ # Check if the ratings_dict is empty
5
+ if not ratings_dict:
6
  # Create a blank DataFrame with the required columns
7
  ratings_df = pd.DataFrame(columns=['bot_name', 'elo_rating', 'games_played'])
8
  else:
9
+ # Convert the dictionary to a pandas DataFrame
10
+ ratings_df = pd.DataFrame.from_dict(ratings_dict, orient='index')
11
+ ratings_df.reset_index(inplace=True)
12
+ ratings_df.columns = ['bot_name', 'elo_rating', 'games_played']
13
 
14
  # Check and add new players if they don't exist in the dataset
15
  for player in [winner, loser]:
 
48
  ratings_df.loc[ratings_df['bot_name'] == winner, 'elo_rating'] = winner_new_rating
49
  ratings_df.loc[ratings_df['bot_name'] == loser, 'elo_rating'] = loser_new_rating
50
 
51
+ # Convert the DataFrame to a dictionary
52
+ updated_ratings_dict = ratings_df.set_index('bot_name').to_dict(orient='index')
53
 
54
+ return updated_ratings_dict