From 8a16ea38461381a42a82b400a1037a70bd56fc5f Mon Sep 17 00:00:00 2001 From: VinVash <2020kucp1046@iiitkota.ac.in> Date: Fri, 26 Dec 2025 22:10:51 -0500 Subject: [PATCH] fix: fixed the rendering and sorting of scoreboard vv2418 --- server.py | 13 +++++++------ static/scoreboard.js | 5 +++-- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/server.py b/server.py index 372a266c..ee9813e0 100644 --- a/server.py +++ b/server.py @@ -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(): @@ -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) \ No newline at end of file diff --git a/static/scoreboard.js b/static/scoreboard.js index 34ce2009..52f0537d 100644 --- a/static/scoreboard.js +++ b/static/scoreboard.js @@ -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"); @@ -45,4 +46,4 @@ function increase_score(id){ $(document).ready(function(){ display_scoreboard(scoreboard); -}) +}) \ No newline at end of file