forked from rDrama/rDrama
world cup leaderboard 2022 (#23)
insert witty PR message here a temporary lb for worldcup stuff Co-authored-by: justcool393 <justcool393@gmail.com> Reviewed-on: rDrama/rDrama#23 Co-authored-by: justcool393 <justcool393@noreply.fsdfsd.net> Co-committed-by: justcool393 <justcool393@noreply.fsdfsd.net>master
parent
4b66e40ca8
commit
0c9d0d1bcd
|
@ -47,3 +47,4 @@ if FEATURES['ASSET_SUBMISSIONS']:
|
|||
from .asset_submissions import *
|
||||
if FEATURES['STREAMERS']:
|
||||
from .streamers import *
|
||||
from .events import *
|
||||
|
|
|
@ -0,0 +1,35 @@
|
|||
from flask import g, jsonify, render_template
|
||||
from files.helpers.get import get_accounts_dict
|
||||
|
||||
from files.routes.wrappers import auth_required
|
||||
from files.__main__ import app
|
||||
|
||||
@app.get('/events/worldcup2022/leaderboard')
|
||||
@auth_required
|
||||
def get_leaderboard(v):
|
||||
result = g.db.execute('''WITH bet_votes AS (
|
||||
SELECT opt.id AS option_id, opt.exclusive, sov.user_id
|
||||
FROM submission_option_votes sov
|
||||
LEFT OUTER JOIN (
|
||||
SELECT so.id, so.exclusive
|
||||
FROM submission_options so
|
||||
JOIN submissions p ON so.submission_id = p.id
|
||||
WHERE p.author_id = 30 AND p.created_utc > 1668953400 AND so.exclusive IN (2, 3)
|
||||
) AS opt ON opt.id = sov.option_id
|
||||
WHERE opt.id IS NOT NULL
|
||||
)
|
||||
SELECT
|
||||
COALESCE(bet_won.user_id, bet_lost.user_id) AS user_id,
|
||||
(COALESCE(bet_won.count_won, 0) + COALESCE(bet_lost.count_lost, 0)) AS bets_total,
|
||||
COALESCE(bet_won.count_won, 0) AS bets_won
|
||||
FROM (
|
||||
SELECT user_id, COUNT(*) AS count_won FROM bet_votes
|
||||
WHERE exclusive = 3 GROUP BY user_id) AS bet_won
|
||||
FULL OUTER JOIN (
|
||||
SELECT user_id, COUNT(*) AS count_lost FROM bet_votes
|
||||
WHERE exclusive = 2 GROUP BY user_id) AS bet_lost
|
||||
ON bet_won.user_id = bet_lost.user_id
|
||||
ORDER BY bets_won DESC, bets_total ASC;''').all()
|
||||
if g.is_api_or_xhr: return jsonify(result)
|
||||
users = get_accounts_dict([r[0] for r in result], v=v, include_shadowbanned=False)
|
||||
return render_template("event/worldcup22_leaderboard.html", v=v, result=result, users=users)
|
|
@ -0,0 +1,28 @@
|
|||
{%- extends 'default.html' -%}
|
||||
{% block content %}
|
||||
<h1>World Cup 2022 Betting Leaderboard</h1>
|
||||
<div class="overflow-x-auto">
|
||||
<table class="table table-striped mb-5">
|
||||
<thead class="bg-primary text-white">
|
||||
<tr>
|
||||
<th onclick="sort_table(0)">#</th>
|
||||
<th onclick="sort_table(1)">Name</th>
|
||||
<th onclick="sort_table(2)">Wins</th>
|
||||
<th onclick="sort_table(3)">Bets</th>
|
||||
<th onclick="sort_table(4)">Wins/Bets Ratio</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for r in result %}
|
||||
{% set user = users.get(r[0]) %}
|
||||
<td>{{loop.index}}</td>
|
||||
<td data-sort-key="{{user.username.lower() if user else ''}}">{%- include 'user_in_table.html' -%}</td>
|
||||
<td>{{r[2]}}</td>
|
||||
<td>{{r[1]}}</td>
|
||||
<td>{{":. 0%" | format(r[2] / r[1]|float)}}</td>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<script defer src="{{'js/sort_table.js' | asset}}"></script>
|
||||
{% endblock %}
|
Loading…
Reference in New Issue