Browse Source

#3 recording starttime and last scanned time.

pull/14/head
Rogier Neeleman 8 years ago
parent
commit
7e21771b87
  1. 19
      nfgame.py
  2. 4
      schema.sql
  3. 4
      templates/overview.html

19
nfgame.py

@ -4,6 +4,7 @@ import sqlite3
from flask import Flask, request, g, redirect, url_for, abort, \ from flask import Flask, request, g, redirect, url_for, abort, \
render_template, flash, session render_template, flash, session
import random import random
from datetime import datetime
# create our little application :) # create our little application :)
app = Flask(__name__) app = Flask(__name__)
@ -63,6 +64,7 @@ def index():
entries = cur.fetchall() entries = cur.fetchall()
user = {} user = {}
time = {}
tags = app.config['TAGS'] tags = app.config['TAGS']
for entry in entries: for entry in entries:
@ -72,13 +74,24 @@ def index():
found_tags = entry['tags'].split(',') found_tags = entry['tags'].split(',')
user[entry['id']] = {} user[entry['id']] = {}
if not entry['lasttime'] == None:
starttime = datetime.strptime(entry['starttime'], "%Y-%m-%d %H:%M:%S")
lasttime = datetime.strptime(entry['lasttime'], "%Y-%m-%d %H:%M:%S")
timediff = lasttime - starttime
hours = timediff.seconds / 3600
minutes = (timediff.seconds - (hours * 3600)) / 60
seconds = timediff.seconds - (minutes * 60)
time[entry['id']] = str(hours) + ":" + str(minutes) + ":" + str(seconds)
for tag in tags: for tag in tags:
user[entry['id']][tag] = 'Not' user[entry['id']][tag] = 'Not'
for found_tag in found_tags: for found_tag in found_tags:
if found_tag == tag: if found_tag == tag:
user[entry['id']][tag] = 'Found' user[entry['id']][tag] = 'Found'
return render_template('overview.html', entries=entries, tags=app.config['TAGS'], user=user) return render_template('overview.html', entries=entries, tags=app.config['TAGS'], user=user, time=time)
@app.route('/newuser/', methods=['GET', 'POST']) @app.route('/newuser/', methods=['GET', 'POST'])
@app.route('/newuser/<string:newhash>/', methods=['GET', 'POST']) @app.route('/newuser/<string:newhash>/', methods=['GET', 'POST'])
@ -94,7 +107,7 @@ def new_user(newhash='None'):
"""Now we got a POST request""" """Now we got a POST request"""
db = get_db() db = get_db()
cur = db.execute("insert into score (username) values (?)", [request.form['username']]) cur = db.execute("insert into score (username,starttime) values (?, datetime())", [request.form['username']])
db.commit() db.commit()
session['username'] = request.form['username'] session['username'] = request.form['username']
@ -146,7 +159,7 @@ def tag_found(taghash):
cur_score = cur_score + "," + taghash cur_score = cur_score + "," + taghash
db = get_db() db = get_db()
cur = db.execute('update score set tags = ? where id = ?', [cur_score, session['id']]) cur = db.execute('update score set tags = ?, lasttime = datetime() where id = ?', [cur_score, session['id']])
db.commit() db.commit()
return render_template('tagfound.html', tagname=tags.get(taghash), color='#00FF00') return render_template('tagfound.html', tagname=tags.get(taghash), color='#00FF00')

4
schema.sql

@ -2,5 +2,7 @@ drop table if exists score;
create table score ( create table score (
id integer primary key autoincrement, id integer primary key autoincrement,
username text not null, username text not null,
tags text null tags text null,
starttime text not null,
lasttime text null
); );

4
templates/overview.html

@ -13,6 +13,7 @@
{% for tag in tags %} {% for tag in tags %}
<td>{{ tags.get(tag) }}</td> <td>{{ tags.get(tag) }}</td>
{% endfor %} {% endfor %}
<td>Duration</td>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
@ -28,6 +29,9 @@
{% endif %} {% endif %}
</td> </td>
{% endfor %} {% endfor %}
<td>
{{ time[entry.id] }}
</td>
</tr> </tr>
{% endfor %} {% endfor %}
</tbody> </tbody>

Loading…
Cancel
Save