Random order working!
This commit is contained in:
parent
4527b62444
commit
dd7770ecb6
@ -32,21 +32,21 @@ configfile2.close()
|
||||
# get the questions:
|
||||
questions = list(config)
|
||||
|
||||
|
||||
# create the model for the response table
|
||||
class Response(db.Model):
|
||||
id = db.Column(db.Integer, primary_key=True)
|
||||
session_user_id = db.Column(db.String(36))
|
||||
id = db.Column(db.UUID(as_uuid=True), primary_key=True, nullable=False)
|
||||
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)
|
||||
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:
|
||||
return "<Response %r>" % self.id
|
||||
|
||||
|
||||
class User(db.Model):
|
||||
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))
|
||||
date_created = db.Column(db.DateTime, default=datetime.today())
|
||||
def __repr__(self) -> str:
|
||||
@ -56,22 +56,58 @@ class User(db.Model):
|
||||
with app.app_context():
|
||||
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?
|
||||
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
|
||||
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(
|
||||
"layout2.html",
|
||||
config=config,
|
||||
videotype=config["question 1"]["type"],
|
||||
video_url= config["question 1"]["video1"],
|
||||
blocks = config["question 1"]["blocks"]
|
||||
current_question = current_question,
|
||||
videotype=config[current_question]["type"],
|
||||
video_url= config[current_question]["video1"],
|
||||
blocks = config[current_question]["blocks"]
|
||||
)
|
||||
|
||||
|
||||
@ -91,28 +127,33 @@ def startpage():
|
||||
|
||||
# get a random question order
|
||||
if random_order:
|
||||
order = random.shuffle(questions)
|
||||
order = questions
|
||||
random.shuffle(order)
|
||||
else:
|
||||
order = questions
|
||||
|
||||
session["question_order"] = order
|
||||
|
||||
|
||||
#save the new user to the database and the session
|
||||
session["agreed_to_tos"] = True
|
||||
new_user_id = uuid.uuid4()
|
||||
session["slaeform_user_id"] = new_user_id
|
||||
device_id = session["slaeform_device_id"]
|
||||
user_id = session["slaeform_user_id"]
|
||||
user_id = new_user_id
|
||||
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:
|
||||
db.session.add(new_user)
|
||||
print("add was ok")
|
||||
db.session.commit()
|
||||
print("commit was ok")
|
||||
return redirect("/form")
|
||||
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(
|
||||
"startpage.html"
|
||||
@ -138,10 +179,14 @@ def delete_all_entries():
|
||||
try:
|
||||
# Query all entries
|
||||
entries = Response.query.all()
|
||||
entries2 = User.query.all()
|
||||
|
||||
# Delete each entry
|
||||
for entry in entries:
|
||||
db.session.delete(entry)
|
||||
|
||||
for entry in entries2:
|
||||
db.session.delete(entry)
|
||||
|
||||
# Commit changes
|
||||
db.session.commit()
|
||||
|
@ -44,7 +44,7 @@
|
||||
"question 3":{
|
||||
"type": "single",
|
||||
"video1": "https://www.youtube-nocookie.com/embed/XTMIomsXxKM?si=r2zB6OKERH6Jdpi6",
|
||||
"scales": {
|
||||
"blocks": {
|
||||
"block1":{
|
||||
"type": "likert",
|
||||
"numberofpoints": "3",
|
||||
|
@ -17,8 +17,9 @@
|
||||
{% endfor %}
|
||||
<h2>Responses</h2>
|
||||
{% for response in responses%}
|
||||
<p>user_id: {{response.id}}</p>
|
||||
<p>session_user_id: {{response.session_user_id}}</p>
|
||||
<p>id: {{response.id}}</p>
|
||||
<p>question_title: {{response.question_title}}</p>
|
||||
<p>user_id: {{response.user_id}}</p>
|
||||
<p>Likert score: {{response.likert_result}}</p>
|
||||
<p>Feedback: {{response.notes}}</p>
|
||||
<p>time: {{response.date_created}}</p>
|
||||
|
@ -8,7 +8,7 @@
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<h2>Task number 1</h2>
|
||||
<h2>Question: {{ current_question }}</h2>
|
||||
{% if (videotype == "single")%} <!-- first figure out what video type we have -->
|
||||
<div class="center">
|
||||
<h3>Video 1</h3>
|
||||
@ -37,7 +37,7 @@
|
||||
{% else %}
|
||||
<p>Error: No Videotype could be matched or was given!</p>
|
||||
{% endif %}
|
||||
<form action="http://localhost:5000/form" method="post">
|
||||
<form action="http://localhost:5000/send" method="post">
|
||||
{% for block in config["question 1"]["blocks"] %}
|
||||
{% if (config["question 1"]["blocks"][block]["type"] == "likert") %}
|
||||
<div class="likercontainer">
|
||||
|
Loading…
Reference in New Issue
Block a user