Replaced upvote ratio with something more descriptive.
All checks were successful
dR export statistics / Compile (push) Successful in 6m50s

This commit is contained in:
retoor 2024-11-25 21:24:06 +01:00
parent 3d7525fee2
commit a5bfb769ec

View File

@ -193,7 +193,7 @@ def get_db():
db.query("DROP VIEW IF EXISTS contributions_extended") db.query("DROP VIEW IF EXISTS contributions_extended")
db.query( 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 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" "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("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';") db.query("CREATE VIEW IF NOT EXISTS views AS SELECT sql, name FROM sqlite_schema WHERE type='view' AND name != 'views';")
return db return db
@ -255,17 +255,10 @@ def get_contributions():
def get_upvote_average(): 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(): 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: with Db() as db:
return [user["username"] for user in db.query("SELECT DISTINCT username FROM contributions ORDER BY username")] return [user["username"] for user in db.query("SELECT DISTINCT username FROM contributions ORDER BY username")]