mirror of
https://github.com/FAUSheppy/skillbird
synced 2025-12-06 06:51:34 +01:00
@@ -63,37 +63,3 @@ def savePlayerToDatabase(player, incrementWins=0):
|
|||||||
def saveMultiplePlayersToDatabase(playerList, incrementWins=0):
|
def saveMultiplePlayersToDatabase(playerList, incrementWins=0):
|
||||||
for p in playerList:
|
for p in playerList:
|
||||||
savePlayerToDatabase(p, incrementWins)
|
savePlayerToDatabase(p, incrementWins)
|
||||||
|
|
||||||
## open leaderboard functions ##
|
|
||||||
def findPlayerByName(playerName):
|
|
||||||
conn = sqlite3.connect(DATABASE)
|
|
||||||
cursor = conn.cursor()
|
|
||||||
playerNamePrepared = "%{}%".format(playerName.replace("%", "%%"))
|
|
||||||
cursor.execute("SELECT * FROM players WHERE name == ?", (playerName,))
|
|
||||||
rows = cursor.fetchall()
|
|
||||||
playerRow = None
|
|
||||||
if len(rows) < 1:
|
|
||||||
cursor.execute("SELECT * FROM players WHERE name LIKE ?", (playerNamePrepared,))
|
|
||||||
rows = cursor.fetchall()
|
|
||||||
if len(rows) < 1:
|
|
||||||
return None
|
|
||||||
playerRow = rows[0]
|
|
||||||
else:
|
|
||||||
playerRow = rows[0]
|
|
||||||
|
|
||||||
playerId, playerName, lastGame, wins, mu, sigma, games = playerRow
|
|
||||||
conn.close()
|
|
||||||
return Players.PlayerInDatabase(playerId, playerName,
|
|
||||||
trueskill.newRating(mu=mu, sigma=sigma), wins, games)
|
|
||||||
|
|
||||||
def getTotalEntries(playerName):
|
|
||||||
conn = sqlite3.connect(DATABASE)
|
|
||||||
cursor = conn.cursor()
|
|
||||||
playerNamePrepared = "%{}%".format(playerName.replace("%", "%%"))
|
|
||||||
cursor.execute("select count(*) from players")
|
|
||||||
count = cursor.fetchone()
|
|
||||||
conn.close()
|
|
||||||
return count
|
|
||||||
|
|
||||||
def getRankRange(start, end):
|
|
||||||
pass
|
|
||||||
|
|||||||
@@ -24,30 +24,6 @@ def getPlayer():
|
|||||||
return ("Player not found", 404)
|
return ("Player not found", 404)
|
||||||
return "{}'s Rating: {}".format(p.name, int(p.rating.mu - 2*p.rating.sigma))
|
return "{}'s Rating: {}".format(p.name, int(p.rating.mu - 2*p.rating.sigma))
|
||||||
|
|
||||||
#### Open Leaderboard ###
|
|
||||||
@app.route('/findplayer')
|
|
||||||
def getFind():
|
|
||||||
playerName = flask.request.args.get("name")
|
|
||||||
p = db.findPlayerbyName(playerName)
|
|
||||||
return p.toJson()
|
|
||||||
|
|
||||||
@app.route('/getmaxentries')
|
|
||||||
def getMaxEntries():
|
|
||||||
return "{}".format(db.getTotalEntries())
|
|
||||||
|
|
||||||
@app.route('/rankrange')
|
|
||||||
def getRankRange():
|
|
||||||
try:
|
|
||||||
start = int(flask.request.args.get("start"))
|
|
||||||
end = int(flask.request.args.get("end"))
|
|
||||||
if end - start <= 0 or end - start > 100:
|
|
||||||
raise ValueError()
|
|
||||||
except ValueError:
|
|
||||||
return invalidParameters(start, end)
|
|
||||||
|
|
||||||
players = db.getRankRange(start, end)
|
|
||||||
return ""
|
|
||||||
|
|
||||||
################# DataSubmission #######################
|
################# DataSubmission #######################
|
||||||
@app.route('/submitt-round', methods=["POST"])
|
@app.route('/submitt-round', methods=["POST"])
|
||||||
def jsonRound():
|
def jsonRound():
|
||||||
|
|||||||
Reference in New Issue
Block a user