diff --git a/sql_queries.py b/sql_queries.py index 4a0ada5a..aa7b29cc 100644 --- a/sql_queries.py +++ b/sql_queries.py @@ -147,7 +147,12 @@ activity_by_hour = """SELECT AVG(discord_members_online) online_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 + extract(hour from timestamp) h +FROM ( + SELECT *, + extract(month from timestamp) month_ + FROM activityreports + ) withmonth +WHERE withmonth.month_ = :current_month +GROUP BY h ORDER BY h;""" \ No newline at end of file diff --git a/templates/activity.html b/templates/activity.html index 6f30d5ce..7b4054d1 100644 --- a/templates/activity.html +++ b/templates/activity.html @@ -155,7 +155,7 @@ });

- Media dell'attività per ogni ora + Attività per ogni ora nell'ultimo mese

+

+ Confronto cv con il mese scorso +

+ + diff --git a/webserver.py b/webserver.py index 05de8a34..685c395e 100644 --- a/webserver.py +++ b/webserver.py @@ -365,8 +365,19 @@ def page_music_individual(discord_id: str): @app.route("/activity") def page_activity(): reports = list(fl_g.session.query(db.ActivityReport).order_by(db.ActivityReport.timestamp.desc()).limit(192).all()) - 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) + hourly_avg = list(fl_g.session.execute(sql_queries.activity_by_hour, {"current_month": datetime.datetime.now().month})) + previous_month = datetime.datetime.now().month - 1 + if previous_month == 0: + previous_month = 12 + hourly_comp = list(fl_g.session.execute(sql_queries.activity_by_hour, {"current_month": previous_month})) + even_before_month = previous_month - 1 + if even_before_month == 0: + even_before_month = 12 + hourly_before = list(fl_g.session.execute(sql_queries.activity_by_hour, {"current_month": even_before_month})) + return render_template("activity.html", activityreports=list(reversed(reports)), + hourly_avg=hourly_avg, + hourly_comp=hourly_comp, + hourly_before=hourly_before) @app.route("/ses/identify")