Skip to content

Commit

Permalink
Another correction for last played
Browse files Browse the repository at this point in the history
  • Loading branch information
BrennanB committed Sep 23, 2024
1 parent 95fc47d commit db9cc5d
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
8 changes: 3 additions & 5 deletions ranked/api/lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,21 +93,19 @@ def get_match_player_info(red_alliance: List[User], blue_alliance: List[User], g



def update_player_elos(match: Match, red_player_elos: List[PlayerElo], blue_player_elos: List[PlayerElo], match_time=None):

def update_player_elos(match: Match, red_player_elos: List[PlayerElo], blue_player_elos: List[PlayerElo]):
"""
Updates the ELO ratings for players in a match.
Args:
match (Match): The match instance.
red_player_elos (List[PlayerElo]): List of PlayerElo objects for the red alliance.
blue_player_elos (List[PlayerElo]): List of PlayerElo objects for the blue alliance.
match_time (datetime, optional): The time of the match. Defaults to timezone.now().
Returns:
Tuple[List[float], List[float]]: ELO changes for red and blue alliances.
"""
if match_time is None:
match_time = timezone.now()

red_elo = match.red_starting_elo
blue_elo = match.blue_starting_elo
Expand Down Expand Up @@ -159,7 +157,7 @@ def update_player_elos(match: Match, red_player_elos: List[PlayerElo], blue_play
player.elo += elo_change

player.matches_played += 1
player.last_match_played_time = match_time # Use match_time instead of timezone.now()
player.last_match_played_time = match.time # Use match.time instead of timezone.now()
player.last_match_played_number = match.match_number

player.save()
Expand Down
2 changes: 1 addition & 1 deletion ranked/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,7 @@ def recalculate_elo(request: Request) -> Response:
blue_player_elos = PlayerElo.objects.filter(player__in=blue_players, game_mode=game_mode)

red_elo_changes, blue_elo_changes = update_player_elos(
match, list(red_player_elos), list(blue_player_elos), match=match.time)
match, list(red_player_elos), list(blue_player_elos))

for player_elo, elo_change in zip(red_player_elos, red_elo_changes):
player_elo.elo += elo_change
Expand Down

0 comments on commit db9cc5d

Please sign in to comment.