=== 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-15 10:15:01 +0000 +++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataelement/DefaultDataElementCategoryService.java 2010-06-17 21:08:46 +0000 @@ -39,7 +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.period.TwoYearlyPeriodType; import org.hisp.dhis.system.util.Filter; import org.hisp.dhis.system.util.FilterUtils; import org.hisp.dhis.system.util.UUIdUtils; @@ -396,7 +396,7 @@ Set categoryOptionCombos = dataElement.getCategoryCombo() .getOptionCombos(); - int frequencyOrder = dataElement.getPeriodType() != null ? dataElement.getPeriodType().getFrequencyOrder() : new DailyPeriodType().getFrequencyOrder(); //TODO improve + int frequencyOrder = dataElement.getPeriodType() != null ? dataElement.getPeriodType().getFrequencyOrder() : new TwoYearlyPeriodType().getFrequencyOrder(); // Assume lowest frequency if no PeriodType if ( categoryOptionCombos.size() > 1 && !(dataElement instanceof CalculatedDataElement) ) { === 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-15 10:15:01 +0000 +++ dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/aggregation/dataelement/AverageBoolAggregator.java 2010-06-17 21:08:46 +0000 @@ -88,7 +88,7 @@ getCrossTabDataValues( operandIndexMap, period.getStartDate(), period.getEndDate(), unit.getId(), hierarchy ); final Map entries = getAggregate( crossTabValues, period.getStartDate(), - period.getEndDate(), period.getStartDate(), period.getEndDate(), unitLevel ); // + period.getEndDate(), period.getStartDate(), period.getEndDate(), unitLevel ); // final Map values = new HashMap( entries.size() ); // @@ -204,8 +204,7 @@ for ( final DataElementOperand operand : operands ) { - if ( operand.getValueType().equals( VALUE_TYPE_BOOL ) && ( operand.getAggregationOperator().equals( AGGREGATION_OPERATOR_AVERAGE ) && - operand.getFrequencyOrder() < periodType.getFrequencyOrder() ) ) + if ( operand.getValueType().equals( VALUE_TYPE_BOOL ) && operand.getAggregationOperator().equals( AGGREGATION_OPERATOR_AVERAGE ) ) { avgOperandIndexMap.put( operand, operandIndexMap.get( operand ) ); } === added file 'dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/aggregation/dataelement/AverageIntSingleValueAggregator.java' --- dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/aggregation/dataelement/AverageIntSingleValueAggregator.java 1970-01-01 00:00:00 +0000 +++ dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/aggregation/dataelement/AverageIntSingleValueAggregator.java 2010-06-17 21:08:46 +0000 @@ -0,0 +1,213 @@ +package org.hisp.dhis.datamart.aggregation.dataelement; + +/* + * 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.VALUE_TYPE_INT; +import static org.hisp.dhis.system.util.DateUtils.getDaysInclusive; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Date; +import java.util.HashMap; +import java.util.Map; +import java.util.Map.Entry; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.hisp.dhis.dataelement.DataElementOperand; +import org.hisp.dhis.datamart.CrossTabDataValue; +import org.hisp.dhis.datamart.DataMartStore; +import org.hisp.dhis.datamart.aggregation.cache.AggregationCache; +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 + * @version $Id: AverageIntAggregator.java 6049 2008-10-28 09:36:17Z larshelg $ + */ +public class AverageIntSingleValueAggregator + implements DataElementAggregator +{ + private static final Log log = LogFactory.getLog( AverageIntSingleValueAggregator.class ); + + // ------------------------------------------------------------------------- + // Dependencies + // ------------------------------------------------------------------------- + + protected DataMartStore dataMartStore; + + public void setDataMartStore( DataMartStore dataMartStore ) + { + this.dataMartStore = dataMartStore; + } + + protected AggregationCache aggregationCache; + + public void setAggregationCache( AggregationCache aggregationCache ) + { + this.aggregationCache = aggregationCache; + } + + // ------------------------------------------------------------------------- + // DataElementAggregator implementation + // ------------------------------------------------------------------------- + + public Map getAggregatedValues( final Map operandIndexMap, + final Period period, final OrganisationUnit unit, int unitLevel, OrganisationUnitHierarchy hierarchy ) + { + if ( operandIndexMap == null || operandIndexMap.size() == 0 ) + { + return new HashMap(); + } + + double average = 0.0; + double existingAverage = 0.0; + + final Collection crossTabValues = + getCrossTabDataValues( operandIndexMap, period.getStartDate(), period.getEndDate(), unit.getId(), hierarchy ); + + final Map entries = getAggregate( crossTabValues, period.getStartDate(), + period.getEndDate(), period.getStartDate(), period.getEndDate(), unitLevel ); // + + final Map values = new HashMap(); // + + for ( final Entry entry : entries.entrySet() ) + { + if ( entry.getValue() != null && entry.getValue()[ 1 ] > 0 ) + { + values.put( entry.getKey(), entry.getValue()[ 0 ] ); + /* + average = entry.getValue()[ 0 ] / entry.getValue()[ 1 ]; + + existingAverage = values.containsKey( entry.getKey() ) ? values.get( entry.getKey() ) : 0; + + values.put( entry.getKey(), average + existingAverage ); //TODO simplify + */ + } + } + + return values; + } + + public Collection getCrossTabDataValues( final Map operandIndexMap, + final Date startDate, final Date endDate, final int parentId, final OrganisationUnitHierarchy hierarchy ) + { + final Collection periods = aggregationCache.getIntersectingPeriods( startDate, endDate ); + + final Collection periodIds = new ArrayList( periods.size() ); + + for ( final Period period : periods ) + { + periodIds.add( period.getId() ); + } + + return dataMartStore.getCrossTabDataValues( operandIndexMap, periodIds, hierarchy.getChildren( parentId ) ); + } + + public Map getAggregate( final Collection crossTabValues, + final Date startDate, final Date endDate, final Date aggregationStartDate, final Date aggregationEndDate, int unitLevel ) + { + final Map totalSums = new HashMap(); // + + Period period = null; + Date currentStartDate = null; + Date currentEndDate = null; + + double value = 0.0; + double relevantDays = 0.0; + double existingValue = 0.0; + double existingRelevantDays = 0.0; + + int dataValueLevel = 0; + + for ( final CrossTabDataValue crossTabValue : crossTabValues ) + { + period = aggregationCache.getPeriod( crossTabValue.getPeriodId() ); + + currentStartDate = period.getStartDate(); + currentEndDate = period.getEndDate(); + + dataValueLevel = aggregationCache.getLevelOfOrganisationUnit( crossTabValue.getSourceId() ); + + for ( final Entry entry : crossTabValue.getValueMap().entrySet() ) // + { + if ( entry.getValue() != null && entry.getKey().aggregationLevelIsValid( unitLevel, dataValueLevel ) ) + { + value = 0.0; + + try + { + value = Double.parseDouble( entry.getValue() ); + } + catch ( NumberFormatException ex ) + { + log.warn( "Value skipped, not numeric: '" + entry.getValue() + + "', for data element with id: '" + entry.getKey() + + "', for period with id: '" + crossTabValue.getPeriodId() + + "', for source with id: '" + crossTabValue.getSourceId() + "'" ); + } + + relevantDays = 0.0; + + if ( currentStartDate.compareTo( endDate ) <= 0 && currentEndDate.compareTo( startDate ) >= 0 ) // Value is intersecting + { + relevantDays = getDaysInclusive( startDate, endDate ); + } + + existingValue = totalSums.containsKey( entry.getKey() ) ? totalSums.get( entry.getKey() )[ 0 ] : 0; + existingRelevantDays = totalSums.containsKey( entry.getKey() ) ? totalSums.get( entry.getKey() )[ 1 ] : 0; + + final double[] values = { ( value + existingValue ), ( relevantDays + existingRelevantDays ) }; + + totalSums.put( entry.getKey(), values ); + } + } + } + + return totalSums; + } + + public Map getOperandIndexMap( Collection operands, PeriodType periodType, Map operandIndexMap ) + { + Map avgOperandIndexMap = new HashMap(); + + 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/SumBoolAggregator.java' --- 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 +++ dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/aggregation/dataelement/SumBoolAggregator.java 2010-06-17 21:08:46 +0000 @@ -27,7 +27,6 @@ * 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; @@ -210,8 +209,7 @@ 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() ) ) ) + if ( operand.getValueType().equals( VALUE_TYPE_BOOL ) && operand.getAggregationOperator().equals( AGGREGATION_OPERATOR_SUM ) ) { sumOperandIndexMap.put( operand, operandIndexMap.get( operand ) ); } === 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-15 10:15:01 +0000 +++ dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/aggregation/dataelement/SumIntAggregator.java 2010-06-17 21:08:46 +0000 @@ -27,7 +27,6 @@ * 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; @@ -218,8 +217,7 @@ 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() ) ) ) + if ( operand.getValueType().equals( VALUE_TYPE_INT ) && operand.getAggregationOperator().equals( AGGREGATION_OPERATOR_SUM ) ) { sumOperandIndexMap.put( operand, operandIndexMap.get( operand ) ); } === modified file 'dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/calculateddataelement/DefaultCalculatedDataElementDataMart.java' --- dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/calculateddataelement/DefaultCalculatedDataElementDataMart.java 2010-06-08 19:47:40 +0000 +++ dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/calculateddataelement/DefaultCalculatedDataElementDataMart.java 2010-06-17 21:08:46 +0000 @@ -31,7 +31,6 @@ import static org.hisp.dhis.system.util.MathUtils.calculateExpression; import static org.hisp.dhis.system.util.MathUtils.getRounded; -import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; import java.util.Map; @@ -98,6 +97,13 @@ this.averageIntAggregator = averageIntDataElementAggregator; } + private DataElementAggregator averageIntSingleValueAggregator; + + public void setAverageIntSingleValueAggregator( DataElementAggregator averageIntSingleValueAggregator ) + { + this.averageIntSingleValueAggregator = averageIntSingleValueAggregator; + } + private CrossTabService crossTabService; public void setCrossTabService( CrossTabService crossTabService ) @@ -136,11 +142,7 @@ public int exportCalculatedDataElements( final Collection calculatedDataElementIds, final Collection periodIds, final Collection organisationUnitIds, final Collection operands ) { - final Collection sumOperands = filterOperands( operands, DataElement.AGGREGATION_OPERATOR_SUM ); - final Collection averageOperands = filterOperands( operands, DataElement.AGGREGATION_OPERATOR_AVERAGE ); - - final Map sumOperandIndexMap = crossTabService.getOperandIndexMap( sumOperands ); - final Map averageOperandIndexMap = crossTabService.getOperandIndexMap( averageOperands ); + final Map operandIndexMap = crossTabService.getOperandIndexMap( operands ); final Collection calculatedDataElements = dataElementService.getDataElements( calculatedDataElementIds ); final Collection periods = periodService.getPeriods( periodIds ); @@ -152,52 +154,42 @@ batchHandler.init(); - OrganisationUnitHierarchy hierarchy = organisationUnitService.getOrganisationUnitHierarchy().prepareChildren( organisationUnitIds ); + final OrganisationUnitHierarchy hierarchy = organisationUnitService.getOrganisationUnitHierarchy().prepareChildren( organisationUnitIds ); int count = 0; - int level = 0; - Map sumIntValueMap = null; - Map averageIntValueMap = null; - - Map> valueMapMap = null; - - Map valueMap = null; - CalculatedDataElement calculatedDataElement = null; - PeriodType periodType = null; - double aggregatedValue = 0.0; final AggregatedDataValue dataValue = new AggregatedDataValue(); - for ( final OrganisationUnit unit : organisationUnits ) + for ( final Period period : periods ) { - level = aggregationCache.getLevelOfOrganisationUnit( unit.getId() ); - - for ( final Period period : periods ) + final PeriodType periodType = period.getPeriodType(); + + final Map sumOperandIndexMap = sumIntAggregator.getOperandIndexMap( operands, periodType, operandIndexMap ); + final Map averageOperandIndexMap = averageIntAggregator.getOperandIndexMap( operands, periodType, operandIndexMap ); + final Map averageSingleValueOperandIndexMap = averageIntSingleValueAggregator.getOperandIndexMap( operands, periodType, operandIndexMap ); + + for ( final OrganisationUnit unit : organisationUnits ) { - sumIntValueMap = sumIntAggregator.getAggregatedValues( sumOperandIndexMap, period, unit, level, hierarchy ); - averageIntValueMap = averageIntAggregator.getAggregatedValues( averageOperandIndexMap, period, unit, level, hierarchy ); - - valueMapMap = new HashMap>( 2 ); - - valueMapMap.put( DataElement.AGGREGATION_OPERATOR_SUM, sumIntValueMap ); - valueMapMap.put( DataElement.AGGREGATION_OPERATOR_AVERAGE, averageIntValueMap ); - - periodType = period.getPeriodType(); + final int level = aggregationCache.getLevelOfOrganisationUnit( unit.getId() ); + + final Map sumIntValueMap = sumIntAggregator.getAggregatedValues( sumOperandIndexMap, period, unit, level, hierarchy ); + final Map averageIntValueMap = averageIntAggregator.getAggregatedValues( averageOperandIndexMap, period, unit, level, hierarchy ); + final Map averageIntSingleValueMap = averageIntSingleValueAggregator.getAggregatedValues( averageSingleValueOperandIndexMap, period, unit, level, hierarchy ); + + final Map valueMap = new HashMap( sumIntValueMap ); + valueMap.putAll( averageIntValueMap ); + valueMap.putAll( averageIntSingleValueMap ); for ( final DataElement element : calculatedDataElements ) { calculatedDataElement = (CalculatedDataElement) element; - valueMap = valueMapMap.get( calculatedDataElement.getAggregationOperator() ); - aggregatedValue = calculateExpression( generateExpression( calculatedDataElement.getExpression().getExpression(), valueMap ) ); - //TODO improve logic for performance - dataValue.clear(); dataValue.setDataElementId( calculatedDataElement.getId() ); @@ -219,25 +211,4 @@ return count; } - - // ------------------------------------------------------------------------- - // Supportive methods - // ------------------------------------------------------------------------- - - private Collection filterOperands( final Collection operands, final String aggregationOperator ) - { - final Collection filteredOperands = new ArrayList(); - - for ( final DataElementOperand operand : operands ) - { - final DataElement dataElement = dataElementService.getDataElement( operand.getDataElementId() ); - - if ( aggregationOperator.equals( dataElement.getAggregationOperator() ) ) - { - filteredOperands.add( operand ); - } - } - - return filteredOperands; - } } === 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-15 10:15:01 +0000 +++ dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/dataelement/DefaultDataElementDataMart.java 2010-06-17 21:08:46 +0000 @@ -115,14 +115,9 @@ batchHandler.init(); - OrganisationUnitHierarchy hierarchy = organisationUnitService.getOrganisationUnitHierarchy().prepareChildren( organisationUnitIds ); + final OrganisationUnitHierarchy hierarchy = organisationUnitService.getOrganisationUnitHierarchy().prepareChildren( organisationUnitIds ); int count = 0; - int level = 0; - - Map valueMap = null; - - PeriodType periodType = null; final AggregatedDataValue value = new AggregatedDataValue(); @@ -132,11 +127,11 @@ for ( final OrganisationUnit unit : organisationUnits ) { - level = aggregationCache.getLevelOfOrganisationUnit( unit.getId() ); - - valueMap = dataElementAggregator.getAggregatedValues( currentOperandIndexMap, period, unit, level, hierarchy ); - - periodType = period.getPeriodType(); + final int level = aggregationCache.getLevelOfOrganisationUnit( unit.getId() ); + + final Map valueMap = dataElementAggregator.getAggregatedValues( currentOperandIndexMap, period, unit, level, hierarchy ); + + final PeriodType periodType = period.getPeriodType(); for ( Entry entry : valueMap.entrySet() ) { === 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-15 10:15:01 +0000 +++ dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/engine/DefaultDataMartEngine.java 2010-06-17 21:08:46 +0000 @@ -129,6 +129,13 @@ this.averageIntAggregator = averageIntDataElementAggregator; } + private DataElementAggregator averageIntSingleValueAggregator; + + public void setAverageIntSingleValueAggregator( DataElementAggregator averageIntSingleValueAggregator ) + { + this.averageIntSingleValueAggregator = averageIntSingleValueAggregator; + } + private DataElementAggregator sumBoolAggregator; public void setSumBoolAggregator( DataElementAggregator sumBooleanDataElementAggregator ) @@ -283,6 +290,13 @@ log.info( "Exported values for data elements with average aggregation operator of type number: " + TimeUtils.getHMS() ); } + if ( intNonCalculatedDataElementOperands.size() > 0 ) + { + count += dataElementDataMart.exportDataValues( intNonCalculatedDataElementOperands, periodIds, organisationUnitIds, averageIntSingleValueAggregator ); + + log.info( "Exported values for data elements with average aggregation operator with single value of type number: " + TimeUtils.getHMS() ); + } + if ( boolNonCalculatedDataElementOperands.size() > 0 ) { count += dataElementDataMart.exportDataValues( boolNonCalculatedDataElementOperands, periodIds, organisationUnitIds, sumBoolAggregator ); === 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-15 10:15:01 +0000 +++ dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/indicator/DefaultIndicatorDataMart.java 2010-06-17 21:08:46 +0000 @@ -107,6 +107,13 @@ { this.averageIntAggregator = averageIntDataElementAggregator; } + + private DataElementAggregator averageIntSingleValueAggregator; + + public void setAverageIntSingleValueAggregator( DataElementAggregator averageIntSingleValueAggregator ) + { + this.averageIntSingleValueAggregator = averageIntSingleValueAggregator; + } private CrossTabService crossTabService; @@ -149,7 +156,7 @@ batchHandler.init(); - OrganisationUnitHierarchy hierarchy = organisationUnitService.getOrganisationUnitHierarchy().prepareChildren( organisationUnitIds ); + final OrganisationUnitHierarchy hierarchy = organisationUnitService.getOrganisationUnitHierarchy().prepareChildren( organisationUnitIds ); int count = 0; @@ -168,6 +175,7 @@ final Map sumOperandIndexMap = sumIntAggregator.getOperandIndexMap( operands, periodType, operandIndexMap ); final Map averageOperandIndexMap = averageIntAggregator.getOperandIndexMap( operands, periodType, operandIndexMap ); + final Map averageSingleValueOperandIndexMap = averageIntSingleValueAggregator.getOperandIndexMap( operands, periodType, operandIndexMap ); for ( final OrganisationUnit unit : organisationUnits ) { @@ -175,9 +183,11 @@ final Map sumIntValueMap = sumIntAggregator.getAggregatedValues( sumOperandIndexMap, period, unit, level, hierarchy ); final Map averageIntValueMap = averageIntAggregator.getAggregatedValues( averageOperandIndexMap, period, unit, level, hierarchy); + final Map averageIntSingleValueMap = averageIntSingleValueAggregator.getAggregatedValues( averageSingleValueOperandIndexMap, period, unit, level, hierarchy ); final Map valueMap = new HashMap( sumIntValueMap ); valueMap.putAll( averageIntValueMap ); + valueMap.putAll( averageIntSingleValueMap ); for ( final Indicator indicator : indicators ) { === modified file 'dhis-2/dhis-services/dhis-service-datamart-default/src/main/resources/META-INF/dhis/beans.xml' --- dhis-2/dhis-services/dhis-service-datamart-default/src/main/resources/META-INF/dhis/beans.xml 2010-06-14 16:27:39 +0000 +++ dhis-2/dhis-services/dhis-service-datamart-default/src/main/resources/META-INF/dhis/beans.xml 2010-06-17 21:08:46 +0000 @@ -51,6 +51,8 @@ ref="org.hisp.dhis.datamart.aggregation.dataelement.SumIntAggregator"/> + + + + + + + +