dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #06323
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 1991: Applied the frequency/aggregation operator trick to data element datamart.
------------------------------------------------------------
revno: 1991
committer: Lars <larshelg@larshelg-laptop>
branch nick: trunk
timestamp: Tue 2010-06-15 12:15:01 +0200
message:
Applied the frequency/aggregation operator trick to data element datamart.
removed:
dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/util/FilterUtils.java
modified:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementOperand.java
dhis-2/dhis-api/src/test/java/org/hisp/dhis/dataelement/OperandTest.java
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataelement/DefaultDataElementCategoryService.java
dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/aggregation/dataelement/AverageBoolAggregator.java
dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/aggregation/dataelement/AverageIntAggregator.java
dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/aggregation/dataelement/DataElementAggregator.java
dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/aggregation/dataelement/SumBoolAggregator.java
dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/aggregation/dataelement/SumIntAggregator.java
dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/dataelement/DefaultDataElementDataMart.java
dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/engine/DefaultDataMartEngine.java
dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/indicator/DefaultIndicatorDataMart.java
dhis-2/dhis-services/dhis-service-datamart-default/src/test/java/org/hisp/dhis/datamart/DataMartServiceTest.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/dataelement/DataElementOperand.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementOperand.java 2010-06-14 15:51:12 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataelement/DataElementOperand.java 2010-06-15 10:15:01 +0000
@@ -68,6 +68,8 @@
private String operandName;
+ private String valueType;
+
private String aggregationOperator;
private List<Integer> aggregationLevels = new ArrayList<Integer>();
@@ -103,12 +105,13 @@
this.operandName = operandName;
}
- public DataElementOperand( int dataElementId, int optionComboId, String operandName, String aggregationOperator, List<Integer> aggregationLevels, int frequencyOrder )
+ public DataElementOperand( int dataElementId, int optionComboId, String operandName, String valueType, String aggregationOperator, List<Integer> aggregationLevels, int frequencyOrder )
{
this.dataElementId = dataElementId;
this.optionComboId = optionComboId;
this.operandId = dataElementId + SEPARATOR + optionComboId;
this.operandName = operandName;
+ this.valueType = valueType;
this.aggregationOperator = aggregationOperator;
this.aggregationLevels = aggregationLevels;
this.frequencyOrder = frequencyOrder;
@@ -276,6 +279,16 @@
this.operandName = operandName;
}
+ public String getValueType()
+ {
+ return valueType;
+ }
+
+ public void setValueType( String valueType )
+ {
+ this.valueType = valueType;
+ }
+
public String getAggregationOperator()
{
return aggregationOperator;
=== modified file 'dhis-2/dhis-api/src/test/java/org/hisp/dhis/dataelement/OperandTest.java'
--- dhis-2/dhis-api/src/test/java/org/hisp/dhis/dataelement/OperandTest.java 2010-06-14 15:51:12 +0000
+++ dhis-2/dhis-api/src/test/java/org/hisp/dhis/dataelement/OperandTest.java 2010-06-15 10:15:01 +0000
@@ -43,11 +43,11 @@
@Test
public void getRelevantAggregationLevel()
{
- DataElementOperand operand = new DataElementOperand( 1, 1, "Operand", null, new ArrayList<Integer>(), 0 );
+ DataElementOperand operand = new DataElementOperand( 1, 1, "Operand", null, null, new ArrayList<Integer>(), 0 );
assertNull( operand.getRelevantAggregationLevel( 1 ) );
- operand = new DataElementOperand( 1, 1, "Operand", null, Arrays.asList( 3, 5 ), 0 );
+ operand = new DataElementOperand( 1, 1, "Operand", null, null, Arrays.asList( 3, 5 ), 0 );
assertEquals( new Integer( 3 ), operand.getRelevantAggregationLevel( 1 ) );
assertEquals( new Integer( 3 ), operand.getRelevantAggregationLevel( 2 ) );
@@ -60,12 +60,12 @@
@Test
public void aggregationLevelIsValid()
{
- DataElementOperand operand = new DataElementOperand( 1, 1, "Operand", null, new ArrayList<Integer>(), 0 );
+ DataElementOperand operand = new DataElementOperand( 1, 1, "Operand", null, null, new ArrayList<Integer>(), 0 );
assertTrue( operand.aggregationLevelIsValid( 1, 3 ) );
assertTrue( operand.aggregationLevelIsValid( 4, 3 ) );
- operand = new DataElementOperand( 1, 1, "Operand", null, Arrays.asList( 3, 5 ), 0 );
+ operand = new DataElementOperand( 1, 1, "Operand", null, null, Arrays.asList( 3, 5 ), 0 );
assertTrue( operand.aggregationLevelIsValid( 2, 2 ) );
assertTrue( operand.aggregationLevelIsValid( 2, 3 ) );
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataelement/DefaultDataElementCategoryService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataelement/DefaultDataElementCategoryService.java 2010-06-14 15:51:12 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataelement/DefaultDataElementCategoryService.java 2010-06-15 10:15:01 +0000
@@ -39,6 +39,7 @@
import org.apache.commons.collections.CollectionUtils;
import org.hisp.dhis.common.GenericIdentifiableObjectStore;
import org.hisp.dhis.common.GenericStore;
+import org.hisp.dhis.period.DailyPeriodType;
import org.hisp.dhis.system.util.Filter;
import org.hisp.dhis.system.util.FilterUtils;
import org.hisp.dhis.system.util.UUIdUtils;
@@ -395,14 +396,14 @@
Set<DataElementCategoryOptionCombo> categoryOptionCombos = dataElement.getCategoryCombo()
.getOptionCombos();
- int frequencyOrder = dataElement.getPeriodType() != null ? dataElement.getPeriodType().getFrequencyOrder() : 0;
+ int frequencyOrder = dataElement.getPeriodType() != null ? dataElement.getPeriodType().getFrequencyOrder() : new DailyPeriodType().getFrequencyOrder(); //TODO improve
if ( categoryOptionCombos.size() > 1 && !(dataElement instanceof CalculatedDataElement) )
{
for ( DataElementCategoryOptionCombo optionCombo : categoryOptionCombos )
{
DataElementOperand operand = new DataElementOperand( dataElement.getId(), optionCombo.getId(), dataElement.getName()
- + optionCombo.getName(), dataElement.getAggregationOperator(), new ArrayList<Integer>( dataElement.getAggregationLevels() ), frequencyOrder );
+ + optionCombo.getName(), dataElement.getType(), dataElement.getAggregationOperator(), new ArrayList<Integer>( dataElement.getAggregationLevels() ), frequencyOrder );
operands.add( operand );
}
@@ -410,7 +411,7 @@
else
{
DataElementOperand operand = new DataElementOperand( dataElement.getId(), categoryOptionCombos.iterator().next().getId(),
- dataElement.getName(), dataElement.getAggregationOperator(), new ArrayList<Integer>( dataElement.getAggregationLevels() ), frequencyOrder );
+ dataElement.getName(), dataElement.getType(), dataElement.getAggregationOperator(), new ArrayList<Integer>( dataElement.getAggregationLevels() ), frequencyOrder );
operands.add( operand );
}
=== modified file 'dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/aggregation/dataelement/AverageBoolAggregator.java'
--- dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/aggregation/dataelement/AverageBoolAggregator.java 2010-06-14 16:27:39 +0000
+++ dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/aggregation/dataelement/AverageBoolAggregator.java 2010-06-15 10:15:01 +0000
@@ -27,6 +27,8 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+import static org.hisp.dhis.dataelement.DataElement.AGGREGATION_OPERATOR_AVERAGE;
+import static org.hisp.dhis.dataelement.DataElement.VALUE_TYPE_BOOL;
import static org.hisp.dhis.system.util.DateUtils.getDaysInclusive;
import java.util.ArrayList;
@@ -43,6 +45,7 @@
import org.hisp.dhis.organisationunit.OrganisationUnit;
import org.hisp.dhis.organisationunit.OrganisationUnitHierarchy;
import org.hisp.dhis.period.Period;
+import org.hisp.dhis.period.PeriodType;
/**
* @author Lars Helge Overland
@@ -194,4 +197,20 @@
return totalSums;
}
+
+ public Map<DataElementOperand, Integer> getOperandIndexMap( Collection<DataElementOperand> operands, PeriodType periodType, Map<DataElementOperand, Integer> operandIndexMap )
+ {
+ Map<DataElementOperand, Integer> avgOperandIndexMap = new HashMap<DataElementOperand, Integer>();
+
+ for ( final DataElementOperand operand : operands )
+ {
+ if ( operand.getValueType().equals( VALUE_TYPE_BOOL ) && ( operand.getAggregationOperator().equals( AGGREGATION_OPERATOR_AVERAGE ) &&
+ operand.getFrequencyOrder() < periodType.getFrequencyOrder() ) )
+ {
+ avgOperandIndexMap.put( operand, operandIndexMap.get( operand ) );
+ }
+ }
+
+ return avgOperandIndexMap;
+ }
}
=== modified file 'dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/aggregation/dataelement/AverageIntAggregator.java'
--- dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/aggregation/dataelement/AverageIntAggregator.java 2010-06-14 16:27:39 +0000
+++ dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/aggregation/dataelement/AverageIntAggregator.java 2010-06-15 10:15:01 +0000
@@ -27,6 +27,8 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+import static org.hisp.dhis.dataelement.DataElement.AGGREGATION_OPERATOR_AVERAGE;
+import static org.hisp.dhis.dataelement.DataElement.VALUE_TYPE_INT;
import static org.hisp.dhis.system.util.DateUtils.getDaysInclusive;
import java.util.ArrayList;
@@ -45,6 +47,7 @@
import org.hisp.dhis.organisationunit.OrganisationUnit;
import org.hisp.dhis.organisationunit.OrganisationUnitHierarchy;
import org.hisp.dhis.period.Period;
+import org.hisp.dhis.period.PeriodType;
/**
* @author Lars Helge Overland
@@ -209,4 +212,20 @@
return totalSums;
}
+
+ public Map<DataElementOperand, Integer> getOperandIndexMap( Collection<DataElementOperand> operands, PeriodType periodType, Map<DataElementOperand, Integer> operandIndexMap )
+ {
+ Map<DataElementOperand, Integer> avgOperandIndexMap = new HashMap<DataElementOperand, Integer>();
+
+ for ( final DataElementOperand operand : operands )
+ {
+ if ( operand.getValueType().equals( VALUE_TYPE_INT ) && operand.getAggregationOperator().equals( AGGREGATION_OPERATOR_AVERAGE ) &&
+ operand.getFrequencyOrder() < periodType.getFrequencyOrder() )
+ {
+ avgOperandIndexMap.put( operand, operandIndexMap.get( operand ) );
+ }
+ }
+
+ return avgOperandIndexMap;
+ }
}
=== modified file 'dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/aggregation/dataelement/DataElementAggregator.java'
--- dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/aggregation/dataelement/DataElementAggregator.java 2010-06-08 19:47:40 +0000
+++ dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/aggregation/dataelement/DataElementAggregator.java 2010-06-15 10:15:01 +0000
@@ -36,6 +36,7 @@
import org.hisp.dhis.organisationunit.OrganisationUnit;
import org.hisp.dhis.organisationunit.OrganisationUnitHierarchy;
import org.hisp.dhis.period.Period;
+import org.hisp.dhis.period.PeriodType;
/**
* @author Lars Helge Overland
@@ -53,4 +54,6 @@
Map<DataElementOperand, double[]> getAggregate( final Collection<CrossTabDataValue> crossTabValues,
final Date startDate, final Date endDate, final Date aggregationStartDate, final Date aggregationEndDate, int unitLevel );
+
+ Map<DataElementOperand, Integer> getOperandIndexMap( Collection<DataElementOperand> operands, PeriodType periodType, Map<DataElementOperand, Integer> operandIndexMap );
}
=== modified file 'dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/aggregation/dataelement/SumBoolAggregator.java'
--- dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/aggregation/dataelement/SumBoolAggregator.java 2010-06-14 16:27:39 +0000
+++ dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/aggregation/dataelement/SumBoolAggregator.java 2010-06-15 10:15:01 +0000
@@ -27,6 +27,9 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+import static org.hisp.dhis.dataelement.DataElement.AGGREGATION_OPERATOR_AVERAGE;
+import static org.hisp.dhis.dataelement.DataElement.AGGREGATION_OPERATOR_SUM;
+import static org.hisp.dhis.dataelement.DataElement.VALUE_TYPE_BOOL;
import static org.hisp.dhis.system.util.DateUtils.getDaysInclusive;
import static org.hisp.dhis.system.util.MathUtils.getFloor;
@@ -44,6 +47,7 @@
import org.hisp.dhis.organisationunit.OrganisationUnit;
import org.hisp.dhis.organisationunit.OrganisationUnitHierarchy;
import org.hisp.dhis.period.Period;
+import org.hisp.dhis.period.PeriodType;
/**
* @author Lars Helge Overland
@@ -199,4 +203,20 @@
return totalSums;
}
+
+ public Map<DataElementOperand, Integer> getOperandIndexMap( Collection<DataElementOperand> operands, PeriodType periodType, Map<DataElementOperand, Integer> operandIndexMap )
+ {
+ Map<DataElementOperand, Integer> sumOperandIndexMap = new HashMap<DataElementOperand, Integer>();
+
+ for ( final DataElementOperand operand : operands )
+ {
+ if ( operand.getValueType().equals( VALUE_TYPE_BOOL ) && ( operand.getAggregationOperator().equals( AGGREGATION_OPERATOR_SUM ) ||
+ ( operand.getAggregationOperator().equals( AGGREGATION_OPERATOR_AVERAGE ) && operand.getFrequencyOrder() >= periodType.getFrequencyOrder() ) ) )
+ {
+ sumOperandIndexMap.put( operand, operandIndexMap.get( operand ) );
+ }
+ }
+
+ return sumOperandIndexMap;
+ }
}
=== modified file 'dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/aggregation/dataelement/SumIntAggregator.java'
--- dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/aggregation/dataelement/SumIntAggregator.java 2010-06-14 16:27:39 +0000
+++ dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/aggregation/dataelement/SumIntAggregator.java 2010-06-15 10:15:01 +0000
@@ -27,6 +27,9 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+import static org.hisp.dhis.dataelement.DataElement.AGGREGATION_OPERATOR_AVERAGE;
+import static org.hisp.dhis.dataelement.DataElement.AGGREGATION_OPERATOR_SUM;
+import static org.hisp.dhis.dataelement.DataElement.VALUE_TYPE_INT;
import static org.hisp.dhis.system.util.DateUtils.getDaysInclusive;
import java.util.ArrayList;
@@ -45,6 +48,7 @@
import org.hisp.dhis.organisationunit.OrganisationUnit;
import org.hisp.dhis.organisationunit.OrganisationUnitHierarchy;
import org.hisp.dhis.period.Period;
+import org.hisp.dhis.period.PeriodType;
/**
* @author Lars Helge Overland
@@ -207,4 +211,20 @@
return totalSums;
}
+
+ public Map<DataElementOperand, Integer> getOperandIndexMap( Collection<DataElementOperand> operands, PeriodType periodType, Map<DataElementOperand, Integer> operandIndexMap )
+ {
+ Map<DataElementOperand, Integer> sumOperandIndexMap = new HashMap<DataElementOperand, Integer>();
+
+ for ( final DataElementOperand operand : operands )
+ {
+ if ( operand.getValueType().equals( VALUE_TYPE_INT ) && ( operand.getAggregationOperator().equals( AGGREGATION_OPERATOR_SUM ) ||
+ ( operand.getAggregationOperator().equals( AGGREGATION_OPERATOR_AVERAGE ) && operand.getFrequencyOrder() >= periodType.getFrequencyOrder() ) ) )
+ {
+ sumOperandIndexMap.put( operand, operandIndexMap.get( operand ) );
+ }
+ }
+
+ return sumOperandIndexMap;
+ }
}
=== modified file 'dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/dataelement/DefaultDataElementDataMart.java'
--- dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/dataelement/DefaultDataElementDataMart.java 2010-06-08 19:47:40 +0000
+++ dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/dataelement/DefaultDataElementDataMart.java 2010-06-15 10:15:01 +0000
@@ -126,13 +126,15 @@
final AggregatedDataValue value = new AggregatedDataValue();
- for ( final OrganisationUnit unit : organisationUnits )
+ for ( final Period period : periods )
{
- level = aggregationCache.getLevelOfOrganisationUnit( unit.getId() );
+ final Map<DataElementOperand, Integer> currentOperandIndexMap = dataElementAggregator.getOperandIndexMap( operands, period.getPeriodType(), operandIndexMap );
- for ( final Period period : periods )
+ for ( final OrganisationUnit unit : organisationUnits )
{
- valueMap = dataElementAggregator.getAggregatedValues( operandIndexMap, period, unit, level, hierarchy );
+ level = aggregationCache.getLevelOfOrganisationUnit( unit.getId() );
+
+ valueMap = dataElementAggregator.getAggregatedValues( currentOperandIndexMap, period, unit, level, hierarchy );
periodType = period.getPeriodType();
=== modified file 'dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/engine/DefaultDataMartEngine.java'
--- dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/engine/DefaultDataMartEngine.java 2010-06-08 19:47:40 +0000
+++ dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/engine/DefaultDataMartEngine.java 2010-06-15 10:15:01 +0000
@@ -27,6 +27,8 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+import static org.hisp.dhis.dataelement.DataElement.VALUE_TYPE_BOOL;
+import static org.hisp.dhis.dataelement.DataElement.VALUE_TYPE_INT;
import static org.hisp.dhis.datamart.util.ParserUtil.getDataElementIdsInExpression;
import java.util.ArrayList;
@@ -208,7 +210,7 @@
log.info( "Deleted existing aggregated data: " + TimeUtils.getHMS() );
// ---------------------------------------------------------------------
- // Crosstabulate data
+ // Filter and get operands
// ---------------------------------------------------------------------
final Set<Integer> nonCalculatedDataElementIds = filterCalculatedDataElementIds( dataElementIds, false );
@@ -225,11 +227,15 @@
final Collection<DataElementOperand> allDataElementOperands = categoryService.getOperandsByIds( allDataElementIds );
final Collection<DataElementOperand> dataElementInIndicatorOperands = categoryService.getOperandsByIds( dataElementInIndicatorIds );
final Collection<DataElementOperand> dataElementInCalculatedDataElementOperands = categoryService.getOperandsByIds( dataElementInCalculatedDataElementIds );
-
+ final Collection<DataElementOperand> nonCalculatedDataElementOperands = categoryService.getOperandsByIds( nonCalculatedDataElementIds );
+
+ final Collection<DataElementOperand> intNonCalculatedDataElementOperands = filterOperands( nonCalculatedDataElementOperands, VALUE_TYPE_INT );
+ final Collection<DataElementOperand> boolNonCalculatedDataElementOperands = filterOperands( nonCalculatedDataElementOperands, VALUE_TYPE_BOOL );
+
log.info( "Filtered data elements" );
// ---------------------------------------------------------------------
- // Validate crosstabtable
+ // Create and trim crosstabtable
// ---------------------------------------------------------------------
if ( crossTabService.validateCrossTabTable( allDataElementOperands ) != 0 )
@@ -257,45 +263,38 @@
log.info( "Trimmed crosstab table: " + TimeUtils.getHMS() );
- final Collection<DataElement> dataElements = dataElementService.getDataElements( nonCalculatedDataElementIds );
-
- final Collection<DataElementOperand> sumIntOperands = getOperands( dataElements, DataElement.AGGREGATION_OPERATOR_SUM, DataElement.VALUE_TYPE_INT );
- final Collection<DataElementOperand> averageIntOperands = getOperands( dataElements, DataElement.AGGREGATION_OPERATOR_AVERAGE, DataElement.VALUE_TYPE_INT );
- final Collection<DataElementOperand> sumBooleanOperands = getOperands( dataElements, DataElement.AGGREGATION_OPERATOR_SUM, DataElement.VALUE_TYPE_BOOL );
- final Collection<DataElementOperand> averageBooleanOperands = getOperands( dataElements, DataElement.AGGREGATION_OPERATOR_AVERAGE, DataElement.VALUE_TYPE_BOOL );
-
// ---------------------------------------------------------------------
// Data element export
// ---------------------------------------------------------------------
state.setMessage( "exporting_data_for_data_elements" );
- if ( sumIntOperands.size() > 0 )
+ if ( intNonCalculatedDataElementOperands.size() > 0 )
{
- count += dataElementDataMart.exportDataValues( sumIntOperands, periodIds, organisationUnitIds, sumIntAggregator );
+ count += dataElementDataMart.exportDataValues( intNonCalculatedDataElementOperands, periodIds, organisationUnitIds, sumIntAggregator );
- log.info( "Exported values for data elements with sum aggregation operator of type number (" + sumIntOperands.size() + "): " + TimeUtils.getHMS() );
+ log.info( "Exported values for data elements with sum aggregation operator of type number: " + TimeUtils.getHMS() );
}
- if ( averageIntOperands.size() > 0 )
+ if ( intNonCalculatedDataElementOperands.size() > 0 )
{
- count += dataElementDataMart.exportDataValues( averageIntOperands, periodIds, organisationUnitIds, averageIntAggregator );
+ count += dataElementDataMart.exportDataValues( intNonCalculatedDataElementOperands, periodIds, organisationUnitIds, averageIntAggregator );
- log.info( "Exported values for data elements with average aggregation operator of type number (" + averageIntOperands.size() + "): " + TimeUtils.getHMS() );
- }
-
- if ( sumBooleanOperands.size() > 0 )
- {
- count += dataElementDataMart.exportDataValues( sumBooleanOperands, periodIds, organisationUnitIds, sumBoolAggregator );
-
- log.info( "Exported values for data elements with sum aggregation operator of type yes/no (" + sumBooleanOperands.size() + "): " + TimeUtils.getHMS() );
- }
-
- if ( averageBooleanOperands.size() > 0 )
- {
- count += dataElementDataMart.exportDataValues( averageBooleanOperands, periodIds, organisationUnitIds, averageBoolAggregator );
-
- log.info( "Exported values for data elements with average aggregation operator of type yes/no (" + averageBooleanOperands.size() + "): " + TimeUtils.getHMS() );
+ log.info( "Exported values for data elements with average aggregation operator of type number: " + TimeUtils.getHMS() );
+ }
+
+ if ( boolNonCalculatedDataElementOperands.size() > 0 )
+ {
+ count += dataElementDataMart.exportDataValues( boolNonCalculatedDataElementOperands, periodIds, organisationUnitIds, sumBoolAggregator );
+
+ log.info( "Exported values for data elements with sum aggregation operator of type yes/no: " + TimeUtils.getHMS() );
+ }
+
+ if ( boolNonCalculatedDataElementOperands.size() > 0 )
+ {
+ count += dataElementDataMart.exportDataValues( boolNonCalculatedDataElementOperands, periodIds, organisationUnitIds, averageBoolAggregator );
+
+ log.info( "Exported values for data elements with average aggregation operator of type yes/no: " + TimeUtils.getHMS() );
}
state.setMessage( "exporting_data_for_indicators" );
@@ -308,7 +307,7 @@
{
count += indicatorDataMart.exportIndicatorValues( indicatorIds, periodIds, organisationUnitIds, dataElementInIndicatorOperands );
- log.info( "Exported values for indicators (" + indicatorIds.size() + "): " + TimeUtils.getHMS() );
+ log.info( "Exported values for indicator: " + TimeUtils.getHMS() );
}
state.setMessage( "exporting_data_for_calculated_data_elements" );
@@ -421,21 +420,20 @@
}
/**
- * Sorts out the data element identifers of the given aggregation operator and
- * the given type.
+ * Filters the data element operands based on the value type.
*/
- private Collection<DataElementOperand> getOperands( final Collection<DataElement> dataElements, String aggregationOperator, String valueType )
+ private Collection<DataElementOperand> filterOperands( Collection<DataElementOperand> operands, String valueType )
{
- final Collection<Integer> section = new ArrayList<Integer>();
+ final Collection<DataElementOperand> filtered = new ArrayList<DataElementOperand>();
- for ( final DataElement element : dataElements )
+ for ( DataElementOperand operand : operands )
{
- if ( element.getAggregationOperator().equals( aggregationOperator ) && element.getType().equals( valueType ) )
+ if ( operand.getValueType().equals( valueType ) )
{
- section.add( element.getId() );
+ filtered.add( operand );
}
}
- return categoryService.getOperandsByIds( section );
+ return filtered;
}
}
=== modified file 'dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/indicator/DefaultIndicatorDataMart.java'
--- dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/indicator/DefaultIndicatorDataMart.java 2010-06-14 17:52:18 +0000
+++ dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/indicator/DefaultIndicatorDataMart.java 2010-06-15 10:15:01 +0000
@@ -27,12 +27,9 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-import static org.hisp.dhis.datamart.util.FilterUtils.getAnnualizationFactor;
-import static org.hisp.dhis.datamart.util.FilterUtils.getAnnualizationString;
-import static org.hisp.dhis.datamart.util.FilterUtils.getAvgOperands;
-import static org.hisp.dhis.datamart.util.FilterUtils.getSumOperands;
import static org.hisp.dhis.datamart.util.ParserUtil.generateExpression;
import static org.hisp.dhis.options.SystemSettingManager.KEY_OMIT_INDICATORS_ZERO_NUMERATOR_DATAMART;
+import static org.hisp.dhis.system.util.DateUtils.DAYS_IN_YEAR;
import static org.hisp.dhis.system.util.MathUtils.calculateExpression;
import static org.hisp.dhis.system.util.MathUtils.getRounded;
@@ -43,7 +40,6 @@
import org.amplecode.quick.BatchHandler;
import org.amplecode.quick.BatchHandlerFactory;
import org.hisp.dhis.aggregation.AggregatedIndicatorValue;
-import org.hisp.dhis.dataelement.DataElement;
import org.hisp.dhis.dataelement.DataElementOperand;
import org.hisp.dhis.datamart.aggregation.cache.AggregationCache;
import org.hisp.dhis.datamart.aggregation.dataelement.DataElementAggregator;
@@ -58,6 +54,7 @@
import org.hisp.dhis.period.Period;
import org.hisp.dhis.period.PeriodService;
import org.hisp.dhis.period.PeriodType;
+import org.hisp.dhis.system.util.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
/**
@@ -68,6 +65,9 @@
implements IndicatorDataMart
{
private static final int DECIMALS = 1;
+
+ private static final String TRUE = "true";
+ private static final String FALSE = "false";
// -------------------------------------------------------------------------
// Dependencies
@@ -153,12 +153,6 @@
int count = 0;
- Map<DataElementOperand, Double> numeratorValueMap = null;
- Map<DataElementOperand, Double> denominatorValueMap = null;
-
- double numeratorValue = 0.0;
- double denominatorValue = 0.0;
-
double annualizationFactor = 0.0;
double factor = 0.0;
double aggregatedValue = 0.0;
@@ -172,8 +166,8 @@
{
final PeriodType periodType = period.getPeriodType();
- final Map<DataElementOperand, Integer> sumOperandIndexMap = getSumOperands( operands, periodType, operandIndexMap );
- final Map<DataElementOperand, Integer> averageOperandIndexMap = getAvgOperands( operands, periodType, operandIndexMap );
+ final Map<DataElementOperand, Integer> sumOperandIndexMap = sumIntAggregator.getOperandIndexMap( operands, periodType, operandIndexMap );
+ final Map<DataElementOperand, Integer> averageOperandIndexMap = averageIntAggregator.getOperandIndexMap( operands, periodType, operandIndexMap );
for ( final OrganisationUnit unit : organisationUnits )
{
@@ -182,28 +176,13 @@
final Map<DataElementOperand, Double> sumIntValueMap = sumIntAggregator.getAggregatedValues( sumOperandIndexMap, period, unit, level, hierarchy );
final Map<DataElementOperand, Double> averageIntValueMap = averageIntAggregator.getAggregatedValues( averageOperandIndexMap, period, unit, level, hierarchy);
- final Map<String, Map<DataElementOperand, Double>> valueMapMap = new HashMap<String, Map<DataElementOperand, Double>>( 2 );
+ final Map<DataElementOperand, Double> valueMap = new HashMap<DataElementOperand, Double>( sumIntValueMap );
+ valueMap.putAll( averageIntValueMap );
- valueMapMap.put( DataElement.AGGREGATION_OPERATOR_SUM, sumIntValueMap );
- valueMapMap.put( DataElement.AGGREGATION_OPERATOR_AVERAGE, averageIntValueMap );
-
for ( final Indicator indicator : indicators )
{
- // ---------------------------------------------------------
- // Numerator
- // ---------------------------------------------------------
-
- numeratorValueMap = valueMapMap.get( indicator.getNumeratorAggregationOperator() );
-
- numeratorValue = calculateExpression( generateExpression( indicator.getNumerator(), numeratorValueMap ) );
-
- // ---------------------------------------------------------
- // Denominator
- // ---------------------------------------------------------
-
- denominatorValueMap = valueMapMap.get( indicator.getDenominatorAggregationOperator() );
-
- denominatorValue = calculateExpression( generateExpression( indicator.getDenominator(), denominatorValueMap ) );
+ final double numeratorValue = calculateExpression( generateExpression( indicator.getNumerator(), valueMap ) );
+ final double denominatorValue = calculateExpression( generateExpression( indicator.getDenominator(), valueMap ) );
// ---------------------------------------------------------
// AggregatedIndicatorValue
@@ -244,4 +223,27 @@
return count;
}
+
+ // -------------------------------------------------------------------------
+ // Supportive methods
+ // -------------------------------------------------------------------------
+
+ public static double getAnnualizationFactor( final Indicator indicator, final Period period )
+ {
+ double factor = 1.0;
+
+ if ( indicator.getAnnualized() != null && indicator.getAnnualized() )
+ {
+ final int daysInPeriod = DateUtils.daysBetween( period.getStartDate(), period.getEndDate() ) + 1;
+
+ factor = DAYS_IN_YEAR / daysInPeriod;
+ }
+
+ return factor;
+ }
+
+ public static String getAnnualizationString( final Boolean annualized )
+ {
+ return ( annualized == null || !annualized ) ? FALSE : TRUE;
+ }
}
=== removed file 'dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/util/FilterUtils.java'
--- dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/util/FilterUtils.java 2010-06-14 17:52:18 +0000
+++ dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/util/FilterUtils.java 1970-01-01 00:00:00 +0000
@@ -1,102 +0,0 @@
-package org.hisp.dhis.datamart.util;
-
-/*
- * Copyright (c) 2004-2010, University of Oslo
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- * * Redistributions of source code must retain the above copyright notice, this
- * list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- * * Neither the name of the HISP project nor the names of its contributors may
- * be used to endorse or promote products derived from this software without
- * specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-import static org.hisp.dhis.dataelement.DataElement.AGGREGATION_OPERATOR_AVERAGE;
-import static org.hisp.dhis.dataelement.DataElement.AGGREGATION_OPERATOR_SUM;
-import static org.hisp.dhis.system.util.DateUtils.DAYS_IN_YEAR;
-
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.Map;
-
-import org.hisp.dhis.dataelement.DataElementOperand;
-import org.hisp.dhis.indicator.Indicator;
-import org.hisp.dhis.period.Period;
-import org.hisp.dhis.period.PeriodType;
-import org.hisp.dhis.system.util.DateUtils;
-
-/**
- * @author Lars Helge Overland
- */
-public class FilterUtils
-{
- private static final String TRUE = "true";
- private static final String FALSE = "false";
-
- public static Map<DataElementOperand, Integer> getSumOperands( Collection<DataElementOperand> operands, PeriodType periodType, Map<DataElementOperand, Integer> operandIndexMap )
- {
- Map<DataElementOperand, Integer> sumOperandIndexMap = new HashMap<DataElementOperand, Integer>();
-
- for ( final DataElementOperand operand : operands )
- {
- if ( operand.getAggregationOperator().equals( AGGREGATION_OPERATOR_SUM ) ||
- ( operand.getAggregationOperator().equals( AGGREGATION_OPERATOR_AVERAGE ) && operand.getFrequencyOrder() >= periodType.getFrequencyOrder() ) )
- {
- sumOperandIndexMap.put( operand, operandIndexMap.get( operand ) );
- }
- }
-
- return sumOperandIndexMap;
- }
-
- public static Map<DataElementOperand, Integer> getAvgOperands( Collection<DataElementOperand> operands, PeriodType periodType, Map<DataElementOperand, Integer> operandIndexMap )
- {
- Map<DataElementOperand, Integer> avgOperandIndexMap = new HashMap<DataElementOperand, Integer>();
-
- for ( final DataElementOperand operand : operands )
- {
- if ( operand.getAggregationOperator().equals( AGGREGATION_OPERATOR_AVERAGE ) &&
- operand.getFrequencyOrder() < periodType.getFrequencyOrder() )
- {
- avgOperandIndexMap.put( operand, operandIndexMap.get( operand ) );
- }
- }
-
- return avgOperandIndexMap;
- }
-
- public static double getAnnualizationFactor( final Indicator indicator, final Period period )
- {
- double factor = 1.0;
-
- if ( indicator.getAnnualized() != null && indicator.getAnnualized() )
- {
- final int daysInPeriod = DateUtils.daysBetween( period.getStartDate(), period.getEndDate() ) + 1;
-
- factor = DAYS_IN_YEAR / daysInPeriod;
- }
-
- return factor;
- }
-
- public static String getAnnualizationString( final Boolean annualized )
- {
- return ( annualized == null || !annualized ) ? FALSE : TRUE;
- }
-}
=== modified file 'dhis-2/dhis-services/dhis-service-datamart-default/src/test/java/org/hisp/dhis/datamart/DataMartServiceTest.java'
--- dhis-2/dhis-services/dhis-service-datamart-default/src/test/java/org/hisp/dhis/datamart/DataMartServiceTest.java 2010-06-08 19:47:40 +0000
+++ dhis-2/dhis-services/dhis-service-datamart-default/src/test/java/org/hisp/dhis/datamart/DataMartServiceTest.java 2010-06-15 10:15:01 +0000
@@ -48,9 +48,11 @@
import org.hisp.dhis.indicator.IndicatorType;
import org.hisp.dhis.organisationunit.OrganisationUnit;
import org.hisp.dhis.organisationunit.OrganisationUnitService;
+import org.hisp.dhis.period.MonthlyPeriodType;
import org.hisp.dhis.period.Period;
import org.hisp.dhis.period.PeriodService;
import org.hisp.dhis.period.PeriodType;
+import org.hisp.dhis.period.QuarterlyPeriodType;
import org.junit.Test;
/**
@@ -141,9 +143,10 @@
// ---------------------------------------------------------------------
// Setup Periods
// ---------------------------------------------------------------------
-
- PeriodType periodType = periodService.getAllPeriodTypes().iterator().next();
-
+
+ PeriodType monthly = new MonthlyPeriodType();
+ PeriodType quarterly = new QuarterlyPeriodType();
+
Date mar01 = getDate( 2005, 3, 1 );
Date mar31 = getDate( 2005, 3, 31 );
Date apr01 = getDate( 2005, 4, 1 );
@@ -151,10 +154,10 @@
Date may01 = getDate( 2005, 5, 1 );
Date may31 = getDate( 2005, 5, 31 );
- periodA = createPeriod( periodType, mar01, mar31 );
- periodB = createPeriod( periodType, apr01, apr30 );
- periodC = createPeriod( periodType, may01, may31 );
- periodD = createPeriod( periodType, mar01, may31 );
+ periodA = createPeriod( monthly, mar01, mar31 );
+ periodB = createPeriod( monthly, apr01, apr30 );
+ periodC = createPeriod( monthly, may01, may31 );
+ periodD = createPeriod( quarterly, mar01, may31 );
periodIds.add( periodService.addPeriod( periodA ) );
periodIds.add( periodService.addPeriod( periodB ) );