dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #23856
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 11622: Added tip on how to use mathematical functions in indicators and validation rules
------------------------------------------------------------
revno: 11622
committer: Lars Helge Øverland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2013-08-09 12:02:06 +0200
message:
Added tip on how to use mathematical functions in indicators and validation rules
modified:
dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/MathUtils.java
dhis-2/dhis-support/dhis-support-system/src/test/java/org/hisp/dhis/system/util/MathUtilsTest.java
dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/resources/org/hisp/dhis/dd/i18n_module.properties
dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/webapp/dhis-web-maintenance-datadictionary/indicatorExpressionBuilderForm.vm
dhis-2/dhis-web/dhis-web-validationrule/src/main/resources/org/hisp/dhis/validationrule/i18n_module.properties
dhis-2/dhis-web/dhis-web-validationrule/src/main/webapp/dhis-web-validationrule/expressionBuilderForm.vm
--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk
Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== modified file 'dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/MathUtils.java'
--- dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/MathUtils.java 2013-08-09 08:09:35 +0000
+++ dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/MathUtils.java 2013-08-09 10:02:06 +0000
@@ -68,9 +68,7 @@
{
final String expression = leftSide + operator.getMathematicalOperator() + rightSide;
- final JEP parser = new JEP();
-
- parser.addStandardFunctions();
+ final JEP parser = getJep();
parser.parseExpression( expression );
return ( parser.getValue() == 1.0 );
@@ -84,9 +82,7 @@
*/
public static double calculateExpression( String expression )
{
- final JEP parser = new JEP();
-
- parser.addStandardFunctions();
+ final JEP parser = getJep();
parser.parseExpression( expression );
double result = parser.getValue();
@@ -102,9 +98,7 @@
*/
public static boolean expressionHasErrors( String expression )
{
- final JEP parser = new JEP();
-
- parser.addStandardFunctions();
+ final JEP parser = getJep();
parser.parseExpression( expression );
return parser.hasError();
@@ -119,15 +113,24 @@
*/
public static String getExpressionErrorInfo( String expression )
{
- final JEP parser = new JEP();
-
- parser.addStandardFunctions();
+ final JEP parser = getJep();
parser.parseExpression( expression );
return parser.getErrorInfo();
}
/**
+ * Returns an JEP parser instance.
+ */
+ private static JEP getJep()
+ {
+ final JEP parser = new JEP();
+ parser.addStandardFunctions();
+ parser.addStandardConstants();
+ return parser;
+ }
+
+ /**
* Rounds off downwards to the next distinct value.
*
* @param value The value to round off
=== modified file 'dhis-2/dhis-support/dhis-support-system/src/test/java/org/hisp/dhis/system/util/MathUtilsTest.java'
--- dhis-2/dhis-support/dhis-support-system/src/test/java/org/hisp/dhis/system/util/MathUtilsTest.java 2013-08-09 08:09:35 +0000
+++ dhis-2/dhis-support/dhis-support-system/src/test/java/org/hisp/dhis/system/util/MathUtilsTest.java 2013-08-09 10:02:06 +0000
@@ -262,5 +262,6 @@
assertEquals( 3d, MathUtils.calculateExpression( "abs(-3)" ), 0.01 );
assertEquals( 3d, MathUtils.calculateExpression( "abs(3-6)" ), 0.01 );
assertEquals( 5d, MathUtils.calculateExpression( "sqrt(25)" ), 0.01 );
+ assertEquals( 1d, MathUtils.calculateExpression( "mod(7,2)" ), 0.01 );
}
}
=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/resources/org/hisp/dhis/dd/i18n_module.properties'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/resources/org/hisp/dhis/dd/i18n_module.properties 2013-06-25 13:58:55 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/resources/org/hisp/dhis/dd/i18n_module.properties 2013-08-09 10:02:06 +0000
@@ -204,4 +204,6 @@
edit_data_element_category_option=Edit data element category option
available_category_options=Available category options
selected_category_options=Selected category options
-use_as_data_dimension=Use as data dimension
\ No newline at end of file
+use_as_data_dimension=Use as data dimension
+tip=Tip
+use=use
\ No newline at end of file
=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/webapp/dhis-web-maintenance-datadictionary/indicatorExpressionBuilderForm.vm'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/webapp/dhis-web-maintenance-datadictionary/indicatorExpressionBuilderForm.vm 2013-04-21 20:06:01 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-datadictionary/src/main/webapp/dhis-web-maintenance-datadictionary/indicatorExpressionBuilderForm.vm 2013-08-09 10:02:06 +0000
@@ -158,6 +158,7 @@
<tr>
<td>
<input type="text" id="description" name="description" style="width:250px" class="{validate:{required:true}}"/>
+ <div class="tipText" style="margin-top: 4px">$i18n.getString( "tip" ): $i18n.getString( "use" ) abs(x) sin(x) cos(x) tan(x) ln(x) log(x) sqrt(x) mod(x,y)</div>
</td>
<td></td>
<td>
=== modified file 'dhis-2/dhis-web/dhis-web-validationrule/src/main/resources/org/hisp/dhis/validationrule/i18n_module.properties'
--- dhis-2/dhis-web/dhis-web-validationrule/src/main/resources/org/hisp/dhis/validationrule/i18n_module.properties 2013-07-25 05:37:29 +0000
+++ dhis-2/dhis-web/dhis-web-validationrule/src/main/resources/org/hisp/dhis/validationrule/i18n_module.properties 2013-08-09 10:02:06 +0000
@@ -127,4 +127,6 @@
skip_for_missing_values=Skip for missing values
select_parameters=Select parameters
compulsory_pair=Compulsory pair
-visible_in_validation_violations=visible in validation violations
\ No newline at end of file
+visible_in_validation_violations=visible in validation violations
+tip=Tip
+use=use
\ No newline at end of file
=== modified file 'dhis-2/dhis-web/dhis-web-validationrule/src/main/webapp/dhis-web-validationrule/expressionBuilderForm.vm'
--- dhis-2/dhis-web/dhis-web-validationrule/src/main/webapp/dhis-web-validationrule/expressionBuilderForm.vm 2012-09-23 08:50:59 +0000
+++ dhis-2/dhis-web/dhis-web-validationrule/src/main/webapp/dhis-web-validationrule/expressionBuilderForm.vm 2013-08-09 10:02:06 +0000
@@ -23,8 +23,9 @@
</tr>
<tr>
<td colspan="2">
- <input type="text" id="description" name="description" style="width:250px" class="{validate:{required:true}}"/><br><br>
+ <input type="text" id="description" name="description" style="width:250px" class="{validate:{required:true}}"/><br>
<input type="checkbox" id="nullIfBlank" name="nullIfBlank" value="true"> <label for="nullIfBlank">$i18n.getString( "skip_for_missing_values" )</label>
+ <div class="tipText" style="margin-top: 4px">$i18n.getString( "tip" ): $i18n.getString( "use" ) abs(x) ln(x) log(x) sqrt(x) mod(x,y)</div>
</td>
<td>
<select id="constantId" name="constantId" size="3" style="min-width:450px" ondblclick="insertText( 'expression', this.value )">