summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLilian Teronen <lteronen@local>2023-11-27 01:37:03 +0200
committerLilian Teronen <lteronen@local>2023-11-27 01:37:03 +0200
commit03b031ea793e91ce2f87cf28c73cefc8ce69a7b5 (patch)
tree882919559651e1b18904404ccc7c5106d167f1fd
parentd2de3ae10b6f5314bd4b8243218212d2004f35b0 (diff)
More rework on routes. Best and worst matches. More visuals.
-rw-r--r--README.md9
-rw-r--r--SCHEMA.sql50
-rw-r--r--db_actions.py19
-rw-r--r--routes/analyse.py60
-rw-r--r--routes/answer.py55
-rw-r--r--routes/base.py39
-rw-r--r--routes/create.py42
-rw-r--r--routes/question.py8
-rw-r--r--static/alert-timeout.js8
-rw-r--r--static/kyselma.css37
-rw-r--r--static/pages.json11
-rw-r--r--templates/analyse.html45
-rw-r--r--templates/answer.html16
-rw-r--r--templates/base.html8
-rw-r--r--templates/create.html15
-rw-r--r--templates/new_answer.html7
-rw-r--r--templates/nick.html6
-rw-r--r--templates/quiz.html4
18 files changed, 287 insertions, 152 deletions
diff --git a/README.md b/README.md
index f42950e..a8f767b 100644
--- a/README.md
+++ b/README.md
@@ -12,11 +12,14 @@ Install poetry if nessesary. (refer your distro)
- $ pip install --user poetry
- $ pipx install poetry
-Clone the source, get tables ready & install poetry dependencies
+Clone the source & install poetry dependencies
- $ git clone https://github.com/triionhe/kyselma.git
- $ cd kyselma
-- $ psql < SCHEMA.sql (BE CAREFUL! This drops some tables.)
+- $ export PYTHON_KEYRING_BACKEND=keyring.backends.fail.Keyring (Just in case..)
- $ poetry install --no-root
+
+Get database ready
+- $ psql < SCHEMA.sql (BE CAREFUL! This drops some tables.)
Start the app in poetry virtual environment
- $ SQLALCHEMY_DATABASE_URI="postgresql:///$USER" SECRET_KEY=29347884 poetry run flask run
@@ -24,6 +27,8 @@ Start the app in poetry virtual environment
Surf to the webpage and start two sessions for better testing
- $ firefox http://localhost:5000/ http://127.0.0.1:5000/
+There is ready made kyselmä named 'kysdemo' for testing.
+
DONE:
diff --git a/SCHEMA.sql b/SCHEMA.sql
index b88215a..50a8b2c 100644
--- a/SCHEMA.sql
+++ b/SCHEMA.sql
@@ -34,38 +34,24 @@ INSERT INTO users (nick, created) VALUES ('Raili Niemi', 57 );
INSERT INTO users (nick, created) VALUES ('Tea Jalava', 36 );
INSERT INTO users (nick, created) VALUES ('Eero Metsäranta', 47 );
INSERT INTO questions (question, neg_answer, pos_answer, created)
- VALUES ('Mikä ikä?', '0', '100', 99 );
-INSERT INTO questions (question, neg_answer, pos_answer, created)
- VALUES ('Mikä vointi?', 'huono', 'hyvä', 99 );
-INSERT INTO questions (question, neg_answer, pos_answer, created)
- VALUES ('Ulkoiletko?', 'viime vuonna', 'joka päivä', 99 );
-INSERT INTO questions (question, neg_answer, pos_answer, created)
- VALUES ('kys?', 'ei vielä', 'ei koskaan', 99 );
-INSERT INTO answers (user_id, question_id, answer, created)
- VALUES (1, 1, 570, 99 );
-INSERT INTO answers (user_id, question_id, answer, created)
- VALUES (1, 2, 670, 99 );
-INSERT INTO answers (user_id, question_id, answer, created)
- VALUES (1, 3, 888, 99 );
-INSERT INTO answers (user_id, question_id, answer, created)
- VALUES (1, 4, 999, 99 );
-INSERT INTO answers (user_id, question_id, answer, created)
- VALUES (2, 1, 360, 99 );
-INSERT INTO answers (user_id, question_id, answer, created)
- VALUES (2, 2, 230, 99 );
-INSERT INTO answers (user_id, question_id, answer, created)
- VALUES (2, 3, 120, 99 );
-INSERT INTO answers (user_id, question_id, answer, created)
- VALUES (2, 4, 123, 99 );
-INSERT INTO answers (user_id, question_id, answer, created)
- VALUES (3, 1, 470, 99 );
-INSERT INTO answers (user_id, question_id, answer, created)
- VALUES (3, 2, 570, 99 );
-INSERT INTO answers (user_id, question_id, answer, created)
- VALUES (3, 3, 321, 99 );
-INSERT INTO answers (user_id, question_id, answer, created)
- VALUES (3, 4, 785, 99 );
+ VALUES ('Mikä ikä?', '0', '100', 99 ),
+ ('Mikä vointi?', 'huono', 'hyvä', 99 ),
+ ('Ulkoiletko?', 'viime vuonna', 'joka päivä', 99 ),
+ ('kys?', 'ei vielä', 'ei koskaan', 99 );
+INSERT INTO answers (user_id, question_id, answer, created)
+ VALUES (1, 1, 570, 99 ),
+ (1, 2, 670, 99 ),
+ (1, 3, 888, 99 ),
+ (1, 4, 999, 99 ),
+ (2, 1, 360, 99 ),
+ (2, 2, 230, 99 ),
+ (2, 3, 120, 99 ),
+ (2, 4, 123, 99 ),
+ (3, 1, 470, 99 ),
+ (3, 2, 570, 99 ),
+ (3, 3, 321, 99 ),
+ (3, 4, 785, 99 );
INSERT INTO questionaires (questionset, creator_id, created)
VALUES ('{1,2,3,4}', 1, 666);
INSERT INTO quiz_links (quiz_id, link, created)
- VALUES (1, 'kyselama', 666);
+ VALUES (1, 'kysdemo', 666);
diff --git a/db_actions.py b/db_actions.py
index 5f793fc..993ef46 100644
--- a/db_actions.py
+++ b/db_actions.py
@@ -80,7 +80,7 @@ def find_quiz_by_link( link ):
FROM quiz_links \
WHERE link=:link;"
result = db.session.execute(text(sql), { "link":link }).fetchone()
- return result[0] if result else result
+ return result[0] if result else False
def get_quiz_link( quiz_id ):
@@ -133,12 +133,12 @@ def get_comparable(quiz_id,user1,user2):
def get_user_answer(user_id, question_id):
sql = "SELECT answer \
FROM answers \
- WHERE question_id = (:question_id) AND user_id = (:user_id);"
+ WHERE question_id = (:question_id) AND user_id = (:user_id);"
result = db.session.execute( text(sql), {
'question_id': question_id,
'user_id': user_id
} ).fetchone()
- return result[0] if result else result
+ return result[0] if result else -1
def get_user_answers_for_quiz(quiz_id, user_id):
@@ -170,4 +170,15 @@ def is_user_answered(quiz_id, user_id):
'quiz_id': quiz_id,
'user_id': user_id
} ).fetchone()
- return results[0] if results else results
+ return True if results else False
+
+
+def get_all_answers_for_quiz(quiz_id):
+ sql = "SELECT a.question_id, a.user_id, a.answer \
+ FROM questionaires quiz \
+ JOIN answers a ON a.question_id = ANY(quiz.questionset) \
+ WHERE quiz.id = (:quiz_id);"
+ return db.session.execute( text(sql), {
+ 'quiz_id': quiz_id
+ } ).fetchall()
+
diff --git a/routes/analyse.py b/routes/analyse.py
index b333e70..3076d99 100644
--- a/routes/analyse.py
+++ b/routes/analyse.py
@@ -1,19 +1,66 @@
+from itertools import combinations
from app import app
from flask import render_template,session,request,redirect
import db_actions as D
from routes.tools import rows2dicts, get_alert, get_nick, red
+def find_best_and_worst(aid, uid):
+ answers=D.get_all_answers_for_quiz(aid)
+ alist=rows2dicts( answers, ['q','u','a'] )
+ questions = set(x['q'] for x in alist)
+ users = set(x['u'] for x in alist)
+ data = {}
+ for q in questions:
+ data[q]={}
+ for i in alist:
+ data[i['q']][i['u']]=i['a']
+ match = {}
+ comb = list(combinations(users,2))
+ if len(comb)<1:
+ comb=[(uid,uid)]
+ min, minme, max, maxme = 101, 101, -1, -1
+ for pair in comb:
+ sum=0
+ for q in questions:
+ sum += 1000 - abs(data[q][pair[0]]-data[q][pair[1]])
+ match[pair]=int(sum / len(questions) / 10 + 0.5)
+ if match[pair] < min:
+ min = match[pair]
+ min_pair = pair
+ if match[pair] > max:
+ max = match[pair]
+ max_pair = pair
+ if pair[0]==uid or pair[1]==uid:
+ if match[pair] < minme:
+ minme = match[pair]
+ minme_pair = pair
+ if match[pair] > maxme:
+ maxme = match[pair]
+ maxme_pair = pair
+ return ( {
+ 'min': min, 'min_u1': min_pair[0], 'min_u2': min_pair[1],
+ 'max': max, 'max_u1': max_pair[0], 'max_u2': max_pair[1],
+ 'minme': minme, 'minme_u1': minme_pair[0], 'minme_u2': minme_pair[1],
+ 'maxme': maxme, 'maxme_u1': maxme_pair[0], 'maxme_u2': maxme_pair[1] })
+
+
@app.route("/pages/analyse.html")
def analyse():
if "id" in session:
sid = session["id"]
else:
- return red["nick"]
+ return render_template(
+ "analyse.html",
+ caller="analyse",
+ alert=get_alert()
+ )
if "answer_id" in session and D.is_user_answered(session["answer_id"],sid):
aid = session["answer_id"]
else:
- return render_template("analyse.html",
+ return render_template(
+ "analyse.html",
+ caller="analyse",
alert=get_alert(),
nick=get_nick()
)
@@ -24,14 +71,16 @@ def analyse():
uid2 = session["anal_user2"] if "anal_user2" in session else sid
uid2 = sid if uid2 != sid and not D.is_user_answered(aid,uid2) else uid2
+
comparable = D.get_comparable( aid, uid1, uid2 )
avg=0
for i in range(len(comparable)):
avg += comparable[i][5]
avg//=len(comparable)
-
- return render_template("analyse.html",
+ return render_template(
+ "analyse.html",
+ caller="analyse",
alert=get_alert(),
nick=get_nick(),
code=D.get_quiz_link(aid),
@@ -39,7 +88,8 @@ def analyse():
users = rows2dicts( D.get_users_answered(aid), ['id','nick'] ),
user1=int(uid1),
user2=int(uid2),
- avg = avg
+ avg = avg,
+ best = find_best_and_worst(aid, sid)
)
@app.route("/set/compare",methods=["POST"])
diff --git a/routes/answer.py b/routes/answer.py
index fa3d138..2fbeec8 100644
--- a/routes/answer.py
+++ b/routes/answer.py
@@ -4,15 +4,6 @@ import db_actions as D
from routes.tools import rows2dicts, get_alert, get_nick, red
-@app.route("/pages/new_answer.html")
-def new_answer():
- if "id" not in session:
- return red["nick"]
- return render_template("new_answer.html",
- alert=get_alert(),
- nick=get_nick()
- )
-
@app.route("/kys/<link>")
def kys_link(link):
if aid := D.find_quiz_by_link( link ):
@@ -22,17 +13,13 @@ def kys_link(link):
@app.route("/set/answer_id",methods=["POST"])
def answer_id():
+ next = "/#"+request.form["caller"] if "caller" in request.form else "/"
if "id" not in session:
session["alert"] = "Nimimerkkiä ei ole asetettu."
- return redirect("/#nick")
+ return redirect(next)
else:
sid = session["id"]
- if "next" not in request.form:
- next = "/#answer"
- else:
- next = "/#"+request.form["next"]
-
if "link" not in request.form or request.form["link"]=="":
session["alert"] = "Kyselmän nimeä ei ole annettu."
return redirect(next)
@@ -48,6 +35,10 @@ def answer_id():
Voit tutkia vastaksia vastattuasi."
return redirect("/#answer")
+ if next == "/#answer" and D.is_user_answered( aid, sid ):
+ session["alert"] = "Olet jo vastannut valitsemaasi kyselyyn."
+ return redirect("/#analyse")
+
return redirect( next )
@app.route("/pages/answer.html")
@@ -55,17 +46,33 @@ def answer():
if "id" in session:
sid = session["id"]
else:
- return red["nick"]
+ return render_template(
+ "answer.html",
+ caller = "answer",
+ alert = get_alert()
+ )
if "answer_id" in session:
aid = session["answer_id"]
else:
- return red["new_answer"]
+ return render_template(
+ "answer.html",
+ caller = "answer",
+ alert = get_alert(),
+ nick = get_nick()
+ )
if D.is_user_answered(aid, sid):
- return red["new_answer"]
+ return render_template(
+ "answer.html",
+ caller = "answer",
+ alert = get_alert(),
+ nick = get_nick()
+ )
- return render_template("answer.html",
+ return render_template(
+ "answer.html",
+ caller = "answer",
alert = get_alert(),
nick = get_nick(),
questions = rows2dicts( D.get_questions(aid), ['i','q','n','p'] ),
@@ -76,25 +83,25 @@ def answer():
def set_answers():
if "id" not in session:
session["alert"]="Nimimerkkiä ei ole vielä valittu!"
- return redirect( "/#nick" )
+ return redirect( "/#answer" )
if "answer_id" not in session:
session["alert"]="Kyselyä ei ole valittu vastaamista varten!"
return redirect( "/#answer" )
sid = session["id"]
- for qid, answer in request.form.items():
+ for question, answer in request.form.items():
try:
if int(answer) < 0 or int(answer) > 999:
session["alert"]="Luvattoman pieniä tai suuria lukuja!"
return redirect( "/#answer" )
- elif D.get_user_answer(sid, int(qid) ):
+ elif D.get_user_answer(int(sid), int(question)) != -1:
session["alert"]="Kyselyyn olikin jo saatu vastauksia."
return redirect( "/#answer" )
except ValueError:
session["alert"] = "Vastaukset ei ole lukuja!"
return redirect( "/#answer" )
- for qid, answer in request.form.items():
- D.answer_new(sid, int(qid), int(answer))
+ for question, answer in request.form.items():
+ D.answer_new(int(sid), int(question), int(answer))
return redirect("/#analyse")
diff --git a/routes/base.py b/routes/base.py
index 695388b..22245c5 100644
--- a/routes/base.py
+++ b/routes/base.py
@@ -9,43 +9,40 @@ def index():
@app.route("/pages/info.html")
def info():
- return render_template("info.html",
+ if "id" in session:
+ return render_template(
+ "info.html",
+ caller="info",
+ alert=get_alert(),
+ nick=get_nick()
+ )
+ return render_template(
+ "info.html",
+ caller="info",
alert=get_alert()
)
-@app.route("/pages/nick.html")
-def nick():
- return render_template("nick.html",
- alert=get_alert()
- )
-
@app.route("/set/nick",methods=["POST"])
def new_nick():
+ next = "/#"+request.form["caller"] if "caller" in request.form else "/"
if "id" in session.keys():
session["alert"]="Sinulla on jo nimimerkki. Käytä sitä."
- return redirect("/")
+ return redirect(next)
if "nick" not in request.form or request.form["nick"]=="":
session["alert"]="Nimimerkkiä ei voi asettaa ilman nimimerkkiä."
- return redirect("/#nick")
+ return redirect(next)
else:
nick = request.form["nick"]
if len(nick) < 4:
session["alert"]="Nimimerkki on liian lyhyt"
- return redirect("/#nick")
+ return redirect(next)
if not nick.isalnum():
session["alert"]="Nimimerkissä saa olla vain kirjaimia ja numeroita."
- return redirect("/#nick")
+ return redirect(next)
if D.user_exists(nick):
session["alert"]="Nimimerkki jonka olet ottamassa on jo varattu."
- return redirect("/#nick")
- session["id"] = D.user_new(nick)
- return redirect("/")
-
-
+ return redirect(next)
+ session["id"] = int(D.user_new(nick))
+ return redirect(next)
-#@app.route("/pages/moderate.html")
-#def moderate():
-# return render_template("moderate.html",
-# alert=get_alert()
-# )
diff --git a/routes/create.py b/routes/create.py
index 0a2a343..36c2521 100644
--- a/routes/create.py
+++ b/routes/create.py
@@ -7,35 +7,43 @@ from routes.tools import rows2dicts, get_alert, get_nick, generate_link, red
@app.route("/pages/create.html")
def create():
if "id" not in session:
- return red["nick"]
+ return render_template(
+ "create.html",
+ caller="create",
+ alert=get_alert()
+ )
if "quiz_id" not in session:
- return red["quiz"]
+ return render_template(
+ "create.html",
+ caller="create",
+ alert=get_alert(),
+ nick=get_nick()
+ )
if D.get_quiz_link(session["quiz_id"]):
- return red["quiz"]
+ return render_template(
+ "create.html",
+ caller="create",
+ alert=get_alert(),
+ nick=get_nick()
+ )
- return render_template("create.html",
+ return render_template(
+ "create.html",
+ caller="create",
alert=get_alert(),
nick=get_nick(),
+ quiz_set=True,
questions=rows2dicts(
D.get_questions(session["quiz_id"]),
['i','q','n','p','a']
)
)
-@app.route("/pages/quiz.html")
-def build():
- if "id" not in session:
- return red["nick"]
- return render_template("quiz.html",
- alert=get_alert(),
- nick=get_nick()
- )
-
@app.route("/set/quiz",methods=["POST"])
def new_quiz():
if not "id" in session.keys():
- session["alert"]="Tarvitset nimimerkin loudaksesi"
- return redirect("/#nick")
+ session["alert"]="Tarvitset nimimerkin loudaksesi."
+ return redirect("/#create")
user_id = session["id"]
session["quiz_id"] = D.quiz_new( user_id )
return redirect("/#create")
@@ -44,7 +52,8 @@ def new_quiz():
@app.route("/set/quiz_ready",methods=["POST"])
def quiz_ready():
if "quiz_id" not in session.keys():
- return "KUOLETTAVA: kyselyä ei ole"
+ session["alert"] = "Kyselmä jota ei ole aloitettu ei voi olla valmis."
+ return redirect("/#create")
if not D.is_user_answered(session["quiz_id"], session["id"]):
session["alert"] = "Tyhjän kyselmän luominen ei käy päinsä!"
return redirect("/#create")
@@ -52,4 +61,3 @@ def quiz_ready():
session["answer_id"] = session["quiz_id"]
D.set_quiz_link(session["quiz_id"], generate_link())
return redirect("/#analyse")
-
diff --git a/routes/question.py b/routes/question.py
index 02261ca..ad31993 100644
--- a/routes/question.py
+++ b/routes/question.py
@@ -5,7 +5,9 @@ from routes.tools import rows2dicts, get_alert, get_nick
@app.route("/pages/question.html")
def question():
- return render_template("question.html",
+ return render_template(
+ "question.html",
+ caller="create",
alert=get_alert(),
nick=get_nick()
)
@@ -25,13 +27,13 @@ def new_question():
sid = session["id"]
except (KeyError):
session["alert"] = "Nimimerkki puuttuukin."
- return redirect("/#nick")
+ return redirect("/#create")
try:
qid = session["quiz_id"]
except (KeyError):
session["alert"] = "Kyselmän luonti ei ollutkaan kesken."
- return redirect("/#quiz")
+ return redirect("/#create")
for entry in [question, neg_ans, pos_ans]:
if len(entry) < 2 or len(entry) > 80:
diff --git a/static/alert-timeout.js b/static/alert-timeout.js
index 01bd260..6fe6def 100644
--- a/static/alert-timeout.js
+++ b/static/alert-timeout.js
@@ -2,4 +2,12 @@ Array.from(document.getElementsByClassName('kysAlert')).forEach( (a) => {
a.addEventListener('click', (event) => {
event.target.remove();
})
+ setTimeout( () => {
+ Array.from(document.getElementsByClassName('kysAlert'))
+ .forEach( (a) => {
+ if (a.style.transition=="opacity 2s") a.remove()
+ a.style.transition="opacity 2s"
+ a.style.opacity=0;
+ } )
+ }, 5000)
})
diff --git a/static/kyselma.css b/static/kyselma.css
index 14c7653..92f51ca 100644
--- a/static/kyselma.css
+++ b/static/kyselma.css
@@ -2,9 +2,9 @@
.kysQuestion {
display: flex;
flex-direction: column;
- max-width: 25em;
- padding: 0.5em;
- border: 0.15em #fed solid;
+ max-width: 25rem;
+ padding: 0.5rem;
+ border: 0.15rem #fed solid;
}
.kysText {
align-self: center;
@@ -33,12 +33,12 @@
.kysNick::before {
content: "Olet:";
- padding-right: 0.4em;
+ padding-right: 0.4rem;
}
.kysNick {
- border: 0.1em solid;
- padding: 0.4em;
+ border: 0.1rem solid;
+ padding: 0.4rem;
position: fixed;
top: 100vh;
left: 100vw;
@@ -48,8 +48,8 @@
}
.kysAlert {
- border: 0.4em solid;
- padding: 0.8em;
+ border: 0.4rem solid;
+ padding: 0.8rem;
display: block;
background-color: #F55;
border-top-color: #F97;
@@ -63,8 +63,26 @@
}
.kysTotal {
- align-self: center;
+ max-width: 25rem;
+ min-width: max-content;
+ display: flex;
+ justify-content: center;
+}
+.kysTotalText {
+ position: absolute;
font-size: xxx-large;
+ height: 8rem;
+ aspect-ratio: 1;
+ text-align: center;
+ padding-top: 0.5rem;
+}
+.kysTotalBackground {
+ position: relative;
+ height: 8rem;
+ aspect-ratio: 1;
+ border-image: radial-gradient(#F00 69.6%,#0000 70.4%) 85%/50%;
+ clip-path: polygon(-42% 0,50% 91%, 142% 0);
+ z-index: -1;
}
.kysSelectU1 {
@@ -90,3 +108,4 @@
.kysUser2::-webkit-slider-thumb, .kysUser2::-moz-range-thumb {
background: #00c;
}
+
diff --git a/static/pages.json b/static/pages.json
index 37e59e4..8d0d376 100644
--- a/static/pages.json
+++ b/static/pages.json
@@ -36,12 +36,6 @@
"hidden": "yes",
"menuName": "Moderoi"
},
- "nick": {
- "pageTitle": "Anna nimimerkki",
- "URL": "pages/nick.html",
- "hidden": "yes",
- "dynamic": "yes"
- },
"question": {
"pageTitle": "Lisää kysymys",
"URL": "pages/question.html",
@@ -51,11 +45,6 @@
"pageTitle": "Luodaanko uusi kyselmä?",
"URL": "pages/quiz.html",
"hidden": "yes"
- },
- "new_answer": {
- "pageTitle": "Anna kyselyn koodi",
- "URL": "pages/new_answer.html",
- "hidden": "yes"
}
}
}
diff --git a/templates/analyse.html b/templates/analyse.html
index 70fb98e..a57376d 100644
--- a/templates/analyse.html
+++ b/templates/analyse.html
@@ -1,13 +1,13 @@
{% include 'base.html' %}
+{% if nick %}
{% if users %}
-Tutkit kyselyä: {{ code }}
+Tutkit kyselmää: {{ code }}
<div class="kysQuestion"><div class="kysScale">
<form action="/set/compare" method="POST">
-<input type="submit" value="Vertaa" class="kysButton">
<select class="kysSelectU1 kysSelect" name="user1">
{% for user in users %}
{% if user1==user.id %}
@@ -26,7 +26,7 @@ Tutkit kyselyä: {{ code }}
{% endif %}
{% endfor %}
</select>
-<div class="kysScaleSpacer"></div>
+<input type="submit" value="Vertaa" class="kysButton">
</form>
</div></div>
@@ -35,9 +35,13 @@ Tutkit kyselyä: {{ code }}
{% if code %}
<div id="questions" class="kysQuestions">
- <div class="kysQuestion">
- <div class="kysTotal">{{ avg }}%</div>
+
+ <div class="kysTotal">
+ <div class="kysTotalBackground">
+ <div class="kysTotalText">{{ avg }}%</div>
+ </div>
</div>
+
{% for q in questions %}
<div class="kysQuestion">
<div class="kysText">{{ q.q }} ({{ q.c }}%)</div>
@@ -53,6 +57,34 @@ Tutkit kyselyä: {{ code }}
</div>
{% endfor %}
+<form action="/set/compare" method="POST">
+<input type="text" name="user1" hidden="true" value={{ best.max_u1 }}>
+<input type="text" name="user2" hidden="true" value={{ best.max_u2 }}>
+<input type="submit" value="Kaikista paras yhtäläisyys ({{ best.max }}%)"
+ class="kysButton">
+</form>
+
+<form action="/set/compare" method="POST">
+<input type="text" name="user1" hidden="true" value={{ best.maxme_u1 }}>
+<input type="text" name="user2" hidden="true" value={{ best.maxme_u2 }}>
+<input type="submit" value="Paras yhtäläisyys kanssani ({{ best.maxme }}%)"
+ class="kysButton">
+</form>
+
+<form action="/set/compare" method="POST">
+<input type="text" name="user1" hidden="true" value={{ best.minme_u1 }}>
+<input type="text" name="user2" hidden="true" value={{ best.minme_u2 }}>
+<input type="submit" value="Huonoin yhtäläisyys kanssani ({{ best.minme }}%)"
+ class="kysButton">
+</form>
+
+<form action="/set/compare" method="POST">
+<input type="text" name="user1" hidden="true" value={{ best.min_u1 }}>
+<input type="text" name="user2" hidden="true" value={{ best.min_u2 }}>
+<input type="submit" value="Kaikista huonoin yhtäläisyys ({{ best.min }}%)"
+ class="kysButton">
+</form>
+
</div>
{% endif %}
@@ -60,7 +92,7 @@ Tutkit kyselyä: {{ code }}
<form action="/set/answer_id" method="POST">
Vaihda kyselyn koodia:
<input type="text" name="link">
-<input type="text" name="next" value="analyse" hidden="true">
+<input type="text" name="caller" value="analyse" hidden="true">
<input type="submit" value="Vaihda">
</form>
@@ -71,3 +103,4 @@ Linkki tähän kyselyyn:
</a>
{% endif %}
+{% endif %}
diff --git a/templates/answer.html b/templates/answer.html
index eb49ff8..6231785 100644
--- a/templates/answer.html
+++ b/templates/answer.html
@@ -1,4 +1,7 @@
{% include 'base.html' %}
+{% if nick %}
+
+{% if link %}
Vastaa kyselmään "{{ link }}":
@@ -19,3 +22,16 @@ Vastaa kyselmään "{{ link }}":
</div>
</form>
+{% else %}
+
+<form action="/set/answer_id" method="POST">
+Vastaa kyselyyn koodilla:
+<input type="text" name="link">
+<input type="text" name="caller" value="answer" hidden="true">
+<input type="submit" value="Kyselmään">
+</form>
+
+{% endif %}
+
+
+{% endif %}
diff --git a/templates/base.html b/templates/base.html
index 839cc88..f38eb12 100644
--- a/templates/base.html
+++ b/templates/base.html
@@ -1,6 +1,14 @@
{% if nick %}
<div class="kysNick">{{ nick }}</div>
+{% else %}
+<form action="/set/nick" method="POST">
+Anna itsellesi nimimerkki ensin:
+<input type="text" name="nick">
+<input type="text" name="caller" value="{{ caller }}" hidden="true">
+<input type="submit" value="Lähetä">
+</form>
{% endif %}
+
{% if alert %}
<div class="kysAlert">{{ alert }}</div>
<script src="alert-timeout.js"></script>
diff --git a/templates/create.html b/templates/create.html
index b369ae8..21520b5 100644
--- a/templates/create.html
+++ b/templates/create.html
@@ -1,5 +1,8 @@
{% include 'base.html' %}
+{% if nick %}
+
+{% if quiz_set %}
<div id="questions" class="kysQuestions">
{% for q in questions %}
@@ -26,4 +29,14 @@
</form>
<div class="kysScale">
</div>
-</div> \ No newline at end of file
+</div>
+
+{% else %}
+
+<form action="/set/quiz" method="POST">
+<input type="submit" value="Aloita uusi kyselmä">
+</form>
+
+{% endif %}
+
+{% endif %}
diff --git a/templates/new_answer.html b/templates/new_answer.html
deleted file mode 100644
index 0d690d4..0000000
--- a/templates/new_answer.html
+++ /dev/null
@@ -1,7 +0,0 @@
-{% include 'base.html' %}
-<form action="/set/answer_id" method="POST">
-Vastaa kyselyyn koodilla:
-<input type="text" name="link">
-<input type="submit" value="Kyselmään">
-</form>
-Saatoit myös päätyä tänne mikäli olet jo vastannut.
diff --git a/templates/nick.html b/templates/nick.html
deleted file mode 100644
index 92e166f..0000000
--- a/templates/nick.html
+++ /dev/null
@@ -1,6 +0,0 @@
-{% include 'base.html' %}
-<form action="/set/nick" method="POST">
-Anna itsellesi nimimerkki ensin:
-<input type="text" name="nick">
-<input type="submit" value="Lähetä">
-</form>
diff --git a/templates/quiz.html b/templates/quiz.html
deleted file mode 100644
index 9e356c3..0000000
--- a/templates/quiz.html
+++ /dev/null
@@ -1,4 +0,0 @@
-{% include 'base.html' %}
-<form action="/set/quiz" method="POST">
-<input type="submit" value="Aloita uusi kyselmä">
-</form>