Welcome to the LimeSurvey Community Forum

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

Strange behaviour Expression Manager

  • pvdemael
  • pvdemael's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
9 years 4 months ago #113690 by pvdemael
Strange behaviour Expression Manager was created by pvdemael
Hi all,

I experience some strange behaviour with EM.
I am implementing the Edinburgh Handedness Inventory which calculates how right or left handed one is.
To make things clear, you may look at zhanglab.wdfiles.com/local--files/survey/handedness.html to test it.
The question type is an array with 12 questions and 5 different answers with different weighting.

From the array, I calculate a left value and a right value using sumifop, which works very well, using 2 equation questions.

I then calculate the index, (R-L)/(R+L). This gives sometimes strange behaviour, below a table with values going right or wrong:


Right Left Result
24 0 0,1 wrong, should be 1
12 0 0,1 wrong, should be 1
0 12 -1 right
0 24 -1 right
<2 equal values> 0 right
14 4 0,55 right

Attached the question group.
Any idea on this one?
The topic has been locked.
More
9 years 4 months ago #113704 by Ben_V
Replied by Ben_V on topic Strange behaviour Expression Manager
Hi,

I manage similar tools and this one seems to work... after turning it to my way (attached).

To reuse your work, maybe you can just try something based on the following syntax for your last question:
Code:
{round((intval(ediHandednessRight)-intval(ediHandednessLeft))/(intval(ediHandednessRight)+intval(ediHandednessLeft)),1)}

File Attachment:

File Name: limesurvey...p_23.lsg
File Size:20 KB

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)
The topic has been locked.
  • pvdemael
  • pvdemael's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
9 years 4 months ago - 9 years 4 months ago #113706 by pvdemael
Replied by pvdemael on topic Strange behaviour Expression Manager
Hi,

Thx for the quick reply.
This is exactly the same solution I came up with.
But do you have an explanation for this behaviour?
The minus sign results in implicit casting and succesful calculation while the plus sign only works with expliciet concatenation.
This is really odd and should be documented if a feature or fixed if a bug.
Do you agree on this?
Last edit: 9 years 4 months ago by pvdemael. Reason: Typo
The topic has been locked.
More
9 years 4 months ago - 9 years 4 months ago #113719 by Ben_V
Replied by Ben_V on topic Strange behaviour Expression Manager
In my opinion there is no bug and this EM "strange behaviour" is related with the configuration of your "ediHandednessRight" and/or "ediHandednessLeft" questions.

I attach you a new group where I've only replaced this 2 questions by numerical inputs ("ediHandednessLI" unchanged)

Conclusion: there is no issue for
24 0 [strike]0,1 wrong[/strike], should be 1
12 0 [strike]0,1 wrong[/strike], should be 1

File Attachment:

File Name: limesurvey...p_24.lsg
File Size:8 KB


Ben.

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: 9 years 4 months ago by Ben_V.
The following user(s) said Thank You: pvdemael
The topic has been locked.
  • pvdemael
  • pvdemael's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
9 years 4 months ago #113729 by pvdemael
Replied by pvdemael on topic Strange behaviour Expression Manager
But I still find it strange that the subtraction works while the addition does not.
What is the logic behind this?
The topic has been locked.
More
9 years 4 months ago #113752 by Ben_V
Replied by Ben_V on topic Strange behaviour Expression Manager
I don't have any strong explication about this :(

If you think that it could be an EM bug, the best is to set a (very light) .lsg sample reproducing this issue and open a ticket in the bug tracker...

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)
The topic has been locked.
  • DenisChenu
  • DenisChenu's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
9 years 4 months ago - 9 years 4 months ago #113784 by DenisChenu
Replied by DenisChenu on topic Strange behaviour Expression Manager
Hi,

In javascript "0"+"1" = "01", it do concatenation.

Then you need to have number.

manual.limesurvey.org/Expression_Manager#Operators

Note, for consistency between JavaScript and PHP, the plus operator (+) does addition if both operands are numeric, but does concatenation if both parts are non-numeric strings. However, we recommend using the join() function for concatenation, as that makes your intent more clear, and avoids unexpected results if you were expecting strings but got numbers instead (or vice versa).


PS:
join(0,1)="01"
sum("0","1")=1

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: 9 years 4 months ago by DenisChenu.
The following user(s) said Thank You: Ben_V, pvdemael
The topic has been locked.

Lime-years ahead

Online-surveys for every purse and purpose