← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 9893: Analytics, impl reporting rates

 

------------------------------------------------------------
revno: 9893
committer: Lars Helge Øverland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2013-02-25 13:09:49 +0100
message:
  Analytics, impl reporting rates
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/PeriodType.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-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/MessageConversationController.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-api/src/main/java/org/hisp/dhis/period/PeriodType.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/PeriodType.java	2013-02-13 03:57:52 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/PeriodType.java	2013-02-25 12:09:49 +0000
@@ -363,6 +363,21 @@
         return periodType.createPeriod( getMediumDate( id[1] ) );
     }
 
+    /**
+     * Return the potential number of periods of the given period type which is
+     * spanned by this period.
+     *
+     * @param type the period type.
+     * @return the potential number of periods of the given period type spanned
+     *         by this period.
+     */
+    public int getPeriodSpan( PeriodType type )
+    {
+        double no = (double) this.getFrequencyOrder() / type.getFrequencyOrder();
+
+        return (int) Math.floor( no );
+    }
+    
     // -------------------------------------------------------------------------
     // ISO format methods
     // -------------------------------------------------------------------------
@@ -383,6 +398,11 @@
      */
     public abstract Period createPeriod( String isoDate );
 
+    /**
+     * Returns the iso8601 format as a string for this period type.
+     * 
+     * @return the iso8601 format.
+     */
     public abstract String getIsoFormat();
 
     // -------------------------------------------------------------------------

=== 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-02-22 17:24:41 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/DataQueryParams.java	2013-02-25 12:09:49 +0000
@@ -42,6 +42,7 @@
 import org.hisp.dhis.common.CombinationGenerator;
 import org.hisp.dhis.common.IdentifiableObject;
 import org.hisp.dhis.dataelement.DataElementOperand;
+import org.hisp.dhis.dataset.DataSet;
 import org.hisp.dhis.period.Period;
 import org.hisp.dhis.period.PeriodType;
 import org.hisp.dhis.system.util.CollectionUtils;
@@ -316,6 +317,24 @@
     }
     
     /**
+     * Returns a mapping between identifier and period type for all data sets
+     * in this query.
+     */
+    public Map<String, PeriodType> getDataSetPeriodTypeMap()
+    {
+        Map<String, PeriodType> map = new HashMap<String, PeriodType>();
+        
+        for ( IdentifiableObject dataSet : getDataSets() )
+        {
+            DataSet ds = (DataSet) dataSet;
+            
+            map.put( ds.getUid(), ds.getPeriodType() );
+        }
+        
+        return map;
+    }
+    
+    /**
      * Returns the index of the category option combo dimension. Returns null
      * if this dimension is not present.
      */

=== 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-02-22 17:24:41 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/data/DefaultAnalyticsService.java	2013-02-25 12:09:49 +0000
@@ -105,9 +105,10 @@
     private static final Log log = LogFactory.getLog( DefaultAnalyticsService.class );
     
     private static final String VALUE_HEADER_NAME = "Value";
+    private static final int PERCENT = 100;
     private static final int MAX_QUERIES = 6; //TODO increase?
     
-    //TODO completeness
+    //TODO completeness on time
     //TODO make sure data x dims are successive
     //TODO max value limit, 5000?
     
@@ -260,28 +261,35 @@
             dataTargetParams.setAggregationType( AggregationType.COUNT );
             dataTargetParams.setSkipPartitioning( true );
 
-            Map<String, Double> targetMap = getAggregatedCompletenessTargetMap( dataTargetParams ); //TODO
+            Map<String, Double> targetMap = getAggregatedCompletenessTargetMap( dataTargetParams );
+            
+            Map<String, PeriodType> dsPtMap = dataSourceParams.getDataSetPeriodTypeMap();
             
             Integer periodIndex = dataSourceParams.getPeriodDimensionIndex();
             Integer dataSetIndex = dataSourceParams.getDataSetDimensionIndex();
             
-            //TODO time aggregation for completeness, use data set period type and period.getPeriodSpan
+            List<Integer> completenessDimIndexes = dataTargetParams.getCompletenessDimensionIndexes();
             
             for ( Map.Entry<String, Double> entry : aggregatedDataMap.entrySet() )
             {
                 List<String> row = new ArrayList<String>( Arrays.asList( entry.getKey().split( DIMENSION_SEP ) ) );
                 
-                List<String> targetRow = ListUtils.getAll( row, dataTargetParams.getCompletenessDimensionIndexes() );
+                List<String> targetRow = ListUtils.getAll( row, completenessDimIndexes );
                 String targetKey = StringUtils.join( targetRow, DIMENSION_SEP );
                 Double target = targetMap.get( targetKey );
                              
                 if ( target != null && entry.getValue() != null )
                 {
-                    double value = entry.getValue() / target;
+                    PeriodType queryPt = PeriodType.getPeriodTypeFromIsoString( row.get( periodIndex ) );
+                    PeriodType dataPt = dsPtMap.get( row.get( dataSetIndex ) );
+                    
+                    target = target * queryPt.getPeriodSpan( dataPt );
+                    
+                    double value = entry.getValue() * PERCENT / target;
                     
                     grid.addRow();
                     grid.addValues( row.toArray() );
-                    grid.addValue( value );
+                    grid.addValue( MathUtils.getRounded( value, 1 ) );
                 }
             }
         }

=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/MessageConversationController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/MessageConversationController.java	2012-10-24 08:31:40 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/MessageConversationController.java	2013-02-25 12:09:49 +0000
@@ -79,7 +79,7 @@
     {
         Boolean markRead = Boolean.parseBoolean( parameters.get( "markRead" ) );
 
-        if( markRead  )
+        if ( markRead  )
         {
             entity.markRead( currentUserService.getCurrentUser() );
             manager.update( entity );