dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #20652
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 9559: Analytics wip support for reporting rates
------------------------------------------------------------
revno: 9559
committer: Lars Helge Øverland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2013-01-18 15:18:49 +0100
message:
Analytics wip support for reporting rates
modified:
dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/AggregationType.java
dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/AnalyticsManager.java
dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/AnalyticsService.java
dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/DataQueryParams.java
dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/data/DefaultAnalyticsService.java
dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/data/JdbcAnalyticsManager.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-analytics/src/main/java/org/hisp/dhis/analytics/AggregationType.java'
--- dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/AggregationType.java 2012-12-27 19:15:15 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/AggregationType.java 2013-01-18 14:18:49 +0000
@@ -29,5 +29,5 @@
public enum AggregationType
{
- SUM, AVERAGE_AGGREGATION, AVERAGE_DISAGGREGATION
+ SUM, AVERAGE_AGGREGATION, AVERAGE_DISAGGREGATION, COUNT_AGGREGATION
}
=== modified file 'dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/AnalyticsManager.java'
--- dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/AnalyticsManager.java 2013-01-15 13:17:29 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/AnalyticsManager.java 2013-01-18 14:18:49 +0000
@@ -38,13 +38,14 @@
/**
* Retrieves aggregated data values for the given query. The data is returned
* as a mapping where the key is concatenated from the dimension options for
- * all dimensions, and the value is the data value.
+ * all dimensions, and the value is the data value. This method is invoked
+ * asynchronously.
*
* @param params the query to retrieve aggregated data for.
* @return a map.
*/
Future<Map<String, Double>> getAggregatedDataValues( DataQueryParams params );
-
+
/**
* Inserts entries for the aggregation periods mapped to each data period
* in the given data value map. Removes the original entry for the data period.
=== modified file 'dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/AnalyticsService.java'
--- dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/AnalyticsService.java 2013-01-07 15:58:50 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/AnalyticsService.java 2013-01-18 14:18:49 +0000
@@ -37,7 +37,7 @@
{
Grid getAggregatedDataValues( DataQueryParams params ) throws Exception;
- Map<String, Double> getAggregatedDataValueMap( DataQueryParams params ) throws Exception;
+ Map<String, Double> getAggregatedDataValueMap( DataQueryParams params, String tableName ) throws Exception;
DataQueryParams getFromUrl( Set<String> dimensionParams, Set<String> filterParams, boolean categories, I18nFormat format );
}
=== modified file 'dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/DataQueryParams.java'
--- dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/DataQueryParams.java 2013-01-17 14:59:00 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/DataQueryParams.java 2013-01-18 14:18:49 +0000
@@ -55,6 +55,7 @@
{
public static final String INDICATOR_DIM_ID = "in";
public static final String DATAELEMENT_DIM_ID = "de";
+ public static final String DATASET_DIM_ID = "ds";
public static final String CATEGORYOPTIONCOMBO_DIM_ID = "coc";
public static final String PERIOD_DIM_ID = "pe";
public static final String ORGUNIT_DIM_ID = "ou";
@@ -648,6 +649,16 @@
dimensions.put( DATAELEMENT_DIM_ID, dataElements );
}
+ public List<IdentifiableObject> getDataSets()
+ {
+ return dimensions.get( DATASET_DIM_ID );
+ }
+
+ public void setDataSets( List<IdentifiableObject> dataSets )
+ {
+ dimensions.get( DATASET_DIM_ID );
+ }
+
public List<IdentifiableObject> getPeriods()
{
return dimensions.get( PERIOD_DIM_ID );
=== modified file 'dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/data/DefaultAnalyticsService.java'
--- dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/data/DefaultAnalyticsService.java 2013-01-17 17:49:13 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/data/DefaultAnalyticsService.java 2013-01-18 14:18:49 +0000
@@ -27,7 +27,10 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+import static org.hisp.dhis.analytics.AnalyticsTableManager.ANALYTICS_TABLE_NAME;
+import static org.hisp.dhis.analytics.AnalyticsTableManager.COMPLETENESS_TABLE_NAME;
import static org.hisp.dhis.analytics.DataQueryParams.DATAELEMENT_DIM_ID;
+import static org.hisp.dhis.analytics.DataQueryParams.DATASET_DIM_ID;
import static org.hisp.dhis.analytics.DataQueryParams.DIMENSION_SEP;
import static org.hisp.dhis.analytics.DataQueryParams.INDICATOR_DIM_ID;
import static org.hisp.dhis.analytics.DataQueryParams.ORGUNIT_DIM_ID;
@@ -44,9 +47,9 @@
import java.util.Set;
import java.util.concurrent.Future;
+import org.hisp.dhis.analytics.AggregationType;
import org.hisp.dhis.analytics.AnalyticsManager;
import org.hisp.dhis.analytics.AnalyticsService;
-import org.hisp.dhis.analytics.AnalyticsTableManager;
import org.hisp.dhis.analytics.DataQueryParams;
import org.hisp.dhis.analytics.DimensionOption;
import org.hisp.dhis.analytics.QueryPlanner;
@@ -57,6 +60,7 @@
import org.hisp.dhis.dataelement.DataElementGroupSet;
import org.hisp.dhis.dataelement.DataElementOperand;
import org.hisp.dhis.dataelement.DataElementService;
+import org.hisp.dhis.dataset.DataSetService;
import org.hisp.dhis.expression.ExpressionService;
import org.hisp.dhis.i18n.I18nFormat;
import org.hisp.dhis.indicator.Indicator;
@@ -78,7 +82,6 @@
{
private static final String VALUE_HEADER_NAME = "Value";
- //TODO indicator aggregation
//TODO completeness
@Autowired
@@ -94,6 +97,9 @@
private DataElementService dataElementService;
@Autowired
+ private DataSetService dataSetService;
+
+ @Autowired
private OrganisationUnitService organisationUnitService;
@Autowired
@@ -132,20 +138,20 @@
if ( params.getIndicators() != null && !params.getIndicators().isEmpty() )
{
- Map<String, Double> constantMap = constantService.getConstantMap();
-
int indicatorIndex = params.getDataElementOrIndicatorDimensionIndex();
+
+ List<Indicator> indicators = asTypedList( params.getIndicators() );
DataQueryParams dataSourceParams = setDataElementsFromIndicators( params );
- List<Indicator> indicators = asTypedList( params.getIndicators() );
-
- Map<String, Double> aggregatedDataMap = getAggregatedDataValueMap( dataSourceParams );
+ Map<String, Double> aggregatedDataMap = getAggregatedDataValueMap( dataSourceParams, ANALYTICS_TABLE_NAME );
Map<String, Map<DataElementOperand, Double>> permutationOperandValueMap = dataSourceParams.getPermutationOperandValueMap( aggregatedDataMap );
List<List<DimensionOption>> dimensionOptionPermutations = dataSourceParams.getDimensionOptionPermutations();
+ Map<String, Double> constantMap = constantService.getConstantMap();
+
for ( Indicator indicator : indicators )
{
for ( List<DimensionOption> options : dimensionOptionPermutations )
@@ -183,26 +189,52 @@
if ( params.getDataElements() != null && !params.getDataElements().isEmpty() )
{
- Map<String, Double> aggregatedDataMap = getAggregatedDataValueMap( params );
-
- for ( Map.Entry<String, Double> entry : aggregatedDataMap.entrySet() )
- {
- grid.addRow();
- grid.addValues( entry.getKey().split( DIMENSION_SEP ) );
- grid.addValue( entry.getValue() );
- }
+ DataQueryParams dataSourceParams = new DataQueryParams( params );
+ dataSourceParams.removeDimension( INDICATOR_DIM_ID );
+ dataSourceParams.removeDimension( DATASET_DIM_ID );
+
+ Map<String, Double> aggregatedDataMap = getAggregatedDataValueMap( dataSourceParams, ANALYTICS_TABLE_NAME );
+
+ for ( Map.Entry<String, Double> entry : aggregatedDataMap.entrySet() )
+ {
+ grid.addRow();
+ grid.addValues( entry.getKey().split( DIMENSION_SEP ) );
+ grid.addValue( entry.getValue() );
+ }
+ }
+
+ // ---------------------------------------------------------------------
+ // Data sets
+ // ---------------------------------------------------------------------
+
+ if ( params.getDataSets() != null && !params.getDataSets().isEmpty() )
+ {
+ DataQueryParams dataSourceParams = new DataQueryParams( params );
+ dataSourceParams.removeDimension( INDICATOR_DIM_ID );
+ dataSourceParams.removeDimension( DATAELEMENT_DIM_ID );
+ dataSourceParams.setCategories( false );
+ dataSourceParams.setAggregationType( AggregationType.COUNT_AGGREGATION );
+
+ Map<String, Double> aggregatedDataMap = getAggregatedDataValueMap( dataSourceParams, COMPLETENESS_TABLE_NAME );
+
+ for ( Map.Entry<String, Double> entry : aggregatedDataMap.entrySet() )
+ {
+ grid.addRow();
+ grid.addValues( entry.getKey().split( DIMENSION_SEP ) );
+ grid.addValue( entry.getValue() );
+ }
}
return grid;
}
- public Map<String, Double> getAggregatedDataValueMap( DataQueryParams params ) throws Exception
+ public Map<String, Double> getAggregatedDataValueMap( DataQueryParams params, String tableName ) throws Exception
{
Timer t = new Timer().start();
int optimalQueries = MathUtils.getWithin( SystemUtils.getCpuCores(), 1, 6 );
- List<DataQueryParams> queries = queryPlanner.planQuery( params, optimalQueries, AnalyticsTableManager.ANALYTICS_TABLE_NAME );
+ List<DataQueryParams> queries = queryPlanner.planQuery( params, optimalQueries, tableName );
t.getTime( "Planned query for optimal: " + optimalQueries + ", got: " + queries.size() );
@@ -285,6 +317,10 @@
{
return asList( dataElementService.getDataElementsByUid( options ) );
}
+ else if ( DATASET_DIM_ID.equals( dimension ) )
+ {
+ return asList( dataSetService.getDataSetsByUid( options ) );
+ }
else if ( ORGUNIT_DIM_ID.equals( dimension ) )
{
return asList( organisationUnitService.getOrganisationUnitsByUid( options ) );
@@ -329,6 +365,7 @@
immutableParams.setDataElements( dataElements );
immutableParams.removeDimension( INDICATOR_DIM_ID );
+ immutableParams.removeDimension( DATASET_DIM_ID );
immutableParams.setCategories( true );
return immutableParams;
=== modified file 'dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/data/JdbcAnalyticsManager.java'
--- dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/data/JdbcAnalyticsManager.java 2013-01-17 14:26:35 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/data/JdbcAnalyticsManager.java 2013-01-18 14:18:49 +0000
@@ -29,6 +29,7 @@
import static org.hisp.dhis.analytics.AggregationType.AVERAGE_AGGREGATION;
import static org.hisp.dhis.analytics.AggregationType.AVERAGE_DISAGGREGATION;
+import static org.hisp.dhis.analytics.AggregationType.COUNT_AGGREGATION;
import static org.hisp.dhis.analytics.DataQueryParams.*;
import static org.hisp.dhis.system.util.TextUtils.getCommaDelimitedString;
import static org.hisp.dhis.system.util.TextUtils.getQuotedCommaDelimitedString;
@@ -78,7 +79,7 @@
// -------------------------------------------------------------------------
// Implementation
// -------------------------------------------------------------------------
-
+
@Async
public Future<Map<String, Double>> getAggregatedDataValues( DataQueryParams params )
{
@@ -95,7 +96,18 @@
int days = PeriodType.getPeriodTypeByName( params.getPeriodType() ).getFrequencyOrder();
- sql += params.isAggregationType( AVERAGE_AGGREGATION ) ? "sum(daysxvalue) / " + days : "sum(value)";
+ if ( params.isAggregationType( AVERAGE_AGGREGATION ) )
+ {
+ sql += "sum(daysxvalue) / " + days;
+ }
+ else if ( params.isAggregationType( COUNT_AGGREGATION ) )
+ {
+ sql += "count(value)";
+ }
+ else
+ {
+ sql += "sum(value)";
+ }
sql += " as value from " + params.getTableName() + " ";