stats: Add stats page
* add stats_table_data() function on the backend * add stats HTML page and route Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
This commit is contained in:
@@ -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")),
|
||||
]
|
||||
)
|
||||
|
||||
|
||||
36
chanbans/templates/stats.html
Normal file
36
chanbans/templates/stats.html
Normal file
@@ -0,0 +1,36 @@
|
||||
{% extends "base.html" %}
|
||||
|
||||
{% block title %}Stats{% endblock title %}
|
||||
|
||||
{% block main %}
|
||||
<h2>Statistics</h2>
|
||||
<div class="infobox">
|
||||
<h4>Histogram</h4>
|
||||
<p>
|
||||
<img src="{{static_url("histogram.svg")}}" width="33%" />
|
||||
</p>
|
||||
<p>
|
||||
<a target="_blank" href="{{static_url("histogram.svg")}}">Click here to see the full histogram view</a>
|
||||
</p>
|
||||
<hr/>
|
||||
<h4>Table</h4>
|
||||
<p>
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Board</th>
|
||||
<th>Bans</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for row in stats_table_data() %}
|
||||
<tr>
|
||||
<td>{{row['board']}}</td>
|
||||
<td>{{row["bans"]}}</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
</p>
|
||||
</div>
|
||||
{% endblock main %}
|
||||
Reference in New Issue
Block a user