javarosa
javarosa copied to clipboard
Once() creating compounding calculation results.
Software and hardware versions
Detected in collect 1.4.5 build 1048 Confirmed in collect 1.9.1 Android 7.x (varies slightly by tablet) Nexus 9 tablet
Problem description
When using once() over only a portion of a calculation, it retains the output value of the entire calculation from one execution of the calculation to the next, instead of just the portion within the once() function.
For example, this calculation: once(random()) * 100
When run 3 times over the course of the survey, has these results: Original result of the random() function: .35232345 1st execution: .35232345 * 100 = 35.232345 2nd execution 35.232345 * 100 = 3523.2345 3rd execution 3523.2345 * 100 = 352323.45
So instead of re-running .35232345 * 100 = 35.232345 each execution, it is substituting the previous output in place of the once(random()) part of the calculation.
Workaround is to put the entire calculation within the once() function: once(random() * 100)
Steps to reproduce the problem
- Create a calculation formatted like the one above.
- Enter data save survey to prompt re-running of calculations.
- Review calculation output.
- Repeat several times to see iterative nature of the issue.
Expected behavior
It is expected that once() will "freeze" the random() function output, and hold that specific value (i.e. .35232345) for multiplication * 100 regardless of the number of times the calculation runs.
Other information
NA