Refactored some stats code.
Made update_roles_stats() and update_game_stats() a bit cleaner.
This commit is contained in:
parent
7f9def0b2c
commit
32fa38a6c9
@ -838,10 +838,7 @@ def stop_game(cli, winner = ""):
|
||||
var.update_role_stats(acc, rol, won, iwon)
|
||||
|
||||
size = len(var.list_players()) + len(var.DEAD)
|
||||
if winner == "wolves":
|
||||
var.update_game_stats(size, False, True)
|
||||
elif winner == "villagers":
|
||||
var.update_game_stats(size, True, False)
|
||||
var.update_game_stats(size, winner)
|
||||
|
||||
reset(cli)
|
||||
|
||||
|
@ -263,15 +263,13 @@ def add_ping(clk):
|
||||
|
||||
def update_role_stats(acc, role, won, iwon):
|
||||
with conn:
|
||||
wins, iwins, totalgames = 0, 0, 0
|
||||
wins, iwins, total = 0, 0, 0
|
||||
|
||||
c.execute(("SELECT teamwins, individualwins, totalgames FROM rolestats "+
|
||||
"WHERE player=? AND role=?"), (acc, role))
|
||||
row = c.fetchone()
|
||||
if row:
|
||||
wins, iwins, total = row
|
||||
else:
|
||||
wins, iwins, total = 0,0,0
|
||||
|
||||
if won:
|
||||
wins += 1
|
||||
@ -282,7 +280,7 @@ def update_role_stats(acc, role, won, iwon):
|
||||
c.execute("INSERT OR REPLACE INTO rolestats VALUES (?,?,?,?,?)",
|
||||
(acc, role, wins, iwins, total))
|
||||
|
||||
def update_game_stats(size, vwon, wwon):
|
||||
def update_game_stats(size, winner):
|
||||
with conn:
|
||||
vwins, wwins, total = 0, 0, 0
|
||||
|
||||
@ -292,10 +290,10 @@ def update_game_stats(size, vwon, wwon):
|
||||
if row:
|
||||
vwins, wwins, total = row
|
||||
|
||||
if vwon:
|
||||
vwins += 1
|
||||
if wwon:
|
||||
if winner == "wolves":
|
||||
wwins += 1
|
||||
elif winner == "villagers":
|
||||
vwins += 1
|
||||
total += 1
|
||||
|
||||
c.execute("INSERT OR REPLACE INTO gamestats VALUES (?,?,?,?)",
|
||||
|
Loading…
Reference in New Issue
Block a user