add 2 leaderboard tables for hats

remotes/1693045480750635534/spooky-22
Aevann1 2022-09-03 20:50:20 +02:00
parent 3e75309821
commit 256b384e69
5 changed files with 59 additions and 11 deletions

View File

@ -153,6 +153,8 @@ class User(Base):
awards = relationship("AwardRelationship", primaryjoin="User.id==AwardRelationship.user_id", back_populates="user")
referrals = relationship("User")
equipped_hat = relationship("HatDef", primaryjoin="User.equipped_hat_id==HatDef.id")
designed_hats = relationship("HatDef", primaryjoin="User.id==HatDef.author_id")
owned_hats = relationship("Hat")
def __init__(self, **kwargs):
@ -174,13 +176,13 @@ class User(Base):
@property
@lazy
def num_of_hats_bought(self):
return g.db.query(Hat).filter_by(user_id=self.id).count()
def num_of_owned_hats(self):
return len(self.owned_hats)
@property
@lazy
def num_of_hats_designed(self):
return g.db.query(HatDef).filter_by(author_id=self.id).count()
def num_of_designed_hats(self):
return len(self.designed_hats)
@property
@lazy

View File

@ -55,11 +55,11 @@ def buy_hat(v, hat_id):
f":marseycapitalistmanlet: @{v.username} has just bought `{hat.name}`, you have received your 5% cut ({int(hat.price * 0.05)} {currency}) :!marseycapitalistmanlet:"
)
if v.num_of_hats_bought >= 250:
if v.num_of_owned_hats >= 250:
badge_grant(user=v, badge_id=154)
elif v.num_of_hats_bought >= 100:
elif v.num_of_owned_hats >= 100:
badge_grant(user=v, badge_id=153)
elif v.num_of_hats_bought >= 25:
elif v.num_of_owned_hats >= 25:
badge_grant(user=v, badge_id=152)
return {"message": "Hat bought!"}

View File

@ -576,12 +576,16 @@ def leaderboard(v):
FROM (SELECT target_id, count(target_id) AS n FROM userblocks GROUP BY target_id) AS blk \
JOIN users ON users.id = blk.target_id ORDER BY blk.n DESC LIMIT 25'))
users16 = 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()
users17 = 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()
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)
usersBlk=usersBlk, users16=users16, users17=users17)
@app.get("/<id>/css")
def get_css(id):

View File

@ -9,8 +9,8 @@
{% block Banner %}
<header class="container pb-1 text-center">
<img class="mt-5" alt="hats banner" src="/i/hats.webp?v=1" width="50%">
<h5 class="mt-4">Number of hats you bought: {{v.num_of_hats_bought}}</h5>
<h5 class="mt-4">Number of hats you designed: {{v.num_of_hats_designed}}</h5>
<h5 class="mt-4">Number of hats you bought: {{v.num_of_owned_hats}}</h5>
<h5 class="mt-4">Number of hats you designed: {{v.num_of_designed_hats}}</h5>
<h5 class="mt-4">Coins you spent on hats: {{v.coins_spent_on_hats}}</h5>
</header>
{% endblock %}

View File

@ -19,7 +19,9 @@
{%- if users13 %}<a href="#leaderboard-upgiven">Upvotes Given</a> &bull; {% endif -%}
<a href="#leaderboard-winnings">Winnings</a> &bull;
<a href="#leaderboard-losses">Losses</a> &bull;
<a href="#leaderboard-blocked">Blocked</a>
<a href="#leaderboard-blocked">Blocked</a> &bull;
<a href="#leaderboard-owned-hats">Owned Hats</a> &bull;
<a href="#leaderboard-designed-hats">Designed Hats</a>
</div>
<h5 class="font-weight-bolder text-center pt-2 pb-3"><a id="leaderboard-coins">Top 25 by coins</a></h5>
@ -427,6 +429,46 @@
{% endfor %}
</table>
<h5 class="font-weight-bolder text-center pt-2 pb-3"><a id="leaderboard-owned-hats">Top 25 by Owned Hats</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>Owned Hats</th>
</tr>
</thead>
{% for user,num in users16 %}
<tr {% if v.id == user.id %}class="self"{% endif %}>
<td>{{loop.index}}</td>
<td><a style="color:#{{user.name_color}};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.name_color}}"{% endif %}>{{user.username}}</span></a></td>
<td>{{num}}</td>
</tr>
{% endfor %}
</table>
<h5 class="font-weight-bolder text-center pt-2 pb-3"><a id="leaderboard-designed-hats">Top 25 by Designed Hats</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>Designed Hats</th>
</tr>
</thead>
{% for user,num in users17 %}
<tr {% if v.id == user.id %}class="self"{% endif %}>
<td>{{loop.index}}</td>
<td><a style="color:#{{user.name_color}};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.name_color}}"{% endif %}>{{user.username}}</span></a></td>
<td>{{num}}</td>
</tr>
{% endfor %}
</table>
<a id="leader--top-btn" href="#leaderboard-contents" role="button"
style="position: fixed; bottom: 5rem; right: 2rem; font-size: 3rem;">
<i class="fas fa-arrow-alt-circle-up"></i>