There will be a short maintenance break on Wed 27.10. at 12:00. Estimated time 30 minutes.

Commit 5bc65185 authored by Ossi Laine's avatar Ossi Laine
Browse files

Cleaning codebase, removed unnecessary migrations folder

parent ef9a7efa
...@@ -2,13 +2,13 @@ import os ...@@ -2,13 +2,13 @@ import os
from datetime import datetime from datetime import datetime
from flask import ( from flask import (
Flask, Flask,
render_template, render_template,
request, request,
session, session,
flash, flash,
redirect, redirect,
url_for, url_for,
Blueprint Blueprint
) )
...@@ -23,44 +23,33 @@ from app.models import background_question_option ...@@ -23,44 +23,33 @@ from app.models import background_question_option
from app.models import answer_set, answer, forced_id from app.models import answer_set, answer, forced_id
from app.models import user, trial_randomization from app.models import user, trial_randomization
from app.forms import ( from app.forms import (
CreateExperimentForm, CreateBackgroundQuestionForm, CreateExperimentForm, CreateBackgroundQuestionForm,
CreateQuestionForm, UploadStimuliForm CreateQuestionForm, UploadStimuliForm
) )
create_blueprint = Blueprint("create", __name__, create_blueprint = Blueprint("create", __name__,
template_folder='templates', template_folder='templates',
#static_folder='static', # static_folder='static',
url_prefix='/create') url_prefix='/create')
@create_blueprint.route('/experiment', methods=['GET', 'POST']) @create_blueprint.route('/experiment', methods=['GET', 'POST'])
@login_required @login_required
def create_experiment(): def create_experiment():
form = CreateExperimentForm(request.form) form = CreateExperimentForm(request.form)
if request.method == 'POST' and form.validate(): if request.method == 'POST' and form.validate():
the_time = datetime.now() the_time = datetime.now()
the_time = the_time.replace(microsecond=0) the_time = the_time.replace(microsecond=0)
new_exp = experiment(name=request.form['name'], instruction=request.form['instruction'], language=request.form['language'], status='Hidden', randomization='Off', single_sentence_instruction=request.form['single_sentence_instruction'], short_instruction=request.form['short_instruction'], creator_name=request.form['creator_name'], is_archived='False', creation_time=the_time, stimulus_size='7', consent_text=request.form['consent_text'], use_forced_id='Off') new_exp = experiment(name=request.form['name'], instruction=request.form['instruction'], language=request.form['language'], status='Hidden', randomization='Off', single_sentence_instruction=request.form['single_sentence_instruction'],
short_instruction=request.form['short_instruction'], creator_name=request.form['creator_name'], is_archived='False', creation_time=the_time, stimulus_size='7', consent_text=request.form['consent_text'], use_forced_id='Off')
db.session.add(new_exp) db.session.add(new_exp)
db.session.commit() db.session.commit()
exp_id = new_exp.idexperiment exp_id = new_exp.idexperiment
#data = request.form.to_dict()
#for key, value in data.items():
#tähän db insertit
#flash(key)
#flash(value)
#flash('{}'.format(form.name.data))
#Input registration page answers to database
# participant_background_question_answers = background_question_answer(answer_set_idanswer_set=session['answer_set'], answer=value, background_question_idbackground_question=key)
# db.session.add(participant_background_question_answers)
# db.session.commit()
return redirect(url_for('create.experiment_bgquestions', exp_id=exp_id)) return redirect(url_for('create.experiment_bgquestions', exp_id=exp_id))
return render_template('create_experiment.html', form=form) return render_template('create_experiment.html', form=form)
...@@ -69,36 +58,38 @@ def create_experiment(): ...@@ -69,36 +58,38 @@ def create_experiment():
@create_blueprint.route('/experiment_bgquestions', methods=['GET', 'POST']) @create_blueprint.route('/experiment_bgquestions', methods=['GET', 'POST'])
@login_required @login_required
def experiment_bgquestions(): def experiment_bgquestions():
exp_id = request.args.get('exp_id', None) exp_id = request.args.get('exp_id', None)
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 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_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:
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:
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()
return redirect(url_for('create.experiment_questions', exp_id=exp_id)) return redirect(url_for('create.experiment_questions', exp_id=exp_id))
return render_template('create_experiment_bgquestions.html', form=form, exp_id=exp_id) return render_template('create_experiment_bgquestions.html', form=form, exp_id=exp_id)
...@@ -107,7 +98,7 @@ def experiment_bgquestions(): ...@@ -107,7 +98,7 @@ def experiment_bgquestions():
@login_required @login_required
def experiment_questions(): def experiment_questions():
"""Add slider questions""" """Add slider questions"""
exp_id = request.args.get('exp_id', None) exp_id = request.args.get('exp_id', None)
form = CreateQuestionForm(request.form) form = CreateQuestionForm(request.form)
...@@ -116,86 +107,87 @@ def experiment_questions(): ...@@ -116,86 +107,87 @@ def experiment_questions():
str = form.questions_and_options.data str = form.questions_and_options.data
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 wrong amount of values for any of the the slider input values # If there are the wrong amount of values for any of the the slider input values
#redirect back to the form # redirect back to the form
if len(list) != 3: if len(list) != 3:
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))
#If all the slider inputs were of length 3 items # If all the slider inputs were of length 3 items
#we can input them to db # we can input them to db
for a in range(len(str_list)): for a in range(len(str_list)):
list = str_list[a].split(';') list = str_list[a].split(';')
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()
return redirect(url_for('create.experiment_upload_stimuli', exp_id=exp_id)) return redirect(url_for('create.experiment_upload_stimuli', exp_id=exp_id))
@create_blueprint.route('/experiment_upload_stimuli', methods=['GET', 'POST']) @create_blueprint.route('/experiment_upload_stimuli', methods=['GET', 'POST'])
@login_required @login_required
def experiment_upload_stimuli(): def experiment_upload_stimuli():
"""Upload stimuli""" """Upload stimuli"""
exp_id = request.args.get('exp_id', None) exp_id = request.args.get('exp_id', None)
form = UploadStimuliForm(request.form) form = UploadStimuliForm(request.form)
if request.method == 'POST' and form.validate(): if request.method == 'POST' and form.validate():
#If stimulus type is text lets parse the information and insert it to database # If stimulus type is text lets parse the information and insert it to database
if form.type.data == 'text': if form.type.data == '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)):
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()
return redirect(url_for('experiment.view', exp_id=exp_id)) return redirect(url_for('experiment.view', exp_id=exp_id))
else: else:
#Upload stimuli into /static/experiment_stimuli/exp_id folder # Upload stimuli into /static/experiment_stimuli/exp_id folder
#Create the pages for the stimuli by inserting experiment_id, stimulus type, text and names of the stimulus files (as a path to the folder) # Create the pages for the stimuli by inserting experiment_id, stimulus type, text and names of the stimulus files (as a path to the folder)
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)
if not os.path.isdir(target): if not os.path.isdir(target):
os.mkdir(target) os.mkdir(target)
#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
filename = file.filename filename = file.filename
destination = "/".join([target, filename]) destination = "/".join([target, filename])
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)
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!") # 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('create.experiment_upload_stimuli', exp_id=exp_id)) return redirect(url_for('create.experiment_upload_stimuli', exp_id=exp_id))
return render_template('create_experiment_upload_stimuli.html', form=form) return render_template('create_experiment_upload_stimuli.html', form=form)
# EOF
\ No newline at end of file
...@@ -731,7 +731,6 @@ def remove_embody(): ...@@ -731,7 +731,6 @@ def remove_embody():
# Stimuli: # Stimuli:
@experiment_blueprint.route('/add_stimuli', methods=['GET', 'POST']) @experiment_blueprint.route('/add_stimuli', methods=['GET', 'POST'])
@login_required @login_required
def add_stimuli(): def add_stimuli():
...@@ -1045,13 +1044,11 @@ def remove_rows(rows): ...@@ -1045,13 +1044,11 @@ def remove_rows(rows):
@socketio.on('connect', namespace="/create_embody") @socketio.on('connect', namespace="/create_embody")
def start_create_embody(): def start_create_embody():
print('io connected')
emit('success', {'connection': 'on'}) emit('success', {'connection': 'on'})
@socketio.on('draw', namespace="/create_embody") @socketio.on('draw', namespace="/create_embody")
def create_embody(meta): def create_embody(meta):
print("draw initialized")
page = meta["page"] page = meta["page"]
embody = meta["embody"] embody = meta["embody"]
img_path = embody_plot.get_coordinates(page, embody) img_path = embody_plot.get_coordinates(page, embody)
...@@ -1061,7 +1058,6 @@ def create_embody(meta): ...@@ -1061,7 +1058,6 @@ def create_embody(meta):
@socketio.on('connect', namespace="/download_csv") @socketio.on('connect', namespace="/download_csv")
def start_download_csv(): def start_download_csv():
print('io connected')
emit('success', {'connection': 'Start generating CSV file'}) emit('success', {'connection': 'Start generating CSV file'})
......
...@@ -19,46 +19,47 @@ class LoginForm(FlaskForm): ...@@ -19,46 +19,47 @@ class LoginForm(FlaskForm):
class RegisterForm(Form): class RegisterForm(Form):
questions1 = FieldList(SelectField([validators.InputRequired()])) questions1 = FieldList(SelectField([validators.InputRequired()]))
submit = SubmitField("Send") submit = SubmitField("Send")
class TaskForm(Form): class TaskForm(Form):
__name__= 'slider' __name__ = 'slider'
categories1 = FieldList(SelectField([validators.InputRequired()])) categories1 = FieldList(SelectField([validators.InputRequired()]))
submit = SubmitField("Send") submit = SubmitField("Send")
class StringForm(Form): class StringForm(Form):
__name__= 'embody' __name__ = 'embody'
text = StringField() text = StringField()
submit = SubmitField("Send") submit = SubmitField("Send")
class ContinueTaskForm(FlaskForm): class ContinueTaskForm(FlaskForm):
participant_id = StringField('participant_id', validators=[DataRequired()]) participant_id = StringField('participant_id', validators=[DataRequired()])
submit = SubmitField( _l('Continue rating') ) submit = SubmitField(_l('Continue rating'))
class StartWithIdForm(FlaskForm): class StartWithIdForm(FlaskForm):
participant_id = StringField('participant_id', validators=[DataRequired()]) participant_id = StringField('participant_id', validators=[DataRequired()])
submit = SubmitField( _l('Start rating') ) submit = SubmitField(_l('Start rating'))
class Questions(FlaskForm): class Questions(FlaskForm):
questions = StringField() questions = StringField()
class Answers(FlaskForm): class Answers(FlaskForm):
background_question_idbackground_question = SelectField(coerce=int, validators=[InputRequired]) background_question_idbackground_question = SelectField(
coerce=int, validators=[InputRequired])
class BackgroundQuestionForm(Form): class BackgroundQuestionForm(Form):
idbackground_question_option = StringField() idbackground_question_option = StringField()
background_question_idbackground_question = StringField() background_question_idbackground_question = StringField()
option = StringField() option = StringField()
...@@ -66,13 +67,13 @@ class BackgroundQuestionForm(Form): ...@@ -66,13 +67,13 @@ class BackgroundQuestionForm(Form):
class TestForm(Form): class TestForm(Form):
question_name = StringField() question_name = StringField()
options1 = SelectField() options1 = SelectField()
class TestForm1(Form): class TestForm1(Form):
questions1 = FieldList(SelectField([validators.InputRequired()])) questions1 = FieldList(SelectField([validators.InputRequired()]))
submit = SubmitField("Send") submit = SubmitField("Send")
...@@ -82,14 +83,16 @@ class TestForm2(Form): ...@@ -82,14 +83,16 @@ class TestForm2(Form):
questions1 = SelectField() questions1 = SelectField()
#Forms for editing functions # Forms for editing functions
class CreateExperimentForm(Form): class CreateExperimentForm(Form):
name = StringField('Name', [validators.DataRequired()]) name = StringField('Name', [validators.DataRequired()])
creator_name = StringField('Creator_name', [validators.DataRequired()]) creator_name = StringField('Creator_name', [validators.DataRequired()])
single_sentence_instruction = StringField('Single_sentence_instruction', [validators.DataRequired()]) single_sentence_instruction = StringField(
short_instruction = TextAreaField('Short_instruction', [validators.DataRequired()]) 'Single_sentence_instruction', [validators.DataRequired()])
short_instruction = TextAreaField(
'Short_instruction', [validators.DataRequired()])
instruction = TextAreaField('Instruction', [validators.DataRequired()]) instruction = TextAreaField('Instruction', [validators.DataRequired()])
consent_text = TextAreaField('Instruction', [validators.DataRequired()]) consent_text = TextAreaField('Instruction', [validators.DataRequired()])
language = StringField('Language', [validators.DataRequired()]) language = StringField('Language', [validators.DataRequired()])
...@@ -102,53 +105,68 @@ class EditExperimentForm(Form): ...@@ -102,53 +105,68 @@ class EditExperimentForm(Form):
creator_name = StringField('Creator_name', [validators.DataRequired()]) creator_name = StringField('Creator_name', [validators.DataRequired()])
instruction = TextAreaField('Instruction', [validators.DataRequired()]) instruction = TextAreaField('Instruction', [validators.DataRequired()])
consent_text = TextAreaField('Instruction', [validators.DataRequired()]) consent_text = TextAreaField('Instruction', [validators.DataRequired()])
short_instruction = TextAreaField('Short_instruction', [validators.DataRequired()]) short_instruction = TextAreaField(
single_sentence_instruction = StringField('Single_sentece_instruction', [validators.DataRequired()]) 'Short_instruction', [validators.DataRequired()])
single_sentence_instruction = StringField(
'Single_sentece_instruction', [validators.DataRequired()])
language = SelectField('Language', choices=[ language = SelectField('Language', choices=[
('Afrikanns', 'Afrikanns'), ('Albanian', 'Albanian'), ('Arabic', 'Arabic'), ('Armenian', 'Armenian'), ('Basque', 'Basque'), ('Bengali', 'Bengali'), ('Bulgarian', 'Bulgarian'), ('Afrikanns', 'Afrikanns'), ('Albanian', 'Albanian'), ('Arabic', 'Arabic'), ('Armenian',
('Catalan', 'Catalan'), ('Cambodian', 'Cambodian'), ('Chinese', 'Chinese'), ('Croation', 'Croation'), ('Czech', 'Czech'), ('Danish', 'Danish'), 'Armenian'), ('Basque', 'Basque'), ('Bengali', 'Bengali'), ('Bulgarian', 'Bulgarian'),
('Dutch', 'Dutch'), ('English', 'English'), ('Estonian', 'Estonian'), ('Fiji', 'Fiji'), ('Finnish', 'Finnish'), ('French', 'French'), ('Georgian', 'Georgian'), ('Catalan', 'Catalan'), ('Cambodian', 'Cambodian'), ('Chinese',
('German', 'German'), ('Greek', 'Greek'), ('Gujarati', 'Gujarati'), ('Hebrew', 'Hebrew'), ('Hindi', 'Hindi'), ('Hungarian', 'Hungarian'), ('Icelandic', 'Icelandic'), 'Chinese'), ('Croation', 'Croation'), ('Czech', 'Czech'), ('Danish', 'Danish'),
('Indonesian', 'Indonesian'), ('Irish', 'Irish'), ('Italian', 'Italian'), ('Japanese', 'Japanese'), ('Javanese', 'Javanese'), ('Korean', 'Korean'), ('Latin', 'Latin'), ('Dutch', 'Dutch'), ('English', 'English'), ('Estonian', 'Estonian'), ('Fiji',
('Latvian', 'Latvian'), ('Lithuanian', 'Lithuanian'), ('Macedonian', 'Macedonian'), ('Malay', 'Malay'), ('Malayalam', 'Malayalam'), ('Maltese', 'Maltese'), ('Maori', 'Maori'), 'Fiji'), ('Finnish', 'Finnish'), ('French', 'French'), ('Georgian', 'Georgian'),
('Marathi', 'Marathi'), ('Mongolian', 'Mongolian'), ('Nepali', 'Nepali'), ('Norwegian', 'Norwegian'), ('Persian', 'Persian'), ('Polish', 'Polish'), ('Portuguese', 'Portuguese'), ('German', 'German'), ('Greek', 'Greek'), ('Gujarati', 'Gujarati'), ('Hebrew',
('Punjabi', 'Punjabi'), ('Quechua', 'Quechua'), ('Romanian', 'Romanian'), ('Russian', 'Russian'), ('Samoan', 'Samoan'), ('Serbian', 'Serbian'), ('Slovak', 'Slovak'), 'Hebrew'), ('Hindi', 'Hindi'), ('Hungarian', 'Hungarian'), ('Icelandic', 'Icelandic'),
('Slovenian', 'Slovenian'), ('Spanish', 'Spanish'), ('Swahili', 'Swahili'), ('Swedish ', 'Swedish '), ('Tamil', 'Tamil'), ('Tatar', 'Tatar'), ('Telugu', 'Telugu'), ('Indonesian', 'Indonesian'), ('Irish', 'Irish'), ('Italian', 'Italian'), ('Japanese',
('Thai', 'Thai'), ('Tibetan', 'Tibetan'), ('Tonga', 'Tonga'), ('Turkish', 'Turkish'), ('Ukranian', 'Ukranian'), ('Urdu', 'Urdu'), ('Uzbek', 'Uzbek'), ('Vietnamese', 'Vietnamese'), 'Japanese'), ('Javanese', 'Javanese'), ('Korean', 'Korean'), ('Latin', 'Latin'),
('Welsh', 'Welsh'), ('Xhosa', 'Xhosa')]) ('Latvian', 'Latvian'), ('Lithuanian', 'Lithuanian'), ('Macedonian', 'Macedonian'), ('Malay',
'Malay'), ('Malayalam', 'Malayalam'), ('Maltese', 'Maltese'), ('Maori', 'Maori'),
('Marathi', 'Marathi'), ('Mongolian', 'Mongolian'), ('Nepali', 'Nepali'), ('Norwegian',
'Norwegian'), ('Persian', 'Persian'), ('Polish', 'Polish'), ('Portuguese', 'Portuguese'),
('Punjabi', 'Punjabi'), ('Quechua', 'Quechua'), ('Romanian', 'Romanian'), ('Russian',
'Russian'), ('Samoan', 'Samoan'), ('Serbian', 'Serbian'), ('Slovak', 'Slovak'),
('Slovenian', 'Slovenian'), ('Spanish', 'Spanish'), ('Swahili', 'Swahili'), ('Swedish ',
'Swedish '), ('Tamil', 'Tamil'), ('Tatar', 'Tatar'), ('Telugu', 'Telugu'),
('Thai', 'Thai'), ('Tibetan', 'Tibetan'), ('Tonga', 'Tonga'), ('Turkish', 'Turkish'), ('Ukranian',
'Ukranian'), ('Urdu', 'Urdu'), ('Uzbek', 'Uzbek'), ('Vietnamese', 'Vietnamese'),
('Welsh', 'Welsh'), ('Xhosa', 'Xhosa')])
stimulus_size = SelectField('Stimulus_size', choices=[ stimulus_size = SelectField('Stimulus_size', choices=[
('1', '1'), ('2', '2'), ('3', '3'), ('4', '4'), ('5', '5'), ('6', '6'), ('7', '7'), ('8', '8'), ('9', '9'), ('10', '10'), ('11', '11'), ('12', '12')]) ('1', '1'), ('2', '2'), ('3', '3'), ('4', '4'), ('5', '5'), ('6', '6'), ('7', '7'), ('8', '8'), ('9', '9'), ('10', '10'), ('11', '11'), ('12', '12')])
submit = SubmitField('Send') submit = SubmitField('Send')
class CreateBackgroundQuestionForm(Form): class CreateBackgroundQuestionForm(Form):
bg_questions_and_options = TextAreaField('Background questions and options', [validators.DataRequired()]) bg_questions_and_options = TextAreaField(
'Background questions and options', [validators.DataRequired()])
submit = SubmitField('Send') submit = SubmitField('Send')
class EditBackgroundQuestionForm(Form): class EditBackgroundQuestionForm(Form):
bg_questions_and_options = TextAreaField('Background questions and options') bg_questions_and_options = TextAreaField(
'Background questions and options')
new_values = TextAreaField('New values', [validators.DataRequired()]) new_values = TextAreaField('New values', [validators.DataRequired()])
submit = SubmitField('Send') submit = SubmitField('Send')
class CreateQuestionForm(Form): class CreateQuestionForm(Form):
questions_and_options = TextAreaField('Questions and options', [validators.DataRequired()])