← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 3690: Centralized method

 

------------------------------------------------------------
revno: 3690
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2011-05-20 15:27:02 +0200
message:
  Centralized method
modified:
  dhis-2/dhis-services/dhis-service-aggregationengine-default/src/main/java/org/hisp/dhis/aggregation/impl/indicator/IndicatorAggregation.java
  dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/indicator/DefaultIndicatorDataMart.java
  dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/DateUtils.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-aggregationengine-default/src/main/java/org/hisp/dhis/aggregation/impl/indicator/IndicatorAggregation.java'
--- dhis-2/dhis-services/dhis-service-aggregationengine-default/src/main/java/org/hisp/dhis/aggregation/impl/indicator/IndicatorAggregation.java	2011-05-20 13:18:16 +0000
+++ dhis-2/dhis-services/dhis-service-aggregationengine-default/src/main/java/org/hisp/dhis/aggregation/impl/indicator/IndicatorAggregation.java	2011-05-20 13:27:02 +0000
@@ -27,8 +27,6 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-import static org.hisp.dhis.system.util.DateUtils.DAYS_IN_YEAR;
-import static org.hisp.dhis.system.util.DateUtils.getDays;
 import static org.hisp.dhis.system.util.MathUtils.INVALID;
 import static org.hisp.dhis.system.util.MathUtils.calculateExpression;
 
@@ -46,6 +44,7 @@
 import org.hisp.dhis.expression.ExpressionService;
 import org.hisp.dhis.indicator.Indicator;
 import org.hisp.dhis.organisationunit.OrganisationUnit;
+import org.hisp.dhis.system.util.DateUtils;
 
 /**
  * @author Lars Helge Overland
@@ -106,7 +105,7 @@
         {
             int factor = indicator.getIndicatorType().getFactor();
 
-            double annualizationFactor = getAnnualizationFactor( indicator, startDate, endDate );
+            double annualizationFactor = DateUtils.getAnnualizationFactor( indicator, startDate, endDate );
             
             double aggregatedValue = ( numeratorValue / denominatorValue ) * factor * annualizationFactor;
 
@@ -131,23 +130,6 @@
     // -------------------------------------------------------------------------
     // Supportive methods
     // -------------------------------------------------------------------------
-
-    /**
-     * Returns the annualized value.
-     */
-    private double getAnnualizationFactor( Indicator indicator, Date startDate, Date endDate )
-    {
-        double factor = 1.0;
-        
-        if ( indicator.getAnnualized() != null && indicator.getAnnualized() )
-        {
-            long days = getDays( startDate, endDate ) + 1;
-            
-            factor = DAYS_IN_YEAR / days;
-        }
-        
-        return factor;
-    }
     
     private String generateExpression( String expression, Date startDate, Date endDate, OrganisationUnit organisationUnit )
     {

=== modified file 'dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/indicator/DefaultIndicatorDataMart.java'
--- dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/indicator/DefaultIndicatorDataMart.java	2011-05-20 12:27:47 +0000
+++ dhis-2/dhis-services/dhis-service-datamart-default/src/main/java/org/hisp/dhis/datamart/indicator/DefaultIndicatorDataMart.java	2011-05-20 13:27:02 +0000
@@ -28,7 +28,6 @@
  */
 
 import static org.hisp.dhis.options.SystemSettingManager.KEY_OMIT_INDICATORS_ZERO_NUMERATOR_DATAMART;
-import static org.hisp.dhis.system.util.DateUtils.DAYS_IN_YEAR;
 import static org.hisp.dhis.system.util.MathUtils.calculateExpression;
 import static org.hisp.dhis.system.util.MathUtils.getRounded;
 
@@ -177,7 +176,7 @@
 
                     if ( denominatorValue != 0 && !( omitZeroNumerator && numeratorValue == 0 ) )
                     {
-                        annualizationFactor = getAnnualizationFactor( indicator, period );
+                        annualizationFactor = DateUtils.getAnnualizationFactor( indicator, period.getStartDate(), period.getEndDate() );
                         
                         factor = indicator.getIndicatorType().getFactor();
                         
@@ -214,21 +213,7 @@
     // -------------------------------------------------------------------------
     // Supportive methods
     // -------------------------------------------------------------------------
-    
-    public static double getAnnualizationFactor( final Indicator indicator, final Period period )
-    {
-        double factor = 1.0;
-        
-        if ( indicator.getAnnualized() != null && indicator.getAnnualized() )
-        {
-            final int daysInPeriod = DateUtils.daysBetween( period.getStartDate(), period.getEndDate() ) + 1;
-            
-            factor = DAYS_IN_YEAR / daysInPeriod;
-        }
-        
-        return factor;
-    }
-    
+        
     public static String getAnnualizationString( final Boolean annualized )
     {
         return ( annualized == null || !annualized ) ? FALSE : TRUE;

=== modified file 'dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/DateUtils.java'
--- dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/DateUtils.java	2011-01-06 14:56:17 +0000
+++ dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/DateUtils.java	2011-05-20 13:27:02 +0000
@@ -27,17 +27,18 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+import static org.hisp.dhis.period.Period.DEFAULT_DATE_FORMAT;
+
 import java.text.ParseException;
 import java.text.SimpleDateFormat;
 import java.util.Calendar;
 import java.util.Date;
 
 import org.apache.commons.validator.DateValidator;
+import org.hisp.dhis.indicator.Indicator;
 import org.joda.time.DateTime;
 import org.joda.time.Days;
 
-import static org.hisp.dhis.period.Period.DEFAULT_DATE_FORMAT;
-
 /**
  * @author Lars Helge Overland
  * @version $Id$
@@ -429,4 +430,20 @@
         }
     }
 
+    /**
+     * Returns the annualization factor for the given indicator and start-end date interval.
+     */
+    public static double getAnnualizationFactor( Indicator indicator, Date startDate, Date endDate )
+    {
+        double factor = 1.0;
+        
+        if ( indicator.isAnnualized() )
+        {
+            final int daysInPeriod = DateUtils.daysBetween( startDate, endDate ) + 1;
+            
+            factor = DAYS_IN_YEAR / daysInPeriod;
+        }
+        
+        return factor;
+    }
 }