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
14 changes: 14 additions & 0 deletions server.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,23 @@ def increase_score():
json_data = request.get_json()
team_id = json_data["id"]

# Option 1 (Python sort() method)
for team in scoreboard:
if team["id"] == team_id:
team["score"] += 1
scoreboard.sort(key=lambda x: x["score"], reverse=True)

# Option 2 (Insertion Sort)
'''
for i in range(len(scoreboard)):
team = scoreboard[i]
if team["id"] == team_id:
team["score"] += 1
for j in range(i, 0, -1):
if scoreboard[j - 1]["score"] < scoreboard[j]["score"]:
scoreboard[j] = scoreboard[j - 1]
scoreboard[j - 1] = team
'''

return jsonify(scoreboard=scoreboard)

Expand Down
2 changes: 1 addition & 1 deletion static/scoreboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ function increase_score(id){
contentType: "application/json; charset=utf-8",
data : JSON.stringify(team_id),
success: function(result){

display_scoreboard(result.scoreboard);
},
error: function(request, status, error){
console.log("Error");
Expand Down