diff --git a/db.py b/db.py index 9e74aa2b..ae142f39 100644 --- a/db.py +++ b/db.py @@ -21,7 +21,7 @@ from discord import User as DiscordUser from telegram import User as TelegramUser import loldata from dirty import Dirty, DirtyDelta -import query_discord_music +import sql_queries from flask import escape import libgravatar import configparser @@ -716,11 +716,11 @@ class Discord(Base, Mini): @classmethod def mini_get_all(cls, session: Session): - return [dict(row) for row in session.execute(query_discord_music.all_query)] + return [dict(row) for row in session.execute(sql_queries.all_query)] @classmethod def mini_get_single(cls, session: Session, **kwargs): - return session.execute(query_discord_music.one_query, {"royal": kwargs["royal"].id}).fetchone() + return session.execute(sql_queries.one_query, {"royal": kwargs["royal"].id}).fetchone() @classmethod def mini_get_single_from_royal(cls, session: Session, royal: "Royal"): @@ -927,7 +927,7 @@ class VoteQuestion(Base): text = f"{self.question}\n\n" none, yes, no, abstain = 0, 0, 0, 0 if self.message_id is not None: - query = session.execute(query_discord_music.vote_answers, {"message_id": self.message_id}) + query = session.execute(sql_queries.vote_answers, {"message_id": self.message_id}) for record in query: if record["username"] == "royalgamesbot": continue diff --git a/query_discord_music.py b/sql_queries.py similarity index 90% rename from query_discord_music.py rename to sql_queries.py index 3e57d21e..4a0ada5a 100644 --- a/query_discord_music.py +++ b/sql_queries.py @@ -1,4 +1,4 @@ -all_query = """SELECT +all_music_query = """SELECT discord.royal_id, discord.discord_id, discord.name, @@ -59,7 +59,7 @@ LEFT JOIN # TODO: can and should be optimized, but I'm too lazy for that -one_query = """SELECT +one_music_query = """SELECT discord.royal_id, discord.discord_id, discord.name, @@ -141,3 +141,13 @@ LEFT JOIN WHERE votequestion.message_id = :message_id ) answer ON telegram.telegram_id = answer.user_id ORDER BY answer.choice;""" + +activity_by_hour = """SELECT AVG(discord_members_online) online_members_avg, + AVG(discord_members_ingame) ingame_members_avg, + AVG(discord_members_cv) cv_members_avg, + AVG(discord_channels_used) channels_used_avg, + AVG(discord_cv) cv_avg, + extract(hour from timestamp) h +FROM activityreports +GROUP BY h +ORDER BY h;""" \ No newline at end of file diff --git a/templates/activity.html b/templates/activity.html index 0d12e871..6f30d5ce 100644 --- a/templates/activity.html +++ b/templates/activity.html @@ -151,6 +151,68 @@ }, "options":{ + } + }); + +