Creating Editing Questionnaires - compsy/u-can-act GitHub Wiki
Creating a questionnaire on the u-can-act platform involves a number of steps.
You need a plain text text editor. For example, Notepad in Windows. Because the questionnaire files should be stored as plain text (not .docx, .rtf, or anything with formatting). If you can use an editor with syntax highlighting for ruby code, it will probably save you some errors.
The filenames of questionnaire files should consist only of (a-z) characters, and the undersscore (_), and should have the extension .rb
. So e.g., the following are valid questionnaire file names: ouders_vragenlijst_start.rb
, gevoelens.rb
, persoonlijke_intelligentie.rb
. And the following file names are not valid: Ouders.rb
, ouders_vragenlijst
, vragenlijst.txt
, ouders gevoelens.rb
.
When creating a new questionnaire, put the following lines at the top of the file:
# frozen_string_literal: true
db_title = 'Eetgedrag van mijn kind'
db_name1 = 'Eetgedrag_Kinderen_Ouderrapportage_4tot11'
dagboek1 = Questionnaire.find_by_key(File.basename(__FILE__)[0...-3])
dagboek1 ||= Questionnaire.new(key: File.basename(__FILE__)[0...-3])
dagboek1.name = db_name1
dagboek_content = [
]
In the above example, please replace Eetgedrag van mijn kind
with the title of the questionnaire (visible to users), and replace Eetgedrag_Kinderen_Ouderrapportage_4tot11
with an internal name you may use for the questionnaire.
At the end of the file, put the following lines:
dagboek1.content = { questions: dagboek_content, scores: [] }
dagboek1.title = db_title
dagboek1.save!
These are the same for every questionnaire (unless you're defining scores, but that's not covered in this tutorial).
The interesting part is the lines with dagboek_content = [ ]
above. This sets the local variable dagboek_content
up as an array of questions for your questionnaire.
- For a 'demo' questionnaire that shows most supported question types, see https://github.com/compsy/u-can-act/blob/develop/projects/demo/seeds/questionnaires/demo.rb
- For more examples, see https://github.com/compsy/u-can-act/tree/develop/projects/Evaluatieonderzoek/seeds/questionnaires or https://github.com/compsy/u-can-act/tree/develop/projects/ikia/seeds/questionnaires or https://github.com/compsy/u-can-act/tree/develop/projects/u-can-act/seeds/questionnaires
- To see all the types of questions that are supported, please see the readme on questionnaire types.
After you filled up the dagboek_content
of your questionnaire with question definitions, it is time to preview your questionnaire.
First, we need to convert the dagboek_content
to JSON. Go to https://repl.it/languages/ruby , paste the whole dagboek_content = [ { (...) } ]
block there, and at the bottom add the following line:
puts dagboek_content.to_json
Then click the Run button, and on the right the JSON definition should appear. Copy this definition to the clipboard, go to https://app.u-can-act.nl/questionnaire/interactive , and paste the contents there and click 'submit'.
This should show a preview of your questionnaire that is fully functional (even the conditional and expandable questions should work correctly), and also, it performs some checks on the syntax of your questionnaire and will notify you of any errors found.
A few notes
- You can use special characters such as é ë ü and so on in the questionnaire texts. But you have to save the file in UTF-8 format. The questionnaire previewer doesn't support showing special characters right now, because of the added translation step, but they will show up in the actual questionnaire.
- Sometimes in the questionnaire definition you see
<p class="flow-text">Some text.</p>
. Theflow-text
class is used to scale the text to the width of the window. So it tries to make text bigger on desktops and smaller on phones, rather than have one static textsize for all screen sizes. Most questionnaires will use the flow-text class everywhere, but if you have a paragraph where you think the text-size will be too large, then you can just use<p>
without the flow-text class there. - The variable
dagboek1
is a local variable. You don't need to change it to dagboek2 or something. It is overwritten for each questionnaire so it can bedagboek1
everywhere. - If you have a bunch of questions that reuse the same options or labels, you can put those in a variable like this:
likert_options = ['bijna nooit waar', 'meestal niet waar', 'soms waar, soms niet waar', 'meestal wel waar', 'bijna altijd waar']
dagboek_content = [
{
type: :raw,
content: '<p class="flow-text">Hieronder staan 65 uitspraken die je kunt gebruiken om jezelf te beschrijven.<br>
We willen graag dat je voor elke uitspraak invult of de uitspraak waar is voor jou.<br>
Lees iedere uitspraak goed en kies dan het antwoord dat <u>het beste bij jou past</u>.<br>
Er zijn geen goede of foute antwoorden.<br><br>
Hoe waar is elke uitspraak voor jou?</p>'
}, {
id: :v1,
type: :likert,
title: 'Ik vind het makkelijk om mijn gedachten goed bij mijn huiswerk te houden (huiswerk is thuis een
opdracht maken voor school, bijvoorbeeld een toets leren of een spreekbeurt maken)',
options: likert_options
}, {
id: :v2,
type: :likert,
title: 'Het grootste deel van de dag voel ik me wel gelukkig',
options: likert_options
}, {
id: :v3,
type: :likert,
title: 'Ik zou het spannend vinden om naar een nieuwe plaats te verhuizen',
options: likert_options
}, {
id: :v4,
type: :likert,
title: 'Ik vind het fijn om een warme wind in mijn gezicht te voelen waaien',
options: likert_options
}]
Be sure to also copy over the lines with variable definitions to the repl.it ruby interpreter (and it should precede the dagboek_content = [
line), otherwise it will give an error.
Please do not add numbering in the titles of the questions themselves. I.e., don't do this:
{
id: :v4,
type: :likert,
title: '4. Ik vind het fijn om een warme wind in mijn gezicht te voelen waaien',
options: likert_options
}
If numbering is needed, we can do it through software, but in practice we don't use numbering because it can get confusing when you have conditionally shown questions. We find in most cases it's better not to show question numbers.
The last question in the question array doesn't need a comma behind it, so if you see anything that looks like this:
bla: blaat
},
]
You can remove the comma.