← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 9257: Analytics table, bool data

 

------------------------------------------------------------
revno: 9257
committer: Lars Helge Øverland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2012-12-10 21:15:39 +0100
message:
  Analytics table, bool data
modified:
  dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/DefaultAnalyticsTableService.java
  dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/JdbcAnalyticsTableManager.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/table/DefaultAnalyticsTableService.java'
--- dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/DefaultAnalyticsTableService.java	2012-12-03 21:04:39 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/DefaultAnalyticsTableService.java	2012-12-10 20:15:39 +0000
@@ -35,6 +35,7 @@
 import org.apache.commons.logging.LogFactory;
 import org.hisp.dhis.analytics.AnalyticsTableManager;
 import org.hisp.dhis.analytics.AnalyticsTableService;
+import org.hisp.dhis.system.util.Clock;
 import org.hisp.dhis.system.util.ConcurrentUtils;
 import org.hisp.dhis.system.util.PaginatedList;
 import org.hisp.dhis.system.util.SystemUtils;
@@ -60,15 +61,19 @@
     @Async
     public Future<?> update()
     {
-        log.info( "Starting update..." );
+        Clock clock = new Clock().startClock().logTime( "Starting update..." );
         
         tableManager.dropTable();
+        clock.logTime( "Dropped analytics table" );
+        
         tableManager.createTable();
+        clock.logTime( "Created analytics table" );
+        
         tableManager.populateTable();
+        clock.logTime( "Populated analytics table" );
         
         createIndexes();
-        
-        log.info( "Update done" );
+        clock.logTime( "Created all indexes, update done" );
         
         return null;
     }

=== modified file 'dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/JdbcAnalyticsTableManager.java'
--- dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/JdbcAnalyticsTableManager.java	2012-12-03 21:04:39 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/JdbcAnalyticsTableManager.java	2012-12-10 20:15:39 +0000
@@ -83,7 +83,7 @@
   
     //TODO all data types
     //TODO create temp table then swap
-    //TODO shard on data year
+    //TODO shard on data quarter based on start date
     //TODO average aggregation operator data, pre-aggregate in time dimension, not in org unit dimension
     
     public void dropTable()
@@ -91,8 +91,6 @@
         final String sql = "drop table " + TABLE_NAME;
         
         executeSilently( sql );
-        
-        log.info( "Dropped table: " + TABLE_NAME );
     }
     
     public void createTable()
@@ -109,8 +107,6 @@
         log.info( "Create SQL: " + sql );
         
         executeSilently( sql );
-        
-        log.info( "Created table: " + TABLE_NAME );
     }
         
     @Async
@@ -133,6 +129,13 @@
     
     public void populateTable()
     {
+        populateTable( "cast(dv.value as double precision)" , "int" );
+        
+        populateTable( "1 as value" , "bool" );
+    }
+    
+    private void populateTable( String valueExpression, String valueType )
+    {
         String insert = "insert into analytics (";
         
         for ( String[] col : getDimensionColumns() )
@@ -151,23 +154,20 @@
         
         select = select.replace( "organisationunitid", "sourceid" ); // Legacy fix
         
-        select += 
-            "cast(dv.value as double precision) " +
+        select += valueExpression + " " +
             "from datavalue dv " +
             "left join _organisationunitgroupsetstructure ougs on dv.sourceid=ougs.organisationunitid " +
             "left join _orgunitstructure ous on dv.sourceid=ous.organisationunitid " +
             "left join _period_no_disaggregation_structure ps on dv.periodid=ps.periodid " +
             "left join dataelement de on dv.dataelementid=de.dataelementid " +
             "left join period pe on dv.periodid=pe.periodid " +
-            "where de.valuetype='int' and pe.startdate >= '2011-10-01'";
+            "where de.valuetype='" + valueType + "' and pe.startdate >= '2011-10-01'";
 
         final String sql = insert + select;
         
         log.info( "Populate SQL: "+ sql );
         
         jdbcTemplate.execute( sql );
-        
-        log.info( "Populated analytics table" );
     }
 
     public List<String[]> getDimensionColumns()


Follow ups