Browse Source

#3 recording starttime and last scanned time.

pull/14/head
Rogier Neeleman 7 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 @@ -4,6 +4,7 @@ import sqlite3
from flask import Flask, request, g, redirect, url_for, abort, \
render_template, flash, session
import random
from datetime import datetime
# create our little application :)
app = Flask(__name__)
@ -63,6 +64,7 @@ def index(): @@ -63,6 +64,7 @@ def index():
entries = cur.fetchall()
user = {}
time = {}
tags = app.config['TAGS']
for entry in entries:
@ -72,13 +74,24 @@ def index(): @@ -72,13 +74,24 @@ def index():
found_tags = entry['tags'].split(',')
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:
user[entry['id']][tag] = 'Not'
for found_tag in found_tags:
if found_tag == tag:
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/<string:newhash>/', methods=['GET', 'POST'])
@ -94,7 +107,7 @@ def new_user(newhash='None'): @@ -94,7 +107,7 @@ def new_user(newhash='None'):
"""Now we got a POST request"""
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()
session['username'] = request.form['username']
@ -146,7 +159,7 @@ def tag_found(taghash): @@ -146,7 +159,7 @@ def tag_found(taghash):
cur_score = cur_score + "," + taghash
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()
return render_template('tagfound.html', tagname=tags.get(taghash), color='#00FF00')

4
schema.sql

@ -2,5 +2,7 @@ drop table if exists score; @@ -2,5 +2,7 @@ drop table if exists score;
create table score (
id integer primary key autoincrement,
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 @@ @@ -13,6 +13,7 @@
{% for tag in tags %}
<td>{{ tags.get(tag) }}</td>
{% endfor %}
<td>Duration</td>
</tr>
</thead>
<tbody>
@ -28,6 +29,9 @@ @@ -28,6 +29,9 @@
{% endif %}
</td>
{% endfor %}
<td>
{{ time[entry.id] }}
</td>
</tr>
{% endfor %}
</tbody>

Loading…
Cancel
Save