Пример #1
0
def get_game_stats(mode, size):
    conn = _conn()
    c = conn.cursor()
    c.execute("SELECT COUNT(1) FROM game WHERE gamemode = ? AND gamesize = ?",
              (mode, size))
    total_games = c.fetchone()[0]
    if not total_games:
        return "No stats for \u0002{0}\u0002 player games.".format(size)
    c.execute(
        """SELECT
                   winner AS team,
                   COUNT(1) AS games,
                   CASE winner
                     WHEN 'villagers' THEN 0
                     WHEN 'wolves' THEN 1
                     ELSE 2 END AS ord
                 FROM game
                 WHERE
                   gamemode = ?
                   AND gamesize = ?
                   AND winner IS NOT NULL
                 GROUP BY team
                 ORDER BY ord ASC, team ASC""", (mode, size))
    msg = "\u0002{0}\u0002 player games | {1}"
    bits = []
    for row in c:
        bits.append(
            "%s wins: %d (%d%%)" %
            (singular(row[0]), row[1], round(row[1] / total_games * 100)))
    bits.append("total games: {0}".format(total_games))
    return msg.format(size, ", ".join(bits))
Пример #2
0
def get_game_stats(mode, size):
    conn = _conn()
    c = conn.cursor()
    c.execute("SELECT COUNT(1) FROM game WHERE gamemode = ? AND gamesize = ?", (mode, size))
    total_games = c.fetchone()[0]
    if not total_games:
        return "No stats for \u0002{0}\u0002 player games.".format(size)
    c.execute("""SELECT
                   winner AS team,
                   COUNT(1) AS games,
                   CASE winner
                     WHEN 'villagers' THEN 0
                     WHEN 'wolves' THEN 1
                     ELSE 2 END AS ord
                 FROM game
                 WHERE
                   gamemode = ?
                   AND gamesize = ?
                   AND winner IS NOT NULL
                 GROUP BY team
                 ORDER BY ord ASC, team ASC""", (mode, size))
    msg = "\u0002{0}\u0002 player games | {1}"
    bits = []
    for row in c:
        bits.append("%s wins: %d (%d%%)" % (singular(row[0]), row[1], round(row[1]/total_games * 100)))
    bits.append("total games: {0}".format(total_games))
    return msg.format(size, ", ".join(bits))
Пример #3
0
def get_game_stats(mode, size):
    conn = _conn()
    c = conn.cursor()

    if mode == "all":
        c.execute("SELECT COUNT(1) FROM game WHERE gamesize = ?", (size,))
    else:
        c.execute("SELECT COUNT(1) FROM game WHERE gamemode = ? AND gamesize = ?", (mode, size))

    total_games = c.fetchone()[0]
    if not total_games:
        return "No stats for \u0002{0}\u0002 player games.".format(size)

    if mode == "all":
        c.execute("""SELECT
                       winner AS team,
                       COUNT(1) AS games,
                       CASE winner
                         WHEN 'villagers' THEN 0
                         WHEN 'wolves' THEN 1
                         ELSE 2 END AS ord
                     FROM game
                     WHERE
                       gamesize = ?
                       AND winner IS NOT NULL
                     GROUP BY team
                     ORDER BY ord ASC, team ASC""", (size,))
    else:
        c.execute("""SELECT
                       winner AS team,
                       COUNT(1) AS games,
                       CASE winner
                         WHEN 'villagers' THEN 0
                         WHEN 'wolves' THEN 1
                         ELSE 2 END AS ord
                     FROM game
                     WHERE
                       gamemode = ?
                       AND gamesize = ?
                       AND winner IS NOT NULL
                     GROUP BY team
                     ORDER BY ord ASC, team ASC""", (mode, size))

    if mode == "all":
        msg = "\u0002{0}\u0002 player games | ".format(size)
    else:
        msg = "\u0002{0}\u0002 player games (\u0002{1}\u0002) | ".format(size, mode)

    bits = []
    for row in c:
        winner = singular(row[0]).title()
        if not winner:
            winner = botconfig.NICK.title()
        bits.append("{0} wins: {1} ({2}%)".format(winner, row[1], round(row[1]/total_games * 100)))
    bits.append("Total games: {0}".format(total_games))

    return msg + ", ".join(bits)
Пример #4
0
def get_game_stats(mode, size):
    conn = _conn()
    c = conn.cursor()

    if mode == "*":
        c.execute("SELECT COUNT(1) FROM game WHERE gamesize = ?", (size,))
    else:
        c.execute("SELECT COUNT(1) FROM game WHERE gamemode = ? AND gamesize = ?", (mode, size))

    total_games = c.fetchone()[0]
    if not total_games:
        return messages["db_gstats_no_game"].format(size)

    if mode == "*":
        c.execute("""SELECT
                       winner AS team,
                       COUNT(1) AS games,
                       CASE winner
                         WHEN 'villagers' THEN 0
                         WHEN 'wolves' THEN 1
                         ELSE 2 END AS ord
                     FROM game
                     WHERE
                       gamesize = ?
                       AND winner IS NOT NULL
                     GROUP BY team
                     ORDER BY ord ASC, team ASC""", (size,))
    else:
        c.execute("""SELECT
                       winner AS team,
                       COUNT(1) AS games,
                       CASE winner
                         WHEN 'villagers' THEN 0
                         WHEN 'wolves' THEN 1
                         ELSE 2 END AS ord
                     FROM game
                     WHERE
                       gamemode = ?
                       AND gamesize = ?
                       AND winner IS NOT NULL
                     GROUP BY team
                     ORDER BY ord ASC, team ASC""", (mode, size))

    key = "db_gstats_specific"
    if mode == "all":
        key = "db_gstats_all"

    bits = []
    for row in c:
        if row[0] == "no_team_wins":
            winner = messages["db_gstats_no_team_wins"]
        elif not row[0]:
            winner = messages["db_gstats_nobody"]
        elif row[0] == "everyone":
            winner = messages["db_gstats_everyone"]
        else:
            # FIXME: kill off singular() and convert the db to just store the role key directly instead of a plural
            winner = LocalRole(singular(row[0])).singular.title()

        bits.append(messages["db_gstats_win"].format(winner, row[1], row[1]/total_games))
    bits.append(messages["db_gstats_total"].format(total_games))

    return messages[key].format(size, mode, bits)
Пример #5
0
def get_game_stats(mode, size):
    conn = _conn()
    c = conn.cursor()

    if mode == "all":
        c.execute("SELECT COUNT(1) FROM game WHERE gamesize = ?", (size, ))
    else:
        c.execute(
            "SELECT COUNT(1) FROM game WHERE gamemode = ? AND gamesize = ?",
            (mode, size))

    total_games = c.fetchone()[0]
    if not total_games:
        return messages["db_gstats_no_game"].format(size)

    if mode == "all":
        c.execute(
            """SELECT
                       winner AS team,
                       COUNT(1) AS games,
                       CASE winner
                         WHEN 'villagers' THEN 0
                         WHEN 'wolves' THEN 1
                         ELSE 2 END AS ord
                     FROM game
                     WHERE
                       gamesize = ?
                       AND winner IS NOT NULL
                     GROUP BY team
                     ORDER BY ord ASC, team ASC""", (size, ))
    else:
        c.execute(
            """SELECT
                       winner AS team,
                       COUNT(1) AS games,
                       CASE winner
                         WHEN 'villagers' THEN 0
                         WHEN 'wolves' THEN 1
                         ELSE 2 END AS ord
                     FROM game
                     WHERE
                       gamemode = ?
                       AND gamesize = ?
                       AND winner IS NOT NULL
                     GROUP BY team
                     ORDER BY ord ASC, team ASC""", (mode, size))

    key = "db_gstats_specific"
    if mode == "all":
        key = "db_gstats_all"

    bits = []
    for row in c:
        winner = singular(row[0])
        winner = get_role_name(winner, number=None).title()
        if not winner:
            winner = botconfig.NICK.title()
        bits.append(messages["db_gstats_win"].format(winner, row[1],
                                                     row[1] / total_games))
    bits.append(messages["db_gstats_total"].format(total_games))

    return messages[key].format(size, mode, bits)