Cleaning up mostly
This commit is contained in:
parent
3959bd6295
commit
6a0d9cfd69
26
slaeforms/Old Code.py
Normal file
26
slaeforms/Old Code.py
Normal 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"
|
||||||
|
)
|
@ -1,14 +1,18 @@
|
|||||||
import sys
|
import sys
|
||||||
import json
|
import json
|
||||||
|
import random
|
||||||
from flask import Flask, redirect, url_for, request, session, make_response
|
from flask import Flask, redirect, url_for, request, session, make_response
|
||||||
from flask import render_template
|
from flask import render_template
|
||||||
from flask_sqlalchemy import SQLAlchemy
|
from flask_sqlalchemy import SQLAlchemy
|
||||||
from sqlalchemy.orm import DeclarativeBase
|
from sqlalchemy.orm import DeclarativeBase
|
||||||
from sqlalchemy import Integer, String
|
from sqlalchemy import Integer, String
|
||||||
from sqlalchemy.orm import Mapped, mapped_column
|
from sqlalchemy.orm import Mapped, mapped_column
|
||||||
|
from sqlalchemy.dialects.postgresql import UUID
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
|
random_order = True
|
||||||
|
|
||||||
#create the app
|
#create the app
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
# configure the database, give it a path (it will be in the instances folder)
|
# 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)
|
config2 = json.load(configfile2)
|
||||||
configfile.close()
|
configfile.close()
|
||||||
configfile2.close()
|
configfile2.close()
|
||||||
print(config["question 1"])
|
# get the questions:
|
||||||
print("\n")
|
questions = list(config)
|
||||||
print(config["question 1"]["type"])
|
|
||||||
print("\n")
|
|
||||||
|
|
||||||
# create the model for the response table
|
# create the model for the response table
|
||||||
class Response(db.Model):
|
class Response(db.Model):
|
||||||
@ -38,22 +41,30 @@ class Response(db.Model):
|
|||||||
notes = db.Column(db.String(200))
|
notes = db.Column(db.String(200))
|
||||||
date_created = db.Column(db.DateTime, default=datetime.today())
|
date_created = db.Column(db.DateTime, default=datetime.today())
|
||||||
def __repr__(self) -> str:
|
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)
|
# create the table (existing tables are not overwritten)
|
||||||
with app.app_context():
|
with app.app_context():
|
||||||
db.create_all()
|
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?
|
@app.route("/form", methods=["GET", "POST"]) # /<username> should not even be needed right?
|
||||||
def formpage():
|
def formpage():
|
||||||
#TODO fill in code that determins at which question the user is
|
#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(
|
return render_template(
|
||||||
"layout2.html",
|
"layout2.html",
|
||||||
@ -64,39 +75,63 @@ def formpage():
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
#just testing
|
|
||||||
@app.route("/", methods=["GET", "POST"])
|
|
||||||
def testpage():
|
@app.route("/start", methods=["GET", "POST"])
|
||||||
if not "slaeform_user_id" in session:
|
def startpage():
|
||||||
# If the cookie doesn't exist
|
if not "slaeform_device_id" in session:
|
||||||
print('Hello, new user! Setting cookie...')
|
# If this device was not seen, remember it.
|
||||||
new_user_id = str(uuid.uuid4())
|
new_device_id = str(uuid.uuid4())
|
||||||
session["slaeform_user_id"] = new_user_id
|
session["slaeform_device_id"] = new_device_id
|
||||||
|
session["agreed_to_tos"] = False
|
||||||
|
|
||||||
if request.method == "POST":
|
if request.method == "POST":
|
||||||
session_user_id = session["slaeform_user_id"]
|
# get a random question order
|
||||||
likert_score = request.form["likertscale"]
|
if random_order:
|
||||||
text_input = request.form["feedback"]
|
order = random.shuffle(questions)
|
||||||
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))
|
else:
|
||||||
new_response = Response(session_user_id = session_user_id,likert_result = likert_score, notes = text_input)
|
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:
|
try:
|
||||||
db.session.add(new_response)
|
db.session.add(new_user)
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
return redirect("/") #url_for("datapage")
|
return redirect("/start") #url_for("datapage")
|
||||||
except:
|
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(
|
return render_template(
|
||||||
"layout1.html"
|
"startpage.html"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@app.route("/data")
|
@app.route("/data")
|
||||||
def datapage():
|
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(
|
return render_template(
|
||||||
"data.html",
|
"data.html",
|
||||||
responses = responses
|
responses = responses,
|
||||||
|
users = users
|
||||||
)
|
)
|
||||||
|
|
||||||
# Route to delete all entries
|
# Route to delete all entries
|
||||||
@ -121,3 +156,7 @@ def delete_all_entries():
|
|||||||
finally:
|
finally:
|
||||||
# Close the session
|
# Close the session
|
||||||
db.session.close()
|
db.session.close()
|
||||||
|
|
||||||
|
@app.route("/")
|
||||||
|
def blank():
|
||||||
|
return "blank page"
|
@ -15,30 +15,8 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"block2":{
|
"block2":{
|
||||||
"type": "likert",
|
|
||||||
"numberofpoints": "5",
|
|
||||||
"points":{
|
|
||||||
"point1": "1",
|
|
||||||
"point2": "2",
|
|
||||||
"point3": "3",
|
|
||||||
"point4": "4",
|
|
||||||
"point5": "5"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"block3":{
|
|
||||||
"type": "textinput",
|
"type": "textinput",
|
||||||
"length": "200"
|
"length": "200"
|
||||||
},
|
|
||||||
"block4":{
|
|
||||||
"type": "likert",
|
|
||||||
"numberofpoints": "5",
|
|
||||||
"points":{
|
|
||||||
"point1": "1",
|
|
||||||
"point2": "2",
|
|
||||||
"point3": "3",
|
|
||||||
"point4": "4",
|
|
||||||
"point5": "5"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -58,30 +36,8 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"block2":{
|
"block2":{
|
||||||
"type": "likert",
|
|
||||||
"numberofpoints": "5",
|
|
||||||
"points":{
|
|
||||||
"point1": "1",
|
|
||||||
"point2": "2",
|
|
||||||
"point3": "3",
|
|
||||||
"point4": "4",
|
|
||||||
"point5": "5"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"block3":{
|
|
||||||
"type": "textinput",
|
"type": "textinput",
|
||||||
"length": "200"
|
"length": "200"
|
||||||
},
|
|
||||||
"block4":{
|
|
||||||
"type": "likert",
|
|
||||||
"numberofpoints": "5",
|
|
||||||
"points":{
|
|
||||||
"point1": "1",
|
|
||||||
"point2": "2",
|
|
||||||
"point3": "3",
|
|
||||||
"point4": "4",
|
|
||||||
"point5": "5"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -101,9 +57,6 @@
|
|||||||
"block2":{
|
"block2":{
|
||||||
"type": "textinput",
|
"type": "textinput",
|
||||||
"length": "200"
|
"length": "200"
|
||||||
},
|
|
||||||
"block3":{
|
|
||||||
"type": "video"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
8
slaeforms/templates/SLAEForms Testing.code-workspace
Normal file
8
slaeforms/templates/SLAEForms Testing.code-workspace
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
{
|
||||||
|
"folders": [
|
||||||
|
{
|
||||||
|
"path": "../.."
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"settings": {}
|
||||||
|
}
|
@ -8,11 +8,20 @@
|
|||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body>
|
<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%}
|
{% 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>Likert score: {{response.likert_result}}</p>
|
||||||
<p>Feedback: {{response.notes}}</p>
|
<p>Feedback: {{response.notes}}</p>
|
||||||
<p>session_user_id: {{response.session_user_id}}</p>
|
<p>time: {{response.date_created}}</p>
|
||||||
<p>-------------------------------------------------------------------------</p>
|
<p>-------------------------------------------------------------------------</p>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</body>
|
</body>
|
||||||
|
@ -41,7 +41,7 @@
|
|||||||
<label for="feedback">Additional Feedback: </label>
|
<label for="feedback">Additional Feedback: </label>
|
||||||
<textarea id="feedback" name="feedback" rows="3" cols="30" maxlength="200"></textarea>
|
<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>
|
</form>
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
|
@ -37,7 +37,7 @@
|
|||||||
{% else %}
|
{% else %}
|
||||||
<p>Error: No Videotype could be matched or was given!</p>
|
<p>Error: No Videotype could be matched or was given!</p>
|
||||||
{% endif %}
|
{% 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"] %}
|
{% for block in config["question 1"]["blocks"] %}
|
||||||
{% if (config["question 1"]["blocks"][block]["type"] == "likert") %}
|
{% if (config["question 1"]["blocks"][block]["type"] == "likert") %}
|
||||||
<div class="likercontainer">
|
<div class="likercontainer">
|
||||||
@ -56,6 +56,8 @@
|
|||||||
<p>Error: A block could not be loaded!</p>
|
<p>Error: A block could not be loaded!</p>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
<p><input id="submitbutton" type = "submit" value = "submit";/></p>
|
||||||
|
</form>
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
</html>
|
</html>
|
21
slaeforms/templates/startpage.html
Normal file
21
slaeforms/templates/startpage.html
Normal 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
110
slaeforms/test.json
Normal 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"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user