dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #14585
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 5000: Datamart, simplified code
Merge authors:
Lars Helge Øverland (larshelge)
------------------------------------------------------------
revno: 5000 [merge]
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Sat 2011-10-22 09:19:54 +0200
message:
Datamart, simplified code
modified:
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/AverageIntSingleValueAggregator.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
--
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/aggregation/dataelement/AverageBoolAggregator.java'
--- dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/aggregation/dataelement/AverageBoolAggregator.java 2011-05-31 20:50:19 +0000
+++ dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/aggregation/dataelement/AverageBoolAggregator.java 2011-10-22 07:19:54 +0000
@@ -42,8 +42,6 @@
import org.hisp.dhis.datamart.CrossTabDataValue;
import org.hisp.dhis.datamart.aggregation.cache.AggregationCache;
import org.hisp.dhis.datamart.crosstab.CrossTabService;
-import org.hisp.dhis.organisationunit.OrganisationUnit;
-import org.hisp.dhis.organisationunit.OrganisationUnitHierarchy;
import org.hisp.dhis.period.Period;
import org.hisp.dhis.period.PeriodType;
import org.springframework.util.CollectionUtils;
@@ -77,7 +75,7 @@
// -------------------------------------------------------------------------
public Map<DataElementOperand, Double> getAggregatedValues( final Collection<DataElementOperand> operands,
- final Period period, final OrganisationUnit unit, int unitLevel, final OrganisationUnitHierarchy hierarchy, String key )
+ final Period period, int unitLevel, final Collection<Integer> organisationUnits, String key )
{
if ( CollectionUtils.isEmpty( operands ) )
{
@@ -85,7 +83,7 @@
}
final Collection<CrossTabDataValue> crossTabValues = crossTabService.getCrossTabDataValues( operands,
- aggregationCache.getIntersectingPeriods( period.getStartDate(), period.getEndDate() ), hierarchy.getChildren( unit.getId() ), key );
+ aggregationCache.getIntersectingPeriods( period.getStartDate(), period.getEndDate() ), organisationUnits, key );
final Map<DataElementOperand, double[]> entries = getAggregate( crossTabValues, period.getStartDate(),
period.getEndDate(), period.getStartDate(), period.getEndDate(), unitLevel ); // <Operand, [total value, total relevant days]>
=== 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 2011-09-24 21:19:26 +0000
+++ dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/aggregation/dataelement/AverageIntAggregator.java 2011-10-22 07:19:54 +0000
@@ -44,8 +44,6 @@
import org.hisp.dhis.datamart.CrossTabDataValue;
import org.hisp.dhis.datamart.aggregation.cache.AggregationCache;
import org.hisp.dhis.datamart.crosstab.CrossTabService;
-import org.hisp.dhis.organisationunit.OrganisationUnit;
-import org.hisp.dhis.organisationunit.OrganisationUnitHierarchy;
import org.hisp.dhis.period.Period;
import org.hisp.dhis.period.PeriodType;
import org.springframework.util.CollectionUtils;
@@ -81,18 +79,16 @@
// -------------------------------------------------------------------------
public Map<DataElementOperand, Double> getAggregatedValues( final Collection<DataElementOperand> operands,
- final Period period, final OrganisationUnit unit, int unitLevel, OrganisationUnitHierarchy hierarchy, String key )
+ final Period period, int unitLevel, final Collection<Integer> organisationUnits, String key )
{
if ( CollectionUtils.isEmpty( operands ) )
{
return new HashMap<DataElementOperand, Double>();
}
- final Collection<Integer> unitIds = hierarchy.getChildren( unit.getId() );
-
final Map<DataElementOperand, Double> values = new HashMap<DataElementOperand, Double>(); // <Operand, total value>
- for ( final Integer unitId : unitIds )
+ for ( final Integer unitId : organisationUnits )
{
final Collection<CrossTabDataValue> crossTabValues =
crossTabService.getCrossTabDataValues( operands, aggregationCache.getIntersectingPeriods( period.getStartDate(), period.getEndDate() ), unitId, key );
=== modified 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 2011-09-24 21:19:26 +0000
+++ dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/aggregation/dataelement/AverageIntSingleValueAggregator.java 2011-10-22 07:19:54 +0000
@@ -29,10 +29,8 @@
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.Collection;
-import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
@@ -44,8 +42,6 @@
import org.hisp.dhis.datamart.CrossTabDataValue;
import org.hisp.dhis.datamart.aggregation.cache.AggregationCache;
import org.hisp.dhis.datamart.crosstab.CrossTabService;
-import org.hisp.dhis.organisationunit.OrganisationUnit;
-import org.hisp.dhis.organisationunit.OrganisationUnitHierarchy;
import org.hisp.dhis.period.Period;
import org.hisp.dhis.period.PeriodType;
import org.springframework.util.CollectionUtils;
@@ -81,7 +77,7 @@
// -------------------------------------------------------------------------
public Map<DataElementOperand, Double> getAggregatedValues( final Collection<DataElementOperand> operands,
- final Period period, final OrganisationUnit unit, int unitLevel, OrganisationUnitHierarchy hierarchy, String key )
+ final Period period, int unitLevel, final Collection<Integer> organisationUnits, String key )
{
if ( CollectionUtils.isEmpty( operands ) )
{
@@ -89,28 +85,9 @@
}
final Collection<CrossTabDataValue> crossTabValues = crossTabService.getCrossTabDataValues( operands,
- aggregationCache.getIntersectingPeriods( period.getStartDate(), period.getEndDate() ), hierarchy.getChildren( unit.getId() ), key );
-
- final Map<DataElementOperand, double[]> entries = getAggregate( crossTabValues, period.getStartDate(),
- period.getEndDate(), period.getStartDate(), period.getEndDate(), unitLevel ); // <Operand, [total value, total relevant days]>
-
- final Map<DataElementOperand, Double> values = new HashMap<DataElementOperand, Double>( entries.size() ); // <Operand, total value>
-
- for ( final Entry<DataElementOperand, double[]> entry : entries.entrySet() )
- {
- if ( entry.getValue() != null && entry.getValue()[ 1 ] > 0 )
- {
- values.put( entry.getKey(), entry.getValue()[ 0 ] );
- }
- }
-
- return values;
- }
-
- public Map<DataElementOperand, double[]> getAggregate( final Collection<CrossTabDataValue> crossTabValues,
- final Date startDate, final Date endDate, final Date aggregationStartDate, final Date aggregationEndDate, int unitLevel )
- {
- final Map<DataElementOperand, double[]> totalSums = new HashMap<DataElementOperand, double[]>(); // <Operand, [total value, total relevant days]>
+ aggregationCache.getIntersectingPeriods( period.getStartDate(), period.getEndDate() ), organisationUnits, key );
+
+ final Map<DataElementOperand, Double> values = new HashMap<DataElementOperand, Double>( crossTabValues.size() * operands.size() ); // <Operand, total value>
for ( final CrossTabDataValue crossTabValue : crossTabValues )
{
@@ -121,7 +98,6 @@
if ( entry.getValue() != null && entry.getKey().aggregationLevelIsValid( unitLevel, dataValueLevel ) )
{
double value = 0.0;
- double relevantDays = getDaysInclusive( startDate, endDate );
try
{
@@ -133,18 +109,16 @@
continue;
}
- final double[] totalSum = totalSums.get( entry.getKey() );
- value += totalSum != null ? totalSum[0] : 0;
- relevantDays += totalSum != null ? totalSum[1] : 0;
- final double[] values = { value, relevantDays };
- totalSums.put( entry.getKey(), values );
+ final Double current = values.get( entry.getKey() );
+ value += current != null ? current : 0.0;
+ values.put( entry.getKey(), value );
}
}
}
- return totalSums;
+ return values;
}
-
+
public Collection<DataElementOperand> filterOperands( final Collection<DataElementOperand> operands, final PeriodType periodType )
{
final Collection<DataElementOperand> filteredOperands = new HashSet<DataElementOperand>();
=== 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 2011-04-15 15:02:55 +0000
+++ dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/aggregation/dataelement/DataElementAggregator.java 2011-10-22 07:19:54 +0000
@@ -28,13 +28,9 @@
*/
import java.util.Collection;
-import java.util.Date;
import java.util.Map;
import org.hisp.dhis.dataelement.DataElementOperand;
-import org.hisp.dhis.datamart.CrossTabDataValue;
-import org.hisp.dhis.organisationunit.OrganisationUnit;
-import org.hisp.dhis.organisationunit.OrganisationUnitHierarchy;
import org.hisp.dhis.period.Period;
import org.hisp.dhis.period.PeriodType;
@@ -46,10 +42,7 @@
final String TRUE = "true";
Map<DataElementOperand, Double> getAggregatedValues( final Collection<DataElementOperand> operands,
- final Period period, final OrganisationUnit unit, int unitLevel, final OrganisationUnitHierarchy hierarchy, String key );
-
- Map<DataElementOperand, double[]> getAggregate( final Collection<CrossTabDataValue> crossTabValues,
- final Date startDate, final Date endDate, final Date aggregationStartDate, final Date aggregationEndDate, int unitLevel );
+ final Period period, int unitLevel, final Collection<Integer> organisationUnits, String key );
Collection<DataElementOperand> filterOperands( Collection<DataElementOperand> operands, PeriodType periodType );
}
=== 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 2011-09-24 21:19:26 +0000
+++ dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/aggregation/dataelement/SumBoolAggregator.java 2011-10-22 07:19:54 +0000
@@ -29,10 +29,8 @@
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.MathUtils.getFloor;
import java.util.Collection;
-import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
@@ -42,8 +40,6 @@
import org.hisp.dhis.datamart.CrossTabDataValue;
import org.hisp.dhis.datamart.aggregation.cache.AggregationCache;
import org.hisp.dhis.datamart.crosstab.CrossTabService;
-import org.hisp.dhis.organisationunit.OrganisationUnit;
-import org.hisp.dhis.organisationunit.OrganisationUnitHierarchy;
import org.hisp.dhis.period.Period;
import org.hisp.dhis.period.PeriodType;
import org.springframework.util.CollectionUtils;
@@ -77,7 +73,7 @@
// -------------------------------------------------------------------------
public Map<DataElementOperand, Double> getAggregatedValues( final Collection<DataElementOperand> operands,
- final Period period, final OrganisationUnit unit, int unitLevel, OrganisationUnitHierarchy hierarchy, String key )
+ final Period period, int unitLevel, final Collection<Integer> organisationUnits, String key )
{
if ( CollectionUtils.isEmpty( operands ) )
{
@@ -85,28 +81,9 @@
}
final Collection<CrossTabDataValue> crossTabValues = crossTabService.getCrossTabDataValues( operands,
- aggregationCache.getIntersectingPeriods( period.getStartDate(), period.getEndDate() ), hierarchy.getChildren( unit.getId() ), key );
-
- final Map<DataElementOperand, double[]> entries = getAggregate( crossTabValues, period.getStartDate(),
- period.getEndDate(), period.getStartDate(), period.getEndDate(), unitLevel ); // <data element id, [total value, total relevant days]>
+ aggregationCache.getIntersectingPeriods( period.getStartDate(), period.getEndDate() ), organisationUnits, key );
- final Map<DataElementOperand, Double> values = new HashMap<DataElementOperand, Double>( entries.size() ); // <Operand, total value>
-
- for ( final Entry<DataElementOperand, double[]> entry : entries.entrySet() )
- {
- if ( entry.getValue() != null )
- {
- values.put( entry.getKey(), getFloor( entry.getValue()[ 0 ] ) );
- }
- }
-
- return values;
- }
-
- public Map<DataElementOperand, double[]> getAggregate( final Collection<CrossTabDataValue> crossTabValues,
- final Date startDate, final Date endDate, final Date aggregationStartDate, final Date aggregationEndDate, int unitLevel )
- {
- final Map<DataElementOperand, double[]> totalSums = new HashMap<DataElementOperand, double[]>(); // <Operand, [total value, total relevant days]>
+ final Map<DataElementOperand, Double> values = new HashMap<DataElementOperand, Double>( crossTabValues.size() * operands.size() ); // <Operand, total value>
for ( final CrossTabDataValue crossTabValue : crossTabValues )
{
@@ -122,18 +99,17 @@
{
value = 1;
}
-
- final double[] totalSum = totalSums.get( entry.getKey() );
- value += totalSum != null ? totalSum[0] : 0;
- final double[] values = { value, 0 };
- totalSums.put( entry.getKey(), values );
+
+ final Double current = values.get( entry.getKey() );
+ value += current != null ? current : 0.0;
+ values.put( entry.getKey(), value );
}
}
}
- return totalSums;
+ return values;
}
-
+
public Collection<DataElementOperand> filterOperands( final Collection<DataElementOperand> operands, final PeriodType periodType )
{
final Collection<DataElementOperand> filteredOperands = new HashSet<DataElementOperand>();
=== 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 2011-09-24 21:19:26 +0000
+++ dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/aggregation/dataelement/SumIntAggregator.java 2011-10-22 07:19:54 +0000
@@ -31,7 +31,6 @@
import static org.hisp.dhis.dataelement.DataElement.VALUE_TYPE_INT;
import java.util.Collection;
-import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
@@ -43,8 +42,6 @@
import org.hisp.dhis.datamart.CrossTabDataValue;
import org.hisp.dhis.datamart.aggregation.cache.AggregationCache;
import org.hisp.dhis.datamart.crosstab.CrossTabService;
-import org.hisp.dhis.organisationunit.OrganisationUnit;
-import org.hisp.dhis.organisationunit.OrganisationUnitHierarchy;
import org.hisp.dhis.period.Period;
import org.hisp.dhis.period.PeriodType;
import org.springframework.util.CollectionUtils;
@@ -80,7 +77,7 @@
// -------------------------------------------------------------------------
public Map<DataElementOperand, Double> getAggregatedValues( final Collection<DataElementOperand> operands,
- final Period period, final OrganisationUnit unit, int unitLevel, OrganisationUnitHierarchy hierarchy, String key )
+ final Period period, int unitLevel, final Collection<Integer> organisationUnits, String key )
{
if ( CollectionUtils.isEmpty( operands ) )
{
@@ -88,28 +85,9 @@
}
final Collection<CrossTabDataValue> crossTabValues = crossTabService.getCrossTabDataValues( operands,
- aggregationCache.getPeriodsBetweenDates( period.getStartDate(), period.getEndDate() ), hierarchy.getChildren( unit.getId() ), key );
-
- final Map<DataElementOperand, double[]> entries = getAggregate( crossTabValues, period.getStartDate(),
- period.getEndDate(), period.getStartDate(), period.getEndDate(), unitLevel ); // <Operand, [total value, total relevant days]>
-
- final Map<DataElementOperand, Double> values = new HashMap<DataElementOperand, Double>( entries.size() ); // <Operand, total value>
-
- for ( final Entry<DataElementOperand, double[]> entry : entries.entrySet() )
- {
- if ( entry.getValue() != null )
- {
- values.put( entry.getKey(), entry.getValue()[ 0 ] );
- }
- }
-
- return values;
- }
-
- public Map<DataElementOperand, double[]> getAggregate( final Collection<CrossTabDataValue> crossTabValues,
- final Date startDate, final Date endDate, final Date aggregationStartDate, final Date aggregationEndDate, int unitLevel )
- {
- final Map<DataElementOperand, double[]> totalSums = new HashMap<DataElementOperand, double[]>(); // <Operand, [total value, total relevant days]>
+ aggregationCache.getPeriodsBetweenDates( period.getStartDate(), period.getEndDate() ), organisationUnits, key );
+
+ final Map<DataElementOperand, Double> values = new HashMap<DataElementOperand, Double>( crossTabValues.size() * operands.size() ); // <Operand, total value>
for ( final CrossTabDataValue crossTabValue : crossTabValues )
{
@@ -131,17 +109,16 @@
continue;
}
- final double[] totalSum = totalSums.get( entry.getKey() );
- value += totalSum != null ? totalSum[0] : 0;
- final double[] values = { value, 0 };
- totalSums.put( entry.getKey(), values );
+ final Double current = values.get( entry.getKey() );
+ value += current != null ? current : 0.0;
+ values.put( entry.getKey(), value );
}
}
}
- return totalSums;
+ return values;
}
-
+
public Collection<DataElementOperand> filterOperands( final Collection<DataElementOperand> operands, final PeriodType periodType )
{
final Collection<DataElementOperand> filteredOperands = new HashSet<DataElementOperand>();
@@ -149,7 +126,7 @@
for ( final DataElementOperand operand : operands )
{
if ( operand.getValueType().equals( VALUE_TYPE_INT ) && operand.getAggregationOperator().equals( AGGREGATION_OPERATOR_SUM ) &&
- operand.getFrequencyOrder() <= periodType.getFrequencyOrder() ) // Ignore disaggregation
+ operand.getFrequencyOrder() <= periodType.getFrequencyOrder() ) // Ignore disaggregation
{
filteredOperands.add( operand );
}
=== 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-10-18 20:48:23 +0000
+++ dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/dataelement/DefaultDataElementDataMart.java 2011-10-22 07:19:54 +0000
@@ -172,11 +172,13 @@
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 ) );
+ final Collection<Integer> orgUnitChildren = hierarchy.getChildren( unit.getId() );
+
+ valueMap.putAll( sumIntAggregator.getAggregatedValues( sumIntOperands, period, level, orgUnitChildren, key ) );
+ valueMap.putAll( averageIntAggregator.getAggregatedValues( averageIntOperands, period, level, orgUnitChildren, key ) );
+ valueMap.putAll( averageIntSingleValueAggregator.getAggregatedValues( averageIntSingleValueOperands, period, level, orgUnitChildren, key ) );
+ valueMap.putAll( sumBoolAggregator.getAggregatedValues( sumBoolOperands, period, level, orgUnitChildren, key ) );
+ valueMap.putAll( averageBoolAggregator.getAggregatedValues( averageBoolOperands, period, level, orgUnitChildren, key ) );
if ( valueMap.size() > 0 )
{