experimenting w/ leaderboard

master
Aevann1 2022-09-06 04:58:04 +02:00
parent 2717b93555
commit 0eb0e4ed5c
2 changed files with 54 additions and 27 deletions

View File

@ -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()

View File

@ -40,7 +40,7 @@
<td>{{user.coins}}</td>
</tr>
{% endfor %}
{% if pos1 > 25 %}
{% if pos1 %}
<tr style="border-top:2px solid var(--primary)">
<td>{{pos1}}</td>
<td>
@ -71,7 +71,7 @@
<td>{{user.coins_spent}}</td>
</tr>
{% endfor %}
{% if pos7 > 25 %}
{% if pos7 %}
<tr style="border-top:2px solid var(--primary)">
<td>{{pos7}}</td>
<td>
@ -102,7 +102,7 @@
<td>{{user.truecoins}}</td>
</tr>
{% endfor %}
{% if pos10 > 25 %}
{% if pos10 %}
<tr style="border-top:2px solid var(--primary)">
<td>{{pos10}}</td>
<td>
@ -133,7 +133,7 @@
<td><a href="/@{{user.username}}/followers">{{user.stored_subscriber_count}}</a></td>
</tr>
{% endfor %}
{% if pos2 > 25 %}
{% if pos2 %}
<tr style="border-top:2px solid var(--primary)">
<td>{{pos2}}</td>
<td>
@ -163,7 +163,7 @@
<td>{{user.post_count}}</td>
</tr>
{% endfor %}
{% if pos3 > 25 %}
{% if pos3 %}
<tr style="border-top:2px solid var(--primary)">
<td>{{pos3}}</td>
<td>
@ -193,7 +193,7 @@
<td>{{user.comment_count}}</td>
</tr>
{% endfor %}
{% if pos4 > 25 %}
{% if pos4 %}
<tr style="border-top:2px solid var(--primary)">
<td>{{pos4}}</td>
<td>
@ -223,7 +223,7 @@
<td>{{user.received_award_count}}</td>
</tr>
{% endfor %}
{% if pos5 > 25 %}
{% if pos5 %}
<tr style="border-top:2px solid var(--primary)">
<td>{{pos5}}</td>
<td>
@ -390,7 +390,7 @@
<td>{{user.winnings}}</td>
</tr>
{% endfor %}
{% if pos14 > 25 %}
{% if pos14 %}
<tr style="border-top:2px solid var(--primary)">
<td>{{pos14}}</td>
<td>
@ -420,7 +420,7 @@
<td>{{user.winnings}}</td>
</tr>
{% endfor %}
{% if pos15 > 25 %}
{% if pos15 %}
<tr style="border-top:2px solid var(--primary)">
<td>{{pos15}}</td>
<td>