dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #39749
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 20154: use aggregation type directly in DefaultQueryPlanner
------------------------------------------------------------
revno: 20154
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2015-09-15 14:13:04 +0700
message:
use aggregation type directly in DefaultQueryPlanner
modified:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/analytics/AggregationType.java
dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementGroup.java
dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/data/DefaultQueryPlanner.java
--
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-api/src/main/java/org/hisp/dhis/analytics/AggregationType.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/analytics/AggregationType.java 2015-09-15 05:39:53 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/analytics/AggregationType.java 2015-09-15 07:13:04 +0000
@@ -33,11 +33,11 @@
*/
public enum AggregationType
{
- SUM( "sum" ),
+ SUM( "sum" ),
AVERAGE( "avg" ),
AVERAGE_SUM_ORG_UNIT( "avg_sum_org_unit" ),
- COUNT( "count" ),
- STDDEV( "stddev" ),
+ COUNT( "count" ),
+ STDDEV( "stddev" ),
VARIANCE( "variance" ),
MIN( "min" ),
MAX( "max" ),
@@ -46,7 +46,7 @@
CUSTOM( "custom" ),
// Internal types
-
+
AVERAGE_SUM_INT( "avg_sum_int" ), // Sum in organisation unit hierarchy
AVERAGE_SUM_INT_DISAGGREGATION( "avg_sum_int_disaggregation" ), // Sum in organisation unit hierarchy
AVERAGE_INT( "avg_int" ),
@@ -64,7 +64,12 @@
{
return value;
}
-
+
+ public boolean isAverage()
+ {
+ return this == AVERAGE_SUM_ORG_UNIT || this == AVERAGE;
+ }
+
public static AggregationType fromValue( String value )
{
for ( AggregationType type : AggregationType.values() )
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementGroup.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementGroup.java 2015-08-31 07:42:50 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementGroup.java 2015-09-15 07:13:04 +0000
@@ -34,6 +34,7 @@
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement;
+import org.hisp.dhis.analytics.AggregationType;
import org.hisp.dhis.attribute.AttributeValue;
import org.hisp.dhis.common.BaseIdentifiableObject;
import org.hisp.dhis.common.BaseNameableObject;
@@ -137,12 +138,12 @@
}
/**
- * Returns the aggregation operator of the data elements in this group. Uses
+ * Returns the aggregation type of the data elements in this group. Uses
* an arbitrary member to determine the aggregation operator.
*/
- public String getAggregationOperator()
+ public AggregationType getAggregationType()
{
- return members != null && !members.isEmpty() ? members.iterator().next().getAggregationOperator() : null;
+ return members != null && !members.isEmpty() ? members.iterator().next().getAggregationType() : null;
}
/**
=== modified file 'dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/data/DefaultQueryPlanner.java'
--- dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/data/DefaultQueryPlanner.java 2015-09-15 06:55:31 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/data/DefaultQueryPlanner.java 2015-09-15 07:13:04 +0000
@@ -56,7 +56,6 @@
import org.hisp.dhis.organisationunit.OrganisationUnitService;
import org.hisp.dhis.period.Period;
import org.hisp.dhis.period.PeriodType;
-import org.hisp.dhis.program.ProgramIndicatorService;
import org.hisp.dhis.setting.SystemSettingManager;
import org.hisp.dhis.system.filter.AggregatableDataElementFilter;
import org.hisp.dhis.system.util.MathUtils;
@@ -616,7 +615,7 @@
if ( deg != null && !deg.getMembers().isEmpty() )
{
PeriodType periodType = PeriodType.getPeriodTypeByName( params.getPeriodType() );
- query.setAggregationType( getAggregationType( deg.getValueType(), deg.getAggregationOperator(), periodType, deg.getPeriodType() ) );
+ query.setAggregationType( getAggregationType( deg.getValueType(), deg.getAggregationType(), periodType, deg.getPeriodType() ) );
}
else
{
@@ -765,7 +764,7 @@
{
DataElement de = (DataElement) element;
- AggregationType aggregationType = getAggregationType( de.getValueType(), de.getAggregationOperator(), aggregationPeriodType, de.getPeriodType() );
+ AggregationType aggregationType = getAggregationType( de.getValueType(), de.getAggregationType(), aggregationPeriodType, de.getPeriodType() );
map.putValue( aggregationType, de );
}
@@ -797,7 +796,7 @@
* Puts the given element into the map according to the value type, aggregation
* operator, aggregation period type and data period type.
*/
- private AggregationType getAggregationType( ValueType valueType, String aggregationOperator,
+ private AggregationType getAggregationType( ValueType valueType, AggregationType aggregationOperator,
PeriodType aggregationPeriodType, PeriodType dataPeriodType )
{
AggregationType aggregationType;
@@ -805,29 +804,29 @@
boolean disaggregation = isDisaggregation( aggregationPeriodType, dataPeriodType );
boolean number = valueType.isNumeric();
- if ( AVERAGE_AGG_OPERATORS.contains( aggregationOperator ) && ValueType.BOOLEAN == valueType )
+ if ( aggregationOperator.isAverage() && ValueType.BOOLEAN == valueType )
{
aggregationType = AggregationType.AVERAGE_BOOL;
}
- else if ( DataElement.AGGREGATION_OPERATOR_AVERAGE_SUM.equals( aggregationOperator ) && number && disaggregation )
+ else if ( AggregationType.AVERAGE_SUM_ORG_UNIT == aggregationOperator && number && disaggregation )
{
aggregationType = AggregationType.AVERAGE_SUM_INT_DISAGGREGATION;
}
- else if ( DataElement.AGGREGATION_OPERATOR_AVERAGE_SUM.equals( aggregationOperator ) && number )
+ else if ( AggregationType.AVERAGE_SUM_ORG_UNIT == aggregationOperator && number )
{
aggregationType = AggregationType.AVERAGE_SUM_INT;
}
- else if ( DataElement.AGGREGATION_OPERATOR_AVERAGE.equals( aggregationOperator ) && number && disaggregation )
+ else if ( AggregationType.AVERAGE == aggregationOperator && number && disaggregation )
{
aggregationType = AggregationType.AVERAGE_INT_DISAGGREGATION;
}
- else if ( DataElement.AGGREGATION_OPERATOR_AVERAGE.equals( aggregationOperator ) && number )
+ else if ( AggregationType.AVERAGE == aggregationOperator && number )
{
aggregationType = AggregationType.AVERAGE_INT;
}
else
{
- aggregationType = AggregationType.fromValue( aggregationOperator );
+ aggregationType = aggregationOperator;
}
return aggregationType;