remove leaderboard_thread

master
Aevann1 2022-10-06 10:23:29 +02:00
parent fc1d56053d
commit e071f9c81b
2 changed files with 11 additions and 81 deletions

View File

@ -21,42 +21,6 @@ import os
import json
from .login import check_for_alts
def leaderboard_thread():
db = db_session()
global users9, users9_1, users9_2
votes1 = db.query(Submission.author_id, func.count(Submission.author_id)).join(Vote).filter(Vote.vote_type==-1).group_by(Submission.author_id).order_by(func.count(Submission.author_id).desc()).all()
votes2 = db.query(Comment.author_id, func.count(Comment.author_id)).join(CommentVote).filter(CommentVote.vote_type==-1).group_by(Comment.author_id).order_by(func.count(Comment.author_id).desc()).all()
votes3 = Counter(dict(votes1)) + Counter(dict(votes2))
users8 = db.query(User.id).filter(User.id.in_(votes3.keys())).all()
users9 = []
for user in users8:
users9.append((user.id, votes3[user.id]))
if not users9: users9 = [(None,None)]
users9 = sorted(users9, key=lambda x: x[1], reverse=True)
users9_1, users9_2 = zip(*users9[:25])
global users13, users13_1, users13_2
votes1 = db.query(Vote.user_id, func.count(Vote.user_id)).filter(Vote.vote_type==1).group_by(Vote.user_id).order_by(func.count(Vote.user_id).desc()).all()
votes2 = db.query(CommentVote.user_id, func.count(CommentVote.user_id)).filter(CommentVote.vote_type==1).group_by(CommentVote.user_id).order_by(func.count(CommentVote.user_id).desc()).all()
votes3 = Counter(dict(votes1)) + Counter(dict(votes2))
users14 = db.query(User).filter(User.id.in_(votes3.keys())).all()
users13 = []
for user in users14:
users13.append((user.id, votes3[user.id]-user.post_count-user.comment_count))
if not users13: users13 = [(None,None)]
users13 = sorted(users13, key=lambda x: x[1], reverse=True)
users13_1, users13_2 = zip(*users13[:25])
db.close()
stdout.flush()
gevent.spawn(leaderboard_thread)
@app.get("/@<username>/upvoters/<uid>/posts")
@auth_required
@ -590,6 +554,16 @@ def leaderboard(v):
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]
votes1 = db.query(Submission.author_id, func.count(Submission.author_id)).join(Vote).filter(Vote.vote_type==-1).group_by(Submission.author_id).order_by(func.count(Submission.author_id).desc()).all()
votes2 = db.query(Comment.author_id, func.count(Comment.author_id)).join(CommentVote).filter(CommentVote.vote_type==-1).group_by(Comment.author_id).order_by(func.count(Comment.author_id).desc()).all()
votes3 = Counter(dict(votes1)) + Counter(dict(votes2))
users8 = db.query(User.id).filter(User.id.in_(votes3.keys())).all()
users9 = []
for user in users8:
users9.append((user.id, votes3[user.id]))
if not users9: users9 = [(None,None)]
users9 = sorted(users9, key=lambda x: x[1], reverse=True)
users9_1, users9_2 = zip(*users9[:25])
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))
@ -624,14 +598,6 @@ def leaderboard(v):
users12 = None
pos12 = None
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 = zip(users13_accs, users13_2)
try:
pos13 = [x[0] for x in users13].index(v.id)
pos13 = (pos13+1, users13[pos13][1])
except: pos13 = (len(users13)+1, 0)
# winnings_sq = g.db.query(Casino_Game.user_id, func.sum(Casino_Game.winnings)).group_by(Casino_Game.user_id).subquery()
# users14 = g.db.query(User).join(winnings_sq, winnings_sq.c.user_id == User.id).order_by(winnings_sq.c.sum.desc()).limit(25).all()
# if v in users14:
@ -669,8 +635,7 @@ def leaderboard(v):
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,
users7=users7, pos7=pos7, users9=users9_accs, pos9=pos9,
users10=users10, pos10=pos10, users11=users11, pos11=pos11, users12=users12, pos12=pos12,
users13=users13_accs, pos13=pos13, users16=users16, pos16=pos16, users17=users17, pos17=pos17, users18=users18, pos18=pos18)
users10=users10, pos10=pos10, users11=users11, pos11=pos11, users12=users12, pos12=pos12, users16=users16, pos16=pos16, users17=users17, pos17=pos17, users18=users18, pos18=pos18)
@app.get("/<id>/css")
def get_css(id):

View File

@ -15,7 +15,6 @@
<a href="#leaderboard-downvotes">Downvotes</a> &bull;
<a href="#leaderboard-badges">Badges</a> &bull;
{% if users12 %}<a href="#leaderboard-marseys">Marseys</a> &bull; {% endif %}
{% if users13 %}<a href="#leaderboard-upgiven">Upvotes Given</a> &bull; {% endif %}
<a href="#leaderboard-blocked">Blocked</a> &bull;
<a href="#leaderboard-owned-hats">Owned Hats</a> &bull;
<a href="#leaderboard-designed-hats">Designed Hats</a>
@ -336,40 +335,6 @@
</table>
{% endif %}
{% if users13 %}
<h5 class="font-weight-bolder text-center pt-2 pb-3"><a id="leaderboard-upgiven">Top 25 by upvotes given</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>Upvotes</th>
</tr>
</thead>
<tbody>
{% for user, num in users13 %}
<tr {% if v.id == user.id %}class="self"{% endif %}>
<td>{{loop.index}}</td>
<td>{% include "user_in_table.html" %}</td>
<td>{{"{:,}".format(num)}}</td>
</tr>
{% endfor %}
{% if pos13 and (pos13[0] > 25 or not pos13[1]) %}
<tr style="border-top:2px solid var(--primary)">
<td>{{pos13[0]}}</td>
<td>
{% with user=v %}
{% include "user_in_table.html" %}
{% endwith %}
</td>
<td>{{"{:,}".format(pos13[1])}}</td>
</tr>
{% endif %}
</tbody>
</table>
{% endif %}
<h5 class="font-weight-bolder text-center pt-2 pb-3"><a id="leaderboard-blocked">Top 25 Most Blocked</a></h5>
<div class="overflow-x-auto"><table class="table table-striped mb-5">