rwitz commited on
Commit
aec4104
·
verified ·
1 Parent(s): 98b5c48

Update elo.py

Browse files
Files changed (1) hide show
  1. elo.py +23 -9
elo.py CHANGED
@@ -1,11 +1,14 @@
1
  import math
2
 
3
- def update_elo_ratings(ratings_dict, winner, loser):
4
- # Extract old ratings and games played
5
- winner_old_rating = ratings_dict.get(winner, {}).get('elo_rating', 1200)
6
- loser_old_rating = ratings_dict.get(loser, {}).get('elo_rating', 1200)
7
- winner_games_played = ratings_dict.get(winner, {}).get('games_played', 0)
8
- loser_games_played = ratings_dict.get(loser, {}).get('games_played', 0)
 
 
 
9
 
10
  # Function to determine the K-factor based on games played
11
  def determine_k_factor(games_played):
@@ -35,8 +38,19 @@ def update_elo_ratings(ratings_dict, winner, loser):
35
  # Calculate new ratings
36
  winner_new_rating, loser_new_rating = elo(winner_old_rating, loser_old_rating, k_factor_winner=winner_k_factor, k_factor_loser=loser_k_factor)
37
 
38
- # Update ratings and games played in the dictionary
39
- ratings_dict[winner] = {'elo_rating': winner_new_rating, 'games_played': winner_games_played + 1}
40
- ratings_dict[loser] = {'elo_rating': loser_new_rating, 'games_played': loser_games_played + 1}
 
 
 
 
 
 
 
 
 
 
 
41
 
42
  return ratings_dict
 
1
  import math
2
 
3
+ def update_elo_ratings(ratings_dict, winner, loser, category):
4
+ # Extract old ratings and games played for the specific category
5
+ winner_category_data = ratings_dict.get(winner, {}).get(category, {})
6
+ loser_category_data = ratings_dict.get(loser, {}).get(category, {})
7
+
8
+ winner_old_rating = winner_category_data.get('elo_rating', 1200)
9
+ loser_old_rating = loser_category_data.get('elo_rating', 1200)
10
+ winner_games_played = winner_category_data.get('games_played', 0)
11
+ loser_games_played = loser_category_data.get('games_played', 0)
12
 
13
  # Function to determine the K-factor based on games played
14
  def determine_k_factor(games_played):
 
38
  # Calculate new ratings
39
  winner_new_rating, loser_new_rating = elo(winner_old_rating, loser_old_rating, k_factor_winner=winner_k_factor, k_factor_loser=loser_k_factor)
40
 
41
+ # Update ratings and games played in the dictionary for the specific category
42
+ if winner not in ratings_dict:
43
+ ratings_dict[winner] = {}
44
+ if category not in ratings_dict[winner]:
45
+ ratings_dict[winner][category] = {}
46
+ ratings_dict[winner][category]['elo_rating'] = winner_new_rating
47
+ ratings_dict[winner][category]['games_played'] = winner_games_played + 1
48
+
49
+ if loser not in ratings_dict:
50
+ ratings_dict[loser] = {}
51
+ if category not in ratings_dict[loser]:
52
+ ratings_dict[loser][category] = {}
53
+ ratings_dict[loser][category]['elo_rating'] = loser_new_rating
54
+ ratings_dict[loser][category]['games_played'] = loser_games_played + 1
55
 
56
  return ratings_dict