Leaderboard: add 'Most Blocked' hiscores.

master
Snakes 2022-05-25 05:24:31 -04:00
parent 1c7458e111
commit ea48c46b0f
2 changed files with 36 additions and 2 deletions

View File

@ -9,6 +9,7 @@ from files.helpers.const import *
from files.mail import *
from flask import *
from files.__main__ import app, limiter, db_session
import sqlalchemy
from pusher_push_notifications import PushNotifications
from collections import Counter
import gevent
@ -537,7 +538,15 @@ def leaderboard(v):
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]
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, users6=users6, pos6=pos6, users7=users7, pos7=pos7, users9=users9_25, pos9=pos9, users10=users10, pos10=pos10, users11=users11, pos11=pos11, users12=users12, pos12=pos12, users13=users13_25, pos13=pos13, users14=users14, pos14=pos14, users15=users15, pos15=pos15)
usersBlk = g.db.query(UserBlock.target_id, func.count().label('blocked_by')) \
.group_by(UserBlock.target_id).order_by(sqlalchemy.desc('blocked_by')).limit(25).all()
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,
users6=users6, pos6=pos6, users7=users7, pos7=pos7, users9=users9_25, pos9=pos9,
users10=users10, pos10=pos10, users11=users11, pos11=pos11, users12=users12, pos12=pos12,
users13=users13_25, pos13=pos13, users14=users14, pos14=pos14, users15=users15, pos15=pos15,
usersBlk=usersBlk)
@app.get("/@<username>/css")
def get_css(username):

View File

@ -18,7 +18,8 @@
{%- if users12 %}<a href="#leaderboard-marseys">Marseys</a> &bull; {% endif -%}
{%- if users13 %}<a href="#leaderboard-upgiven">Upvotes Given</a> &bull; {% endif -%}
<a href="#leaderboard-winnings">Winnings</a> &bull;
<a href="#leaderboard-losses">Losses</a>
<a href="#leaderboard-losses">Losses</a> &bull;
<a href="#leaderboard-blocked">Blocked</a>
</div>
<h5 style="font-weight:bold;text-align: center"><a id="leaderboard-coins">Top 25 by coins</a></h5>
@ -497,6 +498,30 @@
<pre>
</pre>
<h5 style="font-weight:bold;text-align: center"><a id="leaderboard-blocked">Top 25 Most Blocked</a></h5>
<pre></pre>
<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>Blocked By</th>
</tr>
</thead>
{% for user in usersBlk %}
<tr {% if v.id == user.id %}class="self"{% endif %}>
<td>{{loop.index}}</td>
<td><a style="color:#{{user.namecolor}};font-weight:bold" href="/@{{user.username}}"><img loading="lazy" src="{{user.profile_url}}" class="pp20"><span {% if user.patron %}class="patron" style="background-color:#{{user.namecolor}}"{% endif %}>{{user.username}}</span></a></td>
<td>{{user.blocked_by}}</td>
</tr>
{% endfor %}
</table>
<pre>
</pre>
<a id="leader--top-btn" href="#leaderboard-contents" role="button"
style="position: fixed; bottom: 5rem; right: 2rem; font-size: 3rem;">