leaderboard cancer, don't read if u value ur sanity

master
Aevann1 2022-09-06 04:40:11 +02:00
parent 5c854adc20
commit b1933def96
2 changed files with 152 additions and 120 deletions

View File

@ -501,101 +501,144 @@ def leaderboard(v):
users = g.db.query(User) users = g.db.query(User)
users1 = users.order_by(User.coins.desc()).limit(25).all() 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() if v in users1:
pos1 = g.db.query(sq.c.id, sq.c.rank).filter(sq.c.id == v.id).limit(1).one()[1] 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.rank).filter(sq.c.id == v.id).limit(1).one()[0]
users2 = users.order_by(User.stored_subscriber_count.desc()).limit(25).all() 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() if v in users2:
pos2 = g.db.query(sq.c.id, sq.c.rank).filter(sq.c.id == v.id).limit(1).one()[1] 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.rank).filter(sq.c.id == v.id).limit(1).one()[0]
users3 = users.order_by(User.post_count.desc()).limit(25).all() 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() if v in users3:
pos3 = g.db.query(sq.c.id, sq.c.rank).filter(sq.c.id == v.id).limit(1).one()[1] 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.rank).filter(sq.c.id == v.id).limit(1).one()[0]
users4 = users.order_by(User.comment_count.desc()).limit(25).all() 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() if v in users4:
pos4 = g.db.query(sq.c.id, sq.c.rank).filter(sq.c.id == v.id).limit(1).one()[1] 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.rank).filter(sq.c.id == v.id).limit(1).one()[0]
users5 = users.order_by(User.received_award_count.desc()).limit(25).all() 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() if v in users5:
pos5 = g.db.query(sq.c.id, sq.c.rank).filter(sq.c.id == v.id).limit(1).one()[1] pos5 = None
if SITE == 'pcmemes.net':
users6 = users.order_by(User.basedcount.desc()).limit(25).all()
sq = g.db.query(User.id, func.rank().over(order_by=User.basedcount.desc()).label("rank")).subquery()
pos6 = g.db.query(sq.c.id, sq.c.rank).filter(sq.c.id == v.id).limit(1).one()[1]
else: else:
users6 = None sq = g.db.query(User.id, func.rank().over(order_by=User.received_award_count.desc()).label("rank")).subquery()
pos6 = None pos5 = g.db.query(sq.c.rank).filter(sq.c.id == v.id).limit(1).one()[0]
users7 = users.order_by(User.coins_spent.desc()).limit(25).all() 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() if v in users7:
pos7 = g.db.query(sq.c.id, sq.c.rank).filter(sq.c.id == v.id).limit(1).one()[1] pos7 = None
try:
pos9 = [x[0] for x in users9].index(v.id)
pos9 = (pos9+1, users9[pos9][1])
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]
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())
pos11 = g.db.query(User.id, sq.c.rank, sq.c.count).join(sq, User.id==sq.c.user_id).filter(User.id == v.id).one_or_none()
if pos11: pos11 = (pos11[1],pos11[2])
else: pos11 = (users11.count()+1, 0)
users11 = users11.limit(25).all()
if SITE_NAME == 'rDrama':
sq = g.db.query(Marsey.author_id, func.count(Marsey.author_id).label("count"), func.rank().over(order_by=func.count(Marsey.author_id).desc()).label("rank")).group_by(Marsey.author_id).subquery()
users12 = g.db.query(User, sq.c.count).join(sq, User.id==sq.c.author_id).order_by(sq.c.count.desc())
pos12 = g.db.query(User.id, sq.c.rank, sq.c.count).join(sq, User.id==sq.c.author_id).filter(User.id == v.id).one_or_none()
if pos12: pos12 = (pos12[1],pos12[2])
else: pos12 = (users12.count()+1, 0)
users12 = users12.limit(25).all()
else: else:
users12 = None sq = g.db.query(User.id, func.rank().over(order_by=User.coins_spent.desc()).label("rank")).subquery()
pos12 = None pos7 = g.db.query(sq.c.rank).filter(sq.c.id == v.id).limit(1).one()[0]
try:
pos13 = [x[0] for x in users13].index(v.id)
pos13 = (pos13+1, users13[pos13][1])
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]
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]
sq = g.db.query(UserBlock.target_id, func.count(UserBlock.target_id).label("n")).group_by(UserBlock.target_id).subquery()
users16 = g.db.query(User, sq.c.n).join(User, User.id == sq.c.target_id).order_by(sq.c.n.desc()).limit(25).all()
sq = g.db.query(UserBlock.target_id, func.count(UserBlock.target_id).label("n"), func.rank().over(order_by=func.count(UserBlock.target_id).desc()).label("rank")).group_by(UserBlock.target_id).subquery()
pos16 = g.db.query(sq.c.rank, sq.c.n).join(User, User.id == sq.c.target_id).filter(sq.c.target_id == v.id).limit(1).one_or_none()
if not pos16: pos16 = (len(users16)+1, 0)
users17 = g.db.query(User, func.count(User.owned_hats)).join(User.owned_hats).group_by(User).order_by(func.count(User.owned_hats).desc()).limit(25).all()
users18 = g.db.query(User, func.count(User.designed_hats)).join(User.designed_hats).group_by(User).order_by(func.count(User.designed_hats).desc()).limit(25).all()
users9_accs = g.db.query(User).filter(User.id.in_(users9_1)).all() users9_accs = g.db.query(User).filter(User.id.in_(users9_1)).all()
users9_accs = sorted(users9_accs, key=lambda x: users9_1.index(x.id)) users9_accs = sorted(users9_accs, key=lambda x: users9_1.index(x.id))
users9_accs = zip(users9_accs, users9_2) users9_accs = zip(users9_accs, users9_2)
if v in users9_accs:
pos9 = None
else:
try:
pos9 = [x[0] for x in users9].index(v.id)
pos9 = (pos9+1, users9[pos9][1])
except: pos9 = (len(users9)+1, 0)
users10 = users.order_by(User.truecoins.desc()).limit(25).all()
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.rank).filter(sq.c.id == v.id).limit(1).one()[0]
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())
if v in [x[0] for x in users11]:
pos11 = None
else:
pos11 = g.db.query(User.id, sq.c.rank, sq.c.count).join(sq, User.id==sq.c.user_id).filter(User.id == v.id).one_or_none()
if pos11: pos11 = (pos11[1],pos11[2])
else: pos11 = (users11.count()+1, 0)
users11 = users11.limit(25).all()
if SITE_NAME == 'rDrama':
sq = g.db.query(Marsey.author_id, func.count(Marsey.author_id).label("count"), func.rank().over(order_by=func.count(Marsey.author_id).desc()).label("rank")).group_by(Marsey.author_id).subquery()
users12 = g.db.query(User, sq.c.count).join(sq, User.id==sq.c.author_id).order_by(sq.c.count.desc())
if v in [x[0] for x in users12]:
pos12 = None
else:
pos12 = g.db.query(User.id, sq.c.rank, sq.c.count).join(sq, User.id==sq.c.author_id).filter(User.id == v.id).one_or_none()
if pos12: pos12 = (pos12[1],pos12[2])
else: pos12 = (users12.count()+1, 0)
users12 = users12.limit(25).all()
else:
users12 = None
pos12 = None
users13_accs = g.db.query(User).filter(User.id.in_(users13_1)).all() users13_accs = g.db.query(User).filter(User.id.in_(users13_1)).all()
users13_accs = sorted(users13_accs, key=lambda x: users13_1.index(x.id)) users13_accs = sorted(users13_accs, key=lambda x: users13_1.index(x.id))
users13_accs = zip(users13_accs, users13_2) users13_accs = zip(users13_accs, users13_2)
if v in users13_accs:
pos13 = None
else:
try:
pos13 = [x[0] for x in users13].index(v.id)
pos13 = (pos13+1, users13[pos13][1])
except: pos13 = (len(users13)+1, 0)
users14 = users.order_by(User.winnings.desc()).limit(25).all()
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.rank).filter(sq.c.id == v.id).limit(1).one()[0]
users15 = users.order_by(User.winnings).limit(25).all()
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.rank).filter(sq.c.id == v.id).limit(1).one()[0]
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()
if v in [x[0] for x in users16]:
pos16 = None
else:
sq = g.db.query(UserBlock.target_id, func.count(UserBlock.target_id).label("count"), func.rank().over(order_by=func.count(UserBlock.target_id).desc()).label("rank")).group_by(UserBlock.target_id).subquery()
pos16 = g.db.query(sq.c.rank, sq.c.count).join(User, User.id == sq.c.target_id).filter(sq.c.target_id == v.id).limit(1).one_or_none()
if not pos16: pos16 = (len(users16)+1, 0)
users17 = g.db.query(User, func.count(User.owned_hats)).join(User.owned_hats).group_by(User).order_by(func.count(User.owned_hats).desc()).limit(25).all()
if v in [x[0] for x in users17]:
pos17 = None
else:
sq = g.db.query(User.id, func.rank().over(order_by=func.count(User.owned_hats).desc()).label("rank")).join(User.owned_hats).group_by(User).subquery()
pos17 = g.db.query(sq.c.rank).filter(sq.c.id == v.id).limit(1).one_or_none()
if not pos17: pos17 = len(users17)+1
users18 = g.db.query(User, func.count(User.designed_hats)).join(User.designed_hats).group_by(User).order_by(func.count(User.designed_hats).desc()).limit(25).all()
if v in [x[0] for x in users18]:
pos18 = None
else:
sq = g.db.query(User.id, func.rank().over(order_by=func.count(User.designed_hats).desc()).label("rank")).join(User.designed_hats).group_by(User).subquery()
pos18 = g.db.query(sq.c.rank).filter(sq.c.id == v.id).limit(1).one_or_none()
if not pos18: pos18 = len(users18)+1
return render_template("leaderboard.html", v=v, users1=users1, pos1=pos1, users2=users2, pos2=pos2, return render_template("leaderboard.html", v=v, users1=users1, pos1=pos1, users2=users2, pos2=pos2,
users3=users3, pos3=pos3, users4=users4, pos4=pos4, users5=users5, pos5=pos5, users3=users3, pos3=pos3, users4=users4, pos4=pos4, users5=users5, pos5=pos5,users7=users7, pos7=pos7,
users6=users6, pos6=pos6, users7=users7, pos7=pos7, users9=users9_accs, pos9=pos9, users9=users9_accs, pos9=pos9, users10=users10, pos10=pos10, users11=users11, pos11=pos11, users12=users12,
users10=users10, pos10=pos10, users11=users11, pos11=pos11, users12=users12, pos12=pos12, pos12=pos12, users13=users13_accs, pos13=pos13, users14=users14, pos14=pos14, users15=users15, pos15=pos15,
users13=users13_accs, pos13=pos13, users14=users14, pos14=pos14, users15=users15, pos15=pos15, users16=users16, pos16=pos16, users17=users17, pos17=pos17, users18=users18, pos18=pos18)
users16=users16, pos16=pos16, users17=users17, users18=users18)
@app.get("/<id>/css") @app.get("/<id>/css")
def get_css(id): def get_css(id):

View File

@ -41,7 +41,7 @@
<td>{{user.coins}}</td> <td>{{user.coins}}</td>
</tr> </tr>
{% endfor %} {% endfor %}
{% if pos1 > 25 %} {% if pos1 %}
<tr style="border-top:2px solid var(--primary)"> <tr style="border-top:2px solid var(--primary)">
<td>{{pos1}}</td> <td>{{pos1}}</td>
<td> <td>
@ -72,7 +72,7 @@
<td>{{user.coins_spent}}</td> <td>{{user.coins_spent}}</td>
</tr> </tr>
{% endfor %} {% endfor %}
{% if pos7 > 25 %} {% if pos7 %}
<tr style="border-top:2px solid var(--primary)"> <tr style="border-top:2px solid var(--primary)">
<td>{{pos7}}</td> <td>{{pos7}}</td>
<td> <td>
@ -103,7 +103,7 @@
<td>{{user.truecoins}}</td> <td>{{user.truecoins}}</td>
</tr> </tr>
{% endfor %} {% endfor %}
{% if pos10 > 25 %} {% if pos10 %}
<tr style="border-top:2px solid var(--primary)"> <tr style="border-top:2px solid var(--primary)">
<td>{{pos10}}</td> <td>{{pos10}}</td>
<td> <td>
@ -134,7 +134,7 @@
<td><a href="/@{{user.username}}/followers">{{user.stored_subscriber_count}}</a></td> <td><a href="/@{{user.username}}/followers">{{user.stored_subscriber_count}}</a></td>
</tr> </tr>
{% endfor %} {% endfor %}
{% if pos2 > 25 %} {% if pos2 %}
<tr style="border-top:2px solid var(--primary)"> <tr style="border-top:2px solid var(--primary)">
<td>{{pos2}}</td> <td>{{pos2}}</td>
<td> <td>
@ -164,7 +164,7 @@
<td>{{user.post_count}}</td> <td>{{user.post_count}}</td>
</tr> </tr>
{% endfor %} {% endfor %}
{% if pos3 > 25 %} {% if pos3 %}
<tr style="border-top:2px solid var(--primary)"> <tr style="border-top:2px solid var(--primary)">
<td>{{pos3}}</td> <td>{{pos3}}</td>
<td> <td>
@ -194,7 +194,7 @@
<td>{{user.comment_count}}</td> <td>{{user.comment_count}}</td>
</tr> </tr>
{% endfor %} {% endfor %}
{% if pos4 > 25 %} {% if pos4 %}
<tr style="border-top:2px solid var(--primary)"> <tr style="border-top:2px solid var(--primary)">
<td>{{pos4}}</td> <td>{{pos4}}</td>
<td> <td>
@ -224,7 +224,7 @@
<td>{{user.received_award_count}}</td> <td>{{user.received_award_count}}</td>
</tr> </tr>
{% endfor %} {% endfor %}
{% if pos5 > 25 %} {% if pos5 %}
<tr style="border-top:2px solid var(--primary)"> <tr style="border-top:2px solid var(--primary)">
<td>{{pos5}}</td> <td>{{pos5}}</td>
<td> <td>
@ -255,7 +255,7 @@
<td>{{num}}</td> <td>{{num}}</td>
</tr> </tr>
{% endfor %} {% endfor %}
{% if pos9 and (pos9[0] > 25 or not pos9[1]) %} {% if pos9 %}
<tr style="border-top:2px solid var(--primary)"> <tr style="border-top:2px solid var(--primary)">
<td>{{pos9[0]}}</td> <td>{{pos9[0]}}</td>
<td> <td>
@ -288,7 +288,7 @@
<td>{{num}}</td> <td>{{num}}</td>
</tr> </tr>
{% endfor %} {% endfor %}
{% if pos11 and (pos11[0] > 25 or not pos11[1]) %} {% if pos11 %}
<tr style="border-top:2px solid var(--primary)"> <tr style="border-top:2px solid var(--primary)">
<td>{{pos11[0]}}</td> <td>{{pos11[0]}}</td>
<td> <td>
@ -303,39 +303,6 @@
</table> </table>
{% if users6 %}
<h5 class="font-weight-bolder text-center pt-2 pb-3"><a id="leaderboard-based">Top 25 by based count</a></h5>
<div class="overflow-x-auto"><table class="table table-striped mb-5">
<thead class="bg-primary text-white">
<tr>
<th>#</th>
<th>Name</th>
<th>Based count</th>
</tr>
</thead>
{% for user in users6 %}
<tr {% if v.id == user.id %}class="self"{% endif %}>
<td>{{loop.index}}</td>
<td>{% include "user_in_table.html" %}</td>
<td>{{user.basedcount}}</td>
</tr>
{% endfor %}
{% if pos6 > 25 %}
<tr style="border-top:2px solid var(--primary)">
<td>
{% with user=v %}
{% include "user_in_table.html" %}
{% endwith %}
</td>
<td>{{v.basedcount}}</td>
</tr>
{% endif %}
</table>
{% endif %}
{% if users12 %} {% if users12 %}
<h5 class="font-weight-bolder text-center pt-2 pb-3"><a id="leaderboard-marseys">Top 25 by marseys made</a></h5> <h5 class="font-weight-bolder text-center pt-2 pb-3"><a id="leaderboard-marseys">Top 25 by marseys made</a></h5>
@ -356,7 +323,7 @@
<td>{{num}}</td> <td>{{num}}</td>
</tr> </tr>
{% endfor %} {% endfor %}
{% if pos12 and (pos12[0] > 25 or not pos12[1]) %} {% if pos12 %}
<tr style="border-top:2px solid var(--primary)"> <tr style="border-top:2px solid var(--primary)">
<td>{{pos12[0]}}</td> <td>{{pos12[0]}}</td>
<td> <td>
@ -390,7 +357,7 @@
<td>{{num}}</td> <td>{{num}}</td>
</tr> </tr>
{% endfor %} {% endfor %}
{% if pos13 and (pos13[0] > 25 or not pos13[1]) %} {% if pos13 %}
<tr style="border-top:2px solid var(--primary)"> <tr style="border-top:2px solid var(--primary)">
<td>{{pos13[0]}}</td> <td>{{pos13[0]}}</td>
<td> <td>
@ -423,7 +390,7 @@
<td>{{user.winnings}}</td> <td>{{user.winnings}}</td>
</tr> </tr>
{% endfor %} {% endfor %}
{% if pos14 > 25 %} {% if pos14 %}
<tr style="border-top:2px solid var(--primary)"> <tr style="border-top:2px solid var(--primary)">
<td>{{pos14}}</td> <td>{{pos14}}</td>
<td> <td>
@ -453,7 +420,7 @@
<td>{{user.winnings}}</td> <td>{{user.winnings}}</td>
</tr> </tr>
{% endfor %} {% endfor %}
{% if pos15 > 25 %} {% if pos15 %}
<tr style="border-top:2px solid var(--primary)"> <tr style="border-top:2px solid var(--primary)">
<td>{{pos15}}</td> <td>{{pos15}}</td>
<td> <td>
@ -483,7 +450,7 @@
<td><a href="/blockers/{{user.id}}">{{num}}</a></td> <td><a href="/blockers/{{user.id}}">{{num}}</a></td>
</tr> </tr>
{% endfor %} {% endfor %}
{% if pos16 and (pos16[0] > 25 or not pos16[1]) %} {% if pos16 %}
<tr style="border-top:2px solid var(--primary)"> <tr style="border-top:2px solid var(--primary)">
<td>{{pos16[0]}}</td> <td>{{pos16[0]}}</td>
<td> <td>
@ -514,6 +481,17 @@
<td>{{num}}</td> <td>{{num}}</td>
</tr> </tr>
{% endfor %} {% endfor %}
{% if pos17 %}
<tr style="border-top:2px solid var(--primary)">
<td>{{pos17}}</td>
<td>
{% with user=v %}
{% include "user_in_table.html" %}
{% endwith %}
</td>
<td>{{v.num_of_owned_hats}}</td>
</tr>
{% endif %}
</table> </table>
<h5 class="font-weight-bolder text-center pt-2 pb-3"><a id="leaderboard-designed-hats">Top 25 by Designed Hats</a></h5> <h5 class="font-weight-bolder text-center pt-2 pb-3"><a id="leaderboard-designed-hats">Top 25 by Designed Hats</a></h5>
@ -533,6 +511,17 @@
<td>{{num}}</td> <td>{{num}}</td>
</tr> </tr>
{% endfor %} {% endfor %}
{% if pos18 %}
<tr style="border-top:2px solid var(--primary)">
<td>{{pos18}}</td>
<td>
{% with user=v %}
{% include "user_in_table.html" %}
{% endwith %}
</td>
<td>{{v.num_of_designed_hats}}</td>
</tr>
{% endif %}
</table> </table>