mirror of
https://github.com/RYGhub/royalnet.git
synced 2024-11-27 13:34:28 +00:00
Add hourly graph
This commit is contained in:
parent
20eb5ccb9d
commit
f8f4547743
4 changed files with 83 additions and 10 deletions
8
db.py
8
db.py
|
@ -21,7 +21,7 @@ from discord import User as DiscordUser
|
||||||
from telegram import User as TelegramUser
|
from telegram import User as TelegramUser
|
||||||
import loldata
|
import loldata
|
||||||
from dirty import Dirty, DirtyDelta
|
from dirty import Dirty, DirtyDelta
|
||||||
import query_discord_music
|
import sql_queries
|
||||||
from flask import escape
|
from flask import escape
|
||||||
import libgravatar
|
import libgravatar
|
||||||
import configparser
|
import configparser
|
||||||
|
@ -716,11 +716,11 @@ class Discord(Base, Mini):
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def mini_get_all(cls, session: Session):
|
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
|
@classmethod
|
||||||
def mini_get_single(cls, session: Session, **kwargs):
|
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
|
@classmethod
|
||||||
def mini_get_single_from_royal(cls, session: Session, royal: "Royal"):
|
def mini_get_single_from_royal(cls, session: Session, royal: "Royal"):
|
||||||
|
@ -927,7 +927,7 @@ class VoteQuestion(Base):
|
||||||
text = f"<b>{self.question}</b>\n\n"
|
text = f"<b>{self.question}</b>\n\n"
|
||||||
none, yes, no, abstain = 0, 0, 0, 0
|
none, yes, no, abstain = 0, 0, 0, 0
|
||||||
if self.message_id is not None:
|
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:
|
for record in query:
|
||||||
if record["username"] == "royalgamesbot":
|
if record["username"] == "royalgamesbot":
|
||||||
continue
|
continue
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
all_query = """SELECT
|
all_music_query = """SELECT
|
||||||
discord.royal_id,
|
discord.royal_id,
|
||||||
discord.discord_id,
|
discord.discord_id,
|
||||||
discord.name,
|
discord.name,
|
||||||
|
@ -59,7 +59,7 @@ LEFT JOIN
|
||||||
|
|
||||||
|
|
||||||
# TODO: can and should be optimized, but I'm too lazy for that
|
# TODO: can and should be optimized, but I'm too lazy for that
|
||||||
one_query = """SELECT
|
one_music_query = """SELECT
|
||||||
discord.royal_id,
|
discord.royal_id,
|
||||||
discord.discord_id,
|
discord.discord_id,
|
||||||
discord.name,
|
discord.name,
|
||||||
|
@ -141,3 +141,13 @@ LEFT JOIN
|
||||||
WHERE votequestion.message_id = :message_id
|
WHERE votequestion.message_id = :message_id
|
||||||
) answer ON telegram.telegram_id = answer.user_id
|
) answer ON telegram.telegram_id = answer.user_id
|
||||||
ORDER BY answer.choice;"""
|
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;"""
|
|
@ -151,6 +151,68 @@
|
||||||
},
|
},
|
||||||
"options":{
|
"options":{
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
<h1>
|
||||||
|
Media dell'attività per ogni ora
|
||||||
|
</h1>
|
||||||
|
<canvas class="graph members-graph-hour-bucket" id="discord-members-hour-bucket" height="60px"></canvas>
|
||||||
|
<script>
|
||||||
|
new Chart("discord-members-hour-bucket",
|
||||||
|
{
|
||||||
|
"type": "line",
|
||||||
|
"data": {
|
||||||
|
"labels": [
|
||||||
|
{% for point in hourly_avg %}
|
||||||
|
"{{ point.h|int }}:00",
|
||||||
|
{% endfor %}
|
||||||
|
],
|
||||||
|
"datasets": [
|
||||||
|
{
|
||||||
|
"label": "In cv",
|
||||||
|
"borderColor": "#fe7f00",
|
||||||
|
"backgroundColor": "#fe7f0022",
|
||||||
|
"borderWidth": 4,
|
||||||
|
"cubicInterpolationMode": "monotone",
|
||||||
|
"fill": "origin",
|
||||||
|
"data": [
|
||||||
|
{% for point in hourly_avg %}
|
||||||
|
{{ point.cv_members_avg }},
|
||||||
|
{% endfor %}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "In game",
|
||||||
|
"borderColor": "#9ae915",
|
||||||
|
"backgroundColor": "#9ae91511",
|
||||||
|
"borderWidth": 1,
|
||||||
|
"borderDash": [2],
|
||||||
|
"cubicInterpolationMode": "monotone",
|
||||||
|
"fill": "disabled",
|
||||||
|
"data": [
|
||||||
|
{% for point in hourly_avg %}
|
||||||
|
{{ point.ingame_members_avg }},
|
||||||
|
{% endfor %}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"label": "Online",
|
||||||
|
"borderColor": "#6dcff6",
|
||||||
|
"backgroundColor": "#6dcff611",
|
||||||
|
"borderWidth": 1,
|
||||||
|
"cubicInterpolationMode": "monotone",
|
||||||
|
"fill": 0,
|
||||||
|
"data": [
|
||||||
|
{% for point in hourly_avg %}
|
||||||
|
{{ point.online_members_avg }},
|
||||||
|
{% endfor %}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"options":{
|
||||||
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
|
@ -9,7 +9,7 @@ import datetime
|
||||||
# noinspection PyPackageRequirements
|
# noinspection PyPackageRequirements
|
||||||
import telegram
|
import telegram
|
||||||
import errors
|
import errors
|
||||||
import query_discord_music
|
import sql_queries
|
||||||
import random
|
import random
|
||||||
import re
|
import re
|
||||||
import functools
|
import functools
|
||||||
|
@ -310,7 +310,7 @@ def page_diario():
|
||||||
|
|
||||||
@app.route("/music")
|
@app.route("/music")
|
||||||
def page_music():
|
def page_music():
|
||||||
songs = fl_g.session.execute(query_discord_music.top_songs)
|
songs = fl_g.session.execute(sql_queries.top_songs)
|
||||||
return render_template("topsongs.html", songs=songs)
|
return render_template("topsongs.html", songs=songs)
|
||||||
|
|
||||||
|
|
||||||
|
@ -320,14 +320,15 @@ def page_music_individual(discord_id: str):
|
||||||
if discord is None:
|
if discord is None:
|
||||||
abort(404)
|
abort(404)
|
||||||
return
|
return
|
||||||
songs = fl_g.session.execute(query_discord_music.single_top_songs, {"discordid": discord.discord_id})
|
songs = fl_g.session.execute(sql_queries.single_top_songs, {"discordid": discord.discord_id})
|
||||||
return render_template("topsongs.html", songs=songs, discord=discord)
|
return render_template("topsongs.html", songs=songs, discord=discord)
|
||||||
|
|
||||||
|
|
||||||
@app.route("/activity")
|
@app.route("/activity")
|
||||||
def page_activity():
|
def page_activity():
|
||||||
reports = list(fl_g.session.query(db.ActivityReport).order_by(db.ActivityReport.timestamp.desc()).limit(192).all())
|
reports = list(fl_g.session.query(db.ActivityReport).order_by(db.ActivityReport.timestamp.desc()).limit(192).all())
|
||||||
return render_template("activity.html", activityreports=list(reversed(reports)))
|
hourly_avg = list(fl_g.session.execute(sql_queries.activity_by_hour))
|
||||||
|
return render_template("activity.html", activityreports=list(reversed(reports)), hourly_avg=hourly_avg)
|
||||||
|
|
||||||
|
|
||||||
@app.route("/ses/identify")
|
@app.route("/ses/identify")
|
||||||
|
|
Loading…
Reference in a new issue