Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Server maintenance on Tue 31.5. at 12:00.
Open sidebar
Timo Heikkilä
PET-rating
Commits
7ab7e125
Commit
7ab7e125
authored
May 20, 2020
by
Ossi Laine
Browse files
Fixed randomization issues while exporting results
parent
bcb340f1
Changes
6
Expand all
Hide whitespace changes
Inline
Side-by-side
app/experiment/views.py
View file @
7ab7e125
...
...
@@ -921,7 +921,9 @@ def statistics():
slider_answers
=
{}
for
participant
in
participants
:
if
participant
.
answer_counter
>
0
:
answers
=
answer
.
query
.
filter_by
(
answer_set_idanswer_set
=
participant
.
idanswer_set
).
all
()
answers
=
answer
.
query
.
filter_by
(
answer_set_idanswer_set
=
participant
.
idanswer_set
)
\
.
order_by
(
answer
.
page_idpage
)
\
.
all
()
slider_answers
[
participant
.
session
]
=
[
a
.
answer
for
a
in
answers
]
slider_answers
[
'mean'
]
=
get_mean_from_slider_answers
(
slider_answers
)
...
...
app/models.py
View file @
7ab7e125
from
sqlalchemy
import
and_
from
flask
import
session
from
app
import
db
from
sqlalchemy
import
Column
,
Integer
,
String
,
Text
,
Boolean
from
flask_wtf
import
FlaskForm
from
wtforms_sqlalchemy.fields
import
QuerySelectField
,
QuerySelectMultipleField
from
wtforms_sqlalchemy.fields
import
QuerySelectField
,
QuerySelectMultipleField
from
werkzeug.security
import
generate_password_hash
,
check_password_hash
from
flask_login
import
UserMixin
from
app
import
login
...
...
@@ -15,9 +17,10 @@ class background_question(db.Model):
__tablename__
=
"background_question"
idbackground_question
=
db
.
Column
(
db
.
Integer
,
primary_key
=
True
)
background_question
=
db
.
Column
(
db
.
String
(
120
))
answers
=
db
.
relationship
(
'background_question_answer'
,
backref
=
'question'
,
lazy
=
'dynamic'
)
answers
=
db
.
relationship
(
'background_question_answer'
,
backref
=
'question'
,
lazy
=
'dynamic'
)
experiment_idexperiment
=
db
.
Column
(
db
.
Integer
)
def
__repr__
(
self
):
return
"<idbackground_question = '%s', background_question = '%s'>"
%
(
self
.
idbackground_question
,
self
.
background_question
)
...
...
@@ -25,11 +28,12 @@ class background_question(db.Model):
class
background_question_option
(
db
.
Model
):
__tablename__
=
"background_question_option"
idbackground_question_option
=
db
.
Column
(
db
.
Integer
,
primary_key
=
True
)
background_question_idbackground_question
=
db
.
Column
(
db
.
Integer
,
db
.
ForeignKey
(
'background_question.idbackground_question'
))
background_question_idbackground_question
=
db
.
Column
(
db
.
Integer
,
db
.
ForeignKey
(
'background_question.idbackground_question'
))
option
=
db
.
Column
(
db
.
String
(
120
))
def
__repr__
(
self
):
return
"<idbackground_question_option = '%s', background_question_idbackground_question = '%s', option = '%s'>"
%
(
self
.
idbackground_question_option
,
self
.
background_question_idbackground_question
,
self
.
option
)
return
"<idbackground_question_option = '%s', background_question_idbackground_question = '%s', option = '%s'>"
%
(
self
.
idbackground_question_option
,
self
.
background_question_idbackground_question
,
self
.
option
)
class
experiment
(
db
.
Model
):
...
...
@@ -51,7 +55,7 @@ class experiment (db.Model):
consent_text
=
db
.
Column
(
db
.
Text
,
index
=
True
)
use_forced_id
=
db
.
Column
(
db
.
String
(
120
))
embody_enabled
=
db
.
Column
(
db
.
Boolean
,
unique
=
False
,
default
=
False
)
def
__repr__
(
self
):
return
"<idexperiment = '%s', name='%s', instruction='%s', directoryname='%s', language='%s', status='%s', randomization='%s', short_instruction='%s', single_sentence_instruction='%s', is_archived='%s', creator_name='%s', research_notification_filename='%s', creation_time='%s', stimulus_size='%s', consent_text='%s', use_forced_id='%s', embody_enabled='%s'>"
%
(
self
.
idexperiment
,
self
.
name
,
self
.
instruction
,
self
.
directoryname
,
self
.
language
,
self
.
status
,
self
.
randomization
,
self
.
short_instruction
,
self
.
single_sentence_instruction
,
self
.
is_archived
,
self
.
creator_name
,
self
.
research_notification_filename
,
self
.
creation_time
,
self
.
stimulus_size
,
self
.
consent_text
,
self
.
use_forced_id
,
self
.
embody_enabled
)
...
...
@@ -59,13 +63,16 @@ class experiment (db.Model):
class
answer_set
(
db
.
Model
):
__tablename__
=
"answer_set"
idanswer_set
=
db
.
Column
(
db
.
Integer
,
primary_key
=
True
)
experiment_idexperiment
=
db
.
Column
(
db
.
Integer
,
db
.
ForeignKey
(
'experiment.idexperiment'
))
experiment_idexperiment
=
db
.
Column
(
db
.
Integer
,
db
.
ForeignKey
(
'experiment.idexperiment'
))
session
=
db
.
Column
(
db
.
String
(
120
))
agreement
=
db
.
Column
(
db
.
String
(
120
))
answer_counter
=
db
.
Column
(
db
.
Integer
)
answer_type
=
db
.
Column
(
db
.
String
(
120
))
registration_time
=
db
.
Column
(
db
.
DateTime
,
index
=
True
,
default
=
datetime
.
utcnow
)
last_answer_time
=
db
.
Column
(
db
.
DateTime
,
index
=
True
,
default
=
datetime
.
utcnow
)
registration_time
=
db
.
Column
(
db
.
DateTime
,
index
=
True
,
default
=
datetime
.
utcnow
)
last_answer_time
=
db
.
Column
(
db
.
DateTime
,
index
=
True
,
default
=
datetime
.
utcnow
)
def
__repr__
(
self
):
return
"<idanswer_set = '%s', experiment_idexperiment = '%s', session = '%s', agreement = '%s', answer_counter = '%s', registration_time = '%s', last_answer_time = '%s'>"
%
(
self
.
idanswer_set
,
self
.
experiment_idexperiment
,
self
.
session
,
self
.
agreement
,
self
.
answer_counter
,
self
.
registration_time
,
self
.
last_answer_time
)
...
...
@@ -74,17 +81,20 @@ class answer_set (db.Model):
class
background_question_answer
(
db
.
Model
):
__tablename__
=
"background_question_answer"
idbackground_question_answer
=
db
.
Column
(
db
.
Integer
,
primary_key
=
True
)
answer_set_idanswer_set
=
db
.
Column
(
db
.
Integer
,
db
.
ForeignKey
(
'answer_set.idanswer_set'
))
answer_set_idanswer_set
=
db
.
Column
(
db
.
Integer
,
db
.
ForeignKey
(
'answer_set.idanswer_set'
))
answer
=
db
.
Column
(
db
.
String
(
120
))
background_question_idbackground_question
=
db
.
Column
(
db
.
Integer
,
db
.
ForeignKey
(
'background_question.idbackground_question'
))
background_question_idbackground_question
=
db
.
Column
(
db
.
Integer
,
db
.
ForeignKey
(
'background_question.idbackground_question'
))
def
__repr__
(
self
):
return
"<idbackground_question_answer = '%s', answer_set_idanswer_set = '%s', answer = '%s', background_question_idbackground_question = '%s'>"
%
(
self
.
idbackground_question_answer
,
self
.
answer_set_idanswer_set
,
self
.
answer
,
self
.
background_question_idbackground_question
)
return
"<idbackground_question_answer = '%s', answer_set_idanswer_set = '%s', answer = '%s', background_question_idbackground_question = '%s'>"
%
(
self
.
idbackground_question_answer
,
self
.
answer_set_idanswer_set
,
self
.
answer
,
self
.
background_question_idbackground_question
)
def
background_question_answer_query
():
return
background_question_answer
.
query
"""
class ChoiceForm(FlaskForm):
opts = QuerySelectField(query_factory=background_question_answer_query, allow_blank=True)
...
...
@@ -98,30 +108,33 @@ vastaukset = u.answers.all()
class
question
(
db
.
Model
):
__tablename__
=
"question"
idquestion
=
db
.
Column
(
db
.
Integer
,
primary_key
=
True
)
experiment_idexperiment
=
db
.
Column
(
db
.
Integer
,
db
.
ForeignKey
(
'experiment.idexperiment'
))
experiment_idexperiment
=
db
.
Column
(
db
.
Integer
,
db
.
ForeignKey
(
'experiment.idexperiment'
))
question
=
db
.
Column
(
db
.
String
(
120
))
left
=
db
.
Column
(
db
.
String
(
120
))
right
=
db
.
Column
(
db
.
String
(
120
))
def
__repr__
(
self
):
return
"<idquestion = '%s', experiment_idexperiment = '%s', question = '%s', left = '%s', right = '%s'>"
%
(
self
.
idquestion
,
self
.
experiment_idexperiment
,
self
.
question
,
self
.
left
,
self
.
right
)
return
"<idquestion = '%s', experiment_idexperiment = '%s', question = '%s', left = '%s', right = '%s'>"
%
(
self
.
idquestion
,
self
.
experiment_idexperiment
,
self
.
question
,
self
.
left
,
self
.
right
)
class
embody_question
(
db
.
Model
):
__tablename__
=
"embody_question"
idembody
=
db
.
Column
(
db
.
Integer
,
primary_key
=
True
)
experiment_idexperiment
=
db
.
Column
(
db
.
Integer
,
db
.
ForeignKey
(
'experiment.idexperiment'
))
experiment_idexperiment
=
db
.
Column
(
db
.
Integer
,
db
.
ForeignKey
(
'experiment.idexperiment'
))
picture
=
db
.
Column
(
db
.
Text
)
question
=
db
.
Column
(
db
.
Text
)
def
__repr__
(
self
):
return
"<idembody = '%s', experiment_idexperiment = '%s', picture = '%s', question = '%s'>"
%
(
self
.
idembody
,
self
.
experiment_idexperiment
,
self
.
picture
,
self
.
question
)
return
"<idembody = '%s', experiment_idexperiment = '%s', picture = '%s', question = '%s'>"
%
(
self
.
idembody
,
self
.
experiment_idexperiment
,
self
.
picture
,
self
.
question
)
class
page
(
db
.
Model
):
__tablename__
=
"page"
idpage
=
db
.
Column
(
db
.
Integer
,
primary_key
=
True
)
experiment_idexperiment
=
db
.
Column
(
db
.
Integer
,
db
.
ForeignKey
(
'experiment.idexperiment'
))
experiment_idexperiment
=
db
.
Column
(
db
.
Integer
,
db
.
ForeignKey
(
'experiment.idexperiment'
))
type
=
db
.
Column
(
db
.
String
(
120
),
index
=
True
)
text
=
db
.
Column
(
db
.
Text
)
media
=
db
.
Column
(
db
.
String
(
120
),
index
=
True
)
...
...
@@ -133,8 +146,10 @@ class page (db.Model):
class
answer
(
db
.
Model
):
__tablename__
=
"answer"
idanswer
=
db
.
Column
(
db
.
Integer
,
primary_key
=
True
)
question_idquestion
=
db
.
Column
(
db
.
Integer
,
db
.
ForeignKey
(
'question.idquestion'
))
answer_set_idanswer_set
=
db
.
Column
(
db
.
Integer
,
db
.
ForeignKey
(
'answer_set.idanswer_set'
))
question_idquestion
=
db
.
Column
(
db
.
Integer
,
db
.
ForeignKey
(
'question.idquestion'
))
answer_set_idanswer_set
=
db
.
Column
(
db
.
Integer
,
db
.
ForeignKey
(
'answer_set.idanswer_set'
))
answer
=
db
.
Column
(
db
.
String
(
120
))
page_idpage
=
db
.
Column
(
db
.
Integer
,
db
.
ForeignKey
(
'page.idpage'
))
...
...
@@ -145,9 +160,11 @@ class answer (db.Model):
class
embody_answer
(
db
.
Model
):
__tablename__
=
"embody_answer"
idanswer
=
db
.
Column
(
db
.
Integer
,
primary_key
=
True
)
answer_set_idanswer_set
=
db
.
Column
(
db
.
Integer
,
db
.
ForeignKey
(
'answer_set.idanswer_set'
))
answer_set_idanswer_set
=
db
.
Column
(
db
.
Integer
,
db
.
ForeignKey
(
'answer_set.idanswer_set'
))
page_idpage
=
db
.
Column
(
db
.
Integer
,
db
.
ForeignKey
(
'page.idpage'
))
embody_question_idembody
=
db
.
Column
(
db
.
Integer
,
db
.
ForeignKey
(
'embody_question.idembody'
))
embody_question_idembody
=
db
.
Column
(
db
.
Integer
,
db
.
ForeignKey
(
'embody_question.idembody'
))
coordinates
=
db
.
Column
(
db
.
Text
)
def
__repr__
(
self
):
...
...
@@ -161,17 +178,24 @@ class trial_randomization (db.Model):
randomized_idpage
=
db
.
Column
(
db
.
Integer
)
answer_set_idanswer_set
=
db
.
Column
(
db
.
Integer
)
experiment_idexperiment
=
db
.
Column
(
db
.
Integer
)
def
__repr__
(
self
):
return
"<idtrial_randomization = '%s', page_idpage = '%s', randomized_idpage = '%s', answer_set_idanswer_set = '%s', experiment_idexperiment = '%s'>"
%
(
self
.
idtrial_randomization
,
self
.
page_idpage
,
self
.
randomized_idpage
,
self
.
answer_set_idanswer_set
,
self
.
experiment_idexperiment
)
@
classmethod
def
get_randomized_page
(
cls
,
page_id
):
return
cls
.
query
.
filter
(
and_
(
cls
.
answer_set_idanswer_set
==
session
[
'answer_set'
],
cls
.
page_idpage
==
page_id
)).
first
()
class
forced_id
(
db
.
Model
):
__tablename__
=
"forced_id"
idforced_id
=
db
.
Column
(
db
.
Integer
,
primary_key
=
True
)
experiment_idexperiment
=
db
.
Column
(
db
.
Integer
,
db
.
ForeignKey
(
'experiment.idexperiment'
))
pregenerated_id
=
db
.
Column
(
db
.
String
(
120
))
experiment_idexperiment
=
db
.
Column
(
db
.
Integer
,
db
.
ForeignKey
(
'experiment.idexperiment'
))
pregenerated_id
=
db
.
Column
(
db
.
String
(
120
))
def
__repr__
(
self
):
return
"<idforced_id = '%s', experiment_idexperiment = '%s', pregenerated_id = '%s'>"
%
(
self
.
idforced_id
,
self
.
experiment_idexperiment
,
self
.
pregenerated_id
)
...
...
@@ -184,16 +208,15 @@ class user(UserMixin, db.Model):
password_hash
=
db
.
Column
(
db
.
String
(
128
))
def
__repr__
(
self
):
return
'<user {}>'
.
format
(
self
.
username
)
return
'<user {}>'
.
format
(
self
.
username
)
def
set_password
(
self
,
password
):
self
.
password_hash
=
generate_password_hash
(
password
)
def
check_password
(
self
,
password
):
return
check_password_hash
(
self
.
password_hash
,
password
)
@
login
.
user_loader
def
load_user
(
id
):
return
user
.
query
.
get
(
int
(
id
))
\ No newline at end of file
app/routes.py
View file @
7ab7e125
This diff is collapsed.
Click to expand it.
app/static/js/getDrawing.js
View file @
7ab7e125
...
...
@@ -48,6 +48,11 @@ $(document).ready(function() {
//
var
pageId
=
this
.
dataset
.
value
.
split
(
'
-
'
)[
0
]
var
embodyId
=
this
.
dataset
.
value
.
split
(
'
-
'
)[
1
]
console
.
log
(
pageId
)
console
.
log
(
embodyId
)
socket
.
emit
(
'
draw
'
,
{
page
:
pageId
,
embody
:
embodyId
})
progressBarContainer
.
removeClass
(
"
hidden
"
)
...
...
app/task/views.py
View file @
7ab7e125
...
...
@@ -37,10 +37,7 @@ task_blueprint = Blueprint("task", __name__,
def
get_randomized_page
(
page_id
):
"""if trial randomization is on we will still use the same functionality that is used otherwise
but we will pass the randomized pair of the page_id from trial randomization table to the task.html"""
return
trial_randomization
.
query
.
filter
(
and_
(
trial_randomization
.
answer_set_idanswer_set
==
session
[
'answer_set'
],
trial_randomization
.
page_idpage
==
page_id
)).
first
()
return
trial_randomization
.
get_randomized_page
(
page_id
)
def
add_slider_answer
(
key
,
value
,
page_id
=
None
):
...
...
embody_plot.py
View file @
7ab7e125
...
...
@@ -119,13 +119,11 @@ def timeit(method):
return
timed
import
sys
@
timeit
def
get_coordinates
(
idpage
,
idembody
=
None
,
select_clause
=
SELECT_BY_PAGE_AND_PICTURE
):
"""Select all drawn points from certain stimulus and plot them onto
the human body"""
db
=
MyDB
()
db
.
query
(
select_clause
,
(
idpage
,
idembody
))
...
...
@@ -138,13 +136,11 @@ def get_coordinates(idpage, idembody=None, select_clause=SELECT_BY_PAGE_AND_PICT
image_path
=
db
.
_db_cur
.
fetchone
()[
0
]
image_path
=
'./app'
+
image_path
# Draw image
plt
=
plot_coordinates
(
coordinates
,
image_path
)
else
:
plt
=
plot_coordinates
(
coordinates
,
DEFAULT_IMAGE_PATH
)
# Save image to ./app/static/
img_filename
=
'PAGE-'
+
str
(
idpage
)
+
'-'
+
DATE_STRING
+
'.png'
plt
.
savefig
(
STATIC_PATH
+
img_filename
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment