From cc9c5b5f43390bec84280fe3a0c290ca65634d1b Mon Sep 17 00:00:00 2001 From: Alek Ratzloff Date: Sat, 9 Sep 2023 22:59:38 -0700 Subject: [PATCH] stats: Add stats page * add stats_table_data() function on the backend * add stats HTML page and route Signed-off-by: Alek Ratzloff --- chanbans/http.py | 9 +++++++++ chanbans/templates/stats.html | 36 +++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+) create mode 100644 chanbans/templates/stats.html diff --git a/chanbans/http.py b/chanbans/http.py index 5c674a6..a15a1d6 100644 --- a/chanbans/http.py +++ b/chanbans/http.py @@ -13,6 +13,7 @@ from .db import get_db, search_db # 2023-07-24 - eating stirfry tonight. It's pretty bad. # 2023-07-31 - In a meeting. Hope I don't get caught +# 2023-09-09 - watching slime's stream def route_url(url: str, args: Optional[Mapping[str, Any]] = None): @@ -34,6 +35,12 @@ def static_url(resource: str): return f"{config.STATIC_ROOT}/{resource}" +def stats_table_data(): + with get_db() as db: + curs = db.execute("SELECT board, count(*) as bans FROM bans GROUP BY board") + return sorted(list(curs.fetchall()), key=lambda row: -row["bans"]) + + _env = Environment( loader=PackageLoader("chanbans"), autoescape=select_autoescape(), @@ -42,6 +49,7 @@ _env.globals.update( { "route_url": route_url, "static_url": static_url, + "stats_table_data": stats_table_data, } ) @@ -183,6 +191,7 @@ app.add_routes( web.get(config.HTTP_ROOT, IndexView), web.get(f"{config.HTTP_ROOT}/faq", template_view_factory("faq.html")), web.get(f"{config.HTTP_ROOT}/news", template_view_factory("news.html")), + web.get(f"{config.HTTP_ROOT}/stats", template_view_factory("stats.html")), ] ) diff --git a/chanbans/templates/stats.html b/chanbans/templates/stats.html new file mode 100644 index 0000000..2edb115 --- /dev/null +++ b/chanbans/templates/stats.html @@ -0,0 +1,36 @@ +{% extends "base.html" %} + +{% block title %}Stats{% endblock title %} + +{% block main %} +

Statistics

+
+

Histogram

+

+ +

+

+ Click here to see the full histogram view +

+
+

Table

+

+ + + + + + + + + {% for row in stats_table_data() %} + + + + + {% endfor %} + +
BoardBans
{{row['board']}}{{row["bans"]}}
+

+
+{% endblock main %}