Random order working!
This commit is contained in:
parent
4527b62444
commit
dd7770ecb6
@ -32,21 +32,21 @@ configfile2.close()
|
|||||||
# get the questions:
|
# get the questions:
|
||||||
questions = list(config)
|
questions = list(config)
|
||||||
|
|
||||||
|
|
||||||
# create the model for the response table
|
# create the model for the response table
|
||||||
class Response(db.Model):
|
class Response(db.Model):
|
||||||
id = db.Column(db.Integer, primary_key=True)
|
id = db.Column(db.UUID(as_uuid=True), primary_key=True, nullable=False)
|
||||||
session_user_id = db.Column(db.String(36))
|
user_id = db.Column(db.UUID(as_uuid=True), nullable=False)
|
||||||
|
question_title = db.Column(db.String(30))
|
||||||
likert_result = db.Column(db.Integer, nullable=False)
|
likert_result = db.Column(db.Integer, nullable=False)
|
||||||
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)
|
||||||
def __repr__(self) -> str:
|
def __repr__(self) -> str:
|
||||||
return "<Response %r>" % self.id
|
return "<Response %r>" % self.id
|
||||||
|
|
||||||
|
|
||||||
class User(db.Model):
|
class User(db.Model):
|
||||||
user_id = db.Column(db.UUID(as_uuid=True), primary_key=True, nullable=False)
|
user_id = db.Column(db.UUID(as_uuid=True), primary_key=True, nullable=False)
|
||||||
device_id = db.Column(UUID(as_uuid=True), primary_key=True)
|
device_id = db.Column(db.UUID(as_uuid=True), nullable=False)
|
||||||
question_order = db.Column(db.String(60))
|
question_order = db.Column(db.String(60))
|
||||||
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:
|
||||||
@ -56,7 +56,24 @@ class User(db.Model):
|
|||||||
with app.app_context():
|
with app.app_context():
|
||||||
db.create_all()
|
db.create_all()
|
||||||
|
|
||||||
|
@app.route("/send", methods=["GET", "POST"])
|
||||||
|
def sendpage():
|
||||||
|
if request.method == "POST":
|
||||||
|
session_user_id = session["slaeform_user_id"]
|
||||||
|
likert_score = request.form["likertscale"]
|
||||||
|
text_input = request.form["feedback"]
|
||||||
|
question_title = session["current_question"]
|
||||||
|
new_id = uuid.uuid4()
|
||||||
|
date = datetime.today()
|
||||||
|
print("new idea: {new_id} ".format(new_id=new_id))
|
||||||
|
new_response = Response(id=new_id,user_id = session_user_id, question_title = question_title,likert_result = likert_score,notes = text_input, date_created = date)
|
||||||
|
|
||||||
|
#try:
|
||||||
|
db.session.add(new_response)
|
||||||
|
db.session.commit()
|
||||||
|
return redirect("/form") #url_for("datapage")
|
||||||
|
#except:
|
||||||
|
#return "There was a problem while adding the response to the Database"
|
||||||
|
|
||||||
@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():
|
||||||
@ -64,14 +81,33 @@ def formpage():
|
|||||||
if not "slaeform_user_id" in session:
|
if not "slaeform_user_id" in session:
|
||||||
return redirect("/start")
|
return redirect("/start")
|
||||||
|
|
||||||
|
|
||||||
#TODO fill in code that determins at which question the user is
|
#TODO fill in code that determins at which question the user is
|
||||||
|
print("form starts, the sessionorder rn:")
|
||||||
|
print(session["question_order"])
|
||||||
|
if not session["question_order"]:
|
||||||
|
print("---------------question order is empty------------")
|
||||||
|
return redirect("/data")
|
||||||
|
|
||||||
|
print("pop the first element")
|
||||||
|
current_question = session["question_order"].pop(0)
|
||||||
|
session["current_question"] = current_question
|
||||||
|
print(current_question)
|
||||||
|
print("the new sessionorder rn:")
|
||||||
|
print(session["question_order"])
|
||||||
|
session["question_order"] = session["question_order"]
|
||||||
|
print("has this changed sth?:")
|
||||||
|
print(session["question_order"])
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return render_template(
|
return render_template(
|
||||||
"layout2.html",
|
"layout2.html",
|
||||||
config=config,
|
config=config,
|
||||||
videotype=config["question 1"]["type"],
|
current_question = current_question,
|
||||||
video_url= config["question 1"]["video1"],
|
videotype=config[current_question]["type"],
|
||||||
blocks = config["question 1"]["blocks"]
|
video_url= config[current_question]["video1"],
|
||||||
|
blocks = config[current_question]["blocks"]
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@ -91,9 +127,11 @@ def startpage():
|
|||||||
|
|
||||||
# get a random question order
|
# get a random question order
|
||||||
if random_order:
|
if random_order:
|
||||||
order = random.shuffle(questions)
|
order = questions
|
||||||
|
random.shuffle(order)
|
||||||
else:
|
else:
|
||||||
order = questions
|
order = questions
|
||||||
|
session["question_order"] = order
|
||||||
|
|
||||||
|
|
||||||
#save the new user to the database and the session
|
#save the new user to the database and the session
|
||||||
@ -101,18 +139,21 @@ def startpage():
|
|||||||
new_user_id = uuid.uuid4()
|
new_user_id = uuid.uuid4()
|
||||||
session["slaeform_user_id"] = new_user_id
|
session["slaeform_user_id"] = new_user_id
|
||||||
device_id = session["slaeform_device_id"]
|
device_id = session["slaeform_device_id"]
|
||||||
user_id = session["slaeform_user_id"]
|
user_id = new_user_id
|
||||||
question_order = str(order)
|
question_order = str(order)
|
||||||
new_user = User(user_id=user_id, device_id=device_id, question_order=question_order)
|
date = datetime.today()
|
||||||
|
new_user = User(user_id=user_id, device_id=device_id,question_order=question_order,date_created = date) #,question_order=question_order
|
||||||
|
|
||||||
|
db.session.add(new_user)
|
||||||
|
db.session.commit()
|
||||||
|
return redirect("/form")
|
||||||
|
"""
|
||||||
try:
|
try:
|
||||||
db.session.add(new_user)
|
db.session.add(new_user)
|
||||||
print("add was ok")
|
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
print("commit was ok")
|
|
||||||
return redirect("/form")
|
return redirect("/form")
|
||||||
except:
|
except:
|
||||||
return "There was a problem while adding the user to the Database"
|
return "There was a problem while adding the user to the Database" """
|
||||||
|
|
||||||
return render_template(
|
return render_template(
|
||||||
"startpage.html"
|
"startpage.html"
|
||||||
@ -138,11 +179,15 @@ def delete_all_entries():
|
|||||||
try:
|
try:
|
||||||
# Query all entries
|
# Query all entries
|
||||||
entries = Response.query.all()
|
entries = Response.query.all()
|
||||||
|
entries2 = User.query.all()
|
||||||
|
|
||||||
# Delete each entry
|
# Delete each entry
|
||||||
for entry in entries:
|
for entry in entries:
|
||||||
db.session.delete(entry)
|
db.session.delete(entry)
|
||||||
|
|
||||||
|
for entry in entries2:
|
||||||
|
db.session.delete(entry)
|
||||||
|
|
||||||
# Commit changes
|
# Commit changes
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
|
||||||
|
@ -44,7 +44,7 @@
|
|||||||
"question 3":{
|
"question 3":{
|
||||||
"type": "single",
|
"type": "single",
|
||||||
"video1": "https://www.youtube-nocookie.com/embed/XTMIomsXxKM?si=r2zB6OKERH6Jdpi6",
|
"video1": "https://www.youtube-nocookie.com/embed/XTMIomsXxKM?si=r2zB6OKERH6Jdpi6",
|
||||||
"scales": {
|
"blocks": {
|
||||||
"block1":{
|
"block1":{
|
||||||
"type": "likert",
|
"type": "likert",
|
||||||
"numberofpoints": "3",
|
"numberofpoints": "3",
|
||||||
|
@ -17,8 +17,9 @@
|
|||||||
{% endfor %}
|
{% endfor %}
|
||||||
<h2>Responses</h2>
|
<h2>Responses</h2>
|
||||||
{% for response in responses%}
|
{% for response in responses%}
|
||||||
<p>user_id: {{response.id}}</p>
|
<p>id: {{response.id}}</p>
|
||||||
<p>session_user_id: {{response.session_user_id}}</p>
|
<p>question_title: {{response.question_title}}</p>
|
||||||
|
<p>user_id: {{response.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>time: {{response.date_created}}</p>
|
<p>time: {{response.date_created}}</p>
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
<h2>Task number 1</h2>
|
<h2>Question: {{ current_question }}</h2>
|
||||||
{% if (videotype == "single")%} <!-- first figure out what video type we have -->
|
{% if (videotype == "single")%} <!-- first figure out what video type we have -->
|
||||||
<div class="center">
|
<div class="center">
|
||||||
<h3>Video 1</h3>
|
<h3>Video 1</h3>
|
||||||
@ -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/form" method="post">
|
<form action="http://localhost:5000/send" 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">
|
||||||
|
Loading…
Reference in New Issue
Block a user