Welcome to the LimeSurvey Community Forum

Ask the community, share ideas, and connect with other LimeSurvey users!

Question Condition - Expression script sorting and filtering.

  • linuxhooligan
  • linuxhooligan's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
1 month 1 day ago - 1 month 1 day ago #259474 by linuxhooligan
Please help us help you and fill where relevant:
Your LimeSurvey version: Version 5.6.55+240220
Own server or LimeSurvey hosting: Own server
Survey theme/template: fruity
==================

I am deploying a number of surveys and on the last page of the survey I provide the user with a graph of their results using Chartjs and then dispaly one of about 5 questions based on their score to provide them some information about their results.  The display of the question is handled by the Condition field and usually has some Expression script such as this:

{
(((!is_empty(MATHtotal.NAOK) && (MATHtotal.NAOK >= 19)) and (!is_empty(MATHtotal.NAOK) && (MATHtotal.NAOK <= 24))))
}

I have a new survey coming up that on the last page will need to display the top 6 scoring questions out of the 30 being tested for.  I am trying to conceptualize what the Condition field Experssionscript might need to look like in order to write the script to set the display value accordingly.  So, we are gathering data on 30 individual variables and on the last page all 30 variables have their own question that displays some information about the variable, of which we need to show the top 6 scoring questions.

Can someone clue me in, perhaps with pseudocode, on how this might be achieved?  I am drawing a blank on this one for some reason and need to get a pointer on how to start thinking about this.

Thanks.
 
Last edit: 1 month 1 day ago by linuxhooligan.

Please Log in to join the conversation.

  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
1 month 1 day ago #259475 by Joffm
Hi,
always better you send the lss export of the survey or a sample.
So we know what exactly we are talking about.

Joffm 

Volunteers are not paid.
Not because they are worthless, but because they are priceless

Please Log in to join the conversation.

  • linuxhooligan
  • linuxhooligan's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
1 month 1 day ago #259482 by linuxhooligan
Sample survey attached. 

Details:

1) One page questionnaire, second page has results. 

2) On second page we have: 

RPTQ01 - Intro paragraph that is always displayed
MATHtotal - Calculates / stores the total score
RPTQ04 - Displayed or not displayed depending on the results of the the Expression script in the condition field.
RPTQ02 - Displayed or not displayed depending on the results of the the Expression script in the condition field.
RPTQ03  - Displayed or not displayed depending on the results of the the Expression script in the condition field.

The sample quiz is a simplified example for the purposes of illustration.  We basically calculate the score of the survey and show one of the the RPTQ04 / RPTQ03 / RPTQ02 questions to present some information to the user about their results.  In our production survey we have 30 fields and we would like to display the top 6 scoring RPT* questions using the Condition field.  I am not able to visualize how the Expression script would calculate this out using the provided logic and math operators.

Any tips or suggestions are greatly appreciated.
 

Please Log in to join the conversation.

  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
1 month 1 day ago - 1 month 1 day ago #259484 by Joffm
Hi,
before I have a closer look, I ask:
Why do you use alphanumerical codes and have to use this equation?
{sum(if(Q01_SQ001.code == "A01", 0, 0),if(Q01_SQ001.code == "A02", 1, 0),if(Q01_SQ001.code == "A03", 2, 0),if(Q01_SQ001.code == "A04", 3, 0),if(Q01_SQ001.code == "A05", 4, 0),...
instead of using numerical codes (it is a scale)
 
So it's only
{sum(Q01_SQ001.NAOK,Q01_SQ003.NAOK,...)}


And to clarify:

In our production survey we have 30 fields and we would like to display the top 6 scoring RPT* questions using the Condition field. 

What are your 30 fields?
Is it Q01 - Q30, or is it 30 different ways to calculate a score of Q1? I see that in this example you only sum subquestions 1,3,4,7 9,10
And is the split constant 
low: 0-13
mod: 14-18
high: 19+


My rough idea is:
calculate the maximum (max1) of scores (function "max()")
calculate the maximum (max2) of scores without max1.
calculate the maximum (max3) of scores without max1 and max2.
...
to get the sixth highest score.
Now display all scores that are equal or higher.

Joffm

Can't you provide a sample, where we see (let's say) 8 "fields" and may show how to display the three highest?

Volunteers are not paid.
Not because they are worthless, but because they are priceless
Last edit: 1 month 1 day ago by Joffm.

Please Log in to join the conversation.

  • linuxhooligan
  • linuxhooligan's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
1 month 23 hours ago #259498 by linuxhooligan
Thank you very kindly for the follow up. I will try to answer your questions as best as I can.

1) Why do you use alphanumerical codes and have to use this equation?

ANSWER: I am not sure I understand the question. Alphanumeric let's me read the equation at a glance. So A01 reads out as ANSWER01 and I know that "A03",2,0 means If answer03 is selected the value is 2 otherwise 0. I don't see how a simple sum equation can work on an array question whose value is different depending on the selected response. I may have not understood the documentation, of course.

I am totally open to suggestions and additional reading or consideration, feel free to share and critique. And thank you for this type of question, I do appreciate learning about how best to think about these things.

2) What are your 30 fields?

In the sample quiz, on the second page I have 3 questions labeled RPTQ04, RPTQ03, RPTQ02. They are purely used to display text information and their visibility is controlled by the equation in the Condition field for each question. Their purpose is to communicate to the user something about their results and only one of the three is displayed based on their score.

I have 30 of those to either display or not display. I want to only display 6 of the 30 based on top scores and cannot figure out how to do the math + comparison to test if each question is part of the top 6 scores.

3) Your suggestion for calculation is intriguing. I think I can visualise a way to start working on this. I appreciate this very much!

If anyone happens by this question before I post updates please feel free to make additional suggestions, I am looking to learn and discuss. If I figure out how to do it I will post the solution.

Joffm, thank you very kindly for the deep response and for taking the time to load up the quiz and share your questions and insights with me. That is very valuable and greatly appreciated.

Please Log in to join the conversation.

  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
1 month 11 hours ago #259786 by Joffm
Hi, here is a working example
calculating ten scores
and displaying the four highest scores with the verbatim description.
 

File Attachment:

File Name: limesurvey...1292.lss
File Size:97 KB


Please, read trhe manual to get familiar with the basics of access to variables, the "self" and "that" variable, ExpressionScript in general.
You may import the sample surveys in the manual
[url] manual.limesurvey.org/ExpressionScript_sample_surveys [/url]

Some short explanations:
You did not use all items of the array to calculate the score.
Therefore I used a better way of coding.
"Scored" items have codes like "S01", "S02"..., memorizable as "Score"
The other items - not used for the score - have codes like "N01", "N02", memorizable as "No score"
And of course nuzmerical codes of answer options

Now the "sum" function is only
sum(that.Q1.sq_S.NAOK)

You will see that I added a very small number randomly. This to avoid ties.

Now the group "GCalc"
Here the work is done.
"M" is a "container", a question of type "array(numbers)" to store some interim data
Important: The first coulmn with the scores, the fourth column with the ranks.

And your results.
It is not necessary to use three separate displays for just one score. Use a nested IF, and everything is file.

To be honest: You could use just one question to display all results.
Again with a nested IF. But depends a bit on the length of your texts.

As said: The four highest out of ten.

So you only have to extend the "container" M to your amont of scores and the equation "eqScore"

Joffm

Volunteers are not paid.
Not because they are worthless, but because they are priceless

Please Log in to join the conversation.

  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
1 month 5 hours ago #259824 by Joffm
Sorry, I missed that there are reversed items.
But no problem.
If you code the "normal items "S01", "S02",
the "reversed" items "R01", "R02",...
the "not used items "N01", "N02",...

the scores are calculated as
{M_S01_1=sum(sum(that.Q1.sq_S.NAOK),count(that.Q1.sq_R.NAOK)*4,-1*sum(that.Q1.sq_R.NAOK))}
...

Joffm

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

Please Log in to join the conversation.

  • linuxhooligan
  • linuxhooligan's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
4 weeks 1 day ago #259873 by linuxhooligan
Dropping in to provide a huge thank you for the follow up.  I am humbled by you taking your time to drill down into this and assist, I clearly need to spend more time learning.

Thank you kindly Joffm.

Please Log in to join the conversation.

Lime-years ahead

Online-surveys for every purse and purpose