Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
PET-rating
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Timo Heikkilä
PET-rating
Commits
8c4ba60b
Commit
8c4ba60b
authored
5 years ago
by
Ossi Laine
Browse files
Options
Downloads
Patches
Plain Diff
Cleaned experiment editing page and added TODOs
parent
246a59fd
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
app/experiment/views.py
+12
-90
12 additions, 90 deletions
app/experiment/views.py
app/static/js/canvas.js
+7
-7
7 additions, 7 deletions
app/static/js/canvas.js
with
19 additions
and
97 deletions
app/experiment/views.py
+
12
−
90
View file @
8c4ba60b
...
@@ -396,41 +396,30 @@ def add_bg_question():
...
@@ -396,41 +396,30 @@ def add_bg_question():
exp_status
=
experiment
.
query
.
filter_by
(
idexperiment
=
exp_id
).
first
()
exp_status
=
experiment
.
query
.
filter_by
(
idexperiment
=
exp_id
).
first
()
if
exp_status
.
status
!=
'
Hidden
'
:
if
exp_status
.
status
!=
'
Hidden
'
:
flash
(
"
Experiment is public. Cannot modify structure.
"
)
flash
(
"
Experiment is public. Cannot modify structure.
"
)
return
redirect
(
url_for
(
'
experiment.view
'
,
exp_id
=
exp_id
))
return
redirect
(
url_for
(
'
experiment.view
'
,
exp_id
=
exp_id
))
else
:
else
:
form
=
CreateBackgroundQuestionForm
(
request
.
form
)
form
=
CreateBackgroundQuestionForm
(
request
.
form
)
if
request
.
method
==
'
POST
'
and
form
.
validate
():
if
request
.
method
==
'
POST
'
and
form
.
validate
():
str
=
form
.
bg_questions_and_options
.
data
#Split the form data into a list that separates questions followed by the corresponding options
#Split the form data into a list that separates questions followed by the corresponding options
str
=
form
.
bg_questions_and_options
.
data
str_list
=
str
.
split
(
'
/n
'
)
str_list
=
str
.
split
(
'
/n
'
)
#Iterate through the questions and options list
#Iterate through the questions and options list
for
a
in
range
(
len
(
str_list
)):
for
a
in
range
(
len
(
str_list
)):
#Split the list cells further into questions and options
#Split the list cells further into questions and options
list
=
str_list
[
a
].
split
(
'
;
'
)
list
=
str_list
[
a
].
split
(
'
;
'
)
#Input the first item of the list as a question in db and the items followed by that as options for that question
#Input the first item of the list as a question in db and the items followed by that as options for that question
for
x
in
range
(
len
(
list
)):
for
x
in
range
(
len
(
list
)):
if
x
==
0
:
if
x
==
0
:
#flash("Kysymys")
#flash(list[x])
add_bgquestion
=
background_question
(
background_question
=
list
[
x
],
experiment_idexperiment
=
exp_id
)
add_bgquestion
=
background_question
(
background_question
=
list
[
x
],
experiment_idexperiment
=
exp_id
)
db
.
session
.
add
(
add_bgquestion
)
db
.
session
.
add
(
add_bgquestion
)
db
.
session
.
commit
()
db
.
session
.
commit
()
else
:
else
:
#flash("optio")
#flash(list[x])
add_bgq_option
=
background_question_option
(
background_question_idbackground_question
=
add_bgquestion
.
idbackground_question
,
option
=
list
[
x
])
add_bgq_option
=
background_question_option
(
background_question_idbackground_question
=
add_bgquestion
.
idbackground_question
,
option
=
list
[
x
])
db
.
session
.
add
(
add_bgq_option
)
db
.
session
.
add
(
add_bgq_option
)
db
.
session
.
commit
()
db
.
session
.
commit
()
...
@@ -454,7 +443,6 @@ def edit_bg_question():
...
@@ -454,7 +443,6 @@ def edit_bg_question():
options
=
background_question_option
.
query
.
filter_by
(
background_question_idbackground_question
=
bg_question_id
).
all
()
options
=
background_question_option
.
query
.
filter_by
(
background_question_idbackground_question
=
bg_question_id
).
all
()
for
o
in
range
(
len
(
options
)):
for
o
in
range
(
len
(
options
)):
question_string
=
str
(
question_string
)
+
str
(
"
;
"
)
+
str
(
options
[
o
].
option
)
question_string
=
str
(
question_string
)
+
str
(
"
;
"
)
+
str
(
options
[
o
].
option
)
form
=
EditBackgroundQuestionForm
(
request
.
form
)
form
=
EditBackgroundQuestionForm
(
request
.
form
)
...
@@ -462,15 +450,12 @@ def edit_bg_question():
...
@@ -462,15 +450,12 @@ def edit_bg_question():
#After user chooses to update the question and options lets replace the old question and options with the ones from the form
#After user chooses to update the question and options lets replace the old question and options with the ones from the form
if
request
.
method
==
'
POST
'
and
form
.
validate
():
if
request
.
method
==
'
POST
'
and
form
.
validate
():
#Explode the string with new values from the form
#Explode the string with new values from the form
form_values
=
form
.
new_values
.
data
form_values
=
form
.
new_values
.
data
form_values_list
=
form_values
.
split
(
'
;
'
)
form_values_list
=
form_values
.
split
(
'
;
'
)
#Check and remove possible whitespaces from string beginnings with lstrip
#Check and remove possible whitespaces from string beginnings with lstrip
for
x
in
range
(
len
(
form_values_list
)):
for
x
in
range
(
len
(
form_values_list
)):
form_values_list
[
x
]
=
form_values_list
[
x
].
lstrip
()
form_values_list
[
x
]
=
form_values_list
[
x
].
lstrip
()
#Cycle through strings and update db
#Cycle through strings and update db
...
@@ -478,28 +463,16 @@ def edit_bg_question():
...
@@ -478,28 +463,16 @@ def edit_bg_question():
#Replace question and update the object to database
#Replace question and update the object to database
if
x
==
0
:
if
x
==
0
:
#flash("delete kys:")
#flash(current_bg_question.background_question)
#flash("insert kys:")
current_bg_question
.
background_question
=
form_values_list
[
x
]
current_bg_question
.
background_question
=
form_values_list
[
x
]
#flash(current_bg_question.background_question)
#flash(current_bg_question.idbackground_question)
#flash(current_bg_question.experiment_idexperiment)
db
.
session
.
commit
()
db
.
session
.
commit
()
#Delete old options from db
#Delete old options from db
for
o
in
options
:
for
o
in
options
:
db
.
session
.
delete
(
o
)
db
.
session
.
delete
(
o
)
db
.
session
.
commit
()
db
.
session
.
commit
()
#Insert new options to db
#Insert new options to db
else
:
else
:
#flash("insert opt:")
#flash(form_values_list[x])
new_option
=
background_question_option
(
background_question_idbackground_question
=
current_bg_question
.
idbackground_question
,
option
=
form_values_list
[
x
])
new_option
=
background_question_option
(
background_question_idbackground_question
=
current_bg_question
.
idbackground_question
,
option
=
form_values_list
[
x
])
db
.
session
.
add
(
new_option
)
db
.
session
.
add
(
new_option
)
db
.
session
.
commit
()
db
.
session
.
commit
()
...
@@ -522,14 +495,13 @@ def remove_bg_question():
...
@@ -522,14 +495,13 @@ def remove_bg_question():
else
:
else
:
# TODO: cannot remove background question if there are answers
# foreign key constraint fails!!!
# TODO: remove background_question_answer, background_question_options
# before removing background question
remove_id
=
request
.
args
.
get
(
'
idbackground_question
'
,
None
)
remove_id
=
request
.
args
.
get
(
'
idbackground_question
'
,
None
)
remove_options
=
background_question_option
.
query
.
filter_by
(
background_question_idbackground_question
=
remove_id
).
all
()
remove_options
=
background_question_option
.
query
.
filter_by
(
background_question_idbackground_question
=
remove_id
).
all
()
for
a
in
range
(
len
(
remove_options
)):
for
a
in
range
(
len
(
remove_options
)):
#flash(remove_options[a].idbackground_question_option)
db
.
session
.
delete
(
remove_options
[
a
])
db
.
session
.
delete
(
remove_options
[
a
])
db
.
session
.
commit
()
db
.
session
.
commit
()
...
@@ -544,7 +516,7 @@ def remove_bg_question():
...
@@ -544,7 +516,7 @@ def remove_bg_question():
# Rating set:
# Rating set
sliders/embody
:
@experiment_blueprint.route
(
'
/set_embody
'
)
@experiment_blueprint.route
(
'
/set_embody
'
)
@login_required
@login_required
...
@@ -568,13 +540,9 @@ def add_questions():
...
@@ -568,13 +540,9 @@ def add_questions():
exp_status
=
experiment
.
query
.
filter_by
(
idexperiment
=
exp_id
).
first
()
exp_status
=
experiment
.
query
.
filter_by
(
idexperiment
=
exp_id
).
first
()
if
exp_status
.
status
!=
'
Hidden
'
:
if
exp_status
.
status
!=
'
Hidden
'
:
flash
(
"
Experiment is public. Cannot modify structure.
"
)
flash
(
"
Experiment is public. Cannot modify structure.
"
)
return
redirect
(
url_for
(
'
experiment.view
'
,
exp_id
=
exp_id
))
return
redirect
(
url_for
(
'
experiment.view
'
,
exp_id
=
exp_id
))
else
:
else
:
form
=
CreateQuestionForm
(
request
.
form
)
form
=
CreateQuestionForm
(
request
.
form
)
if
request
.
method
==
'
POST
'
and
form
.
validate
():
if
request
.
method
==
'
POST
'
and
form
.
validate
():
...
@@ -583,28 +551,18 @@ def add_questions():
...
@@ -583,28 +551,18 @@ def add_questions():
str_list
=
str
.
split
(
'
/n
'
)
str_list
=
str
.
split
(
'
/n
'
)
for
a
in
range
(
len
(
str_list
)):
for
a
in
range
(
len
(
str_list
)):
list
=
str_list
[
a
].
split
(
'
;
'
)
list
=
str_list
[
a
].
split
(
'
;
'
)
#If there are the right amount of values for the slider input values
#If there are the right amount of values for the slider input values
if
len
(
list
)
==
3
:
if
len
(
list
)
==
3
:
#flash("Question:")
#flash(list[0])
#flash("Left:")
#flash(list[1])
#flash("Right:")
#flash(list[2])
add_question
=
question
(
experiment_idexperiment
=
exp_id
,
question
=
list
[
0
],
left
=
list
[
1
],
right
=
list
[
2
])
add_question
=
question
(
experiment_idexperiment
=
exp_id
,
question
=
list
[
0
],
left
=
list
[
1
],
right
=
list
[
2
])
db
.
session
.
add
(
add_question
)
db
.
session
.
add
(
add_question
)
db
.
session
.
commit
()
db
.
session
.
commit
()
#If slider has too many or too litlle parameters give an error and redirect back to input form
#If slider has too many or too litlle parameters give an error and redirect back to input form
else
:
else
:
flash
(
"
Error Each slider must have 3 parameters separated by ; Some slider has:
"
)
flash
(
"
Error Each slider must have 3 parameters separated by ; Some slider has:
"
)
flash
(
len
(
list
))
flash
(
len
(
list
))
return
redirect
(
url_for
(
'
create.experiment_questions
'
,
exp_id
=
exp_id
))
return
redirect
(
url_for
(
'
create.experiment_questions
'
,
exp_id
=
exp_id
))
return
redirect
(
url_for
(
'
experiment.view
'
,
exp_id
=
exp_id
))
return
redirect
(
url_for
(
'
experiment.view
'
,
exp_id
=
exp_id
))
...
@@ -646,6 +604,8 @@ def remove_question():
...
@@ -646,6 +604,8 @@ def remove_question():
remove_id
=
request
.
args
.
get
(
'
idquestion
'
,
None
)
remove_id
=
request
.
args
.
get
(
'
idquestion
'
,
None
)
remove_question
=
question
.
query
.
filter_by
(
idquestion
=
remove_id
).
first
()
remove_question
=
question
.
query
.
filter_by
(
idquestion
=
remove_id
).
first
()
# TODO: foreign key constraint fails!!!
# answers has reference to question -> remove answers first
db
.
session
.
delete
(
remove_question
)
db
.
session
.
delete
(
remove_question
)
db
.
session
.
commit
()
db
.
session
.
commit
()
...
@@ -653,8 +613,6 @@ def remove_question():
...
@@ -653,8 +613,6 @@ def remove_question():
# Stimuli:
# Stimuli:
@experiment_blueprint.route
(
'
/add_stimuli
'
,
methods
=
[
'
GET
'
,
'
POST
'
])
@experiment_blueprint.route
(
'
/add_stimuli
'
,
methods
=
[
'
GET
'
,
'
POST
'
])
...
@@ -669,7 +627,6 @@ def add_stimuli():
...
@@ -669,7 +627,6 @@ def add_stimuli():
return
redirect
(
url_for
(
'
experiment.view
'
,
exp_id
=
exp_id
))
return
redirect
(
url_for
(
'
experiment.view
'
,
exp_id
=
exp_id
))
else
:
else
:
#If there are no pages set for the experiment lets reroute user to create experiment stimuli upload instead
#If there are no pages set for the experiment lets reroute user to create experiment stimuli upload instead
is_there_any_stimuli
=
page
.
query
.
filter_by
(
experiment_idexperiment
=
exp_id
).
first
()
is_there_any_stimuli
=
page
.
query
.
filter_by
(
experiment_idexperiment
=
exp_id
).
first
()
if
is_there_any_stimuli
is
None
:
if
is_there_any_stimuli
is
None
:
...
@@ -680,21 +637,13 @@ def add_stimuli():
...
@@ -680,21 +637,13 @@ def add_stimuli():
if
request
.
method
==
'
POST
'
:
if
request
.
method
==
'
POST
'
:
if
stimulus_type
==
'
text
'
:
if
stimulus_type
==
'
text
'
:
#flash("db insert text")
string
=
form
.
text
.
data
string
=
form
.
text
.
data
str_list
=
string
.
split
(
'
/n
'
)
str_list
=
string
.
split
(
'
/n
'
)
for
a
in
range
(
len
(
str_list
)):
for
a
in
range
(
len
(
str_list
)):
#flash("lisättiin:")
#flash(str_list[a])
add_text_stimulus
=
page
(
experiment_idexperiment
=
exp_id
,
type
=
'
text
'
,
text
=
str_list
[
a
],
media
=
'
none
'
)
add_text_stimulus
=
page
(
experiment_idexperiment
=
exp_id
,
type
=
'
text
'
,
text
=
str_list
[
a
],
media
=
'
none
'
)
db
.
session
.
add
(
add_text_stimulus
)
db
.
session
.
add
(
add_text_stimulus
)
db
.
session
.
commit
()
db
.
session
.
commit
()
#flash("Succes!")
return
redirect
(
url_for
(
'
experiment.view
'
,
exp_id
=
exp_id
))
return
redirect
(
url_for
(
'
experiment.view
'
,
exp_id
=
exp_id
))
...
@@ -706,33 +655,20 @@ def add_stimuli():
...
@@ -706,33 +655,20 @@ def add_stimuli():
if
not
os
.
path
.
isdir
(
target
):
if
not
os
.
path
.
isdir
(
target
):
os
.
mkdir
(
target
)
os
.
mkdir
(
target
)
#flash("make dir")
#This returns a list of filenames: request.files.getlist("file")
#This returns a list of filenames: request.files.getlist("file")
for
file
in
request
.
files
.
getlist
(
"
file
"
):
for
file
in
request
.
files
.
getlist
(
"
file
"
):
#save files in the correct folder
#save files in the correct folder
#flash(file.filename)
filename
=
file
.
filename
filename
=
file
.
filename
destination
=
"
/
"
.
join
([
target
,
filename
])
destination
=
"
/
"
.
join
([
target
,
filename
])
#flash("destination")
#flash(destination)
file
.
save
(
destination
)
file
.
save
(
destination
)
#add pages to the db
#add pages to the db
db_path
=
path
+
str
(
'
/
'
)
+
str
(
filename
)
db_path
=
path
+
str
(
'
/
'
)
+
str
(
filename
)
#flash("db path")
#flash(db_path)
new_page
=
page
(
experiment_idexperiment
=
exp_id
,
type
=
form
.
type
.
data
,
media
=
db_path
)
new_page
=
page
(
experiment_idexperiment
=
exp_id
,
type
=
form
.
type
.
data
,
media
=
db_path
)
db
.
session
.
add
(
new_page
)
db
.
session
.
add
(
new_page
)
db
.
session
.
commit
()
db
.
session
.
commit
()
#flash("Succes!")
return
redirect
(
url_for
(
'
experiment.view
'
,
exp_id
=
exp_id
))
return
redirect
(
url_for
(
'
experiment.view
'
,
exp_id
=
exp_id
))
return
redirect
(
url_for
(
'
experiment.view
'
,
exp_id
=
exp_id
))
return
redirect
(
url_for
(
'
experiment.view
'
,
exp_id
=
exp_id
))
...
@@ -750,48 +686,30 @@ def edit_stimuli():
...
@@ -750,48 +686,30 @@ def edit_stimuli():
form
=
EditPageForm
(
request
.
form
,
obj
=
edit_page
)
form
=
EditPageForm
(
request
.
form
,
obj
=
edit_page
)
if
request
.
method
==
'
POST
'
and
form
.
validate
():
if
request
.
method
==
'
POST
'
and
form
.
validate
():
#If the stimulus type is not text, then the old stimulus file is deleted from os and replaced
#If the stimulus type is not text, then the old stimulus file is deleted from os and replaced
if
edit_page
.
type
!=
'
text
'
:
if
edit_page
.
type
!=
'
text
'
:
#remove old file
#remove old file
target
=
os
.
path
.
join
(
APP_ROOT
,
edit_page
.
media
)
target
=
os
.
path
.
join
(
APP_ROOT
,
edit_page
.
media
)
#flash("Remove:")
#flash(target)
os
.
remove
(
target
)
os
.
remove
(
target
)
#upload new file
#upload new file
path
=
'
static/experiment_stimuli/
'
+
str
(
exp_id
)
path
=
'
static/experiment_stimuli/
'
+
str
(
exp_id
)
target
=
os
.
path
.
join
(
APP_ROOT
,
path
)
target
=
os
.
path
.
join
(
APP_ROOT
,
path
)
#flash(target)
if
not
os
.
path
.
isdir
(
target
):
if
not
os
.
path
.
isdir
(
target
):
os
.
mkdir
(
target
)
os
.
mkdir
(
target
)
#flash("make dir")
#This returns a list of filenames: request.files.getlist("file")
#This returns a list of filenames: request.files.getlist("file")
for
file
in
request
.
files
.
getlist
(
"
file
"
):
for
file
in
request
.
files
.
getlist
(
"
file
"
):
#save files in the correct folder
#save files in the correct folder
#flash(file.filename)
filename
=
file
.
filename
filename
=
file
.
filename
destination
=
"
/
"
.
join
([
target
,
filename
])
destination
=
"
/
"
.
join
([
target
,
filename
])
#flash("destination")
#flash(destination)
file
.
save
(
destination
)
file
.
save
(
destination
)
#update db object
#update db object
db_path
=
path
+
str
(
'
/
'
)
+
str
(
filename
)
db_path
=
path
+
str
(
'
/
'
)
+
str
(
filename
)
#flash("db path")
#flash(db_path)
edit_page
.
media
=
db_path
edit_page
.
media
=
db_path
db
.
session
.
commit
()
db
.
session
.
commit
()
#flash("Succes!")
#If editing text stimulus no need for filehandling
#If editing text stimulus no need for filehandling
else
:
else
:
...
@@ -839,6 +757,8 @@ def remove_stimuli():
...
@@ -839,6 +757,8 @@ def remove_stimuli():
target
=
os
.
path
.
join
(
APP_ROOT
,
remove_page
.
media
)
target
=
os
.
path
.
join
(
APP_ROOT
,
remove_page
.
media
)
os
.
remove
(
target
)
os
.
remove
(
target
)
# TODO: foreign key constraint fails!!!
# answers has reference to page -> remove answers first
db
.
session
.
delete
(
remove_page
)
db
.
session
.
delete
(
remove_page
)
db
.
session
.
commit
()
db
.
session
.
commit
()
...
@@ -846,6 +766,8 @@ def remove_stimuli():
...
@@ -846,6 +766,8 @@ def remove_stimuli():
if
remove_page
.
type
==
'
text
'
:
if
remove_page
.
type
==
'
text
'
:
# TODO: foreign key constraint fails!!!
# answers has reference to page -> remove answers first
db
.
session
.
delete
(
remove_page
)
db
.
session
.
delete
(
remove_page
)
db
.
session
.
commit
()
db
.
session
.
commit
()
...
...
This diff is collapsed.
Click to expand it.
app/static/js/canvas.js
+
7
−
7
View file @
8c4ba60b
...
@@ -26,7 +26,7 @@ $(document).ready(function() {
...
@@ -26,7 +26,7 @@ $(document).ready(function() {
var
clickY
=
new
Array
();
var
clickY
=
new
Array
();
var
clickDrag
=
new
Array
();
var
clickDrag
=
new
Array
();
var
paint
;
var
paint
;
var
drawRadius
=
1
5
;
var
drawRadius
=
1
3
;
// Click handlers
// Click handlers
canvas
.
mousedown
(
function
(
e
){
canvas
.
mousedown
(
function
(
e
){
...
@@ -73,21 +73,21 @@ $(document).ready(function() {
...
@@ -73,21 +73,21 @@ $(document).ready(function() {
// Change brush size
// Change brush size
if
(
event
.
originalEvent
.
detail
>=
0
){
if
(
event
.
originalEvent
.
detail
>=
0
){
if
(
drawRadius
>=
1
5
)
{
if
(
drawRadius
>=
1
3
)
{
drawRadius
-=
5
;
drawRadius
-=
5
;
}
}
}
else
{
}
else
{
if
(
drawRadius
<=
1
5
)
{
if
(
drawRadius
<=
1
3
)
{
drawRadius
+=
5
;
drawRadius
+=
5
;
}
}
}
}
// Show brush size to user
// Show brush size to user
if
(
drawRadius
==
10
)
{
if
(
drawRadius
==
8
)
{
canvasInfo
.
html
(
"
small brush
"
)
canvasInfo
.
html
(
"
small brush
"
)
}
else
if
(
drawRadius
==
1
5
)
{
}
else
if
(
drawRadius
==
1
3
)
{
canvasInfo
.
html
(
"
normal brush
"
)
canvasInfo
.
html
(
"
normal brush
"
)
}
else
if
(
drawRadius
==
20
)
{
}
else
if
(
drawRadius
==
18
)
{
canvasInfo
.
html
(
"
large brush
"
)
canvasInfo
.
html
(
"
large brush
"
)
}
}
}
}
...
@@ -143,7 +143,7 @@ $(document).ready(function() {
...
@@ -143,7 +143,7 @@ $(document).ready(function() {
lastY
=
clickY
[
clickY
.
length
-
1
]
lastY
=
clickY
[
clickY
.
length
-
1
]
// Opacity (there was 0.2 opacity in the old version):
// Opacity (there was 0.2 opacity in the old version):
context
.
globalAlpha
=
0.
2
context
.
globalAlpha
=
0.
15
// Gradient:
// Gradient:
var
gradient
=
context
.
createRadialGradient
(
lastX
,
lastY
,
1
,
lastX
,
lastY
,
drawRadius
);
var
gradient
=
context
.
createRadialGradient
(
lastX
,
lastY
,
1
,
lastX
,
lastY
,
drawRadius
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment