Bumped version to 8.2; added a simple /stats page

This commit is contained in:
Jaakko Keränen 2024-01-16 13:30:55 +02:00
parent 78f936cc22
commit 1b0d2b6acc
No known key found for this signature in database
GPG Key ID: BACCFCFB98DB2EDC
3 changed files with 40 additions and 1 deletions

View File

@ -18,7 +18,7 @@ from utils import *
from worker import *
__version__ = '8.1'
__version__ = '8.2'
class Bubble:
@ -961,6 +961,9 @@ Deleting a subspace will delete all posts and comments in the subspace, i.e., th
if session.user and session.user.flags & User.HOME_FOLLOWED_FEED_FLAG \
else 'all'
elif req.path == self.path + 'stats':
return make_stats_page(session)
else:
return 51, "Not found"

View File

@ -222,3 +222,20 @@ def admin_actions(session):
page += f'\n=> {session.path}admin/ Back to Administration\n'
return page
def make_stats_page(session):
db = session.db
page = '# Statistics\n\n'
stats = db.get_statistics()
page += f"""```Table: Accounts and activity
Total accounts {stats['total']:4d}
Total posters {stats['posters']:4d}
Total commenters {stats['commenters']:4d}
Visited <= 30 days {stats['m_visited']:4d}
Post/comment <= 30 days {stats['m_post_cmt']:4d}
```
=> {session.path} Back to front page\n
"""
return page

View File

@ -2886,6 +2886,25 @@ class Database:
cur.execute("INSERT INTO log (remote, type) VALUES (?, ?)", (address_hash(from_addr), type))
self.commit()
def get_statistics(self):
cur = self.conn.cursor()
cur.execute("""SELECT
(SELECT COUNT(id) FROM users) AS total,
(SELECT COUNT(id) FROM users WHERE TIMESTAMPDIFF(DAY, ts_active, CURRENT_TIMESTAMP()) <= 30) AS m_visited,
(SELECT COUNT(DISTINCT(user)) FROM posts WHERE TIMESTAMPDIFF(DAY, ts_created, CURRENT_TIMESTAMP()) <= 30) AS m_post_cmt,
(SELECT COUNT(DISTINCT(user)) FROM posts WHERE parent=0) AS posters,
(SELECT COUNT(DISTINCT(user)) FROM posts WHERE parent!=0) AS commenters
""")
for (total, m_visited, m_post_cmt, posters, commenters) in cur:
return {
'total': total,
'posters': posters,
'commenters': commenters,
'm_visited': m_visited,
'm_post_cmt': m_post_cmt
}
return {}
class Search:
def __init__(self, db):