Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions server.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@

@app.route('/')
def show_scoreboard():
return render_template('scoreboard.html', scoreboard = scoreboard)
# Sort change 2 here - sort by score in descending order before rendering
sorted_scoreboard = sorted(scoreboard, key=lambda x: x["score"], reverse=True)
return render_template('scoreboard.html', scoreboard = sorted_scoreboard)

@app.route('/increase_score', methods=['GET', 'POST'])
def increase_score():
Expand All @@ -51,12 +53,11 @@ def increase_score():
if team["id"] == team_id:
team["score"] += 1

# Sort change 1 here - sort by score in descending order
scoreboard.sort(key=lambda x: x["score"], reverse=True)

return jsonify(scoreboard=scoreboard)


if __name__ == '__main__':
app.run(debug = True)




app.run(debug = True)
5 changes: 3 additions & 2 deletions static/scoreboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ function increase_score(id){
contentType: "application/json; charset=utf-8",
data : JSON.stringify(team_id),
success: function(result){

// Add the display_scoreboard call here - display without refreshing
display_scoreboard(result.scoreboard);
},
error: function(request, status, error){
console.log("Error");
Expand All @@ -45,4 +46,4 @@ function increase_score(id){

$(document).ready(function(){
display_scoreboard(scoreboard);
})
})