diff options
author | lonkaars <l.leblansch@gmail.com> | 2021-03-10 17:15:07 +0100 |
---|---|---|
committer | lonkaars <l.leblansch@gmail.com> | 2021-03-10 17:15:07 +0100 |
commit | e7358f0d8a4ce56f7eed5927cfadf0ee29f4508f (patch) | |
tree | c551326f1e36e14fa3147e8816c94a8ee20951bb /api | |
parent | 6fbf48dcd658db76d6ccd375ac9e8b0f5123df18 (diff) |
home page w/l/d + working outcome calc
Diffstat (limited to 'api')
-rw-r--r-- | api/user/games.py | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/api/user/games.py b/api/user/games.py index c61151a..009e5ee 100644 --- a/api/user/games.py +++ b/api/user/games.py @@ -7,6 +7,11 @@ from user.info import format_user from ruleset import resolve_ruleset import json +def outcome(outcome_str, player_1): + outcome_int = { "w": 1, "l": -1, "d": 0 }[outcome_str] + if not player_1: outcome_int *= -1 + return { 1: "w", -1: "l", 0: "d" }[outcome_int] + def game_info(game_id, user_id = None): game = cursor.execute("select " + ", ".join([ "game_id", # 0 @@ -25,14 +30,12 @@ def game_info(game_id, user_id = None): "private", # 13 ]) + " from games where game_id = ?", [game_id]).fetchone() is_player_1 = game[4] != user_id - outcome = "d" if game[5] == "d" else \ - "w" if game[5] == "w" and is_player_1 else "l" return { "id": game[0], "parent": game[1], "moves": [int(move) for move in str(game[2]).split(",")], "opponent": format_user(game[4] if is_player_1 else game[3]), - "outcome": outcome, + "outcome": outcome(game[5], is_player_1), "created": game[6], "started": game[7], "duration": game[8], @@ -93,11 +96,11 @@ def index(): not token: return "", 400 - if not cursor.execute("select user_id from users where user_id = ?", [user_id]).fetchone(): return "", 403 - if token and not user_id: user_id = token_login(token) + if not cursor.execute("select user_id from users where user_id = ?", [user_id]).fetchone(): return "", 403 + export = {} merge(export, {"totals": sum_games(user_id)}, |