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
24 changes: 15 additions & 9 deletions server.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from flask import Response, request, jsonify
app = Flask(__name__)

#scoreboard is a json file with a hashmap that contains id, name and score
scoreboard = [
{
"id": 1,
Expand Down Expand Up @@ -36,11 +37,11 @@
]


@app.route('/')
@app.route('/')
def show_scoreboard():
return render_template('scoreboard.html', scoreboard = scoreboard)

@app.route('/increase_score', methods=['GET', 'POST'])
@app.route('/increase_score', methods=['GET', 'POST']) #when get method is sent, post to update the value and update it on screen
def increase_score():
global scoreboard

Expand All @@ -50,13 +51,18 @@ def increase_score():
for team in scoreboard:
if team["id"] == team_id:
team["score"] += 1


for i in range(1, len(scoreboard)):
key = scoreboard[i]
j = i - 1
while j >= 0 and key["score"] > scoreboard[j]["score"]:
scoreboard[j + 1] = scoreboard[j]
j -= 1
scoreboard[j + 1] = key


return jsonify(scoreboard=scoreboard)


#implement sorting algorithm, change the display: use counting sort
if __name__ == '__main__':
app.run(debug = True)




app.run(debug = True)
7 changes: 4 additions & 3 deletions static/scoreboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ function addTeamView(id, name, score){
$("#teams").append(team_template);
}

function increase_score(id){
function increase_score(id){
var team_id = {"id": id}
$.ajax({
type: "POST",
Expand All @@ -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 All @@ -41,8 +41,9 @@ function increase_score(id){
console.log(error)
}
});

}

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