Cleaning up mostly

This commit is contained in:
Jan 2024-03-25 16:14:00 +01:00
parent 3959bd6295
commit 6a0d9cfd69
9 changed files with 250 additions and 82 deletions

26
slaeforms/Old Code.py Normal file
View File

@ -0,0 +1,26 @@
#test
@app.route("/test", methods=["GET", "POST"])
def testpage():
if not "slaeform_user_id" in session:
# If the cookie doesn't exist
print('Hello, new user! Setting cookie...')
new_user_id = str(uuid.uuid4())
session["slaeform_user_id"] = new_user_id
if request.method == "POST":
session_user_id = session["slaeform_user_id"]
likert_score = request.form["likertscale"]
text_input = request.form["feedback"]
print("new response: {session_user_id} {likert_score_1} {text_input_1}".format(session_user_id = session_user_id, likert_score_1 = likert_score, text_input_1 = text_input))
new_response = Response(session_user_id = session_user_id,likert_result = likert_score, notes = text_input)
try:
db.session.add(new_response)
db.session.commit()
return redirect("/start") #url_for("datapage")
except:
return "There was a problem while adding the response to the Database"
return render_template(
"layout1.html"
)

View File

@ -1,14 +1,18 @@
import sys
import json
import random
from flask import Flask, redirect, url_for, request, session, make_response
from flask import render_template
from flask_sqlalchemy import SQLAlchemy
from sqlalchemy.orm import DeclarativeBase
from sqlalchemy import Integer, String
from sqlalchemy.orm import Mapped, mapped_column
from sqlalchemy.dialects.postgresql import UUID
from datetime import datetime
import uuid
random_order = True
#create the app
app = Flask(__name__)
# configure the database, give it a path (it will be in the instances folder)
@ -25,10 +29,9 @@ config = json.load(configfile)
config2 = json.load(configfile2)
configfile.close()
configfile2.close()
print(config["question 1"])
print("\n")
print(config["question 1"]["type"])
print("\n")
# get the questions:
questions = list(config)
# create the model for the response table
class Response(db.Model):
@ -38,22 +41,30 @@ class Response(db.Model):
notes = db.Column(db.String(200))
date_created = db.Column(db.DateTime, default=datetime.today())
def __repr__(self) -> str:
return "<Task %r>" % self.id
return "<Response %r>" % self.id
class User(db.Model):
#user_id = db.Column(UUID(as_uuid=True), primary_key=True)
#device_id = db.Column(UUID(as_uuid=True), primary_key=True)
#question_order = db.Column(db.String(60))
date_created = db.Column(db.DateTime, default=datetime.today())
def __repr__(self) -> str:
return "<User %r>" % self.user_id
# create the table (existing tables are not overwritten)
with app.app_context():
db.create_all()
print("Table created")
print(config["question 1"]["blocks"])
print(config["question 1"]["blocks"].keys())
@app.route("/form", methods=["GET", "POST"]) # /<username> should not even be needed right?
def formpage():
#user is not yet registered and should not be here
if not "slaeform_user_id" in session:
return redirect("/start")
#TODO fill in code that determins at which question the user is
return render_template(
"layout2.html",
@ -64,39 +75,63 @@ def formpage():
)
#just testing
@app.route("/", methods=["GET", "POST"])
def testpage():
if not "slaeform_user_id" in session:
# If the cookie doesn't exist
print('Hello, new user! Setting cookie...')
new_user_id = str(uuid.uuid4())
session["slaeform_user_id"] = new_user_id
@app.route("/start", methods=["GET", "POST"])
def startpage():
if not "slaeform_device_id" in session:
# If this device was not seen, remember it.
new_device_id = str(uuid.uuid4())
session["slaeform_device_id"] = new_device_id
session["agreed_to_tos"] = False
if request.method == "POST":
session_user_id = session["slaeform_user_id"]
likert_score = request.form["likertscale"]
text_input = request.form["feedback"]
print("new response: {session_user_id} {likert_score_1} {text_input_1}".format(session_user_id = session_user_id, likert_score_1 = likert_score, text_input_1 = text_input))
new_response = Response(session_user_id = session_user_id,likert_result = likert_score, notes = text_input)
# get a random question order
if random_order:
order = random.shuffle(questions)
else:
order = questions
#if the user accepts, save the new user to the database
new_user_id = str(uuid.uuid4())
session["slaeform_user_id"] = new_user_id
session_user_id = new_user_id
user_id = session["slaeform_user_id"]
question_order = str(order)
new_user = User(user_id=user_id,question_order=question_order)
try:
db.session.add(new_response)
db.session.add(new_user)
db.session.commit()
return redirect("/") #url_for("datapage")
return redirect("/start") #url_for("datapage")
except:
return "There was a problem while adding the response to the Database"
return "There was a problem while adding the user to the Database"
session["agreed_to_tos"] = True
return redirect("/form")
return render_template(
"layout1.html"
"startpage.html"
)
@app.route("/data")
def datapage():
responses = Response.query.order_by(Response.id).all()
responses = Response.query.order_by(Response.date_created).all()
users = User.query.order_by(User.date_created).all()
return render_template(
"data.html",
responses = responses
responses = responses,
users = users
)
# Route to delete all entries
@ -120,4 +155,8 @@ def delete_all_entries():
return f'Error occurred: {str(e)}', 500
finally:
# Close the session
db.session.close()
db.session.close()
@app.route("/")
def blank():
return "blank page"

View File

@ -15,30 +15,8 @@
}
},
"block2":{
"type": "likert",
"numberofpoints": "5",
"points":{
"point1": "1",
"point2": "2",
"point3": "3",
"point4": "4",
"point5": "5"
}
},
"block3":{
"type": "textinput",
"length": "200"
},
"block4":{
"type": "likert",
"numberofpoints": "5",
"points":{
"point1": "1",
"point2": "2",
"point3": "3",
"point4": "4",
"point5": "5"
}
}
}
},
@ -58,30 +36,8 @@
}
},
"block2":{
"type": "likert",
"numberofpoints": "5",
"points":{
"point1": "1",
"point2": "2",
"point3": "3",
"point4": "4",
"point5": "5"
}
},
"block3":{
"type": "textinput",
"length": "200"
},
"block4":{
"type": "likert",
"numberofpoints": "5",
"points":{
"point1": "1",
"point2": "2",
"point3": "3",
"point4": "4",
"point5": "5"
}
}
}
},
@ -101,9 +57,6 @@
"block2":{
"type": "textinput",
"length": "200"
},
"block3":{
"type": "video"
}
}
}

View File

@ -0,0 +1,8 @@
{
"folders": [
{
"path": "../.."
}
],
"settings": {}
}

View File

@ -8,11 +8,20 @@
</head>
<body>
<h2>Task number 1 responses</h2>
<h2>Users</h2>
{% for user in users%}
<p>user_id: {{user.user_id}}</p>
<p>question_order: {{user.question_order}}</p>
<p>time: {{user.date_created}}</p>
<p>-------------------------------------------------------------------------</p>
{% endfor %}
<h2>Responses</h2>
{% for response in responses%}
<p>user_id: {{response.id}}</p>
<p>session_user_id: {{response.session_user_id}}</p>
<p>Likert score: {{response.likert_result}}</p>
<p>Feedback: {{response.notes}}</p>
<p>session_user_id: {{response.session_user_id}}</p>
<p>time: {{response.date_created}}</p>
<p>-------------------------------------------------------------------------</p>
{% endfor %}
</body>

View File

@ -41,7 +41,7 @@
<label for="feedback">Additional Feedback: </label>
<textarea id="feedback" name="feedback" rows="3" cols="30" maxlength="200"></textarea>
<p><input id="submitbutton" type = "submit" value = "submit";"/></p>
<p><input id="submitbutton" type = "submit" value = "submit";/></p>
</form>
</body>

View File

@ -37,7 +37,7 @@
{% else %}
<p>Error: No Videotype could be matched or was given!</p>
{% endif %}
<form action="http://localhost:5000/{{ user_id }}" method="post"></form>
<form action="http://localhost:5000/form" method="post">
{% for block in config["question 1"]["blocks"] %}
{% if (config["question 1"]["blocks"][block]["type"] == "likert") %}
<div class="likercontainer">
@ -56,6 +56,8 @@
<p>Error: A block could not be loaded!</p>
{% endif %}
{% endfor %}
<p><input id="submitbutton" type = "submit" value = "submit";/></p>
</form>
</body>
</html>

View File

@ -0,0 +1,21 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<link rel="stylesheet" type="text/css" href="{{ url_for('static', filename='styles.css')}}"" /> <!-- styles.css {{ url_for('static', filename='styles.css')}}-->
<title>DGS Avatar Study</title>
</head>
<body>
<h2>Hello! Thank you for participating in our study!</h2>
<form action="http://localhost:5000/start" method="post">
<label for="terms-and-conditions">
<input class="inline" id="terms-and-conditions" type="checkbox" required name="terms-and-conditions" /> I accept the +terms and conditions</a>
</label>
<p><input id="submitbutton" type = "submit" value = "submit" /></p>
</form>
</body>
</html>

110
slaeforms/test.json Normal file
View File

@ -0,0 +1,110 @@
{
"question 1":{
"type": "single",
"video1": "https://www.youtube-nocookie.com/embed/VtnwHmabyzo?si=H3rrG-GHtlSymR70",
"blocks": {
"block1":{
"type": "likert",
"numberofpoints": "5",
"points":{
"point1": "1",
"point2": "2",
"point3": "3",
"point4": "4",
"point5": "5"
}
},
"block2":{
"type": "likert",
"numberofpoints": "5",
"points":{
"point1": "1",
"point2": "2",
"point3": "3",
"point4": "4",
"point5": "5"
}
},
"block3":{
"type": "textinput",
"length": "200"
},
"block4":{
"type": "likert",
"numberofpoints": "5",
"points":{
"point1": "1",
"point2": "2",
"point3": "3",
"point4": "4",
"point5": "5"
}
}
}
},
"question 2":{
"type": "single",
"video1": "https://www.youtube-nocookie.com/embed/EL76Ok4r0aQ?si=hqUm8eUUfX39NN4L",
"blocks": {
"block1":{
"type": "likert",
"numberofpoints": "5",
"points":{
"point1": "1",
"point2": "2",
"point3": "3",
"point4": "4",
"point5": "5"
}
},
"block2":{
"type": "likert",
"numberofpoints": "5",
"points":{
"point1": "1",
"point2": "2",
"point3": "3",
"point4": "4",
"point5": "5"
}
},
"block3":{
"type": "textinput",
"length": "200"
},
"block4":{
"type": "likert",
"numberofpoints": "5",
"points":{
"point1": "1",
"point2": "2",
"point3": "3",
"point4": "4",
"point5": "5"
}
}
}
},
"question 3":{
"type": "single",
"video1": "https://www.youtube-nocookie.com/embed/XTMIomsXxKM?si=r2zB6OKERH6Jdpi6",
"scales": {
"block1":{
"type": "likert",
"numberofpoints": "3",
"points":{
"point1": "left",
"point2": "none",
"point3": "right"
}
},
"block2":{
"type": "textinput",
"length": "200"
},
"block3":{
"type": "video"
}
}
}
}