win loss stats to casino games (#475)

* casino: add stats to casino

* casino: stats should target the right thing
casino: properly style

* pluralize properly

* refactor casino leaderboards :marseytroublemarker:

* fsfsdsd

* fsdsdsdsd

* i'm r-slurred

* -
pull/2/head
justcool393 2022-11-22 07:11:01 -08:00 committed by GitHub
parent 007e41e7d0
commit b0ff8916a5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 28 additions and 42 deletions

View File

@ -23,8 +23,14 @@ def get_game_feed(game, db):
return list(map(format_game, games))
def get_user_stats(u:User, game:str, db:scoped_session, include_ties=False):
games = db.query(Casino_Game.user_id, Casino_Game.winnings).filter(Casino_Game.kind == game, Casino_Game.user_id == u.id)
wins = games.filter(Casino_Game.winnings > 0).count()
ties = games.filter(Casino_Game.winnings == 0).count() if include_ties else 0
losses = games.filter(Casino_Game.winnings < 0).count()
return (wins, ties, losses)
def get_game_leaderboard(game, db):
def get_game_leaderboard(game, db:scoped_session):
timestamp_24h_ago = time.time() - 86400
timestamp_all_time = CASINO_RELEASE_DAY # "All Time" starts on release day

View File

@ -16,7 +16,7 @@ from files.__main__ import app, limiter
@auth_required
def casino(v):
if v.rehab:
return render_template("casino/rehab.html", v=v)
return render_template("casino/rehab.html", v=v), 403
return render_template("casino.html", v=v)
@ -26,12 +26,13 @@ def casino(v):
@auth_required
def casino_game_page(v, game):
if v.rehab:
return render_template("casino/rehab.html", v=v)
return render_template("casino/rehab.html", v=v), 403
elif game not in CASINO_GAME_KINDS:
abort(404)
feed = json.dumps(get_game_feed(game, g.db))
leaderboard = json.dumps(get_game_leaderboard(game, g.db))
v_stats = get_user_stats(v, game, g.db, game == 'blackjack')
game_state = ''
if game == 'blackjack':
@ -44,6 +45,7 @@ def casino_game_page(v, game):
game=game,
feed=feed,
leaderboard=leaderboard,
v_stats=v_stats,
game_state=game_state
)

View File

@ -312,7 +312,7 @@
transform: scaleX(-1) scaleY(-1);
}
#casinoGameResult {
#casinoGameResult, #casinoGameStats {
text-transform: uppercase;
text-align: center;
letter-spacing: 3px;
@ -365,6 +365,12 @@
{% block result %} {% endblock %}
</div>
</div>
<div class="col">
{% set stats_alert_class = 'success' if v_stats[0] >= v_stats[2] else 'danger' %}
<div id="casinoGameStats" class="alert alert-{{stats_alert_class}}" role="alert">
{{v_stats[0]}} win{{macros.plural(v_stats[0])}}{% if v_stats[1] %} - {{v_stats[1]}} tie{{macros.plural(v_stats[1])}}{% endif %} - {{v_stats[2]}} loss{{macros.plural(v_stats[2], 'es')}}
</div>
</div>
<div class="col">
<div class="row row-cols-2">
<div class="col">
@ -419,50 +425,22 @@
<hr>
</div>
<div id="gameLeaderboard" data-leaderboard="{{leaderboard}}">
<!-- Biggest Winner All Time -->
{%- macro leaderboard(text, css_class, marsey, color) -%}
<div class="casino-game-leaderboard">
<div class="leaderboard-marsey-trophy">
<img class="leaderboard-marsey-trophy__marsey" src="/e/marseyhappytears.webp">
<i class="fas fa-trophy leaderboard-marsey-trophy__trophy" style="color: gold;"></i>
<img class="leaderboard-marsey-trophy__marsey" src="/e/{{marsey}}.webp">
<i class="fas fa-trophy leaderboard-marsey-trophy__trophy" style="color: {{color}};"></i>
</div>
<div class="casino-game-leaderboard-info">
<small>Biggest Winner (All Time)</small>
<h3 id="biggestWinnerAllTime">-</h3>
</div>
</div>
<!-- Biggest Winner 24h -->
<div class="casino-game-leaderboard">
<div class="leaderboard-marsey-trophy">
<img class="leaderboard-marsey-trophy__marsey" src="/e/marseyexcited.webp">
<i class="fas fa-trophy leaderboard-marsey-trophy__trophy" style="color: gold;"></i>
</div>
<div class="casino-game-leaderboard-info">
<small>Biggest Winner (Last 24h)</small>
<h3 id="biggestWinner24h">-</h3>
</div>
</div>
<!-- Biggest Loser 24h -->
<div class="casino-game-leaderboard">
<div class="leaderboard-marsey-trophy">
<img class="leaderboard-marsey-trophy__marsey" src="/e/marseycry.webp">
<i class="fas fa-trophy leaderboard-marsey-trophy__trophy" style="color: darkred;"></i>
</div>
<div class="casino-game-leaderboard-info">
<small>Biggest Loser (Last 24h)</small>
<h3 id="biggestLoser24h">-</h3>
</div>
</div>
<!-- Biggest Loser All Time -->
<div class="casino-game-leaderboard">
<div class="leaderboard-marsey-trophy">
<img class="leaderboard-marsey-trophy__marsey" src="/e/marseyrain.webp">
<i class="fas fa-trophy leaderboard-marsey-trophy__trophy" style="color: darkred;"></i>
</div>
<div class="casino-game-leaderboard-info">
<small>Biggest Loser (All Time)</small>
<h3 id="biggestLoserAllTime">-</h3>
<small>{{text}}</small>
<h3 id="{{css_class}}">-</h3>
</div>
</div>
{%- endmacro -%}
{{leaderboard('Biggest Winner (All Time)', 'biggestWinnerAllTime', 'marseyhappytears', 'gold')}}
{{leaderboard('Biggest Winner (Last 24h)', 'biggestWinner24h', 'marseyexcited', 'gold')}}
{{leaderboard('Biggest Loser (Last 24h)', 'biggestLoser24h', 'marseycry', 'darkred')}}
{{leaderboard('Biggest Loser (All Time)', 'biggestLoserAllTime', 'marseyrain', 'darkred')}}
</div>
</div>
</div>