add effortposts leaderboard

master
Aevann 2024-02-07 03:42:17 +02:00
parent 3a31ae9019
commit 32e8160fe2
3 changed files with 24 additions and 1 deletions

View File

@ -200,3 +200,17 @@ class Leaderboard:
if not position: position = (leaderboard.count() + 1, 0)
leaderboard = leaderboard.limit(limit).all()
return (leaderboard, position[0], position[1])
@classmethod
def get_effortposts_lb(cls, lb_criteria, v, users, limit, desc):
sq = g.db.query(lb_criteria, cls.count_and_label(lb_criteria), cls.rank_filtered_rank_label_by_desc(lb_criteria))
sq = sq.filter(Post.effortpost == True)
sq = sq.group_by(lb_criteria).subquery()
sq_criteria = User.id == sq.c.author_id
leaderboard = g.db.query(User, sq.c.count).join(sq, sq_criteria).order_by(sq.c.count.desc())
position = g.db.query(User.id, sq.c.rank, sq.c.count).join(sq, sq_criteria).filter(User.id == v.id).one_or_none()
if position: position = (position[1], position[2])
else: position = (leaderboard.count() + 1, 0)
leaderboard = leaderboard.limit(limit).all()
return (leaderboard, position[0], position[1])

View File

@ -159,3 +159,11 @@ def leaderboard_average_upvotes_per_post(v):
def leaderboard_average_upvotes_per_comment(v):
leaderboard = Leaderboard("Average upvotes per comment", "average upvotes per comment", "average-upvotes-per-comment", "Average Upvotes per Comment", "comments", Leaderboard.get_avg_upvotes_lb, Comment, v, None, None)
return render_template("leaderboard.html", v=v, leaderboard=leaderboard)
@app.get("/leaderboard/effortposts")
@limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400)
@limiter.limit(DEFAULT_RATELIMIT, deduct_when=lambda response: response.status_code < 400, key_func=get_ID)
@auth_required
def leaderboard_effortposts(v):
leaderboard = Leaderboard("Effortposts", "effortposts", "effortposts", "Effortposts", None, Leaderboard.get_effortposts_lb, Post.author_id, v, None, None)
return render_template("leaderboard.html", v=v, leaderboard=leaderboard)

View File

@ -28,7 +28,8 @@
<a {% if request.path == "/leaderboard/casino_winnings_top" %}class="font-weight-bolder"{% endif %} href="/leaderboard/casino_winnings_top">Casino winnings (top)</a>
<a {% if request.path == "/leaderboard/casino_winnings_bottom" %}class="font-weight-bolder"{% endif %} href="/leaderboard/casino_winnings_bottom">Casino winnings (bottom)</a>
<a {% if request.path == "/leaderboard/average_upvotes_per_post" %}class="font-weight-bolder"{% endif %} href="/leaderboard/average_upvotes_per_post">Average upvotes per post</a>
<a {% if request.path == "/leaderboard/average_upvotes_per_comment" %}class="font-weight-bolder"{% endif %} href="/leaderboard/average_upvotes_per_comment">Average upvotes per comment</a>
<a {% if request.path == "/leaderboard/average_upvotes_per_comment" %}class="font-weight-bolder"{% endif %} href="/leaderboard/average_upvotes_per_comment">Average upvotes per comment</a>
<a {% if request.path == "/leaderboard/effortposts" %}class="font-weight-bolder"{% endif %} href="/leaderboard/effortposts">Effortposts</a>
</div>
{% macro format_user_in_table(user, style, position_no, value, user_relative_url) %}