diff --git a/server.py b/server.py index 372a266c..893a7219 100644 --- a/server.py +++ b/server.py @@ -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) diff --git a/static/scoreboard.js b/static/scoreboard.js index 34ce2009..f48d7c1c 100644 --- a/static/scoreboard.js +++ b/static/scoreboard.js @@ -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");