From 0eb0e4ed5c2dccc49281448f741d2616bf40fb98 Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Tue, 6 Sep 2022 04:58:04 +0200 Subject: [PATCH] experimenting w/ leaderboard --- files/routes/users.py | 63 +++++++++++++++++++++++--------- files/templates/leaderboard.html | 18 ++++----- 2 files changed, 54 insertions(+), 27 deletions(-) diff --git a/files/routes/users.py b/files/routes/users.py index da11d3070..91504da41 100644 --- a/files/routes/users.py +++ b/files/routes/users.py @@ -501,28 +501,46 @@ def leaderboard(v): users = g.db.query(User) users1 = users.order_by(User.coins.desc()).limit(25).all() - sq = g.db.query(User.id, func.rank().over(order_by=User.coins.desc()).label("rank")).subquery() - pos1 = g.db.query(sq.c.id, sq.c.rank).filter(sq.c.id == v.id).limit(1).one()[1] + if v in users1: + pos1 = None + else: + sq = g.db.query(User.id, func.rank().over(order_by=User.coins.desc()).label("rank")).subquery() + pos1 = g.db.query(sq.c.id, sq.c.rank).filter(sq.c.id == v.id).limit(1).one()[1] users2 = users.order_by(User.stored_subscriber_count.desc()).limit(25).all() - sq = g.db.query(User.id, func.rank().over(order_by=User.stored_subscriber_count.desc()).label("rank")).subquery() - pos2 = g.db.query(sq.c.id, sq.c.rank).filter(sq.c.id == v.id).limit(1).one()[1] + if v in users2: + pos2 = None + else: + sq = g.db.query(User.id, func.rank().over(order_by=User.stored_subscriber_count.desc()).label("rank")).subquery() + pos2 = g.db.query(sq.c.id, sq.c.rank).filter(sq.c.id == v.id).limit(1).one()[1] users3 = users.order_by(User.post_count.desc()).limit(25).all() - sq = g.db.query(User.id, func.rank().over(order_by=User.post_count.desc()).label("rank")).subquery() - pos3 = g.db.query(sq.c.id, sq.c.rank).filter(sq.c.id == v.id).limit(1).one()[1] + if v in users3: + pos3 = None + else: + sq = g.db.query(User.id, func.rank().over(order_by=User.post_count.desc()).label("rank")).subquery() + pos3 = g.db.query(sq.c.id, sq.c.rank).filter(sq.c.id == v.id).limit(1).one()[1] users4 = users.order_by(User.comment_count.desc()).limit(25).all() - sq = g.db.query(User.id, func.rank().over(order_by=User.comment_count.desc()).label("rank")).subquery() - pos4 = g.db.query(sq.c.id, sq.c.rank).filter(sq.c.id == v.id).limit(1).one()[1] + if v in users4: + pos4 = None + else: + sq = g.db.query(User.id, func.rank().over(order_by=User.comment_count.desc()).label("rank")).subquery() + pos4 = g.db.query(sq.c.id, sq.c.rank).filter(sq.c.id == v.id).limit(1).one()[1] users5 = users.order_by(User.received_award_count.desc()).limit(25).all() - sq = g.db.query(User.id, func.rank().over(order_by=User.received_award_count.desc()).label("rank")).subquery() - pos5 = g.db.query(sq.c.id, sq.c.rank).filter(sq.c.id == v.id).limit(1).one()[1] + if v in users5: + pos5 = None + else: + sq = g.db.query(User.id, func.rank().over(order_by=User.received_award_count.desc()).label("rank")).subquery() + pos5 = g.db.query(sq.c.id, sq.c.rank).filter(sq.c.id == v.id).limit(1).one()[1] users7 = users.order_by(User.coins_spent.desc()).limit(25).all() - sq = g.db.query(User.id, func.rank().over(order_by=User.coins_spent.desc()).label("rank")).subquery() - pos7 = g.db.query(sq.c.id, sq.c.rank).filter(sq.c.id == v.id).limit(1).one()[1] + if v in users7: + pos7 = None + else: + sq = g.db.query(User.id, func.rank().over(order_by=User.coins_spent.desc()).label("rank")).subquery() + pos7 = g.db.query(sq.c.id, sq.c.rank).filter(sq.c.id == v.id).limit(1).one()[1] users9_accs = g.db.query(User).filter(User.id.in_(users9_1)).all() @@ -534,8 +552,11 @@ def leaderboard(v): except: pos9 = (len(users9)+1, 0) users10 = users.order_by(User.truecoins.desc()).limit(25).all() - sq = g.db.query(User.id, func.rank().over(order_by=User.truecoins.desc()).label("rank")).subquery() - pos10 = g.db.query(sq.c.id, sq.c.rank).filter(sq.c.id == v.id).limit(1).one()[1] + if v in users10: + pos10 = None + else: + sq = g.db.query(User.id, func.rank().over(order_by=User.truecoins.desc()).label("rank")).subquery() + pos10 = g.db.query(sq.c.id, sq.c.rank).filter(sq.c.id == v.id).limit(1).one()[1] sq = g.db.query(Badge.user_id, func.count(Badge.user_id).label("count"), func.rank().over(order_by=func.count(Badge.user_id).desc()).label("rank")).group_by(Badge.user_id).subquery() users11 = g.db.query(User, sq.c.count).join(sq, User.id==sq.c.user_id).order_by(sq.c.count.desc()) @@ -564,12 +585,18 @@ def leaderboard(v): except: pos13 = (len(users13)+1, 0) users14 = users.order_by(User.winnings.desc()).limit(25).all() - sq = g.db.query(User.id, func.rank().over(order_by=User.winnings.desc()).label("rank")).subquery() - pos14 = g.db.query(sq.c.id, sq.c.rank).filter(sq.c.id == v.id).limit(1).one()[1] + if v in users14: + pos14 = None + else: + sq = g.db.query(User.id, func.rank().over(order_by=User.winnings.desc()).label("rank")).subquery() + pos14 = g.db.query(sq.c.id, sq.c.rank).filter(sq.c.id == v.id).limit(1).one()[1] users15 = users.order_by(User.winnings).limit(25).all() - sq = g.db.query(User.id, func.rank().over(order_by=User.winnings).label("rank")).subquery() - pos15 = g.db.query(sq.c.id, sq.c.rank).filter(sq.c.id == v.id).limit(1).one()[1] + if v in users15: + pos15 = None + else: + sq = g.db.query(User.id, func.rank().over(order_by=User.winnings).label("rank")).subquery() + pos15 = g.db.query(sq.c.id, sq.c.rank).filter(sq.c.id == v.id).limit(1).one()[1] sq = g.db.query(UserBlock.target_id, func.count(UserBlock.target_id).label("count")).group_by(UserBlock.target_id).subquery() users16 = g.db.query(User, sq.c.count).join(User, User.id == sq.c.target_id).order_by(sq.c.count.desc()).limit(25).all() diff --git a/files/templates/leaderboard.html b/files/templates/leaderboard.html index 2e976c437..22237f811 100644 --- a/files/templates/leaderboard.html +++ b/files/templates/leaderboard.html @@ -40,7 +40,7 @@ {{user.coins}} {% endfor %} -{% if pos1 > 25 %} +{% if pos1 %} {{pos1}} @@ -71,7 +71,7 @@ {{user.coins_spent}} {% endfor %} -{% if pos7 > 25 %} +{% if pos7 %} {{pos7}} @@ -102,7 +102,7 @@ {{user.truecoins}} {% endfor %} - {% if pos10 > 25 %} + {% if pos10 %} {{pos10}} @@ -133,7 +133,7 @@ {{user.stored_subscriber_count}} {% endfor %} -{% if pos2 > 25 %} +{% if pos2 %} {{pos2}} @@ -163,7 +163,7 @@ {{user.post_count}} {% endfor %} -{% if pos3 > 25 %} +{% if pos3 %} {{pos3}} @@ -193,7 +193,7 @@ {{user.comment_count}} {% endfor %} -{% if pos4 > 25 %} +{% if pos4 %} {{pos4}} @@ -223,7 +223,7 @@ {{user.received_award_count}} {% endfor %} -{% if pos5 > 25 %} +{% if pos5 %} {{pos5}} @@ -390,7 +390,7 @@ {{user.winnings}} {% endfor %} -{% if pos14 > 25 %} +{% if pos14 %} {{pos14}} @@ -420,7 +420,7 @@ {{user.winnings}} {% endfor %} -{% if pos15 > 25 %} +{% if pos15 %} {{pos15}}