dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #12458
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 3838: Minor re-arrangement of code in datamart
------------------------------------------------------------
revno: 3838
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2011-06-03 23:33:10 +0200
message:
Minor re-arrangement of code in datamart
modified:
dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/dataelement/DataElementDataMart.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/main/resources/META-INF/dhis/beans.xml
--
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-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/dataelement/DataElementDataMart.java'
--- dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/dataelement/DataElementDataMart.java 2011-04-15 15:02:55 +0000
+++ dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/dataelement/DataElementDataMart.java 2011-06-03 21:33:10 +0000
@@ -30,7 +30,6 @@
import java.util.Collection;
import org.hisp.dhis.dataelement.DataElementOperand;
-import org.hisp.dhis.datamart.aggregation.dataelement.DataElementAggregator;
import org.hisp.dhis.organisationunit.OrganisationUnit;
import org.hisp.dhis.period.Period;
@@ -40,5 +39,5 @@
public interface DataElementDataMart
{
int exportDataValues( Collection<DataElementOperand> operands, Collection<Period> periods,
- Collection<OrganisationUnit> organisationUnits, DataElementAggregator dataElementAggregator, String key );
+ Collection<OrganisationUnit> organisationUnits, String key );
}
=== 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 2011-04-15 15:02:55 +0000
+++ dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/dataelement/DefaultDataElementDataMart.java 2011-06-03 21:33:10 +0000
@@ -30,11 +30,14 @@
import static org.hisp.dhis.system.util.MathUtils.getRounded;
import java.util.Collection;
+import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import org.amplecode.quick.BatchHandler;
import org.amplecode.quick.BatchHandlerFactory;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
import org.hisp.dhis.aggregation.AggregatedDataValue;
import org.hisp.dhis.dataelement.DataElementOperand;
import org.hisp.dhis.datamart.aggregation.cache.AggregationCache;
@@ -51,6 +54,8 @@
public class DefaultDataElementDataMart
implements DataElementDataMart
{
+ private static final Log log = LogFactory.getLog( DefaultDataElementDataMart.class );
+
private static final int DECIMALS = 1;
// -------------------------------------------------------------------------
@@ -78,12 +83,47 @@
this.aggregationCache = aggregationCache;
}
+ private DataElementAggregator sumIntAggregator;
+
+ public void setSumIntAggregator( DataElementAggregator sumIntDataElementAggregator )
+ {
+ this.sumIntAggregator = sumIntDataElementAggregator;
+ }
+
+ private DataElementAggregator averageIntAggregator;
+
+ public void setAverageIntAggregator( DataElementAggregator averageIntDataElementAggregator )
+ {
+ this.averageIntAggregator = averageIntDataElementAggregator;
+ }
+
+ private DataElementAggregator averageIntSingleValueAggregator;
+
+ public void setAverageIntSingleValueAggregator( DataElementAggregator averageIntSingleValueAggregator )
+ {
+ this.averageIntSingleValueAggregator = averageIntSingleValueAggregator;
+ }
+
+ private DataElementAggregator sumBoolAggregator;
+
+ public void setSumBoolAggregator( DataElementAggregator sumBooleanDataElementAggregator )
+ {
+ this.sumBoolAggregator = sumBooleanDataElementAggregator;
+ }
+
+ private DataElementAggregator averageBoolAggregator;
+
+ public void setAverageBoolAggregator( DataElementAggregator averageBooleanDataElementAggregator )
+ {
+ this.averageBoolAggregator = averageBooleanDataElementAggregator;
+ }
+
// -------------------------------------------------------------------------
// DataMart functionality
// -------------------------------------------------------------------------
public int exportDataValues( final Collection<DataElementOperand> operands, final Collection<Period> periods,
- final Collection<OrganisationUnit> organisationUnits, final DataElementAggregator dataElementAggregator, String key )
+ final Collection<OrganisationUnit> organisationUnits, String key )
{
final BatchHandler<AggregatedDataValue> batchHandler = batchHandlerFactory.createBatchHandler( AggregatedDataValueBatchHandler.class ).init();
@@ -95,34 +135,43 @@
for ( final Period period : periods )
{
- final Collection<DataElementOperand> currentOperands = dataElementAggregator.filterOperands( operands, period.getPeriodType() );
+ final Collection<DataElementOperand> sumIntOperands = sumIntAggregator.filterOperands( operands, period.getPeriodType() );
+ final Collection<DataElementOperand> averageIntOperands = averageIntAggregator.filterOperands( operands, period.getPeriodType() );
+ final Collection<DataElementOperand> averageIntSingleValueOperands = averageIntSingleValueAggregator.filterOperands( operands, period.getPeriodType() );
+ final Collection<DataElementOperand> sumBoolOperands = sumBoolAggregator.filterOperands( operands, period.getPeriodType() );
+ final Collection<DataElementOperand> averageBoolOperands = averageBoolAggregator.filterOperands( operands, period.getPeriodType() );
- if ( currentOperands != null && currentOperands.size() > 0 )
+ for ( final OrganisationUnit unit : organisationUnits )
{
- for ( final OrganisationUnit unit : organisationUnits )
+ final int level = aggregationCache.getLevelOfOrganisationUnit( unit.getId() );
+
+ final Map<DataElementOperand, Double> valueMap = new HashMap<DataElementOperand, Double>();
+
+ valueMap.putAll( sumIntAggregator.getAggregatedValues( sumIntOperands, period, unit, level, hierarchy, key ) );
+ valueMap.putAll( averageIntAggregator.getAggregatedValues( averageIntOperands, period, unit, level, hierarchy, key ) );
+ valueMap.putAll( averageIntSingleValueAggregator.getAggregatedValues( averageIntSingleValueOperands, period, unit, level, hierarchy, key ) );
+ valueMap.putAll( sumBoolAggregator.getAggregatedValues( sumBoolOperands, period, unit, level, hierarchy, key ) );
+ valueMap.putAll( averageBoolAggregator.getAggregatedValues( averageBoolOperands, period, unit, level, hierarchy, key ) );
+
+ for ( Entry<DataElementOperand, Double> entry : valueMap.entrySet() )
{
- final int level = aggregationCache.getLevelOfOrganisationUnit( unit.getId() );
-
- final Map<DataElementOperand, Double> valueMap = dataElementAggregator.getAggregatedValues( currentOperands, period, unit, level, hierarchy, key );
-
- for ( Entry<DataElementOperand, Double> entry : valueMap.entrySet() )
- {
- value.clear();
-
- value.setDataElementId( entry.getKey().getDataElementId() );
- value.setCategoryOptionComboId( entry.getKey().getOptionComboId() );
- value.setPeriodId( period.getId() );
- value.setPeriodTypeId( period.getPeriodType().getId() );
- value.setOrganisationUnitId( unit.getId() );
- value.setLevel( level );
- value.setValue( getRounded( entry.getValue(), DECIMALS ) );
-
- batchHandler.addObject( value );
-
- count++;
- }
+ value.clear();
+
+ value.setDataElementId( entry.getKey().getDataElementId() );
+ value.setCategoryOptionComboId( entry.getKey().getOptionComboId() );
+ value.setPeriodId( period.getId() );
+ value.setPeriodTypeId( period.getPeriodType().getId() );
+ value.setOrganisationUnitId( unit.getId() );
+ value.setLevel( level );
+ value.setValue( getRounded( entry.getValue(), DECIMALS ) );
+
+ batchHandler.addObject( value );
+
+ count++;
}
}
+
+ log.debug( "Exported data values for period: " + period );
}
batchHandler.flush();
=== 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 2011-04-24 15:50:02 +0000
+++ dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/engine/DefaultDataMartEngine.java 2011-06-03 21:33:10 +0000
@@ -40,7 +40,6 @@
import org.hisp.dhis.dataelement.DataElementOperand;
import org.hisp.dhis.dataelement.DataElementService;
import org.hisp.dhis.datamart.aggregation.cache.AggregationCache;
-import org.hisp.dhis.datamart.aggregation.dataelement.DataElementAggregator;
import org.hisp.dhis.datamart.crosstab.CrossTabService;
import org.hisp.dhis.datamart.dataelement.DataElementDataMart;
import org.hisp.dhis.datamart.indicator.IndicatorDataMart;
@@ -103,41 +102,6 @@
this.indicatorDataMart = indicatorDataMart;
}
- private DataElementAggregator sumIntAggregator;
-
- public void setSumIntAggregator( DataElementAggregator sumIntDataElementAggregator )
- {
- this.sumIntAggregator = sumIntDataElementAggregator;
- }
-
- private DataElementAggregator averageIntAggregator;
-
- public void setAverageIntAggregator( DataElementAggregator averageIntDataElementAggregator )
- {
- this.averageIntAggregator = averageIntDataElementAggregator;
- }
-
- private DataElementAggregator averageIntSingleValueAggregator;
-
- public void setAverageIntSingleValueAggregator( DataElementAggregator averageIntSingleValueAggregator )
- {
- this.averageIntSingleValueAggregator = averageIntSingleValueAggregator;
- }
-
- private DataElementAggregator sumBoolAggregator;
-
- public void setSumBoolAggregator( DataElementAggregator sumBooleanDataElementAggregator )
- {
- this.sumBoolAggregator = sumBooleanDataElementAggregator;
- }
-
- private DataElementAggregator averageBoolAggregator;
-
- public void setAverageBoolAggregator( DataElementAggregator averageBooleanDataElementAggregator )
- {
- this.averageBoolAggregator = averageBooleanDataElementAggregator;
- }
-
private DataElementService dataElementService;
public void setDataElementService( DataElementService dataElementService )
@@ -283,25 +247,9 @@
if ( dataElementOperands.size() > 0 )
{
- count += dataElementDataMart.exportDataValues( dataElementOperands, periods, organisationUnits, sumIntAggregator, key );
-
- log.info( "Exported values for data element operands with sum aggregation operator of type number: " + TimeUtils.getHMS() );
-
- count += dataElementDataMart.exportDataValues( dataElementOperands, periods, organisationUnits, averageIntAggregator, key );
-
- log.info( "Exported values for data element operands with average aggregation operator of type number: " + TimeUtils.getHMS() );
-
- count += dataElementDataMart.exportDataValues( dataElementOperands, periods, organisationUnits, averageIntSingleValueAggregator, key );
-
- log.info( "Exported values for data element operands with average aggregation operator with single value of type number: " + TimeUtils.getHMS() );
-
- count += dataElementDataMart.exportDataValues( dataElementOperands, periods, organisationUnits, sumBoolAggregator, key );
-
- log.info( "Exported values for data element operands with sum aggregation operator of type yes/no: " + TimeUtils.getHMS() );
-
- count += dataElementDataMart.exportDataValues( dataElementOperands, periods, organisationUnits, averageBoolAggregator, key );
-
- log.info( "Exported values for data element operands with average aggregation operator of type yes/no: " + TimeUtils.getHMS() );
+ count += dataElementDataMart.exportDataValues( dataElementOperands, periods, organisationUnits, key );
+
+ log.info( "Exported values for data element operands: " + TimeUtils.getHMS() );
}
// ---------------------------------------------------------------------
=== 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 2011-05-20 16:00:10 +0000
+++ dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/indicator/DefaultIndicatorDataMart.java 2011-06-03 21:33:10 +0000
@@ -38,6 +38,8 @@
import org.amplecode.quick.BatchHandler;
import org.amplecode.quick.BatchHandlerFactory;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
import org.hisp.dhis.aggregation.AggregatedIndicatorValue;
import org.hisp.dhis.dataelement.DataElementOperand;
import org.hisp.dhis.datamart.aggregation.cache.AggregationCache;
@@ -59,6 +61,8 @@
public class DefaultIndicatorDataMart
implements IndicatorDataMart
{
+ private static final Log log = LogFactory.getLog( DefaultIndicatorDataMart.class );
+
private static final int DECIMALS = 1;
private static final String TRUE = "true";
@@ -206,6 +210,8 @@
}
}
}
+
+ log.debug( "Exported indicator values for period: " + period );
}
batchHandler.flush();
=== 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 2011-05-20 12:27:47 +0000
+++ dhis-2/dhis-services/dhis-service-datamart-default/src/main/resources/META-INF/dhis/beans.xml 2011-06-03 21:33:10 +0000
@@ -40,16 +40,6 @@
ref="org.hisp.dhis.datamart.dataelement.DataElementDataMart"/>
<property name="indicatorDataMart"
ref="org.hisp.dhis.datamart.indicator.IndicatorDataMart"/>
- <property name="sumIntAggregator"
- ref="org.hisp.dhis.datamart.aggregation.dataelement.SumIntAggregator"/>
- <property name="averageIntAggregator"
- ref="org.hisp.dhis.datamart.aggregation.dataelement.AverageIntAggregator"/>
- <property name="averageIntSingleValueAggregator"
- ref="org.hisp.dhis.datamart.aggregation.dataelement.AverageIntSingleValueAggregator"/>
- <property name="sumBoolAggregator"
- ref="org.hisp.dhis.datamart.aggregation.dataelement.SumBoolAggregator"/>
- <property name="averageBoolAggregator"
- ref="org.hisp.dhis.datamart.aggregation.dataelement.AverageBoolAggregator"/>
<property name="dataElementService"
ref="org.hisp.dhis.dataelement.DataElementService"/>
<property name="indicatorService"
@@ -152,6 +142,16 @@
<property name="batchHandlerFactory" ref="batchHandlerFactory"/>
<property name="aggregationCache"
ref="org.hisp.dhis.datamart.aggregation.cache.AggregationCache"/>
+ <property name="sumIntAggregator"
+ ref="org.hisp.dhis.datamart.aggregation.dataelement.SumIntAggregator"/>
+ <property name="averageIntAggregator"
+ ref="org.hisp.dhis.datamart.aggregation.dataelement.AverageIntAggregator"/>
+ <property name="averageIntSingleValueAggregator"
+ ref="org.hisp.dhis.datamart.aggregation.dataelement.AverageIntSingleValueAggregator"/>
+ <property name="sumBoolAggregator"
+ ref="org.hisp.dhis.datamart.aggregation.dataelement.SumBoolAggregator"/>
+ <property name="averageBoolAggregator"
+ ref="org.hisp.dhis.datamart.aggregation.dataelement.AverageBoolAggregator"/>
</bean>
<!-- IndicatorDataMart -->