Browse Source

#7 and #3 In the overview, a column is added. The time remaining a player can play.

pull/14/head
Rogier Neeleman 7 years ago
parent
commit
b9eb73b77d
  1. 21
      nfgame.py
  2. 35
      templates/highscores.html
  3. 4
      templates/overview.html

21
nfgame.py

@ -72,6 +72,7 @@ def index(): @@ -72,6 +72,7 @@ def index():
user = {}
tags = app.config['TAGS']
timeremaining = {}
for entry in entries:
if entry['tags'] == None:
@ -87,7 +88,23 @@ def index(): @@ -87,7 +88,23 @@ def index():
if found_tag == tag:
user[entry['id']][tag] = 'Found'
return render_template('overview.html', entries=entries, tags=app.config['TAGS'], user=user, type='Current players', refresh=app.config['REFRESH_TIME'])
'''Calculate time remaining'''
starttime = datetime.strptime(entry['starttime'], "%Y-%m-%d %H:%M:%S")
endtime = starttime + timedelta(seconds=int(app.config['MAX_TIME']))
playtime = endtime - datetime.now()
if datetime.now() > endtime:
timeremaining[entry['id']] = "Time's up"
else:
hours = playtime.seconds / 3600
minutes = (playtime.seconds - (hours * 3600)) / 60
seconds = playtime.seconds - (minutes * 60)
if len(str(minutes)) == 1:
minutes = '0' + str(minutes)
if len(str(seconds)) == 1:
seconds = '0' + str(seconds)
timeremaining[entry['id']] = str(hours) + ":" + str(minutes) + ":" + str(seconds)
return render_template('overview.html', entries=entries, tags=app.config['TAGS'], user=user, type='Current players', refresh=app.config['REFRESH_TIME'], timeremaining=timeremaining)
@app.route('/highscores')
def highscores():
@ -119,7 +136,7 @@ def highscores(): @@ -119,7 +136,7 @@ def highscores():
if found_tag == tag:
user[entry['id']][tag] = 'Found'
return render_template('overview.html', entries=entries, tags=app.config['TAGS'], user=user, type='Highscores', refresh=app.config['REFRESH_TIME'])
return render_template('highscores.html', entries=entries, tags=app.config['TAGS'], user=user, type='Highscores', refresh=app.config['REFRESH_TIME'])
@app.route('/newuser/', methods=['GET', 'POST'])
@app.route('/newuser/<string:newhash>/', methods=['GET', 'POST'])

35
templates/highscores.html

@ -0,0 +1,35 @@ @@ -0,0 +1,35 @@
{% extends "layout-overview.html" %}
{% block body %}
<h1 class="uk-heading-primary uk-text-center uk-heading-divider">{{ type }}</h1>
<center>
<div class="uk-text-large uk-align-center">
<table class="uk-table uk-align-center">
<caption></caption>
<thead>
<tr>
<td>Name</td>
<td>Duration</td>
</tr>
</thead>
<tbody>
{% for entry in entries %}
<tr>
<td>{{ entry.username }}</td>
<td>
{% if entry.duration == '99:99:99' %}
No time yet
{% else %}
{{ entry.duration }}
{% endif %}
</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</center>
{% endblock %}

4
templates/overview.html

@ -14,6 +14,7 @@ @@ -14,6 +14,7 @@
<td>{{ tags.get(tag) }}</td>
{% endfor %}
<td>Duration</td>
<td>Time remaining</td>
</tr>
</thead>
<tbody>
@ -36,6 +37,9 @@ @@ -36,6 +37,9 @@
{{ entry.duration }}
{% endif %}
</td>
<td>
{{ timeremaining[entry.id] }}
</td>
</tr>
{% endfor %}
</tbody>

Loading…
Cancel
Save