dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #20496
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 9371: Analytics, more dynamic code
------------------------------------------------------------
revno: 9371
committer: Lars Helge Øverland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2012-12-19 15:35:23 +0100
message:
Analytics, more dynamic code
modified:
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/DefaultQueryPlanner.java
dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/data/JdbcAnalyticsManager.java
dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/security/login.vm
--
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/DataQueryParams.java'
--- dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/DataQueryParams.java 2012-12-18 16:01:44 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/DataQueryParams.java 2012-12-19 14:35:23 +0000
@@ -46,6 +46,8 @@
public static final String PERIOD_DIM_ID = "pe";
public static final String ORGUNIT_DIM_ID = "ou";
public static final String VALUE_ID = "value";
+
+ private static final String LEVEL_PREFIX = "uidlevel";
private List<String> indicators = new ArrayList<String>();
@@ -110,15 +112,26 @@
{
List<String> list = new ArrayList<String>();
- list.add( DATAELEMENT_DIM_ID );
+ if ( dataElements != null && !dataElements.isEmpty() )
+ {
+ list.add( DATAELEMENT_DIM_ID );
+ }
if ( categories )
{
list.add( CATEGORYOPTIONCOMBO_DIM_ID );
}
- list.add( PERIOD_DIM_ID );
- list.add( ORGUNIT_DIM_ID );
+ if ( periods != null && !periods.isEmpty() )
+ {
+ list.add( periodType != null ? periodType : PERIOD_DIM_ID );
+ }
+
+ if ( organisationUnits != null && !organisationUnits.isEmpty() )
+ {
+ list.add( organisationUnitLevel != 0 ? ( "uidlevel" + organisationUnitLevel ) : ORGUNIT_DIM_ID );
+ }
+
list.addAll( dimensions.keySet() );
return list;
@@ -128,6 +141,18 @@
{
return new ArrayList<String>( dimensions.keySet() );
}
+
+ public Map<String, List<String>> getDimensionMap()
+ {
+ Map<String, List<String>> map = new HashMap<String, List<String>>();
+
+ map.put( DATAELEMENT_DIM_ID, dataElements );
+ map.put( periodType != null ? periodType : PERIOD_DIM_ID, periods );
+ map.put( organisationUnitLevel != 0 ? ( LEVEL_PREFIX + organisationUnitLevel ) : ORGUNIT_DIM_ID, organisationUnits );
+ map.putAll( dimensions );
+
+ return map;
+ }
public void setDimension( String dimension, List<String> values )
{
=== 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 2012-12-18 16:01:44 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/data/DefaultAnalyticsService.java 2012-12-19 14:35:23 +0000
@@ -54,6 +54,9 @@
//TODO category sub-totals and totals
//TODO use data mart when query can be satisfied
//TODO create data mart for average, less-than yearly data elements
+ // aggregate in time dimension only
+ // insert into standard analytics table?
+ //TODO filter, exclude from select
//TODO investigate whether quarterly partitions are faster
@@ -90,7 +93,7 @@
{
Timer t = new Timer().start();
- int optimalQueries = MathUtils.getWithin( SystemUtils.getCpuCores(), 1, 16 );
+ int optimalQueries = MathUtils.getWithin( SystemUtils.getCpuCores(), 1, 4 );
List<DataQueryParams> queries = queryPlanner.planQuery( params, optimalQueries );
=== modified file 'dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/data/DefaultQueryPlanner.java'
--- dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/data/DefaultQueryPlanner.java 2012-12-18 00:49:03 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/data/DefaultQueryPlanner.java 2012-12-19 14:35:23 +0000
@@ -213,7 +213,7 @@
for ( String period : isoPeriods )
{
- String periodTypeName = PeriodType.getPeriodTypeFromIsoString( period ).getName();
+ String periodTypeName = PeriodType.getPeriodTypeFromIsoString( period ).getName().toLowerCase();
map.putValue( periodTypeName, period );
}
=== 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 2012-12-18 16:01:44 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/data/JdbcAnalyticsManager.java 2012-12-19 14:35:23 +0000
@@ -27,10 +27,9 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-import static org.hisp.dhis.analytics.DataQueryParams.*;
+import static org.hisp.dhis.analytics.DataQueryParams.VALUE_ID;
import static org.hisp.dhis.system.util.TextUtils.getCommaDelimitedString;
import static org.hisp.dhis.system.util.TextUtils.getQuotedCommaDelimitedString;
-import static org.hisp.dhis.system.util.TextUtils.getString;
import java.util.HashMap;
import java.util.List;
@@ -41,11 +40,13 @@
import org.apache.commons.logging.LogFactory;
import org.hisp.dhis.analytics.AnalyticsManager;
import org.hisp.dhis.analytics.DataQueryParams;
+import org.hisp.dhis.system.util.SqlHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.support.rowset.SqlRowSet;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.AsyncResult;
+import org.springframework.util.Assert;
/**
* This class is responsible for producing aggregated data values. It reads data
@@ -71,31 +72,24 @@
@Async
public Future<Map<String, Double>> getAggregatedDataValues( DataQueryParams params )
{
- int level = params.getOrganisationUnitLevel();
- String periodType = params.getPeriodType();
List<String> dimensions = params.getDimensionNames();
- List<String> extraDimensions = params.getDynamicDimensionNames();
+ Map<String, List<String>> dimensionMap = params.getDimensionMap();
+
+ Assert.isTrue( dimensions.size() > 0, "Must be at least one dimension" );
+
+ SqlHelper sqlHelper = new SqlHelper();
String sql =
- "select " + DATAELEMENT_DIM_ID + ", " +
- getString( CATEGORYOPTIONCOMBO_DIM_ID + ", ", !params.isCategories() ) +
- periodType + " as " + PERIOD_DIM_ID + ", " +
- "uidlevel" + level + " as " + ORGUNIT_DIM_ID + ", " +
- getCommaDelimitedString( extraDimensions, false, true ) +
- "sum(value) as value " +
+ "select " + getCommaDelimitedString( dimensions ) + ", sum(value) as value " +
+ "from " + params.getTableName() + " ";
- "from " + params.getTableName() + " " +
- "where " + DATAELEMENT_DIM_ID + " in ( " + getQuotedCommaDelimitedString( params.getDataElements() ) + " ) " +
- "and " + periodType + " in ( " + getQuotedCommaDelimitedString( params.getPeriods() ) + " ) " +
- "and uidlevel" + level + " in ( " + getQuotedCommaDelimitedString( params.getOrganisationUnits() ) + " ) " +
- getExtraDimensionQuery( params ) +
+ for ( String dim : dimensions )
+ {
+ sql += sqlHelper.whereAnd() + " " + dim + " in (" + getQuotedCommaDelimitedString( dimensionMap.get( dim ) ) + " ) ";
+ }
- "group by " + DATAELEMENT_DIM_ID + ", " +
- getString( CATEGORYOPTIONCOMBO_DIM_ID + ", ", !params.isCategories() ) +
- periodType + ", " +
- "uidlevel" + level +
- getCommaDelimitedString( extraDimensions, true, false );
-
+ sql += "group by " + getCommaDelimitedString( dimensions );
+
log.info( sql );
SqlRowSet rowSet = jdbcTemplate.queryForRowSet( sql );
@@ -119,23 +113,5 @@
}
return new AsyncResult<Map<String, Double>>( map );
- }
-
- // -------------------------------------------------------------------------
- // Supportive methods
- // -------------------------------------------------------------------------
-
- private String getExtraDimensionQuery( DataQueryParams params )
- {
- Map<String, List<String>> dimensionValues = params.getDimensions();
-
- String sql = "";
-
- for ( String dim : params.getDynamicDimensionNames() )
- {
- sql += "and " + dim + " in ( " + getQuotedCommaDelimitedString( dimensionValues.get( dim ) ) + " ) ";
- }
-
- return sql;
}
}
=== modified file 'dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/security/login.vm'
--- dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/security/login.vm 2012-12-13 15:23:19 +0000
+++ dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/security/login.vm 2012-12-19 14:35:23 +0000
@@ -21,6 +21,7 @@
</head>
<body>
<h1 style="display:none">$encoder.htmlEncode( $applicationTitle )</h1>
+ <div style="display:none">DHIS 2</div>
<div>
#if ( $keyFlag )
<img id="flagArea" src="../flags/${keyFlagImage}">