Spaces:
Runtime error
Runtime error
Update elo.py
Browse files
elo.py
CHANGED
@@ -1,13 +1,15 @@
|
|
1 |
import pandas as pd
|
2 |
|
3 |
-
def update_elo_ratings(
|
4 |
-
# Check if the
|
5 |
-
if
|
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
|
10 |
-
ratings_df = pd.DataFrame(
|
|
|
|
|
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
|
50 |
-
|
51 |
|
52 |
-
return
|
|
|
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
|