aboutsummaryrefslogtreecommitdiff
path: root/api/rating.py
diff options
context:
space:
mode:
authorlonkaars <l.leblansch@gmail.com>2021-03-28 12:19:28 +0200
committerlonkaars <l.leblansch@gmail.com>2021-03-28 12:19:28 +0200
commit2f4536d6b08b69168ebf3e718cbd8e3002b9af5a (patch)
tree5307692fb341d7f924ee9b73f3751e7e56cfb192 /api/rating.py
parent1f897d3f5ad11178cf4776ae4070c9d3e832f5f3 (diff)
added comments
Diffstat (limited to 'api/rating.py')
-rw-r--r--api/rating.py4
1 files changed, 4 insertions, 0 deletions
diff --git a/api/rating.py b/api/rating.py
index e05645f..bc49fda 100644
--- a/api/rating.py
+++ b/api/rating.py
@@ -14,13 +14,17 @@ def get_all_games(user_id):
"where (player_1_id = ? or player_2_id = ?) " + \
"and status = \"finished\" or status = \"resign\"", [user_id, user_id]).fetchall()
+# simple rating function that doesn't use game analysis
def get_rating(user_id):
score = 400
games = get_all_games(user_id)
+ # get all games for user_id and switch perspective in which user_id is player_2_id
mapped_games = [game if game[0] == user_id else (game[1], game[0], outcome(game[2], False)) for game in games]
counted_opponents = {}
for game in mapped_games:
+ # calculate sum score against user (+1 for win, -1 for lose, 0 for draw game)
counted_opponents |= {game[1]: (counted_opponents.get(game[1]) or 0) + { "w": 1, "l": -1, "d": 0 }[game[2]]}
for opponent in counted_opponents:
+ # apply the cool curve to the sum score and add to the base score of 400
score += rating_v1(counted_opponents.get(opponent))
return int(score)