Welcome to the LimeSurvey Community Forum

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

Combine equations & send risk alerts

  • mu_akubaraly
  • mu_akubaraly's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
1 year 11 months ago #228003 by mu_akubaraly
Combine equations & send risk alerts was created by mu_akubaraly
Please help us help you and fill where relevant:
Your LimeSurvey version: [see right hand bottom of your LimeSurvey admin screen]
Own server or LimeSurvey hosting:
Survey theme/template:
==================
I have 2 equations (which work perfectly) and gives us a % score. I want to combine 2 equations to say if equationA is < 100% AND equationB is < 85% then risky & send out email alerts. I know how to configure the email notifications, I just need to know how to combine these 2 equations into one.

EquationA : {if(100-sum(if(INSERTANS:324926X17X804SQ031=="No",100,0),if(INSERTANS:324926X17X804SQ032=="No",100,0),if(INSERTANS:324926X17X804SQ033=="No",100,0),if(INSERTANS:324926X17X804SQ034=="No",100,0),if(INSERTANS:324926X17X804SQ035=="No",100,0),if(INSERTANS:324926X17X804SQ036=="No",100,0),if(INSERTANS:324926X17X804SQ037=="No",100,0))<100,0,100)}%

EquationB: {if(100-sum(if(INSERTANS:324926X17X804SQ031=="No",100,0),if(INSERTANS:324926X17X804SQ032=="No",100,0),if(INSERTANS:324926X17X804SQ033=="No",100,0),if(INSERTANS:324926X17X804SQ034=="No",100,0),if(INSERTANS:324926X17X804SQ035=="No",100,0),if(INSERTANS:324926X17X804SQ036=="No",100,0),if(INSERTANS:324926X17X804SQ037=="No",100,0))<100,0,round(sum(if(INSERTANS:324926X17X804SQ001=="No",5,0),if(INSERTANS:324926X17X804SQ002=="No",2,0),if(INSERTANS:324926X17X804SQ003=="No",2,0),if(INSERTANS:324926X17X804SQ004=="No",3,0),if(INSERTANS:324926X17X804SQ005!="No",3,0),if(INSERTANS:324926X17X804SQ006=="No",2,0),if(INSERTANS:324926X17X804SQ007=="No",2,0),if(INSERTANS:324926X17X804SQ008=="No",2,0),if(INSERTANS:324926X17X804SQ009=="No",5,0),if(INSERTANS:324926X17X804SQ010=="No",5,0),if(INSERTANS:324926X17X804SQ011=="No",5,0),if(INSERTANS:324926X17X804SQ012=="No",5,0),if(INSERTANS:324926X17X804SQ013=="No",2,0),if(INSERTANS:324926X17X804SQ014=="No",2,0),if(INSERTANS:324926X17X804SQ015=="No",3,0),if(INSERTANS:324926X17X804SQ016=="No",3,0),if(INSERTANS:324926X17X804SQ017=="No",3,0),if(INSERTANS:324926X17X804SQ018=="No",5,0),if(INSERTANS:324926X17X804SQ019!="No",5,0),if(INSERTANS:324926X17X804SQ020=="No",5,0),if(INSERTANS:324926X17X804SQ021=="No",5,0)if(INSERTANS:324926X17X804SQ022=="No",5,0),if(INSERTANS:324926X17X804SQ023=="No",3,0),if(INSERTANS:324926X17X804SQ024=="No",3,0),if(INSERTANS:324926X17X804SQ025=="No",5,0),if(INSERTANS:324926X17X804SQ026=="No",5,0),if(INSERTANS:324926X17X804SQ027=="No",3,0),if(INSERTANS:324926X17X804SQ028=="No",3,0),if(INSERTANS:324926X17X804SQ029=="No",3,0),if(INSERTANS:324926X17X804SQ030=="No",5,0),if(INSERTANS:324926X17X804SQ031=="No",5,0),if(INSERTANS:324926X17X804SQ032=="No",5,0),if(INSERTANS:324926X17X804SQ033=="No",5,0),if(INSERTANS:324926X17X804SQ034=="No",5,0),if(INSERTANS:324926X17X804SQ035=="No",5,0),if(INSERTANS:324926X17X804SQ036=="No",5,0),if(INSERTANS:324926X17X804SQ037=="No",5,0),if(INSERTANS:324926X17X804SQ038=="No",2,0),if(INSERTANS:324926X17X804SQ039=="No",2,0),if(INSERTANS:324926X17X804SQ040=="No",2,0),if(INSERTANS:324926X17X804SQ041=="No",2,0),if(INSERTANS:324926X17X804SQ042=="No",2,0),if(INSERTANS:324926X17X804SQ043=="No",2,0),if(INSERTANS:324926X17X804SQ044=="No",2,0))/158*100,2))}%

Please Log in to join the conversation.

  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
1 year 11 months ago - 1 year 11 months ago #228007 by Joffm
Replied by Joffm on topic Combine equations & send risk alerts
Please, answer the initial questions.

And it is difficult for me to read something with this INSERTANS stuff.
Better you use ExpressionScript.

1. I am sure you can shorten the equation by using
  • suitable codes
  • suitable functions
  • some mathematical transformations
But why do you want to combine them?

You have two equations "eqA" and "eqB"
So create a third "eqC" with
{if(eqA<100 and eqB<85,1,0)}
Now, if eqC is "1", send out, if it is "0", do not.

Joffm

Oh, and do not add the % sign; you won't be able to calculate eqC.

Volunteers are not paid.
Not because they are worthless, but because they are priceless
Last edit: 1 year 11 months ago by Joffm.
The following user(s) said Thank You: holch

Please Log in to join the conversation.

  • mu_akubaraly
  • mu_akubaraly's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
1 year 11 months ago #228035 by mu_akubaraly
Replied by mu_akubaraly on topic Combine equations & send risk alerts
Thanks for getting back to me Joffm. I am still very new to Lime, apologies for the messy code. I managed to simplify it by creating a 3rd equation as follows:

{if(G03Q25.shown < 100 OR G03Q24.shown < 85, 1, 0)}

Im not sure if the above is correct? Can I use an "OR" statement in place of the "AND"?

Also with regards to the % sign, we cant remove this as we use it in a power query, is there any way to use another expression ? I've researched str_replace & intval but not sure how to use them:

intval((if(str_replace(G03Q25.shown, "%", " ") < 100 OR str_replace(G03Q24.shown, "%", " ") < 85, 1, 0)))

Really appreciate your assistance

Please Log in to join the conversation.

  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
1 year 11 months ago - 1 year 11 months ago #228038 by Joffm
Replied by Joffm on topic Combine equations & send risk alerts

{if(G03Q25.shown < 100 OR G03Q24.shown < 85, 1, 0)}

Im not sure if the above is correct? Can I use an "OR" statement in place of the "AND"?

We do not know what your real condition is.
Have both equations to be fulfilled to send the mail?  -> AND
Or only one of them? -> OR
As we learned at school in Boolean Algebra.

By the way: Both your equations - as you showed them before - do not give a result that is worth to compare.
equationA is either 0 or 100
equationB is either 0 (if equationA, which is included in equationB is 0) or has some percentage as result.
So it should be necessary at all to combine again.

Also with regards to the % sign, we cant remove this as we use it in a power query

Of course, you can. The equation is is independent of what you do later with the result.

And you should really read the manual about "this, self, that", "implemented functions" and "access to variables"

As said before:
You can simplify your two equations using:
  • suitable codes
  • suitable functions
  • some mathematical transformations
equationA:
{if(100-countif("No",that.Q804.sq_N1.NAOK)*100<100,0,100)} 

equationB: (linefeeds inserted for more clarity)
{if(100-countif("No",that.Q804.sq_N1.NAOK)*100<100,0,round(sum(
countif("No",that.Q804.sq_N2.NAOK)*2,
countif("No",that.Q804.sq_N3.NAOK)*3,
countif("No",that.Q804.sq_N5.NAOK,that.Q804.sq_N1.NAOK)*5,
(5-countif("No",that.Q804.sq_R5.NAOK)*5),
(3-countif("No",that.Q804.sq_R3.NAOK)*3)
)/158*100,2))}


with:
  • no use of "INSERTANS, but ExpressionScript
  • question called "Q804"  (I used this because the questionID was 804)
  • "normal" calculated subquestion codes starting with "N"
  • "reverse" calculated subquestion codes starting with "R" 
  • Codes weighted with "2" have a "2" in second place
  • Codes weighted with "3" have a "3" in second place
  • Codes weighted with "5" have a "5" in second place
  • Three times used codes (31-37)   have a "1" in second place

Example:
Q804_SQ001 -> Q804_N501
Q804_SQ002 -> Q804_N202
Q804_SQ003 -> Q804_N203
Q804_SQ004 -> Q804_N304
Q804_SQ005 -> Q804_R305
Q804_SQ006 -> Q804_N206
Q804_SQ032 -> Q804_N132

This is not really tested.
I have no time to create something that might be similar to your survey.

So, for further questions you should send a lss export of these relevant questions.

Joffm

Volunteers are not paid.
Not because they are worthless, but because they are priceless
Last edit: 1 year 11 months ago by Joffm.

Please Log in to join the conversation.

Lime-years ahead

Online-surveys for every purse and purpose