mirror of
https://github.com/FAUSheppy/open-web-leaderboard.git
synced 2025-12-07 15:41: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}"
|
BASE_URL = "http://{server}{path}?{paramStart}={start}&{paramEnd}={end}"
|
||||||
SEGMENT = 100
|
SEGMENT = 100
|
||||||
|
SEPERATOR = ','
|
||||||
|
|
||||||
class Player:
|
class Player:
|
||||||
def __init__(self, line):
|
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')
|
@app.route('/leaderboard')
|
||||||
def leaderboard():
|
def leaderboard():
|
||||||
@@ -46,33 +75,26 @@ def leaderboard():
|
|||||||
start=start, \
|
start=start, \
|
||||||
end=end)
|
end=end)
|
||||||
|
|
||||||
response = str(requests.get(requestURL), "utf-8")
|
responseString = str(requests.get(requestURL).content, "utf-8")
|
||||||
|
|
||||||
# create relevant html-lines from player
|
# create relevant html-lines from player
|
||||||
players = [Player(line) for line in response.split("\n")]
|
players = [Player(line) for line in responseString.split("\n")]
|
||||||
playersHTMLs = [p.getLineHTML() for p in players]
|
|
||||||
|
|
||||||
# sanity check reponse #
|
# sanity check reponse #
|
||||||
if len(players) > 100:
|
if len(players) > 100:
|
||||||
raise ValueError("Bad reponse from rating server")
|
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"
|
columContent = "LOL"
|
||||||
leaderBoardContent = leaderBoardColumnNames.format(columContent)
|
|
||||||
|
|
||||||
for i in range(0, len(players)):
|
finalResponse = flask.render_template("base.html", playerList=players, \
|
||||||
if i%2 == 0:
|
columNames=columContent, \
|
||||||
leaderBoardContent += leaderBoardEvenLine.format(players[i].getLineHTML())
|
start=start)
|
||||||
else:
|
|
||||||
leaderBoardContent += leaderBoardOdd.format(players[i].getLineHTML())
|
|
||||||
|
|
||||||
finalResponse = render_template("base.html",
|
|
||||||
return finalResponse
|
return finalResponse
|
||||||
|
|
||||||
|
@app.route('/static/<path:path>')
|
||||||
|
def send_js(path):
|
||||||
|
return send_from_directory('static', path)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
parser = argparse.ArgumentParser(description='Start open-leaderboard')
|
parser = argparse.ArgumentParser(description='Start open-leaderboard')
|
||||||
|
|||||||
@@ -54,10 +54,46 @@ body{
|
|||||||
.line-even{
|
.line-even{
|
||||||
width: 100%;
|
width: 100%;
|
||||||
background-color: grey;
|
background-color: grey;
|
||||||
|
overflow: hidden;
|
||||||
|
padding-top: 2px;
|
||||||
|
padding-bottom: 2px;
|
||||||
}
|
}
|
||||||
.line-odd{
|
.line-odd{
|
||||||
width: 100%;
|
width: 100%;
|
||||||
background-color: lightgrey;
|
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 ####################### */
|
/* ######################## FOOTER ####################### */
|
||||||
|
|||||||
@@ -12,14 +12,13 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class=leaderboard-container>
|
<div class=leaderboard-container>
|
||||||
<div class=colum-names>{{ columNames }}</div>
|
<div class=colum-names>{{ columNames }}</div>
|
||||||
{% set count = 1 %}
|
{% set count = start+1 %}
|
||||||
{% for player in playerList %}
|
{% for player in playerList %}
|
||||||
{% if count % 2 == 0 %}
|
{% if count % 2 == 0 %}
|
||||||
<div class=line-even>{{ player.getLineHTML() }}</div>
|
<div class=line-even>{{ player.getLineHTML(count) }}</div>
|
||||||
{% else %}
|
{% else %}
|
||||||
<div class=line-odd>{{ player.getLineHTML() }}</div>
|
<div class=line-odd>{{ player.getLineHTML(count) }}</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<option value="">{{country}}</option>
|
|
||||||
{% set count = count + 1 %}
|
{% set count = count + 1 %}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</div>
|
</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