Commit 0fc6b150 authored by Sorrel Harriet's avatar Sorrel Harriet
Browse files

updating query for leaderboard

parent 8719abfc
......@@ -59,6 +59,18 @@ def record_game(cursor, form_data):
def leaderboard():
""" The leaderboard component
#TODO: make it output the query results row by row
in a for loop - a job for a `proper' template engine?
"""
query = ("SELECT Player.username AS player, "
"(SELECT COUNT(*) FROM Game WHERE Game.player_id=Player.id) AS num_plays, "
"(SELECT COUNT(*) FROM Game WHERE Game.player_id=Player.id AND Game.won=1) AS num_wins "
"FROM Player "
"INNER JOIN Game ON Game.player_id=Player.id "
"GROUP BY username "
"ORDER BY num_wins/num_plays DESC")
# execute the query
cursor.execute(query, data)
# finish this component...
print( utils.render_template( config['TEMPLATE_DIR'] + 'leaderboard.html') )
return
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment