Salt Issue: add -624 lbs

Whoops – I just had a user encounter an issue with @psoup1965 's salt formula: https://app.pooldash.com/formula/motherly_mind_741

The app was telling him to add -624 pounds of salt, which was really confusing, until I took a look at the function:

// I only set this up for 8-40000 gallons
if ((Gallonage < 8000) || (Gallonage > 40000))
{
 return -9999;
}

// Need a mutiplier to determine the amount of salt to add. 

     if (Gallonage ==  8000 ) { mutiplier =6.650;} 
else if (Gallonage ==  9000 ) { mutiplier =7.500; } 
else if (Gallonage == 10000 ) { mutiplier =8.325; }  
else if (Gallonage == 11000 ) { mutiplier =9.150; } 
else if (Gallonage == 12000 ) { mutiplier =10.000;} 
else if (Gallonage == 13000 ) { mutiplier =10.825;} 
else if (Gallonage == 14000 ) { mutiplier =11.650;}
else if (Gallonage == 15000 ) { mutiplier =12.500;}
else if (Gallonage == 16000 ) { mutiplier =13.320;}  
else if (Gallonage == 17000 ) { mutiplier =14.150;}  
else if (Gallonage == 18000 ) { mutiplier =15.000;}  
else if (Gallonage == 19000 ) { mutiplier =15.820;} 
else if (Gallonage == 20000 ) { mutiplier =16.650;} 
else if (Gallonage == 21000 ) { mutiplier =17.500;} 
else if (Gallonage == 22000 ) { mutiplier =18.320;} 
else if (Gallonage == 23000 ) { mutiplier =19.150;}  
else if (Gallonage == 24000 ) { mutiplier =20.000;}
else if (Gallonage == 25000 ) { mutiplier =20.820;}  
else if (Gallonage == 26000 ) { mutiplier =21.650;} 
else if (Gallonage == 27000 ) { mutiplier =22.500;} 
else if (Gallonage == 28000 ) { mutiplier =23.325;}  
else if (Gallonage == 29000 ) { mutiplier =24.150;}  
else if (Gallonage == 30000 ) { mutiplier =25.000;}  
else if (Gallonage == 31000 ) { mutiplier =25.820;}  
else if (Gallonage == 32000 ) { mutiplier =26.650;}  
else if (Gallonage == 33000 ) { mutiplier =27.500;} 
else if (Gallonage == 34000 ) { mutiplier =28.320;}  
else if (Gallonage == 35000 ) { mutiplier =29.150;}  
else if (Gallonage == 36000 ) { mutiplier =30.000;} 
else if (Gallonage == 37000 ) { mutiplier =30.820;} 
else if (Gallonage == 38000 ) { mutiplier =31.650;} 
else if (Gallonage == 39000 ) { mutiplier =33.325;} 
else if (Gallonage == 40000 ) { mutiplier =34.150;} 
 
     if (Saltage ==  0    ) { saltMutiplier =  32 ;}
else if (Saltage ==  100  ) { saltMutiplier =  31 ;}
else if (Saltage ==  200  ) { saltMutiplier =  30 ;}
else if (Saltage ==  300  ) { saltMutiplier =  29 ;}
else if (Saltage ==  400  ) { saltMutiplier =  28 ;}
else if (Saltage ==  500  ) { saltMutiplier =  27 ;}
else if (Saltage ==  600  ) { saltMutiplier =  26 ;}
else if (Saltage ==  700  ) { saltMutiplier =  25 ;}
else if (Saltage ==  800  ) { saltMutiplier =  24 ;}
else if (Saltage ==  900  ) { saltMutiplier =  23 ;}
else if (Saltage ==  1000 ) { saltMutiplier =  22 ;}
else if (Saltage ==  1100 ) { saltMutiplier =  21 ;}
else if (Saltage ==  1200 ) { saltMutiplier =  20 ;}
else if (Saltage ==  1300 ) { saltMutiplier =  19 ;}
else if (Saltage ==  1400 ) { saltMutiplier =  18 ;}
else if (Saltage ==  1500 ) { saltMutiplier =  17 ;}
else if (Saltage ==  1600 ) { saltMutiplier =  16 ;}
else if (Saltage ==  1700 ) { saltMutiplier =  15 ;}
else if (Saltage ==  1800 ) { saltMutiplier =  14 ;}
else if (Saltage ==  1900 ) { saltMutiplier =  13 ;}
else if (Saltage ==  2000 ) { saltMutiplier =  12 ;}
else if (Saltage ==  2100 ) { saltMutiplier =  11 ;}
else if (Saltage ==  2200 ) { saltMutiplier =  10 ;}
else if (Saltage ==  2300 ) { saltMutiplier =  9 ; }
else if (Saltage ==  2400 ) { saltMutiplier =  8 ; }
else if (Saltage ==  2500 ) { saltMutiplier =  7 ; }
else if (Saltage ==  2600 ) { saltMutiplier =  6 ; }
else if (Saltage ==  2700 ) { saltMutiplier =  5 ; }
else if (Saltage ==  2800 ) { saltMutiplier =  4 ; }
else if (Saltage ==  2900 ) { saltMutiplier =  3 ; }
else if (Saltage ==  3000 ) { saltMutiplier =  2 ; }
else if (Saltage ==  3100 ) { saltMutiplier =  1 ; }

//Ounces
return Math.round((saltMutiplier * mutiplier)*16);

The aha moment was realizing that 9999 ounces is about 624 pounds.

I think the formula is actually really great, and I’m glad he took the time to make it! I’ll probably replace the long if-else statements with some algebra that works for any size pool, and then clean a few other little things up.

2 Likes

Ok, I’ve remixed the formula here, with a new salt function: https://app.pooldash.com/formula/jumpy_bear_993/edit#t-NaCl

I left a shoutout to psoup in the comments :slight_smile:

In the next app update, I’ll make sure it auto-assigns salt pools to this new formula. In the meantime, users will need to select the “official” Salt Pool recipe:

2 Likes

That formula was a strange one where I took some existing charts that are published and reverse engineered them. By time I was able to get the proper formula I was tired haha… it worked.

Agreed, the long if statement is not the greatest but I was not able to come up with a conclusive formula elsewise.

I love the magicMutiplier and the delta!

Since the return required a number, I thought I’d make it a little absurd glad it was caught and that -624 lbs of salt was not extracted 8=)

Mahalo for the shoutout… love my name in code - a programmers dream come true!

2 Likes