- Posts: 8
- Thank you received: 0
Welcome to the LimeSurvey Community Forum
Ask the community, share ideas, and connect with other LimeSurvey users!
Expression Manager - personalized feedback
- askirkov
- Topic Author
- Offline
- New Member
Less
More
8 years 2 months ago #129980
by askirkov
Expression Manager - personalized feedback was created by askirkov
I need some help writing the code for Expressions Manager.
I want to run a psychological test with over 10 subscales and provide immediate personalized feedback based on the mixture of the scores on each subscale. I understand that it is best to use hidden Equation Questions to calculate and store the score on each subscale. Should I then simply write the Expression Manager code in the End Message field in order to replace the score with pre-defined text? Each version of feedback is based on simple score ranges.
So, let's say that the first Equation Question for the first subscale is coded as BPD. I want to display simple text in the End Message if the following condition is met.
{if(BPD.value >= 0 && BPD.value <= 9,
I don't know how to proceed. Then I want to continue with another range, that is, 10-19 and so on. Could anyone help? If you help me with the first one, I guess I will know how to do the rest.
I want to run a psychological test with over 10 subscales and provide immediate personalized feedback based on the mixture of the scores on each subscale. I understand that it is best to use hidden Equation Questions to calculate and store the score on each subscale. Should I then simply write the Expression Manager code in the End Message field in order to replace the score with pre-defined text? Each version of feedback is based on simple score ranges.
So, let's say that the first Equation Question for the first subscale is coded as BPD. I want to display simple text in the End Message if the following condition is met.
{if(BPD.value >= 0 && BPD.value <= 9,
I don't know how to proceed. Then I want to continue with another range, that is, 10-19 and so on. Could anyone help? If you help me with the first one, I guess I will know how to do the rest.
The topic has been locked.
- holch
- Away
- LimeSurvey Community Team
Less
More
- Posts: 11746
- Thank you received: 2750
8 years 2 months ago #129987
by holch
I answer at the LimeSurvey forum in my spare time, I'm not a LimeSurvey GmbH employee.
No support via private message.
Replied by holch on topic Expression Manager - personalized feedback
I personally would probably use one or more text display questions on the last page before the end message, but I guess this is personal taste.
To your code: This looks pretty good already, but if you do not have values below 0 in your scale / assessment values, you could just skip that part and ask for <10, which would include 0-9. Makes the code shorter and cleaner and you don't need the AND connection.
After that you would write the text that you want. For each scale I would create nested IF loops.
So the IF loops are usually structured this way: if(formula to check, what to do, what to do else), so here is what you could do:
This isn't tested and it is assuming that the scale ends with 40. But I think you get the idea. There might be more elegant solutions. Give it a try. Maybe first test with a few ranges to see if and how it works, then go for the whole scale (I assume you go from 1-100?).
To your code: This looks pretty good already, but if you do not have values below 0 in your scale / assessment values, you could just skip that part and ask for <10, which would include 0-9. Makes the code shorter and cleaner and you don't need the AND connection.
After that you would write the text that you want. For each scale I would create nested IF loops.
So the IF loops are usually structured this way: if(formula to check, what to do, what to do else), so here is what you could do:
Code:
{if(BPD.value < 10, "You have scored between 0-9", if(BPD.value < 20, "You have scored between 10-19", if(BPD.value < 30, "You have scored between 20-29", "You have scored between 30-40") ) ) }
This isn't tested and it is assuming that the scale ends with 40. But I think you get the idea. There might be more elegant solutions. Give it a try. Maybe first test with a few ranges to see if and how it works, then go for the whole scale (I assume you go from 1-100?).
I answer at the LimeSurvey forum in my spare time, I'm not a LimeSurvey GmbH employee.
No support via private message.
The following user(s) said Thank You: askirkov
The topic has been locked.
- askirkov
- Topic Author
- Offline
- New Member
Less
More
- Posts: 8
- Thank you received: 0
8 years 2 months ago - 8 years 2 months ago #129989
by askirkov
Replied by askirkov on topic Expression Manager - personalized feedback
Thanks a lot. I have another problem. I'm playing with the demo right now. I want the BPD Equation Question to become the sum of answers for questions A1-A5 (radio lists with answers 1-7 coded also 1-7). I've tried typing the following in the Equation field while editing BPD:
{sum(A1.value, A2.value, A3.value, A4.value, A5.value)}
or the following:
{A1.value + A2.value + A3.value + A4.value + A5.value}
Then I typed:
{BPD.value}
into the End message field but no matter which answers I choose for questions A1-A5, I always get 0 instead of the sum.
Is the code correct? Should I enter it somewhere else? I would be grateful for some hints.
{sum(A1.value, A2.value, A3.value, A4.value, A5.value)}
or the following:
{A1.value + A2.value + A3.value + A4.value + A5.value}
Then I typed:
{BPD.value}
into the End message field but no matter which answers I choose for questions A1-A5, I always get 0 instead of the sum.
Is the code correct? Should I enter it somewhere else? I would be grateful for some hints.
Last edit: 8 years 2 months ago by askirkov.
The topic has been locked.
- holch
- Away
- LimeSurvey Community Team
Less
More
- Posts: 11746
- Thank you received: 2750
8 years 2 months ago #129992
by holch
I answer at the LimeSurvey forum in my spare time, I'm not a LimeSurvey GmbH employee.
No support via private message.
Replied by holch on topic Expression Manager - personalized feedback
Reading this, I assume that BPD is an equation question, right? But BPD.value is referring to the assessment value of a question, which an equation question shouldn't have.
Try only {BPD} or {BPD.NOAK}.
Try only {BPD} or {BPD.NOAK}.
I answer at the LimeSurvey forum in my spare time, I'm not a LimeSurvey GmbH employee.
No support via private message.
The following user(s) said Thank You: askirkov
The topic has been locked.
- askirkov
- Topic Author
- Offline
- New Member
Less
More
- Posts: 8
- Thank you received: 0
8 years 2 months ago #129993
by askirkov
Replied by askirkov on topic Expression Manager - personalized feedback
I typed:
{sum(A1, A2, A3, A4, A5)}
into the Equation field while editing the BPD Equation Question and now it works. Now I will try the nested IFs for personalized feedback.
{sum(A1, A2, A3, A4, A5)}
into the Equation field while editing the BPD Equation Question and now it works. Now I will try the nested IFs for personalized feedback.
The topic has been locked.
- askirkov
- Topic Author
- Offline
- New Member
Less
More
- Posts: 8
- Thank you received: 0
8 years 2 months ago #129996
by askirkov
Replied by askirkov on topic Expression Manager - personalized feedback
I had some trouble with the nested IFs, there was some syntax problem, so I wrote it all in one line. Now it works. I also believe that the final "}" mark in the code should be glued to whatever comes before, am I right? Anyway, everything seems to be working the way I wanted. Thanks again for your help.
The topic has been locked.
- holch
- Away
- LimeSurvey Community Team
Less
More
- Posts: 11746
- Thank you received: 2750
8 years 2 months ago #130001
by holch
I answer at the LimeSurvey forum in my spare time, I'm not a LimeSurvey GmbH employee.
No support via private message.
Replied by holch on topic Expression Manager - personalized feedback
Yes, I had a similar problem once. But to show how it works it is better to write the code in separate lines, otherwise it is difficult to read.
Glad that it worked.
Glad that it worked.
I answer at the LimeSurvey forum in my spare time, I'm not a LimeSurvey GmbH employee.
No support via private message.
The topic has been locked.
- DenisChenu
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 13912
- Thank you received: 2549
8 years 2 months ago - 8 years 2 months ago #130022
by DenisChenu
Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand , plugin development .
I don't answer to private message.
Replied by DenisChenu on topic Expression Manager - personalized feedback
Hi,
I really don't like nested system (and always use a good text editor to do complex Equation) but for kind of system, i use:
Maybe more server operation, but REALLY more easy to update and fix.
Denis
I really don't like nested system (and always use a good text editor to do complex Equation) but for kind of system, i use:
Code:
{if(BPD.NAOK < 10, "You have scored between 0-9", "")} {if(BPD.NAOK >= 10 and BPD.NAOK < 20, "You have scored between 10-19", "")} {if(BPD.NAOK >= 20 and BPD.NAOK < 30, "You have scored between 20-29", "")} {if(BPD.NAOK >= 30 and BPD.NAOK < 30, "You have scored more than 29", "")}
Denis
Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand , plugin development .
I don't answer to private message.
Last edit: 8 years 2 months ago by DenisChenu.
The topic has been locked.
- holch
- Away
- LimeSurvey Community Team
Less
More
- Posts: 11746
- Thank you received: 2750
8 years 2 months ago #130033
by holch
I answer at the LimeSurvey forum in my spare time, I'm not a LimeSurvey GmbH employee.
No support via private message.
Replied by holch on topic Expression Manager - personalized feedback
Yes, nested systems can get a little confusing, when they are longer. But I personally don't like the AND options either, because it is also easy to make mistakes with the two limits (high and low).
At the end of the day it probably comes down to personal taste.
At the end of the day it probably comes down to personal taste.
I answer at the LimeSurvey forum in my spare time, I'm not a LimeSurvey GmbH employee.
No support via private message.
The topic has been locked.