feat: initial project setup

This commit is contained in:
Stijnvandenbroek
2026-03-06 12:25:07 +00:00
commit e1a67da3ce
33 changed files with 2069 additions and 0 deletions

26
backend/app/elo.py Normal file
View File

@@ -0,0 +1,26 @@
"""ELO rating calculation."""
def calculate_elo(
winner_rating: float,
loser_rating: float,
k_factor: float = 32.0,
) -> tuple[float, float]:
"""Calculate new ELO ratings after a match.
Uses the standard ELO formula:
E = 1 / (1 + 10^((R_opponent - R_self) / 400))
R_new = R_old + K * (S - E)
where S = 1 for a win, S = 0 for a loss.
Returns:
(new_winner_rating, new_loser_rating)
"""
expected_winner = 1.0 / (1.0 + 10.0 ** ((loser_rating - winner_rating) / 400.0))
expected_loser = 1.0 - expected_winner
new_winner = winner_rating + k_factor * (1.0 - expected_winner)
new_loser = loser_rating + k_factor * (0.0 - expected_loser)
return round(new_winner, 2), round(new_loser, 2)