Spaces:
Sleeping
Sleeping
| import math | |
| from typing import Tuple | |
| def calculate_elo( | |
| rating_a: float, | |
| rating_b: float, | |
| score_a: float, | |
| k_factor: int = 32 | |
| ) -> Tuple[float, float]: | |
| """ | |
| Calculates the new ELO ratings for two participants. | |
| Args: | |
| rating_a: Current rating of participant A. | |
| rating_b: Current rating of participant B. | |
| score_a: Score for participant A (1.0 for win, 0.5 for tie, 0.0 for loss). | |
| k_factor: The K-factor determines how much the ratings change. | |
| Returns: | |
| A tuple containing (new_rating_a, new_rating_b). | |
| """ | |
| expected_a = 1 / (1 + math.pow(10, (rating_b - rating_a) / 400)) | |
| expected_b = 1 - expected_a | |
| score_b = 1 - score_a | |
| new_rating_a = rating_a + k_factor * (score_a - expected_a) | |
| new_rating_b = rating_b + k_factor * (score_b - expected_b) | |
| return round(new_rating_a, 2), round(new_rating_b, 2) | |