diff --git a/slaeforms/Old Code.py b/slaeforms/Old Code.py new file mode 100644 index 0000000..84b3352 --- /dev/null +++ b/slaeforms/Old Code.py @@ -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" + ) \ No newline at end of file diff --git a/slaeforms/app.py b/slaeforms/app.py index 6ee6986..d9a4eae 100644 --- a/slaeforms/app.py +++ b/slaeforms/app.py @@ -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 "" % self.id + return "" % 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 "" % 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"]) # / 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() \ No newline at end of file + db.session.close() + +@app.route("/") +def blank(): + return "blank page" \ No newline at end of file diff --git a/slaeforms/singleformconfig.json b/slaeforms/singleformconfig.json index 04a0449..539fa33 100644 --- a/slaeforms/singleformconfig.json +++ b/slaeforms/singleformconfig.json @@ -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" } } } diff --git a/slaeforms/templates/SLAEForms Testing.code-workspace b/slaeforms/templates/SLAEForms Testing.code-workspace new file mode 100644 index 0000000..407c760 --- /dev/null +++ b/slaeforms/templates/SLAEForms Testing.code-workspace @@ -0,0 +1,8 @@ +{ + "folders": [ + { + "path": "../.." + } + ], + "settings": {} +} \ No newline at end of file diff --git a/slaeforms/templates/data.html b/slaeforms/templates/data.html index 45c57ca..4700d38 100644 --- a/slaeforms/templates/data.html +++ b/slaeforms/templates/data.html @@ -8,11 +8,20 @@ -

Task number 1 responses

+

Users

+ {% for user in users%} +

user_id: {{user.user_id}}

+

question_order: {{user.question_order}}

+

time: {{user.date_created}}

+

-------------------------------------------------------------------------

+ {% endfor %} +

Responses

{% for response in responses%} +

user_id: {{response.id}}

+

session_user_id: {{response.session_user_id}}

Likert score: {{response.likert_result}}

Feedback: {{response.notes}}

-

session_user_id: {{response.session_user_id}}

+

time: {{response.date_created}}

-------------------------------------------------------------------------

{% endfor %} diff --git a/slaeforms/templates/layout1.html b/slaeforms/templates/layout1.html index 3c509fa..72c5835 100644 --- a/slaeforms/templates/layout1.html +++ b/slaeforms/templates/layout1.html @@ -41,7 +41,7 @@ -

+

diff --git a/slaeforms/templates/layout2.html b/slaeforms/templates/layout2.html index a6b60a3..6e5b02c 100644 --- a/slaeforms/templates/layout2.html +++ b/slaeforms/templates/layout2.html @@ -37,7 +37,7 @@ {% else %}

Error: No Videotype could be matched or was given!

{% endif %} -
+
{% for block in config["question 1"]["blocks"] %} {% if (config["question 1"]["blocks"][block]["type"] == "likert") %}
@@ -56,6 +56,8 @@

Error: A block could not be loaded!

{% endif %} {% endfor %} +

+ \ No newline at end of file diff --git a/slaeforms/templates/startpage.html b/slaeforms/templates/startpage.html new file mode 100644 index 0000000..03c5d92 --- /dev/null +++ b/slaeforms/templates/startpage.html @@ -0,0 +1,21 @@ + + + + + + + DGS Avatar Study + + + +

Hello! Thank you for participating in our study!

+
+ + +

+
+ + + \ No newline at end of file diff --git a/slaeforms/test.json b/slaeforms/test.json new file mode 100644 index 0000000..04a0449 --- /dev/null +++ b/slaeforms/test.json @@ -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" + } + } + } +} \ No newline at end of file