Skip to content

Commit

Permalink
sync server
Browse files Browse the repository at this point in the history
  • Loading branch information
dgomes committed Oct 30, 2019
1 parent c0c3d16 commit 038eaa2
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions prof/grading.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from flask_sqlalchemy import SQLAlchemy
from flask_marshmallow import Marshmallow
import os
from sqlalchemy import and_, func

app = Flask(__name__, static_url_path='')
basedir = os.path.abspath(os.path.dirname(__file__))
Expand Down Expand Up @@ -45,7 +46,7 @@ def add_game():
db.session.add(new_game)
db.session.commit()

return game_schema.jsonify(new_game)
return game_schema.jsonify(new_game)

@app.route("/static/<path:path>")
def send_static(path):
Expand All @@ -55,15 +56,20 @@ def send_static(path):
@app.route("/highscores", methods=["GET"])
def get_game():
page = request.args.get('page', 1, type=int)
all_games = db.session.query(Game).order_by(Game.score.desc()).paginate(page, 20, False)

q = db.session.query(Game.id, Game.timestamp, Game.player, Game.level, func.max(Game.score).label('score')).group_by(Game.player).order_by(Game.score.desc(), Game.timestamp)
print(q.statement)

all_games = q.paginate(page, 20, False)
# all_games = db.session.query(Game).order_by(Game.score.desc()).paginate(page, 20, False)
result = games_schema.dump(all_games.items)
return jsonify(result)


# endpoint to show player games
@app.route("/highscores/<player>", methods=["GET"])
def game_detail(player):
game = db.session.query(Game).filter(Game.player == player).order_by(Game.score.desc()).limit(10)
game = db.session.query(Game).filter(and_(Game.player == player, Game.score > 0)).order_by(Game.score.desc()).limit(10)
result = games_schema.dump(game)
return jsonify(result)

Expand Down

0 comments on commit 038eaa2

Please sign in to comment.