From a5bfb769ece5f14556e31dde9c936bc3ed056470 Mon Sep 17 00:00:00 2001 From: retoor Date: Mon, 25 Nov 2024 21:24:06 +0100 Subject: [PATCH] Replaced upvote ratio with something more descriptive. --- src/drstats/db.py | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/src/drstats/db.py b/src/drstats/db.py index 9be5561..fd13de8 100644 --- a/src/drstats/db.py +++ b/src/drstats/db.py @@ -193,7 +193,7 @@ def get_db(): db.query("DROP VIEW IF EXISTS contributions_extended") db.query( """ - CREATE VIEW contributions_extended as SELECT username, contributions,ROUND(CAST(contributions AS REAL) / CAST((select contributions from contributions) AS REAL),2) as ownership, upvotes, ROUND(CAST(upvotes AS REAL) / CAST((SELECT SUM(upvotes) from contributions) AS REAL),2) upvotes_ownership, ROUND(CAST(upvotes AS REAL) / CAST(contributions AS REAL),2) upvote_ratio,content_length as post_length_total, ROUND(CAST(content_length AS REAL) / CAST((SELECT SUM(content_length) from contributions) AS REAL)) as ownership_content,post_length_average + CREATE VIEW contributions_extended as SELECT username, contributions,ROUND(CAST(contributions AS REAL) / CAST((select contributions from contributions) AS REAL),2) as ownership, upvotes, ROUND(CAST(upvotes AS REAL) / CAST((SELECT SUM(upvotes) from contributions) AS REAL),2) upvotes_ownership, ROUND(CAST(upvotes AS REAL) / CAST(contributions AS REAL),2) as upvotes_per_post_on_average,content_length as post_length_total, ROUND(CAST(content_length AS REAL) / CAST((SELECT SUM(content_length) from contributions) AS REAL)) as ownership_content,post_length_average FROM contributions """ ) @@ -206,7 +206,7 @@ def get_db(): "CREATE VIEW posts_of_user AS SELECT user_username as username, GROUP_CONCAT(body) as text FROM comments" ) db.query("DROP VIEW IF EXISTS contributions_extended_ranked") - db.query("CREATE VIEW contributions_extended_ranked AS SELECT ROW_NUMBER() OVER (ORDER BY upvote_ratio DESC) as rank, * FROM contributions_extended ORDER BY upvote_ratio DESC") + db.query("CREATE VIEW contributions_extended_ranked AS SELECT ROW_NUMBER() OVER (ORDER BY upvotes_per_post_on_average DESC) as rank, * FROM contributions_extended ORDER BY upvotes_per_post_on_average DESC") db.query("CREATE VIEW IF NOT EXISTS views AS SELECT sql, name FROM sqlite_schema WHERE type='view' AND name != 'views';") return db @@ -255,17 +255,10 @@ def get_contributions(): def get_upvote_average(): - return avg(contribution["upvote_ratio"] for contribution in get_contributions()) + return avg(contribution["upvotes_per_post_on_average"] for contribution in get_contributions()) def get_users(): - """ - Retrieve a list of distinct usernames from the contributions table. - - Returns: - list: A list of usernames in ascending order. - """ - with Db() as db: return [user["username"] for user in db.query("SELECT DISTINCT username FROM contributions ORDER BY username")]