Sum of an array question (from / to)

More
1 month 3 weeks ago #199362 by apollopa
Hello,

I'm working on an array type question, where I need to add some values ​​according to the answers for each line.
After the sum, I need to include it in a question to be exported.


I'm starting my studies on the tool, I looked at the material, but I couldn't go any further. :(


F5_F501 [0,3,7,10,14]
F5_F502 [0,3,7,10,13]
F5_F503 [0,3,5,8,11]
F5_F504 [0,3,6,8,11]
F5_F505 [0,3,6,6,6]
F5_F506 [0,2,3,5,5]
F5_F507 [0,2,4,6,6]
F5_F508 [0,2,4,6,6]
F5_F509 [0,1,3,4,6]
F5_F510 [0,2,4,4,4]
F5_F511 [0,1,3,3,3]
F5_F512 [0,2,2,2,2]

Best regards.
Attachments:

Please Log in to join the conversation.

LimeSurvey Partners
More
1 month 3 weeks ago #199364 by Joffm
Hi,
you did not say, how you coded the answer options.
I show it with numerical codes, like
0: 0, 1: 1, 2: 2; 3: 3, 4: 4+

What do you want to do?
You want to sum up the values in red of the selected answer
So this means:
If the answer code of the first item is 0, sum 0, if it is 1, sum 3, if it is 2, sum 7, if it is 3, sum 10, else sum 14.
Here the "else" is allowed because your question is mandatory.

Same with second, third item,...

Translated into the IF-statement:
{IF(F5_F501.NAOK==0,0,IF(F5_F501.NAOK==1,3,IF(F5_F501.NAOK==2,7,IF(F5_F501.NAOK==3,10,14))))}
Now you have the value of the first item.

now you use the sum-function
{sum(item1,item2,item3,...)}
You find these implemeted functions in the manual:
https://manual.limesurvey.org/ExpressionScript_-_Presentation#Implemented_functions

Now we combine it.

In a question of type equation (let's call it SumF5) you enter (linefeeds here only to display better):
{sum(
IF(F5_F501.NAOK==0,0,IF(F5_F501.NAOK==1,3,IF(F5_F501.NAOK==2,7,IF(F5_F501.NAOK==3,10,14)))),
IF(F5_F502.NAOK==0,0,IF(F5_F502.NAOK==1,3,IF(F5_F502.NAOK==2,7,IF(F5_F502.NAOK==3,10,13)))),
IF(F5_F503.NAOK==0,0,IF(F5_F503.NAOK==1,3,IF(F5_F503.NAOK==2,5,IF(F5_F503.NAOK==3,8,11)))),
...
IF(F5_F512.NAOK==0,0,IF(F5_F503.NAOK==1,2,IF(F5_F503.NAOK==2,2,IF(F5_F503.NAOK==3,2,2))))
)}

Now the sum of all your items is stored in the code of this question and you can use it later by {SumF5}

Remember: If you did not change the answer codes and still use this "A1", "A2", ... you have to adapt the function (now you compare with a text) to
IF(F5_F501.NAOK=="A1",0,IF(F5_F501.NAOK=="A2",3,IF(F5_F501.NAOK=="A3",7,IF(F5_F501.NAOK=="A4",10,14))))

Joffm

By the way:
What does the "(from/to)" mean?


Volunteers are not paid.
Not because they are worthless, but because they are priceless
The following user(s) said Thank You: apollopa

Please Log in to join the conversation.

More
1 month 3 weeks ago #199384 by apollopa
Hi Joffm,

Thank you for your answer!
It's working. \o/

I was trying to do this by inserting the code in "Source" with javascript, working with "Array Object", something like the code below, but I couldn't:
	var arrPontosItens = new Array(
		[0,3,7,10,14],
		[0,3,7,10,13],
		[0,3,5,8,11],
		[0,3,6,8,11],
		[0,3,6,6,6],
		[0,2,3,5,5],
		[0,2,4,6,6],
		[0,2,4,6,6],
		[0,1,3,4,6],
		[0,2,4,4,4],
		[0,1,3,3,3],
		[0,2,2,2,2]
	);
 
	var nPontos = 0;
 
	for (var i=0;i < SubQuestions.length;i++){
		var code = AnswerSubQuestion(i);
		nPontos += arrPontosItens[i][code];
	}
 
 
	SetAnswer(SumF5,nPontos);


About "from / to", maybe I expressed it badly, but that was exactly it:
0: 0, 1: 1, 2: 2; 3: 3, 4: 4+

Thanks,
Bruno

Please Log in to join the conversation.

More
1 month 3 weeks ago #199393 by DenisChenu
Not a devlopemnt, because it can be done with expression
I move it after answered

With a equation question type , i prefer to use (more easy to do with spreadsheet)
{sum(
 
intval(F5_F501.NAOK==0) *0,
intval(F5_F502.NAOK==1) *3,
intval(F5_F502.NAOK==2) *7,
…
0)}

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.
The following user(s) said Thank You: apollopa

Please Log in to join the conversation.

More
1 month 3 weeks ago #199402 by apollopa
Hi Denis,

Thanks for the message!


I'm a junior developer, but I've worked with other research tools.

Regarding the use of a question like "equation" or inserting the code in "source", do you believe that the best option would be "equation"?

As I am not familiar with the tool, I am concerned with finding the same situation that requires me to keep repeating the code (with many "if").

Can I use a "for" in the "equation"?

Thanks,
Bruno

Please Log in to join the conversation.

More
1 month 3 weeks ago #199409 by DenisChenu
manual.limesurvey.org/Question_type_-_Equation : best is to use dedicated part; you can add your line feed etc …

Else : manual.limesurvey.org/Expression_Manager

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.
The following user(s) said Thank You: apollopa

Please Log in to join the conversation.

More
1 month 3 weeks ago - 1 month 3 weeks ago #199494 by holch
This is obviously the CCEB (Criterio Brazil) and it is possible to create this with equations, but is a little bit of work. I have done it before, need to check if I can find it.

I would go with one equation per subquestion first in order to not mess anything up, because if you do it all in one equation, it can become quite messy.

I answer at the LimeSurvey forum in my spare time, I'm not a LimeSurvey GmbH employee.
No support via private message.
Last edit: 1 month 3 weeks ago by holch.
The following user(s) said Thank You: apollopa

Please Log in to join the conversation.

More
1 month 3 weeks ago #199501 by DenisChenu
It's the reason why i use sum.
If you have a lot of subquestion : it can became a real big machine ?

No ?

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.
The following user(s) said Thank You: apollopa

Please Log in to join the conversation.

More
1 month 3 weeks ago #199555 by apollopa
Hi Holch,

Exactly!

I said I needed to make a sum, because with this information I would do the rest of the code. But yes, it is the CCEB!
This classification is made in most studies here in Brazil.

If you find this code, it would help me a lot! :woohoo:

Best regards,

Please Log in to join the conversation.

More
1 month 3 weeks ago #199556 by DenisChenu
I think you have the answer no ?

Some code sample, you just have to adapt …

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.
The following user(s) said Thank You: apollopa

Please Log in to join the conversation.

More
1 month 3 weeks ago #199560 by holch
If you find this code, it would help me a lot!

Bruno, I think we have met already here in São Paulo in your office in Pinheiros at your previous company. ;-)

I have found one version that one of our interns has programmed a while ago as an experience (might not be the latest version of the CCEB, not sure on which vesion he has based this on). I can't remember if we tested it thoroughly and if everything works 100% correct, but I did a quick check and it seems to work.

Send me a private message and I'll send you the LSS file. We had separated each score of each question/subquestion into a separate Equation in this case, because this way it was easier for him to understand how this works and also to find errors. So there are quite a few equations in this example.

I might have another version of the CCEB with everything in one equation, but I am not 100% and haven't found it yet.

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: apollopa

Please Log in to join the conversation.

More
1 month 3 weeks ago #199565 by Joffm
As Denis,
what do you need more?
You have two options.
The first, which you said "It's working".

Here holch recommended to split the equation into parts.
One equation for each row, and at the end an equations that sums up the results.

Then the version with "intval".
As Denis said: This is easy to construct in a spreadsheet.
Like the concatination of the values

Then you copy and paste it into your question.

Joffm


Volunteers are not paid.
Not because they are worthless, but because they are priceless
Attachments:
The following user(s) said Thank You: DenisChenu, apollopa

Please Log in to join the conversation.

More
1 month 3 weeks ago #199567 by apollopa
Thank you Joffm!

Please Log in to join the conversation.

Start now!

Just create your account and start using Limesurvey today.

Register now