Using Logic for Calculations

From Lifeguide Wiki
Jump to navigation Jump to search

Logic for setting up scores in your intervention

Logic commands can be used to score the responses that end-users give to interactions. This is particularly useful for scoring questionnaire items or if your intervention includes a quiz.

The simplest interaction to use is the numeric value interactions as responses are already given a numeric value. However responses to single and multiple choice interactions can also be set with a numeric value.

This logic uses the key command set and any of the mathematical commands (sum, /, *, <, >, =).

Example 1: Scoring numeric value interactions

Numeric value interactions come in three forms; slider, drop-down box or individual buttons (see figure 1). The logic changes slightly depending on which form is used.

In this example we have named the slider interaction ‘stressq1’, the individual button interaction ‘stressq2’ and the drop-down menu interaction is called ‘stressq3’.

Measuringstress.JPG

Figure 1: The three types of numeric value interaction


The responses that end-users give on these interactions will need to be set as variables.

In this example the names answer1, answer2 and answer3 are given to the score generated from the interactions called stressq1, stressq2, and stressq3 respectively.

The following logic illustrates how a score can be generated from the three interactions presented in figure 1 and then presented to end-users on the next page.


show stressquestions1


Shows end-users the page containing the interactions, here this has been given the unique name stressquestions1


set answer1 to stressquestions1.stressq1


Stressq1 is the unique name for the slider interaction. In this interaction end-users can indicate where on the slider they would rate their stress levels. This interaction goes up in increments of 5 from 0 to 100. This logic will set the variable name answer1 to whatever number is indicated by the end-user’s response.


set answer2 to (10 * stressquestions1.stressq2)

set answer3 to (10 * stressquestions1.stressq3)


The unique names stressq2 and stressq3 have been given to the individual button and drop down interactions respectively. As these interactions have been set to go up in increments of 1 from 0 to 10 we need to multiply the response given by 10 to get an answer out of 100. This logic will set the variable names answer2 and answer3 to whatever this number will be.


set week1_score to (sum (answer1, answer2, answer3))


Finally, all three values are summed together and set to the unique variable week1_score


show stressanswer set stressanswer.stressscore to week1_score


This score can then be presented to the end-user on another page using a normal textbox where a word (in this case stressscore) has been set as a variable.

This score could also be e-mailed to a research manager or other person managing the intervention (see sending e-mails for more information)

Example 2: Scoring multiple choice, single choice and numeric value interactions