forked from Hanabi/hanabi-league
start website implementation
This commit is contained in:
parent
7289dce5d9
commit
fec81a6c15
4 changed files with 89 additions and 1 deletions
|
@ -293,7 +293,7 @@ CREATE TABLE user_ratings (
|
||||||
* I would use the league_id here for proper ordering.
|
* I would use the league_id here for proper ordering.
|
||||||
* Also note that this can then be used to identify whether a given league game has already been processed for rating change.
|
* Also note that this can then be used to identify whether a given league game has already been processed for rating change.
|
||||||
*/
|
*/
|
||||||
league_id INTEGER REFERENCES games (league_id),
|
league_id INTEGER NOT NULL REFERENCES games (league_id),
|
||||||
|
|
||||||
user_id INTEGER NOT NULL,
|
user_id INTEGER NOT NULL,
|
||||||
type SMALLINT NOT NULL,
|
type SMALLINT NOT NULL,
|
||||||
|
|
|
@ -7,3 +7,4 @@ unidecode
|
||||||
requests
|
requests
|
||||||
requests_cache
|
requests_cache
|
||||||
termcolor
|
termcolor
|
||||||
|
jinja2
|
||||||
|
|
|
@ -47,3 +47,6 @@ USER_HISTORY_CACHE_TIME = 5 * 60
|
||||||
|
|
||||||
# Fraction of seeds which is assumed to be unwinnable
|
# Fraction of seeds which is assumed to be unwinnable
|
||||||
UNWINNABLE_SEED_FRACTION = 0.02
|
UNWINNABLE_SEED_FRACTION = 0.02
|
||||||
|
|
||||||
|
|
||||||
|
WEBSITE_OUTPUT_DIRECTORY = 'build'
|
||||||
|
|
84
src/render_site.py
Normal file
84
src/render_site.py
Normal file
|
@ -0,0 +1,84 @@
|
||||||
|
import jinja2
|
||||||
|
import psycopg2.extras
|
||||||
|
|
||||||
|
import constants
|
||||||
|
import utils
|
||||||
|
import ratings
|
||||||
|
|
||||||
|
from database import conn_manager
|
||||||
|
|
||||||
|
|
||||||
|
def get_rating_leaderboards():
|
||||||
|
cur = conn_manager.get_connection().cursor(cursor_factory=psycopg2.extras.DictCursor)
|
||||||
|
cur.execute(
|
||||||
|
"SELECT * FROM ("
|
||||||
|
" SELECT DISTINCT ON (type, user_accounts.user_id)"
|
||||||
|
" type,"
|
||||||
|
" player_name,"
|
||||||
|
" string_agg(user_accounts.username, %s ORDER BY user_accounts.username) AS user_accounts,"
|
||||||
|
" value_after AS current_rating"
|
||||||
|
" FROM user_ratings "
|
||||||
|
" INNER JOIN users "
|
||||||
|
" ON user_ratings.user_id = users.id "
|
||||||
|
" LEFT OUTER JOIN user_accounts "
|
||||||
|
" ON users.id = user_accounts.user_id "
|
||||||
|
" GROUP BY (user_accounts.user_id, player_name, value_after, league_id, type) "
|
||||||
|
" ORDER BY type, user_accounts.user_id, league_id DESC"
|
||||||
|
" ) AS ratings "
|
||||||
|
"ORDER BY type ASC, current_rating DESC",
|
||||||
|
(", ",)
|
||||||
|
)
|
||||||
|
novar_leaderboard = []
|
||||||
|
clue_starved_leaderboard = []
|
||||||
|
for row in cur.fetchall():
|
||||||
|
if row['type'] == utils.get_rating_type(False):
|
||||||
|
novar_leaderboard.append(row)
|
||||||
|
else:
|
||||||
|
clue_starved_leaderboard.append(row)
|
||||||
|
|
||||||
|
return novar_leaderboard, clue_starved_leaderboard
|
||||||
|
|
||||||
|
|
||||||
|
def get_streak_leaderboards():
|
||||||
|
cur = conn_manager.get_connection().cursor(cursor_factory=psycopg2.extras.DictCursor)
|
||||||
|
cur.execute(
|
||||||
|
"SELECT * FROM "
|
||||||
|
)
|
||||||
|
novar_leaderboard = []
|
||||||
|
clue_starved_leaderboard = []
|
||||||
|
for row in cur.fetchall():
|
||||||
|
if row['type'] == utils.get_rating_type(False):
|
||||||
|
novar_leaderboard.append(row)
|
||||||
|
else:
|
||||||
|
clue_starved_leaderboard.append(row)
|
||||||
|
|
||||||
|
return novar_leaderboard, clue_starved_leaderboard
|
||||||
|
|
||||||
|
|
||||||
|
def get_total_games():
|
||||||
|
cur = conn_manager.get_new_cursor()
|
||||||
|
cur.execute("SELECT MAX(league_id) FROM games")
|
||||||
|
(num_games, ) = cur.fetchone()
|
||||||
|
return num_games
|
||||||
|
|
||||||
|
|
||||||
|
def render_leaderboard():
|
||||||
|
novar_leaderboard, clue_starved_leaderboard = get_rating_leaderboards()
|
||||||
|
|
||||||
|
env = jinja2.Environment(loader=jinja2.FileSystemLoader('templates'))
|
||||||
|
template = env.get_template('content.html')
|
||||||
|
# rendered_html = template.render(leaders=leaders, leaderboards=leaderboards, variants=variants)
|
||||||
|
rendered_html = template.render(
|
||||||
|
# leaders=leaders,
|
||||||
|
# leaderboards=leaderboards,
|
||||||
|
# variants=variants,
|
||||||
|
# total_games_played=constants['total_games_played'],
|
||||||
|
# latest_run=latest_run_utc_formatted,
|
||||||
|
# total_players=total_players
|
||||||
|
)
|
||||||
|
with open(constants.WEBSITE_OUTPUT_DIRECTORY / 'index.html') as f:
|
||||||
|
f.write(rendered_html)
|
||||||
|
|
||||||
|
|
||||||
|
get_leaderboards()
|
||||||
|
#render_leaderboard()
|
Loading…
Reference in a new issue