CALCULATED field

Joel Palmius <[email protected]> Fri, 28 Mar 2008 14:28:46 +0100 (CET)
Newsgroups gmane.comp.apache.mod-survey.general
Message-ID <[email protected]>
I've been tinkering a bit with calculated fields and added support for 
them through a new tag, CALCULATED. The following works in the current 
SVN:

<SURVEY TITLE="Make a mean">
   <TEXT NAME="val1" CAPTION="Insert value 1" NUMERICAL="yes" />
   <TEXT NAME="val2" CAPTION="Insert value 2" NUMERICAL="yes" />

   <CALCULATED NAME="mean" CALCULATION="($val1 + $val2) / 2" />

</SURVEY>

If entering 3 and 4 in the text fields, the data would contain a field 
"mean" with the value "3.5".

There's a bit of regexp going on in there, but I'm reasonably sure it will 
work with most simple (+-*/ and parentheses) mathematical constructs and 
integer values. Floating point values (for example multiplying a variable 
with 0.5) will bug out because of the dot being interpreted by the regular 
expression.

I need to make a thorough analysis of the security around this before 
releasing it properly, but if you feel you need it and only have trusted 
users, you can always check out the SVN.

   // Joel
Skickat av Joel Palmius <[email protected]>
till survey-discussion