From b0ff8916a5cdf7b7a93ded5a349376cb5e62c817 Mon Sep 17 00:00:00 2001 From: justcool393 Date: Tue, 22 Nov 2022 07:11:01 -0800 Subject: [PATCH] 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 * - --- files/helpers/casino.py | 8 +++- files/routes/casino.py | 6 ++- files/templates/casino/game_screen.html | 56 ++++++++----------------- 3 files changed, 28 insertions(+), 42 deletions(-) diff --git a/files/helpers/casino.py b/files/helpers/casino.py index 7aae15893..92441e784 100644 --- a/files/helpers/casino.py +++ b/files/helpers/casino.py @@ -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 diff --git a/files/routes/casino.py b/files/routes/casino.py index 37edefc6c..93e1a830e 100644 --- a/files/routes/casino.py +++ b/files/routes/casino.py @@ -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 ) diff --git a/files/templates/casino/game_screen.html b/files/templates/casino/game_screen.html index df6fb5b02..9aab40c72 100644 --- a/files/templates/casino/game_screen.html +++ b/files/templates/casino/game_screen.html @@ -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 %} +
+ {% set stats_alert_class = 'success' if v_stats[0] >= v_stats[2] else 'danger' %} + +
@@ -419,50 +425,22 @@
- + {%- macro leaderboard(text, css_class, marsey, color) -%}
- - + +
- Biggest Winner (All Time) -

-

-
-
- -
-
- - -
-
- Biggest Winner (Last 24h) -

-

-
-
- -
-
- - -
-
- Biggest Loser (Last 24h) -

-

-
-
- -
-
- - -
-
- Biggest Loser (All Time) -

-

+ {{text}} +

-

+ {%- 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')}}