Improve some comments/output
This commit is contained in:
parent
adccdf737b
commit
f0b658f290
1 changed files with 11 additions and 2 deletions
13
ratings.py
13
ratings.py
|
@ -103,10 +103,11 @@ def get_current_variant_rating(variant_id: int, player_count: int) -> float:
|
|||
def process_rating_of_next_game():
|
||||
game_id = next_game_to_rate()
|
||||
if game_id is None:
|
||||
logger.info("All games already processed for rating changes.")
|
||||
logger.verbose("All games already processed for rating changes.")
|
||||
return
|
||||
logger.verbose("Processing rating for game {}".format)
|
||||
logger.verbose("Processing rating for game {}".format(game_id))
|
||||
cur = conn_manager.get_new_cursor()
|
||||
|
||||
# Fetch data on the game played
|
||||
cur.execute(
|
||||
"SELECT games.league_id, games.num_players, games.score, variants.num_suits, variants.clue_starved, variants.id "
|
||||
|
@ -118,6 +119,7 @@ def process_rating_of_next_game():
|
|||
)
|
||||
league_id, num_players, score, num_suits, clue_starved, variant_id = cur.fetchone()
|
||||
|
||||
# Fetch game participants
|
||||
cur.execute("SELECT game_participants.user_id FROM games "
|
||||
"INNER JOIN game_participants "
|
||||
" ON games.id = game_participants.game_id "
|
||||
|
@ -132,20 +134,27 @@ def process_rating_of_next_game():
|
|||
logger.error(err_msg)
|
||||
raise ValueError(err_msg)
|
||||
|
||||
# Fetch current ratings of variant and players involved
|
||||
rating_type = utils.get_rating_type(clue_starved)
|
||||
user_ratings = get_current_user_ratings(user_ids, rating_type)
|
||||
variant_rating = get_current_variant_rating(variant_id, num_players)
|
||||
|
||||
# Calculate changes in rating
|
||||
# TODO: If we want to use, we still have to think about how to define the K-factor and add it here
|
||||
user_changes, variant_change = rating_change(user_ratings, variant_rating, score == 5 * num_suits)
|
||||
|
||||
# Update database for variants
|
||||
cur.execute("INSERT INTO variant_ratings (league_id, variant_id, player_count, change, value_after) "
|
||||
"VALUES (%s, %s, %s, %s, %s)",
|
||||
(league_id, variant_id, num_players, variant_change, variant_rating + variant_change)
|
||||
)
|
||||
# Note: We do not commit here, only after players have been processed as well
|
||||
|
||||
user_ratings_vals = []
|
||||
for user_id, change in user_changes.items():
|
||||
user_ratings_vals.append((league_id, user_id, rating_type, change, user_ratings[user_id] + change))
|
||||
|
||||
# This updates the player rating.
|
||||
psycopg2.extras.execute_values(
|
||||
cur,
|
||||
"INSERT INTO user_ratings (league_id, user_id, type, change, value_after) "
|
||||
|
|
Loading…
Reference in a new issue