Actions

ExpressionScript Engine - Quick start guide/nl: Difference between revisions

From LimeSurvey Manual

m (FuzzyBot moved page Expression Manager - quick start guide/nl to ExpressionScript Engine - Quick start guide/nl without leaving a redirect: Part of translatable page "Expression Manager - quick start guide")
(Updating to match new version of source page)
Line 4: Line 4:




=Snelstartgids=
=Quick start guide=




In [https://www.limesurvey.org LimeSurvey] kun je een enquête verder aanpassen door gebruik te maken van Expressiebeheer (EM).
Within [https://www.limesurvey.org LimeSurvey], you can further customize your surveys via the usage of the ExpressionScript (short: ES).
NB: De nieuwe naam van dit onderdeel wordt ExpressionScript (ES).
Sidenote: "ExpressionScript was named Expression Manager (EM) in earlier version. If you read Expression Manager somewhere, it is just the old name of ES."


Je kunt hiermee het volgende bepalen:
ES can be used to specify the following:


# '''Navigatie/Vertakking''' : door de antwoorden van de deelnemer kan de volgorde van de vragen worden gewijzigd.
# '''Navigation/Branching''' - allows a respondent's answers to change the order in which the questions are displayed;
# '''Maatwerk''' : je kunt de vraag opmaken. Bijvoorbeeld antwoorden op eerdere vragen gebruiken, of zinnen opbouwen met een vervoeging van gegevens van de deelnemer (bijvoorbeeld leeftijd of sekse) of bepalen hoe een rapport (beoordelingsscore of maatadvies) wordt samengesteld.
# '''Tailoring/Piping''' - helps you phrase the question (such as referring to prior answers, or conjugating sentences based upon the age or gender of your subjects) or how to generate custom reports (like assessment scores or tailored advice);
# '''Validatie''' : ervoor zorgen dat de antwoorden aan gestelde voorwaarden voldoen, zoals een minimum of een maximum of voldoen aan een patroon.
# '''Validation''' - ensures that answers pass certain criteria, like min and max values or a certain input pattern.


In EM wordt een eenvoudige manier gebruikt om deze functies te specificeren. Bijna alles wat je kunt schrijven als een standaard mathematische vergelijking is een geldige expressie.  
ES provides an intuitive way to specify the logic for each of those features. Nearly anything that you can write as a standard mathematical equation is a valid expression.  


EM ondersteunt op dit moment 70 functies, bovendien kunnen er eenvoudig meer functies ondersteunt worden. Je hebt ook toegang tot variabelen met leesbare namen (anders dan bij [[SGQA_identifier/nl|SGQA-identifiers]]).
ES currently provides access to 70 functions and it can be easily extended to support more. It also lets you access you
variables using human-readable variable names (rather than [[SGQA_identifier|SGQA names]]).


Hieronder beschrijven we waar EM meestal voor wordt gebruikt.
The upcoming sections show the main places where the ES is used.




==Relevantie (Controle Navigatie/Vertakking)==
==Relevance (Controlling Navigation/Branching)==




Bij sommige enquête-systemen wordt een "Goto Logic" gebruikt, als de deelnemer bij Vraag1 optie C kiest, ga dan naar Vraag5. Het controleren van een dergelijke enquête is lastig. Ook bij het verplaatsen van vragen kan er gemakkelijk iets verkeerd gaan waardoor de enquête niet meer werkt. In LimeSurvey wordt de EM gebruikt waardoor er gebruikt gemaakt wordt van [https://nl.wikipedia.org/wiki/Booleaanse_algebra Booleanse algebra] om de condities te specificeren wanneer een vraag getoond moet worden. Alleen als de vraag relevant is wordt de vraag getoond. Als de vraag niet relevant is, dan wordt die niet getoond en wordt de waarde "NULL" vastgelegd in de database.  
Some surveys use "Goto Logic", such that if you answer Question1 with option C, you are redirected to Question5. This approach is very limited since it is hard to validate it. Moreover, it easily breaks when you have to reorder questions. On the other hand, ES uses [https://en.wikipedia.org/wiki/Boolean_algebra Boolean relevance equations] to specify all the conditions under which a question might be valid. If the question is relevant, then the question is shown, otherwise, it is not applicable, and the value "NULL" is stored in the database.  


<div class='simplebox'> '''NB:''' Dit kan op een vergelijkbare manier in de [[Setting conditions/nl|Conditie-editor]] worden gedaan, maar in  EM kun je gemakkelijk meer complexe en krachtige criteria gebruiken (en dan met een variabele-naam in plaats van een SGQA-identifier).</div>
<div class='simplebox'> '''Note:''' This is similar to what can be done via the [[Setting conditions|Conditions editor]], but ES lets you easily specify much more complex and powerful criteria (and lets you use the variable name rather than SGQA identifiers).</div>




Line 34: Line 35:




Om het begrip relevantie beter te begrijpen, gebruiken we een voorbeeld met een enquête waarin de BMI (Body Mass Index) wordt bepaald van de deelnemer. [[Media:EM_survey_-_Cohabs.zip|Voorbeeld downloaden]].
To better understand the relevance concept, let's focus on the following survey which computes the Body Mass Index (BMI) of survey respondents. To download it, click on the following link: [[Media:ES_survey_-_Cohabs.zip|Body Mass Index survey example]].


De relevantievergelijking staat in de kolom '''Relevantie'''. De waarde is hier bij de variabelen weight, weight_units, height en height_units altijd 1 (standaardwaarde), dat geeft aan dat de vraag wordt getoond. De relevantie bij BMI is {!is_empty(height) and !is_empty(weight)}, dat betekent dat de BMI alleen wordt bepaald als zowel height en weight een waarde hebben (geen 0). Ook de vraag "Report" wordt alleen getoond als de deelnemer alle 4 vragen heeft ingevuld (height, heightunits, weight en weightunits).
De relevantievergelijking staat in de kolom '''Relevantie'''. De waarde is hier bij de variabelen weight, weight_units, height en height_units altijd 1 (standaardwaarde), dat geeft aan dat de vraag wordt getoond. De relevantie bij BMI is {!is_empty(height) and !is_empty(weight)}, dat betekent dat de BMI alleen wordt bepaald als zowel height en weight een waarde hebben (geen 0). Ook de vraag "Report" wordt alleen getoond als de deelnemer alle 4 vragen heeft ingevuld (height, heightunits, weight en weightunits).
Line 42: Line 43:




<div class="simplebox"> [[File:help.png]] '''NB:''' Het bovenstaand plaatje staat in het [[Show logic file/nl|enquête logica-bestand]], de  functie om de enquête op syntaxfouten te controleren voor het activeren.</div>
<div class="simplebox"> [[File:help.png]] '''Note:''' The above image comes from the [[Show logic file|survey logic file]] which allows you to look for syntax errors before activating the survey.</div>




Line 50: Line 51:




===Bekijken / Wijzigen relevantie op vraagniveau===
===Viewing / Editing Question-Level Relevance===




Deze vergelijking bepaalt de index voor het lichaamsgewicht (BMI). De vraag wordt alleen getoond als de deelnemer eerst het gewicht en de lengte heeft ingevuld.
This equation computes the Body Mass Index (BMI). It is only asked if the person enters their height and weight.




Line 59: Line 60:




Het wijzigscherm voor de vraag over het BMI.
This is the edit screen for the "BMI" question.




Line 65: Line 66:




De accolades worden niet gebruikt als je een relevantievergelijking invult.
Note that you do not use the curly braces when you enter a relevance equation.




===Bekijken / Wijzigen relevantie op groepsniveau===
===Viewing / Editing Group-Level Relevance===




We gebruiken nu een voorbeeld met een eenvoudige telling. [[Media:EM survey - Cohabs.zip|Voorbeeld downloaden]].  
Let's focus now on another example - a simple census survey. To download it, click on the following link: [[Media:ES survey - Cohabs.zip|Census survey example]].  


Op de beginpagina vragen we met hoeveel mensen je, de deelnemer, samenleeft, hiervoor we gebruiken we de variabele ''cohabs''. De volgende pagina wordt alleen getoond als je met iemand samenleeft. De velden p2name, p2age. p2sum worden ook alleen dan getoond als er een respons is.
The first page asks how many people live with you and stores that in the "cohabs" variable. This page is only shown if you have more than one cohabitant (it is shown for the second person cohabitating with you). Also, p2name, p2age. p2sum are displayed only if the question before each of them contains a response.




Line 79: Line 80:




Zoals je kunt zien, heeft de groep ook relevantie-criteria op vraagniveau. Een vraag wordt soms alleen gesteld als je een bepaalde voorgaande vraag hebt beantwoordt (zie vraag p2age, als vraag p2name is beantwoord). De relevantie voor de groep en de vraag worden vanzelf gecombineerd. Een vraag in de groep wordt alleen gesteld als de groep relevant is.  Binnen de groep worden alleen de relevante vragen gesteld.
So, the group also has question-level relevance criteria, such that some questions only appear if you answered certain questions before them (e.g., p2age is displayed if p2name was answered). ES combines the Group and Question-level relevance for you. '''Questions in a group are only asked if the group as a whole is relevant. Then, only the subset of questions within the group that are relevant are asked.'''


Het scherm voor het wijzigen van de relevantie op groepsniveau van ''Cohabitant 2'':
Here is the screenshot for editing the group-level relevance of ''Cohabitant 2'':




Line 87: Line 88:




De accolades worden niet gebruikt als je een relevantie-vergelijking invult.
Note that you do not use the curly braces when you enter a relevance equation.




==Maatwerk==
==Tailoring/Piping==




Je kunt eenvoudig allerlei conditioneel maatwerk in je vragen gebruiken. Soms is een eenvoudige vervanging al voldoende. Voorbeeld: "U heeft <nowiki>[</nowiki>Product] gekocht.  Wat vond u het sterkste punt ervan?".  Soms wil je een vervanging op een conditie doen. Bijvoorbeeld: "<nowiki>[</nowiki>Dhr./Mevr.] <nowiki>[</nowiki>Achternaam], wilt u deze enquête invullen?". Je wilt hier dan natuurlijk de keuze tussen Dhr. en Mevr. op basis van het geslacht door het programma laten maken. Je kunt ook hele complexe vervangingen doen met bijvoorbeeld berekeningen.
ES lets you easily do simple and complex conditional tailoring. Sometimes you just need a simple substitution, like saying, "You said you purchased <nowiki>[</nowiki>Product]. What did you like best about it?". Sometimes you need conditional substitution like "<nowiki>[</nowiki>Mr./Mrs.] <nowiki>[</nowiki>LastName], would you be willing to complete our survey?". In this case, you want to use "Mr. or Mrs." based on the person's gender. Other times you need even more complex substitution (such as based upon a mathematical computation). ES supports each of these types of tailoring/piping.




===Conditionele vergelijking===
===Conditional Equations===




Het voorbeeld met de BMI toont de mogelijkheid om dit BMI te berekenen, omdat je daar de lengte, het gewicht en de gebruikte eenheden (die kunnen per land verschillen) opvraagt:
The Body Mass Index example shows the ability to compute a person's BMI, even while letting them enter their height and weight in two different units (cms vs inches and kgs vs lbs):




Line 105: Line 106:




Hier is weight_kg  {if(weight_units == 'kg', weight, weight * .453592)}.  Deze if() functie betekent dat als het gewicht in kg is ingevuld, dat dan als gewicht de eerste waarde moet worden genomen (de ingevulde waarde) en anders dat het gewicht dat is ingevuld moet worden vermenigvuldigd met een constante (om de ponden om te zetten in kg).  De variabele  height_m wordt gebruikt om de lengte in meters om te zetten als die in inches is ingevuld (1 meter is 3.28084 inches).
In this case, weightkg is {if(weightunits == "kg", weight, weight * 0.453592)}. This "if()" function means that if the subject enters the weight using kilograms, use that value, otherwise multiply the entered value (pounds is the alternative) by 0.453592 to convert it to kilograms. The heightm variable uses a similar approach to compute the person's height in meters (height in cms/100), even if he has entered his height in inches (1 meter=3.28084 inches).


De BMI wordt bepaald door het gewicht te delen door kwadraat van de lengte: {weightkg / (heightm * heightm)}.
BMI is computed as: {weightkg / (heightm * heightm)}.


Tot slot wordt het rapport conditioneel afgesloten met wat de invoergegevens waren. ("U heeft gezegd dat u 2 meter lang bent en 70 kg weegt.")
Lastly, the report conditionally tailors the message for the subject, telling her what he entered. (e.g., "You said you are 2 meters tall and weight 70 kg.")


In het bovenstaande plaatje zie je de verdere uitwerking om met geneste if()-condities de persoon in te delen in een categorieën als  ondergewicht of obesitas. Je ziet de vergelijkingen ook bij de functie "Logica tonen".
In the below image, weightstatus uses nested "if()" statements to categorize the person as underweight to severely obese. You can see its equation by checking its logic:




Line 117: Line 118:




Op het wijzigscherm van de vraag, kun je zien dat:  
From the edit window for this question, you can see two things:
#je bij maatwerk de expressie tussen accolades moet zetten
#Tailoring must surround expressions with curly braces
#Een expressie kan heel lang zijn. Je wilt het dan meer leesbaar maken om de geneste conditionele logica beter te kunnen lezen.
#Expressions can span multiple lines if, as in this case, you want to make it easier to read the nested conditional logic.




Line 125: Line 126:




===Maatwerk vragen, antwoorden en rapporten===
===Tailored Questions, Answers, and Reports===




<div class="simplebox">[[File:help.png]] '''NB:''' Dynamisch maatwerk kan mogelijk niet werken als de antwoordopties op hetzelfde scherm kunnen worden geselecteerd uit een lijst. Dit komt omdat bij maatwerk er een <nowiki><span></nowiki>-tag wordt toegevoegd, dat is niet mogelijk binnen een selectielijst.</div>
<div class="simplebox">[[File:help.png]] '''Note:''' Dynamic tailoring may not work if answer options are made available in select boxes on the same question page. This results from the fact that tailoring inserts a <nowiki><span></nowiki> tag which is not valid inside select options.</div>


Het BMI-rapport:
The BMI report looks like this:




Line 136: Line 137:




Het wijzigscherm voor dezelfde vraag.
Here is the edit window for the same question.




Line 142: Line 143:




Alles tussen haakjes wordt gezien als een expressie, in het voorgaande plaatje worden deze expressies gemarkeerd met kleur. Bij een fout (bijvoorbeeld een foutje in de naam of in de functienaam), toont EM een foutmelding. In onderstaand voorbeeld is:
Anything within curly braces is treated as an expression, being syntax-highlighted (color coded) in the prior image. If you have any typos (such as misspelled or undefined variable names or functions), ES would show an error. In our below example:
* heightunit.shown is een ongedefinieerde variabele (het moet heightunits.shown zijn) en
* heightunit.shown is an undefined variable name (it is actually heightunits.shown) and
* "rnd( )" is een ongedefinieerde functie (het moet "round( )" zijn).  
* "rnd()" is an undefined function (the proper function name is "round()").  


Een fout wordt getoond in een rood veld, daardoor valt de fout eerder op.
In both cases, the errors are located within a red box to make it easier to spot and fix them.




Line 152: Line 153:




Je kunt ook snel complexe rapporten maken, zoals een tabel met ingevoerde waarden of advies op maat.
You can also see that you can quickly create complex reports, such as a table of entered values or tailored advice.


Al het maatwerk moet dus tussen accolades, zodat LimeSurvey in de vraag het onderscheid ziet tussen vaste tekst en expressies (die in Expressiebeheer worden verwerkt).
Please remember that all tailoring must surround expressions with curly braces so that LimeSurvey knows which parts of the question are free text and which should be parsed by the ExpressionScript engine.




==Validatie==
==Validation==




Expressiebeheer bepaald hoe de speciale vraagopties werken. Dit betreft o.a.:  min/max aantal antwoorden; min/max persoonlijke waarden; min/max totalen; en controleren dat de invoer voldoet aan gespecificeerde patronen. Het gebruik van deze opties is niet gewijzigd. Alle waarden in een van deze velden wordt echter nu gezien als een expressie, zodat je min/max criteria kunt hebben met complexe relaties met andere vragen.
ES controls how most of the advanced question options work. These control aspects like min/max numbers of answers, min/max individual values, min/max sum values, and checking that entered values match specified string patterns. Any value in one of those fields is considered an expression, so you can have min/max criteria with complex conditional relationships to other questions.


In al van deze gevallen hoef je bij het specificeren geen accolades te gebruiken omdat de speciale vraagopties altijd als expressie beschouwd worden.
In all of these cases, since the advanced question attribute is always considered an expression, you do not use curly braces when specifying it.


Op de pagina met [[Expression Manager sample surveys/nl|voorbeeld enquêtes]] staan meerdere voorbeelden van validatie met expressies.
The [[ExpressionScript sample surveys|sample surveys]] page shows many working examples containing a variety of validation expressions.


=Expressiebeheer - presentatie=
=Expression Manager - presentation=




Meer [https://manual.limesurvey.org/Expression_Manager_-_presentation/nl informatie] over Expressiebeheer en hoe je verschillende expressies kunt gebruiken in je enquête.
To find out more about the Expression Manager and how you can use different expressions to enhance your survey, please click on the following [https://manual.limesurvey.org/Expression_Manager_-_presentation link].

Revision as of 15:45, 11 February 2020


Quick start guide

Within LimeSurvey, you can further customize your surveys via the usage of the ExpressionScript (short: ES). Sidenote: "ExpressionScript was named Expression Manager (EM) in earlier version. If you read Expression Manager somewhere, it is just the old name of ES."

ES can be used to specify the following:

  1. Navigation/Branching - allows a respondent's answers to change the order in which the questions are displayed;
  2. Tailoring/Piping - helps you phrase the question (such as referring to prior answers, or conjugating sentences based upon the age or gender of your subjects) or how to generate custom reports (like assessment scores or tailored advice);
  3. Validation - ensures that answers pass certain criteria, like min and max values or a certain input pattern.

ES provides an intuitive way to specify the logic for each of those features. Nearly anything that you can write as a standard mathematical equation is a valid expression.

ES currently provides access to 70 functions and it can be easily extended to support more. It also lets you access you variables using human-readable variable names (rather than SGQA names).

The upcoming sections show the main places where the ES is used.


Relevance (Controlling Navigation/Branching)

Some surveys use "Goto Logic", such that if you answer Question1 with option C, you are redirected to Question5. This approach is very limited since it is hard to validate it. Moreover, it easily breaks when you have to reorder questions. On the other hand, ES uses Boolean relevance equations to specify all the conditions under which a question might be valid. If the question is relevant, then the question is shown, otherwise, it is not applicable, and the value "NULL" is stored in the database.

Note: This is similar to what can be done via the Conditions editor, but ES lets you easily specify much more complex and powerful criteria (and lets you use the variable name rather than SGQA identifiers).




To better understand the relevance concept, let's focus on the following survey which computes the Body Mass Index (BMI) of survey respondents. To download it, click on the following link: Body Mass Index survey example.

De relevantievergelijking staat in de kolom Relevantie. De waarde is hier bij de variabelen weight, weight_units, height en height_units altijd 1 (standaardwaarde), dat geeft aan dat de vraag wordt getoond. De relevantie bij BMI is {!is_empty(height) and !is_empty(weight)}, dat betekent dat de BMI alleen wordt bepaald als zowel height en weight een waarde hebben (geen 0). Ook de vraag "Report" wordt alleen getoond als de deelnemer alle 4 vragen heeft ingevuld (height, heightunits, weight en weightunits).



Note: The above image comes from the survey logic file which allows you to look for syntax errors before activating the survey.


De relevantievergelijking wordt getoond en kan gewijzigd worden:

  • op vraagniveau
  • op vraaggroepniveau


Viewing / Editing Question-Level Relevance

This equation computes the Body Mass Index (BMI). It is only asked if the person enters their height and weight.



This is the edit screen for the "BMI" question.



Note that you do not use the curly braces when you enter a relevance equation.


Viewing / Editing Group-Level Relevance

Let's focus now on another example - a simple census survey. To download it, click on the following link: Census survey example.

The first page asks how many people live with you and stores that in the "cohabs" variable. This page is only shown if you have more than one cohabitant (it is shown for the second person cohabitating with you). Also, p2name, p2age. p2sum are displayed only if the question before each of them contains a response.



So, the group also has question-level relevance criteria, such that some questions only appear if you answered certain questions before them (e.g., p2age is displayed if p2name was answered). ES combines the Group and Question-level relevance for you. Questions in a group are only asked if the group as a whole is relevant. Then, only the subset of questions within the group that are relevant are asked.

Here is the screenshot for editing the group-level relevance of Cohabitant 2:



Note that you do not use the curly braces when you enter a relevance equation.


Tailoring/Piping

ES lets you easily do simple and complex conditional tailoring. Sometimes you just need a simple substitution, like saying, "You said you purchased [Product]. What did you like best about it?". Sometimes you need conditional substitution like "[Mr./Mrs.] [LastName], would you be willing to complete our survey?". In this case, you want to use "Mr. or Mrs." based on the person's gender. Other times you need even more complex substitution (such as based upon a mathematical computation). ES supports each of these types of tailoring/piping.


Conditional Equations

The Body Mass Index example shows the ability to compute a person's BMI, even while letting them enter their height and weight in two different units (cms vs inches and kgs vs lbs):



In this case, weightkg is {if(weightunits == "kg", weight, weight * 0.453592)}. This "if()" function means that if the subject enters the weight using kilograms, use that value, otherwise multiply the entered value (pounds is the alternative) by 0.453592 to convert it to kilograms. The heightm variable uses a similar approach to compute the person's height in meters (height in cms/100), even if he has entered his height in inches (1 meter=3.28084 inches).

BMI is computed as: {weightkg / (heightm * heightm)}.

Lastly, the report conditionally tailors the message for the subject, telling her what he entered. (e.g., "You said you are 2 meters tall and weight 70 kg.")

In the below image, weightstatus uses nested "if()" statements to categorize the person as underweight to severely obese. You can see its equation by checking its logic:



From the edit window for this question, you can see two things:

  1. Tailoring must surround expressions with curly braces
  2. Expressions can span multiple lines if, as in this case, you want to make it easier to read the nested conditional logic.



Tailored Questions, Answers, and Reports

Note: Dynamic tailoring may not work if answer options are made available in select boxes on the same question page. This results from the fact that tailoring inserts a <span> tag which is not valid inside select options.

The BMI report looks like this:



Here is the edit window for the same question.



Anything within curly braces is treated as an expression, being syntax-highlighted (color coded) in the prior image. If you have any typos (such as misspelled or undefined variable names or functions), ES would show an error. In our below example:

  • heightunit.shown is an undefined variable name (it is actually heightunits.shown) and
  • "rnd()" is an undefined function (the proper function name is "round()").

In both cases, the errors are located within a red box to make it easier to spot and fix them.



You can also see that you can quickly create complex reports, such as a table of entered values or tailored advice.

Please remember that all tailoring must surround expressions with curly braces so that LimeSurvey knows which parts of the question are free text and which should be parsed by the ExpressionScript engine.


Validation

ES controls how most of the advanced question options work. These control aspects like min/max numbers of answers, min/max individual values, min/max sum values, and checking that entered values match specified string patterns. Any value in one of those fields is considered an expression, so you can have min/max criteria with complex conditional relationships to other questions.

In all of these cases, since the advanced question attribute is always considered an expression, you do not use curly braces when specifying it.

The sample surveys page shows many working examples containing a variety of validation expressions.

Expression Manager - presentation

To find out more about the Expression Manager and how you can use different expressions to enhance your survey, please click on the following link.