mirror of
https://github.com/FAUSheppy/open-web-leaderboard.git
synced 2025-12-06 23:21:35 +01:00
fist working version
This commit is contained in:
@@ -13,13 +13,42 @@ PARAM_END = "end"
|
||||
|
||||
BASE_URL = "http://{server}{path}?{paramStart}={start}&{paramEnd}={end}"
|
||||
SEGMENT = 100
|
||||
SEPERATOR = ','
|
||||
|
||||
class Player:
|
||||
def __init__(self, line):
|
||||
pass
|
||||
'''Initialize a player object later to be serialized to HTML'''
|
||||
|
||||
# parse input line #
|
||||
name, playerID, rating, games, wins = line.split(SEPERATOR)
|
||||
|
||||
# set relevant values #
|
||||
self.name = name
|
||||
self.playerID = playerID
|
||||
self.rating = int(float(rating))
|
||||
self.games = int(games)
|
||||
self.wins = int(wins)
|
||||
self.loses = self.games - self.wins
|
||||
|
||||
# determine winratio #
|
||||
if self.games == 0:
|
||||
self.winratio = "N/A"
|
||||
else:
|
||||
self.winratio = str(int(self.wins/self.games * 100))
|
||||
|
||||
def getLineHTML(self, rank):
|
||||
'''Build a single line for a specific player in the leaderboard'''
|
||||
|
||||
string = flask.render_template("playerLine.html", \
|
||||
playerRank = rank, \
|
||||
playerName = self.name, \
|
||||
playerRating = self.rating, \
|
||||
playerGames = self.games, \
|
||||
playerWinratio = self.winratio)
|
||||
|
||||
# mark returned string as preformated html #
|
||||
return flask.Markup(string)
|
||||
|
||||
def getLineHTML(self):
|
||||
pass
|
||||
|
||||
@app.route('/leaderboard')
|
||||
def leaderboard():
|
||||
@@ -46,33 +75,26 @@ def leaderboard():
|
||||
start=start, \
|
||||
end=end)
|
||||
|
||||
response = str(requests.get(requestURL), "utf-8")
|
||||
responseString = str(requests.get(requestURL).content, "utf-8")
|
||||
|
||||
# create relevant html-lines from player
|
||||
players = [Player(line) for line in response.split("\n")]
|
||||
playersHTMLs = [p.getLineHTML() for p in players]
|
||||
players = [Player(line) for line in responseString.split("\n")]
|
||||
|
||||
# sanity check reponse #
|
||||
if len(players) > 100:
|
||||
raise ValueError("Bad reponse from rating server")
|
||||
|
||||
# template html #
|
||||
leaderBoardColumnNames = "<div class=colum-names>{}</div>"
|
||||
leaderBoardEvenLine = "<div class=line-even>{}</div>"
|
||||
leaderBoardOddLine = "<div class=line-odd>{}</div>"
|
||||
|
||||
columContent = "LOL"
|
||||
leaderBoardContent = leaderBoardColumnNames.format(columContent)
|
||||
|
||||
for i in range(0, len(players)):
|
||||
if i%2 == 0:
|
||||
leaderBoardContent += leaderBoardEvenLine.format(players[i].getLineHTML())
|
||||
else:
|
||||
leaderBoardContent += leaderBoardOdd.format(players[i].getLineHTML())
|
||||
|
||||
finalResponse = render_template("base.html",
|
||||
finalResponse = flask.render_template("base.html", playerList=players, \
|
||||
columNames=columContent, \
|
||||
start=start)
|
||||
return finalResponse
|
||||
|
||||
@app.route('/static/<path:path>')
|
||||
def send_js(path):
|
||||
return send_from_directory('static', path)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
parser = argparse.ArgumentParser(description='Start open-leaderboard')
|
||||
|
||||
@@ -54,10 +54,46 @@ body{
|
||||
.line-even{
|
||||
width: 100%;
|
||||
background-color: grey;
|
||||
overflow: hidden;
|
||||
padding-top: 2px;
|
||||
padding-bottom: 2px;
|
||||
}
|
||||
.line-odd{
|
||||
width: 100%;
|
||||
background-color: lightgrey;
|
||||
overflow: hidden;
|
||||
padding-top: 2px;
|
||||
padding-bottom: 2px;
|
||||
}
|
||||
|
||||
/* ############# PLAYER INFORMATION IN LINES ############# */
|
||||
.playerRank{
|
||||
float: left;
|
||||
width: 10%;
|
||||
}
|
||||
|
||||
.playerName{
|
||||
float: left;
|
||||
width: 30%;
|
||||
}
|
||||
|
||||
.playerRating{
|
||||
float: right;
|
||||
width: 20%;
|
||||
text-align: right;
|
||||
|
||||
}
|
||||
|
||||
.playerGames{
|
||||
float: right;
|
||||
width: 20%;
|
||||
text-align: right;
|
||||
}
|
||||
|
||||
.playerWinratio{
|
||||
float: right;
|
||||
width: 20%;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
/* ######################## FOOTER ####################### */
|
||||
|
||||
@@ -12,14 +12,13 @@
|
||||
</div>
|
||||
<div class=leaderboard-container>
|
||||
<div class=colum-names>{{ columNames }}</div>
|
||||
{% set count = 1 %}
|
||||
{% set count = start+1 %}
|
||||
{% for player in playerList %}
|
||||
{% if count % 2 == 0 %}
|
||||
<div class=line-even>{{ player.getLineHTML() }}</div>
|
||||
<div class=line-even>{{ player.getLineHTML(count) }}</div>
|
||||
{% else %}
|
||||
<div class=line-odd>{{ player.getLineHTML() }}</div>
|
||||
<div class=line-odd>{{ player.getLineHTML(count) }}</div>
|
||||
{% endif %}
|
||||
<option value="">{{country}}</option>
|
||||
{% set count = count + 1 %}
|
||||
{% endfor %}
|
||||
</div>
|
||||
|
||||
5
templates/playerLine.html
Normal file
5
templates/playerLine.html
Normal file
@@ -0,0 +1,5 @@
|
||||
<div class=playerRank>{{ playerRank }}</div>
|
||||
<div class=playerName>{{ playerName }}</div>
|
||||
<div class=playerWinratio>{{ playerWinratio }}</div>
|
||||
<div class=playerRating>{{ playerRating }}</div>
|
||||
<div class=playerGames>{{ playerGames }} </div>
|
||||
Reference in New Issue
Block a user