gamestats are stored per roleset
This commit is contained in:
parent
15c8335349
commit
059fe556ec
@ -1184,6 +1184,7 @@ def stop_game(cli, winner = ""):
|
|||||||
iwon = False
|
iwon = False
|
||||||
elif rol == "fool" and "@" + splr == winner:
|
elif rol == "fool" and "@" + splr == winner:
|
||||||
iwon = True
|
iwon = True
|
||||||
|
winner = "fool"
|
||||||
elif rol == "monster" and splr in survived and winner == "monsters":
|
elif rol == "monster" and splr in survived and winner == "monsters":
|
||||||
iwon = True
|
iwon = True
|
||||||
elif splr in var.LOVERS and splr in survived:
|
elif splr in var.LOVERS and splr in survived:
|
||||||
@ -1245,7 +1246,7 @@ def stop_game(cli, winner = ""):
|
|||||||
size = len(survived) + len(var.DEAD)
|
size = len(survived) + len(var.DEAD)
|
||||||
# Only update if someone actually won, "" indicates everyone died or abnormal game stop
|
# Only update if someone actually won, "" indicates everyone died or abnormal game stop
|
||||||
if winner != "":
|
if winner != "":
|
||||||
var.update_game_stats(size, winner)
|
var.update_game_stats(var.CURRENT_ROLESET, size, winner)
|
||||||
|
|
||||||
# spit out the list of winners
|
# spit out the list of winners
|
||||||
winners.sort()
|
winners.sort()
|
||||||
@ -5810,38 +5811,45 @@ def game_stats(cli, nick, chan, rest):
|
|||||||
if (chan != nick and var.LAST_GSTATS and var.GSTATS_RATE_LIMIT and
|
if (chan != nick and var.LAST_GSTATS and var.GSTATS_RATE_LIMIT and
|
||||||
var.LAST_GSTATS + timedelta(seconds=var.GSTATS_RATE_LIMIT) >
|
var.LAST_GSTATS + timedelta(seconds=var.GSTATS_RATE_LIMIT) >
|
||||||
datetime.now()):
|
datetime.now()):
|
||||||
cli.notice(nick, ('This command is rate-limited. Please wait a while '
|
cli.notice(nick, ("This command is rate-limited. Please wait a while "
|
||||||
'before using it again.'))
|
"before using it again."))
|
||||||
return
|
return
|
||||||
|
|
||||||
if chan != nick:
|
if chan != nick:
|
||||||
var.LAST_GSTATS = datetime.now()
|
var.LAST_GSTATS = datetime.now()
|
||||||
|
|
||||||
if var.PHASE not in ('none', 'join'):
|
if var.PHASE not in ('none', 'join'):
|
||||||
cli.notice(nick, 'Wait until the game is over to view stats.')
|
cli.notice(nick, "Wait until the game is over to view stats.")
|
||||||
|
return
|
||||||
|
|
||||||
|
roleset = var.CURRENT_ROLESET
|
||||||
|
rest = rest.strip().split()
|
||||||
|
# Check for roleset
|
||||||
|
if len(rest) and not rest[0].isdigit():
|
||||||
|
roleset = rest[0]
|
||||||
|
if roleset not in var.GAME_MODES.keys():
|
||||||
|
cli.notice(nick, "{0} is not a valid roleset".format(roleset))
|
||||||
|
return
|
||||||
|
rest.pop(0)
|
||||||
|
# Check for invalid input
|
||||||
|
if len(rest) and rest[0].isdigit() and (
|
||||||
|
int(rest[0]) > var.GAME_MODES[roleset][2] or int(rest[0]) < var.GAME_MODES[roleset][1]):
|
||||||
|
cli.notice(nick, "Please enter an integer between "+\
|
||||||
|
"{0} and {1}.".format(var.GAME_MODES[roleset][1], var.GAME_MODES[roleset][2]))
|
||||||
return
|
return
|
||||||
|
|
||||||
# List all games sizes and totals if no size is given
|
# List all games sizes and totals if no size is given
|
||||||
if not rest:
|
if not len(rest):
|
||||||
if chan == nick:
|
if chan == nick:
|
||||||
pm(cli, nick, var.get_game_totals())
|
pm(cli, nick, var.get_game_totals(roleset))
|
||||||
else:
|
else:
|
||||||
cli.msg(chan, var.get_game_totals())
|
cli.msg(chan, var.get_game_totals(roleset))
|
||||||
|
|
||||||
return
|
|
||||||
|
|
||||||
# Check for invalid input
|
|
||||||
rest = rest.strip()
|
|
||||||
if not rest.isdigit() or int(rest) > var.MAX_PLAYERS or int(rest) < var.MIN_PLAYERS:
|
|
||||||
cli.notice(nick, ('Please enter an integer between {} and '
|
|
||||||
'{}.').format(var.MIN_PLAYERS, var.MAX_PLAYERS))
|
|
||||||
return
|
|
||||||
|
|
||||||
# Attempt to find game stats for the given game size
|
|
||||||
if chan == nick:
|
|
||||||
pm(cli, nick, var.get_game_stats(int(rest)))
|
|
||||||
else:
|
else:
|
||||||
cli.msg(chan, var.get_game_stats(int(rest)))
|
# Attempt to find game stats for the given game size
|
||||||
|
if chan == nick:
|
||||||
|
pm(cli, nick, var.get_game_stats(roleset, int(rest[0])))
|
||||||
|
else:
|
||||||
|
cli.msg(chan, var.get_game_stats(roleset, int(rest[0])))
|
||||||
|
|
||||||
|
|
||||||
@pmcmd('gamestats', 'gstats')
|
@pmcmd('gamestats', 'gstats')
|
||||||
|
@ -692,8 +692,8 @@ with conn:
|
|||||||
'UNIQUE(player, role))'))
|
'UNIQUE(player, role))'))
|
||||||
|
|
||||||
|
|
||||||
c.execute(('CREATE TABLE IF NOT EXISTS gamestats (size SMALLINT, villagewins SMALLINT, ' +
|
c.execute(('CREATE TABLE IF NOT EXISTS gamestats (roleset TEXT, size SMALLINT, villagewins SMALLINT, ' +
|
||||||
'wolfwins SMALLINT, totalgames SMALLINT, UNIQUE(size))'))
|
'wolfwins SMALLINT, monsterwins SMALLINT, foolwins SMALLINT, totalgames SMALLINT, UNIQUE(roleset, size))'))
|
||||||
|
|
||||||
|
|
||||||
if OPT_IN_PING:
|
if OPT_IN_PING:
|
||||||
@ -779,24 +779,28 @@ def update_role_stats(acc, role, won, iwon):
|
|||||||
c.execute("INSERT OR REPLACE INTO rolestats VALUES (?,?,?,?,?)",
|
c.execute("INSERT OR REPLACE INTO rolestats VALUES (?,?,?,?,?)",
|
||||||
(acc, role, wins, iwins, total))
|
(acc, role, wins, iwins, total))
|
||||||
|
|
||||||
def update_game_stats(size, winner):
|
def update_game_stats(roleset, size, winner):
|
||||||
with conn:
|
with conn:
|
||||||
vwins, wwins, total = 0, 0, 0
|
vwins, wwins, mwins, fwins, total = 0, 0, 0, 0, 0
|
||||||
|
|
||||||
c.execute("SELECT villagewins, wolfwins, totalgames FROM gamestats "+
|
c.execute("SELECT villagewins, wolfwins, monsterwins, foolwins, totalgames "+
|
||||||
"WHERE size=?", (size,))
|
"FROM gamestats WHERE roleset=? AND size=?", (roleset, size))
|
||||||
row = c.fetchone()
|
row = c.fetchone()
|
||||||
if row:
|
if row:
|
||||||
vwins, wwins, total = row
|
vwins, wwins, mwins, fwins, total = row
|
||||||
|
|
||||||
if winner == "wolves":
|
if winner == "wolves":
|
||||||
wwins += 1
|
wwins += 1
|
||||||
elif winner == "villagers":
|
elif winner == "villagers":
|
||||||
vwins += 1
|
vwins += 1
|
||||||
|
elif winner == "monsters":
|
||||||
|
mwins += 1
|
||||||
|
elif winner == "fool":
|
||||||
|
fwins += 1
|
||||||
total += 1
|
total += 1
|
||||||
|
|
||||||
c.execute("INSERT OR REPLACE INTO gamestats VALUES (?,?,?,?)",
|
c.execute("INSERT OR REPLACE INTO gamestats VALUES (?,?,?,?,?,?,?)",
|
||||||
(size, vwins, wwins, total))
|
(roleset, size, vwins, wwins, mwins, fwins, 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()]:
|
if role.lower() not in [k.lower() for k in ROLE_GUIDE.keys()]:
|
||||||
@ -831,27 +835,31 @@ def get_player_totals(acc):
|
|||||||
else:
|
else:
|
||||||
return "\u0002{0}\u0002 has not played any games.".format(acc)
|
return "\u0002{0}\u0002 has not played any games.".format(acc)
|
||||||
|
|
||||||
def get_game_stats(size):
|
def get_game_stats(roleset, size):
|
||||||
with conn:
|
with conn:
|
||||||
for row in c.execute("SELECT * FROM gamestats WHERE size=?", (size,)):
|
for row in c.execute("SELECT * FROM gamestats WHERE roleset=? AND size=?", (roleset, size)):
|
||||||
msg = "\u0002{0}\u0002 player games | Village wins: {1} (%d%%), Wolf wins: {2} (%d%%), Total games: {3}".format(*row)
|
msg = "\u0002%d\u0002 player games | Village wins: %d (%d%%), Wolf wins: %d (%d%%)" % (row[1], row[2], round(row[2]/row[6] * 100), row[3], round(row[3]/row[6] * 100))
|
||||||
return msg % (round(row[1]/row[3] * 100), round(row[2]/row[3] * 100))
|
if row[4] > 0:
|
||||||
|
msg += ", Monster wins: %d (%d%%)" % (row[4], round(row[4]/row[6] * 100))
|
||||||
|
if row[5] > 0:
|
||||||
|
msg += ", Fool wins: %d (%d%%)" % (row[5], round(row[5]/row[6] * 100))
|
||||||
|
return msg + ", Total games: {0}".format(row[6])
|
||||||
else:
|
else:
|
||||||
return "No stats for \u0002{0}\u0002 player games.".format(size)
|
return "No stats for \u0002{0}\u0002 player games.".format(size)
|
||||||
|
|
||||||
def get_game_totals():
|
def get_game_totals(roleset):
|
||||||
size_totals = []
|
size_totals = []
|
||||||
total = 0
|
total = 0
|
||||||
with conn:
|
with conn:
|
||||||
for size in range(MIN_PLAYERS, MAX_PLAYERS + 1):
|
for size in range(MIN_PLAYERS, MAX_PLAYERS + 1):
|
||||||
c.execute("SELECT size, totalgames FROM gamestats WHERE size=?", (size,))
|
c.execute("SELECT size, totalgames FROM gamestats WHERE roleset=? AND size=?", (roleset, size))
|
||||||
row = c.fetchone()
|
row = c.fetchone()
|
||||||
if row:
|
if row:
|
||||||
size_totals.append("\u0002{0}p\u0002: {1}".format(*row))
|
size_totals.append("\u0002{0}p\u0002: {1}".format(*row))
|
||||||
total += row[1]
|
total += row[1]
|
||||||
|
|
||||||
if len(size_totals) == 0:
|
if len(size_totals) == 0:
|
||||||
return "No games have been played."
|
return "No games have been played in the {0} roleset.".format(roleset)
|
||||||
else:
|
else:
|
||||||
return "Total games ({0}) | {1}".format(total, ", ".join(size_totals))
|
return "Total games ({0}) | {1}".format(total, ", ".join(size_totals))
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user