Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
data-networks-web
lab-exercises
Commits
0fc6b150
Commit
0fc6b150
authored
Apr 21, 2018
by
Sorrel Harriet
Browse files
updating query for leaderboard
parent
8719abfc
Changes
1
Show whitespace changes
Inline
Side-by-side
resit-app/cgi-bin/components.py
View file @
0fc6b150
...
@@ -59,6 +59,18 @@ def record_game(cursor, form_data):
...
@@ -59,6 +59,18 @@ def record_game(cursor, form_data):
def
leaderboard
():
def
leaderboard
():
""" The leaderboard component
""" 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'
)
)
print
(
utils
.
render_template
(
config
[
'TEMPLATE_DIR'
]
+
'leaderboard.html'
)
)
return
return
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment