Ajout du graphe pour toutes les pages

This commit is contained in:
guimoz 2017-01-30 09:44:35 +01:00
parent 177752a6f2
commit 63224d8f0e

View file

@ -180,7 +180,7 @@ def playable_required(f):
user = get_player_from_ip(ip) user = get_player_from_ip(ip)
if not user: if not user:
return render_template('not_subscribed.html') return render_template('not_subscribed.html',stats=statistiques())
# Un utilisateur banni ne peut pas jouer # Un utilisateur banni ne peut pas jouer
elif is_banned(user['id']): elif is_banned(user['id']):
@ -296,6 +296,12 @@ def banned():
else: else:
explanation = u'Tu t\'es tranché toi-même, pas de chance...' explanation = u'Tu t\'es tranché toi-même, pas de chance...'
timeleft = int(player['ban_end'] - time())
return render_template('banned.html', \
explanation=explanation, timeleft=timeleft, stats=statistiques())
def statistiques():
#Calcul des statistiques #Calcul des statistiques
con = connect_sqlite() con = connect_sqlite()
cur = con.cursor() cur = con.cursor()
@ -316,11 +322,7 @@ def banned():
n_tranchés += 1 n_tranchés += 1
stats = (tranchés,n_tranchés) stats = (tranchés,n_tranchés)
return stats
timeleft = int(player['ban_end'] - time())
return render_template('banned.html', \
explanation=explanation, timeleft=timeleft, stats=stats)
@app.route('/banned_ip') @app.route('/banned_ip')
@ -352,31 +354,11 @@ def banned_ip():
@app.route('/') @app.route('/')
@playable_required @playable_required
def home(): def home():
#Calcul des statistiques
con = connect_sqlite()
cur = con.cursor()
cur.execute("""select firstname,name,ban_end from players""")
rows = cur.fetchall()
con.close()
tranchés = 0
n_tranchés = 0
with open(IMMUNITY_FILE, 'r') as f:
immunity = f.read()
for row in rows:
if row[0]+' '+row[1] not in immunity:
if row[2] > time():
tranchés += 1
else:
n_tranchés += 1
stats = (tranchés,n_tranchés)
player = get_player_from_ip(get_ip()) player = get_player_from_ip(get_ip())
if DEBUG: if DEBUG:
print(STATE) print(STATE)
if "down" in STATE: if "down" in STATE:
return render_template('down.html', user=player,stats=stats) return render_template('down.html', user=player,stats=statistiques())
elif "up" in STATE: elif "up" in STATE:
if DEBUG: if DEBUG:
print(player, 'arrived') print(player, 'arrived')
@ -407,37 +389,17 @@ def home():
% (date, target['firstname'], target['name'])) % (date, target['firstname'], target['name']))
bans_hist.append(entry) bans_hist.append(entry)
return render_template('home.html', bans_hist=bans_hist, stats=stats) return render_template('home.html', bans_hist=bans_hist, stats=statistiques())
else: else:
return render_template('precampagne.html', user=player,stats=stats) return render_template('precampagne.html', user=player,stats=statistiques())
@app.route('/jouer', methods=['GET', 'POST']) @app.route('/jouer', methods=['GET', 'POST'])
@playable_required @playable_required
def play(): def play():
ip = get_ip() ip = get_ip()
player = get_player_from_ip(ip) player = get_player_from_ip(ip)
#Calcul des statistiques
con = connect_sqlite()
cur = con.cursor()
cur.execute("""select firstname,name,ban_end from players""")
rows = cur.fetchall()
con.close()
tranchés = 0
n_tranchés = 0
with open(IMMUNITY_FILE, 'r') as f:
immunity = f.read()
for row in rows:
if row[0]+' '+row[1] not in immunity:
if row[2] > time():
tranchés += 1
else:
n_tranchés += 1
stats = (tranchés,n_tranchés)
if "down" in STATE: if "down" in STATE:
return render_template('down.html', user=player) return render_template('down.html', user=player,stats=statistiques())
elif "up" in STATE: elif "up" in STATE:
# Traitement de la requête de bannissement # Traitement de la requête de bannissement
if request.method == 'POST': if request.method == 'POST':
@ -464,9 +426,9 @@ def play():
# sans le joueur actuel # sans le joueur actuel
players = filter(lambda p: p['id'] != player['id'], players) players = filter(lambda p: p['id'] != player['id'], players)
return render_template('play.html', players=players, stats=stats) return render_template('play.html', players=players, stats=statistiques())
else: else:
return render_template('precampagne.html', user=player,stats=stats) return render_template('precampagne.html', user=player,stats=statistiques())
if __name__ == '__main__': if __name__ == '__main__':
app.run() app.run()