New! Added total wins of every player once the game is finished
This commit is contained in:
pare
efbe4c8f46
commit
9f18c72762
S'han modificat 1 arxius amb 55 adicions i 1 eliminacions
|
@ -419,6 +419,50 @@ def close_game():
|
|||
|
||||
conn.close()
|
||||
|
||||
def get_stats(player):
|
||||
|
||||
played_games = 0
|
||||
|
||||
wins = 0
|
||||
|
||||
try:
|
||||
|
||||
conn = None
|
||||
|
||||
conn = psycopg2.connect(database = chess_db, user = chess_db_user, password = "", host = "/var/run/postgresql", port = "5432")
|
||||
|
||||
cur = conn.cursor()
|
||||
|
||||
cur.execute("select count(*) from stats where white_user = (%s) or black_user = (%s) and finished", (player, player))
|
||||
|
||||
row = cur.fetchone()
|
||||
|
||||
if row != None:
|
||||
|
||||
played_games = row[0]
|
||||
|
||||
cur.execute("select count(*) from stats where winner = (%s) and finished", (player,))
|
||||
|
||||
row = cur.fetchone()
|
||||
|
||||
if row != None:
|
||||
|
||||
wins = row[0]
|
||||
|
||||
cur.close()
|
||||
|
||||
return (played_games, wins)
|
||||
|
||||
except (Exception, psycopg2.DatabaseError) as error:
|
||||
|
||||
sys.exit(error)
|
||||
|
||||
finally:
|
||||
|
||||
if conn is not None:
|
||||
|
||||
conn.close()
|
||||
|
||||
def waiting_games():
|
||||
|
||||
try:
|
||||
|
@ -907,10 +951,20 @@ if __name__ == '__main__':
|
|||
|
||||
toot_text += "\nEscac i mat! \nEl guanyador és: " + "@"+username + '\n'
|
||||
|
||||
toot_text += "\n@"+playing_user + ": ben jugat!"
|
||||
toot_text += "\n@"+playing_user + ": ben jugat!" + "\n"
|
||||
|
||||
close_game()
|
||||
|
||||
played_games, wins = get_stats(username)
|
||||
|
||||
toot_text += "\nPartides guanyades" + "\n"
|
||||
|
||||
toot_text += username + ": " + str(wins) + " de " + str(played_games) + "\n"
|
||||
|
||||
played_games, wins = get_stats(playing_user)
|
||||
|
||||
toot_text += playing_user + ": " + str(wins) + " de " + str(played_games) + "\n"
|
||||
|
||||
else:
|
||||
|
||||
toot_text = "@"+playing_user + ' el teu torn.'+ '\n'
|
||||
|
|
Loading…
Referencia en una nova incidència