Assessment with Expression Manager - Clear solution?

More
3 years 1 week ago #113398 by holch
holch created the topic: Assessment with Expression Manager - Clear solution?
Hi EM experts!

I was playing around with an assessment that I need to calculate the socio-economic class.

I got it to work, but as this is my first major "programming" with EM, I was wondering if there might be a leaner, cleaner solution. I am using a lot of IF loops within the SUM function, maybe there is something better.
sum(CCEB1_1, CCEB1_2, if(CCEB1_3 == 1, 4, if(CCEB1_3 == 2, 5, if(CCEB1_3 == 3, 6, if(CCEB1_3 == 4, 7, 0)))), if(CCEB1_4 == 1, 4, if(CCEB1_4 == 2, 7, if(CCEB1_4 == 3, 9, if(CCEB1_4 == 4, 9, 0)))), if(CCEB1_5 == 1, 3, if(CCEB1_5 == 2, 4, if(CCEB1_5 == 3, 4, if(CCEB1_5 == 4, 4, 0)))), if(CCEB1_6 == 1, 2, if(CCEB1_6 == 2, 2, if(CCEB1_6 == 3, 2, if(CCEB1_6 == 4, 2, 0)))), if(CCEB1_7 == 1, 2, if(CCEB1_7 == 2, 2, if(CCEB1_7 == 3, 2, if(CCEB1_7 == 4, 2, 0)))), if(CCEB1_8 == 1, 4, if(CCEB1_8 == 2, 4, if(CCEB1_8 == 3, 4, if(CCEB1_8 == 4, 4, 0)))), if(CCEB1_9 == 1, 2, if(CCEB1_9 == 2, 2, if(CCEB1_9 == 3, 2, if(CCEB1_9 == 4, 2, 0)))), CCEB2)

So I have basically two questions.

The first one is an array question (CCEB1) with a scale from "0" to "4 or more" and has 9 subquestions. So I gave the scale items the values 0,1,2,3,4. For the first two sub-questions the points are equal to the response code. But for some sub-questions the actual points to gain do not follow the response code. I could have done this question in 9 separate questions and then give the respective answer codes, but for an array questions you can't give different answer codes per sub-question.

At the end there is a list radio question (CCEB2), where I could just apply the right points.

Is this already as clean as it gets? It works, but I was just wondering if there is a more elegant solution. If not, that is fine with me. Just trying to learn.

I'm not a LimeSurvey GmbH member. I answer at the LimeSurvey forum in my spare time. No support via private message.
Some helpful links: Manual (EN) | Question Types | Workarounds

Please Log in to join the conversation.

More
3 years 1 week ago - 3 years 1 week ago #113400 by Ben_V
Ben_V replied the topic: Assessment with Expression Manager - Clear solution?
Hi Holch,

maybe you can play with to EM allowed syntaxes :

1) composite sum using {ASSESMENT_CURRENT_TOTAL} and question codes.
{sum(ASSESMENT_CURRENT_TOTAL, Q3,Q7)}
=> source (french forum)


2) Syntax used when there is some reverse scored items in an array
{sum(QQ_sq1.value,QQ_sq2.value,(5-QQ_sq3.value),(5-QQ_sq4.value))}
=> source (eng forum)
.

Benoît

EM Variables => bit.ly/1TKQyNu | EM Roadmap => bit.ly/1UTrOB4
Last Releases => 2.6x.x goo.gl/ztWfIV | 2.06/2.6.x => bit.ly/1Qv44A1
Demo Surveys => goo.gl/HuR6Xe (already included in /docs/demosurveys)
Last Edit: 3 years 1 week ago by Ben_V.

Please Log in to join the conversation.

More
3 years 1 week ago #113402 by holch
holch replied the topic: Assessment with Expression Manager - Clear solution?
Hi Ben,

Thanks for the response.

Solution 1: My problem is, that within the array question, I need to give different values to responses. E.g. subquestion 2 gets 2 points for answer 2, while in subquestion 3 the value for response 2 might be 4.

The values are not reverse scored. The only thing that is constant is that the first answer (0) scores always zero points (0). The other values are changing depending on the subquestion.

I thought there might be an easier way than the cascading IF loops. Like a shorter version on how to write this.

Things are working fine, so I am not too concerned. I just know that due to my limited knowledge when it comes to programming, sometimes my solution, despite working, is not always the most straight forward. ;-)

I'm not a LimeSurvey GmbH member. I answer at the LimeSurvey forum in my spare time. No support via private message.
Some helpful links: Manual (EN) | Question Types | Workarounds

Please Log in to join the conversation.

More
3 years 1 week ago #113410 by tpartner
tpartner replied the topic: Assessment with Expression Manager - Clear solution?
I don't think you'll see any performance problems with nested IF statements.

Having said that, maybe you could shorten them to something like this (line-breaks inserted for clarity):

sum(
	CCEB1_1, 
	CCEB1_2, 
	if(CCEB1_3 > 0, CCEB1_3+3, 0), 
	if(CCEB1_4 == 1, 4, if(CCEB1_4 == 2, 7, if(CCEB1_4 > 2, 9, 0))), 
	if(CCEB1_5 == 1, 3, if(CCEB1_5 > 1, 4, 0)), 
	if(CCEB1_6 > 0, 2, 0), 
	if(CCEB1_7 > 0, 2, 0), 
	if(CCEB1_8 > 0, 4, 0), 
	if(CCEB1_9 == 1, 2, if(CCEB1_9 == 2, 2, if(CCEB1_9 == 3, 2, if(CCEB1_9 == 4, 2, 0)))), 
	CCEB2
)

Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.

Please Log in to join the conversation.

More
3 years 6 days ago #113431 by holch
holch replied the topic: Assessment with Expression Manager - Clear solution?
Hi Tony!

Thank you very much!

These are great examples how someone with more experience can reduce code and coding efforts significantly (looks like 50% less code).

I especially like the solution for the ones that have the same points for most of the answers, but also the CCEB1_3 thingy with adding 3 points. I didn't see that pattern at all.

All in all I was already happy that I managed to get this done with EM at all. ;-)

I can now use this as my standard questions for SECs and actually also create quota and screening based on this.

I'm not a LimeSurvey GmbH member. I answer at the LimeSurvey forum in my spare time. No support via private message.
Some helpful links: Manual (EN) | Question Types | Workarounds

Please Log in to join the conversation.

Start now!

Just create your account and start using Limesurvey today.

Register now