add demoniac and succubus wins to gstats

tables should be automaticly converted
This commit is contained in:
jacob1 2015-10-31 12:13:52 -04:00
parent 4abd9a41dd
commit d4f9e59576
2 changed files with 34 additions and 17 deletions

View File

@ -665,7 +665,19 @@ def init_db():
c.execute(('CREATE TABLE IF NOT EXISTS gamestats (gamemode TEXT, size SMALLINT, villagewins SMALLINT, ' + c.execute(('CREATE TABLE IF NOT EXISTS gamestats (gamemode TEXT, size SMALLINT, villagewins SMALLINT, ' +
'wolfwins SMALLINT, monsterwins SMALLINT, foolwins SMALLINT, piperwins SMALLINT, totalgames SMALLINT, UNIQUE(gamemode, size))')) 'wolfwins SMALLINT, monsterwins SMALLINT, foolwins SMALLINT, piperwins SMALLINT, succubuswins SMALLINT, ' +
'demoniacwins SMALLINT, totalgames SMALLINT, UNIQUE(gamemode, size))'))
try:
# Check if table has been updated with new stats
c.execute('SELECT succubuswins from gamestats')
except sqlite3.OperationalError:
c.execute('ALTER TABLE gamestats RENAME TO gamestatsold')
c.execute('CREATE TABLE gamestats (gamemode TEXT, size SMALLINT, villagewins SMALLINT, wolfwins SMALLINT, ' +
'monsterwins SMALLINT, foolwins SMALLINT, piperwins SMALLINT,succubuswins SMALLINT, ' +
'demoniacwins SMALLINT, totalgames SMALLINT, UNIQUE(gamemode, size))')
c.execute('INSERT into gamestats (gamemode, size, villagewins, wolfwins, monsterwins, foolwins, piperwins, succubuswins, demoniacwins, totalgames) ' +
'SELECT gamemode, size, villagewins, wolfwins, monsterwins, foolwins, piperwins, 0, 0, totalgames FROM gamestatsold')
c.execute('DROP TABLE gamestatsold')
def remove_simple_rolemsg(clk): def remove_simple_rolemsg(clk):
@ -781,13 +793,13 @@ def update_role_stats(acc, role, won, iwon):
def update_game_stats(gamemode, size, winner): def update_game_stats(gamemode, size, winner):
with conn: with conn:
vwins, wwins, mwins, fwins, pwins, total = 0, 0, 0, 0, 0, 0 vwins, wwins, mwins, fwins, pwins, swins, dwins, total = 0, 0, 0, 0, 0, 0, 0, 0
c.execute("SELECT villagewins, wolfwins, monsterwins, foolwins, totalgames "+ c.execute("SELECT villagewins, wolfwins, monsterwins, foolwins, piperwins, succubuswins, "
"FROM gamestats WHERE gamemode=? AND size=?", (gamemode, size)) "demoniacwins, totalgames FROM gamestats WHERE gamemode=? AND size=?", (gamemode, size))
row = c.fetchone() row = c.fetchone()
if row: if row:
vwins, wwins, mwins, fwins, total = row vwins, wwins, mwins, fwins, pwins, swins, dwins, total = row
if winner == "wolves": if winner == "wolves":
wwins += 1 wwins += 1
@ -797,12 +809,16 @@ def update_game_stats(gamemode, size, winner):
mwins += 1 mwins += 1
elif winner == "pipers": elif winner == "pipers":
pwins += 1 pwins += 1
elif winner == "succubi":
swins += 1
elif winner == "demoniacs":
dwins += 1
elif winner.startswith("@"): elif winner.startswith("@"):
fwins += 1 fwins += 1
total += 1 total += 1
c.execute("INSERT OR REPLACE INTO gamestats VALUES (?,?,?,?,?,?,?,?)", c.execute("INSERT OR REPLACE INTO gamestats VALUES (?,?,?,?,?,?,?,?,?,?)",
(gamemode, size, vwins, wwins, mwins, fwins, pwins, total)) (gamemode, size, vwins, wwins, mwins, fwins, pwins, swins, dwins, total))
def get_player_stats(acc, role): def get_player_stats(acc, role):
if role.lower() not in [k.lower() for k in ROLE_GUIDE.keys()] and role != "lover": if role.lower() not in [k.lower() for k in ROLE_GUIDE.keys()] and role != "lover":
@ -847,14 +863,18 @@ def get_player_totals(acc):
def get_game_stats(gamemode, size): def get_game_stats(gamemode, size):
with conn: with conn:
for row in c.execute("SELECT * FROM gamestats WHERE gamemode=? AND size=?", (gamemode, size)): for row in c.execute("SELECT * FROM gamestats WHERE gamemode=? AND size=?", (gamemode, size)):
msg = "\u0002%d\u0002 player games | Village wins: %d (%d%%), Wolf wins: %d (%d%%)" % (row[1], row[2], round(row[2]/row[7] * 100), row[3], round(row[3]/row[7] * 100)) msg = "\u0002%d\u0002 player games | Village wins: %d (%d%%), Wolf wins: %d (%d%%)" % (row[1], row[2], round(row[2]/row[9] * 100), row[3], round(row[3]/row[9] * 100))
if row[4] > 0: if row[4] > 0:
msg += ", Monster wins: %d (%d%%)" % (row[4], round(row[4]/row[7] * 100)) msg += ", Monster wins: %d (%d%%)" % (row[4], round(row[4]/row[9] * 100))
if row[5] > 0: if row[5] > 0:
msg += ", Fool wins: %d (%d%%)" % (row[5], round(row[5]/row[7] * 100)) msg += ", Fool wins: %d (%d%%)" % (row[5], round(row[5]/row[9] * 100))
if row[6] > 0: if row[6] > 0:
msg += ", Piper wins: %d (%d%%)" % (row[6], round(row[6]/row[7] * 100)) msg += ", Piper wins: %d (%d%%)" % (row[6], round(row[6]/row[9] * 100))
return msg + ", Total games: {0}".format(row[7]) if row[7] > 0:
msg += ", Succubus wins: %d (%d%%)" % (row[7], round(row[7]/row[9] * 100))
if row[8] > 0:
msg += ", Demoniac wins: %d (%d%%)" % (row[8], round(row[8]/row[9] * 100))
return msg + ", Total games: {0}".format(row[9])
else: else:
return "No stats for \u0002{0}\u0002 player games.".format(size) return "No stats for \u0002{0}\u0002 player games.".format(size)

View File

@ -2524,11 +2524,8 @@ def stop_game(cli, winner = "", abort = False, additional_winners = None):
# determine if this player's team won # determine if this player's team won
if rol in var.TRUE_NEUTRAL_ROLES: if rol in var.TRUE_NEUTRAL_ROLES:
# most true neutral roles never have a team win, only individual wins. Exceptions to that are here # most true neutral roles never have a team win, only individual wins. Exceptions to that are here
if rol == "monster" and winner == "monsters": teams = {"monster":"monsters", "piper":"pipers", "succubus":"succubi", "demoniac":"demoniacs"}
won = True if rol in teams and winner == teams[rol]:
elif rol == "piper" and winner == "pipers":
won = True
elif rol == "succubus" and winner == "succubi":
won = True won = True
elif rol == "turncoat" and splr in var.TURNCOATS and var.TURNCOATS[splr][0] != "none": elif rol == "turncoat" and splr in var.TURNCOATS and var.TURNCOATS[splr][0] != "none":
won = (winner == var.TURNCOATS[splr][0]) won = (winner == var.TURNCOATS[splr][0])