From bcb5389a4a0dd6b82de631a4c751f62376e5d2bc Mon Sep 17 00:00:00 2001 From: spla Date: Mon, 10 Jul 2023 11:58:17 +0200 Subject: [PATCH] Added user values --- app/libraries/database.py | 14 ++++++++++++-- versions.py | 11 +++++++++-- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/app/libraries/database.py b/app/libraries/database.py index e452900..416cdf2 100644 --- a/app/libraries/database.py +++ b/app/libraries/database.py @@ -31,6 +31,8 @@ class Database(): topten_versions = [] + topten_users = [] + try: conn = None @@ -39,7 +41,7 @@ class Database(): cur = conn.cursor() - cur.execute("select count(version), version from mau where software='mastodon' and alive group by version order by count(version) desc limit 10") + cur.execute("select count(version), version, sum(users) from mau where software='mastodon' and alive group by version order by count(version) desc limit 10") rows = cur.fetchall() @@ -49,12 +51,20 @@ class Database(): topten_versions.append(row[1]) + topten_users.append(row[2]) + cur.execute("select count(version) from mau where software='mastodon' and alive") row = cur.fetchone() mast_servers = row[0] + cur.execute ("select sum(users) from mau where software='mastodon' and alive") + + row = cur.fetchone() + + mast_users = row[0] + cur.close() except (Exception, psycopg2.DatabaseError) as error: @@ -67,7 +77,7 @@ class Database(): conn.close() - return (topten_servers, topten_versions, mast_servers) + return (topten_servers, topten_versions, topten_users, mast_servers, mast_users) @staticmethod def __check_dbsetup(self): diff --git a/versions.py b/versions.py index 18bea56..8814141 100644 --- a/versions.py +++ b/versions.py @@ -15,17 +15,24 @@ if __name__ == '__main__': api_base_url= setup.mastodon_hostname ) - topten_servers, topten_versions, mast_servers = db.get_versions() + topten_servers, topten_versions, topten_users, mast_servers, mast_users = db.get_versions() toot_text = f'\nTotal alive Mastodon servers: {str(mast_servers)}\n\n' toot_text += f'Top ten most used Mastodon versions: \n\n' + toot_text += f'version, servers, users\n\n' + i = 0 while i < 10: - toot_text += f'{str(i+1)} - v{topten_versions[i]} -> {str(topten_servers[i])} ({str(round(((topten_servers[i] * 100) / mast_servers), 2))}%)\n' + servers = '{0:,}'.format((topten_servers[i])) + + users = '{0:,}'.format((topten_users[i])) + + toot_text += f'v{topten_versions[i]}, {servers} ({str(round(((topten_servers[i] * 100) / mast_servers), 2))}%), {users} ({str(round(((topten_users[i] * 100) / mast_users), 2))}%)\n' + i += 1 toot_text += '\n#Mastodon'