dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #09380
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 2472: Centralized period interval calculation in aggregationservice
------------------------------------------------------------
revno: 2472
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2011-01-06 15:56:17 +0100
message:
Centralized period interval calculation in aggregationservice
modified:
dhis-2/dhis-services/dhis-service-aggregationengine-default/src/main/java/org/hisp/dhis/aggregation/impl/dataelement/AverageBoolDataElementAggregation.java
dhis-2/dhis-services/dhis-service-aggregationengine-default/src/main/java/org/hisp/dhis/aggregation/impl/dataelement/AverageIntDataElementAggregation.java
dhis-2/dhis-services/dhis-service-aggregationengine-default/src/main/java/org/hisp/dhis/aggregation/impl/dataelement/AverageIntSingleValueDataElementAggregation.java
dhis-2/dhis-services/dhis-service-aggregationengine-default/src/main/java/org/hisp/dhis/aggregation/impl/dataelement/SumBoolDataElementAggregation.java
dhis-2/dhis-services/dhis-service-aggregationengine-default/src/main/java/org/hisp/dhis/aggregation/impl/dataelement/SumIntDataElementAggregation.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/dataelement/AverageBoolDataElementAggregation.java'
--- dhis-2/dhis-services/dhis-service-aggregationengine-default/src/main/java/org/hisp/dhis/aggregation/impl/dataelement/AverageBoolDataElementAggregation.java 2010-07-10 15:19:02 +0000
+++ dhis-2/dhis-services/dhis-service-aggregationengine-default/src/main/java/org/hisp/dhis/aggregation/impl/dataelement/AverageBoolDataElementAggregation.java 2011-01-06 14:56:17 +0000
@@ -27,7 +27,7 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-import static org.hisp.dhis.system.util.DateUtils.getDays;
+import static org.hisp.dhis.system.util.DateUtils.getDaysInclusive;
import java.util.Collection;
import java.util.Date;
@@ -118,21 +118,21 @@
if ( currentStartDate.compareTo( startDate ) >= 0 && currentEndDate.compareTo( endDate ) <= 0 )
{
- relevantDays = getDays( currentEndDate ) - getDays( currentStartDate );
+ relevantDays = getDaysInclusive( currentStartDate, currentEndDate );
}
else if ( currentStartDate.compareTo( startDate ) <= 0 && currentEndDate.compareTo( startDate ) >= 0
&& currentEndDate.compareTo( endDate ) <= 0 )
{
- relevantDays = getDays( currentEndDate ) - getDays( startDate );
+ relevantDays = getDaysInclusive( startDate, currentEndDate );
}
else if ( currentStartDate.compareTo( startDate ) >= 0 && currentStartDate.compareTo( endDate ) <= 0
&& currentEndDate.compareTo( endDate ) >= 0 )
{
- relevantDays = getDays( endDate ) - getDays( currentStartDate );
+ relevantDays = getDaysInclusive( currentStartDate, endDate );
}
else if ( currentStartDate.compareTo( startDate ) <= 0 && currentEndDate.compareTo( endDate ) >= 0 )
{
- relevantDays = getDays( endDate ) - getDays( startDate );
+ relevantDays = getDaysInclusive( startDate, endDate );
}
String stringValue = dataValue.getValue();
=== modified file 'dhis-2/dhis-services/dhis-service-aggregationengine-default/src/main/java/org/hisp/dhis/aggregation/impl/dataelement/AverageIntDataElementAggregation.java'
--- dhis-2/dhis-services/dhis-service-aggregationengine-default/src/main/java/org/hisp/dhis/aggregation/impl/dataelement/AverageIntDataElementAggregation.java 2010-07-10 15:19:02 +0000
+++ dhis-2/dhis-services/dhis-service-aggregationengine-default/src/main/java/org/hisp/dhis/aggregation/impl/dataelement/AverageIntDataElementAggregation.java 2011-01-06 14:56:17 +0000
@@ -27,7 +27,7 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-import static org.hisp.dhis.system.util.DateUtils.getDays;
+import static org.hisp.dhis.system.util.DateUtils.getDaysInclusive;
import java.util.Collection;
import java.util.Date;
@@ -148,21 +148,21 @@
if ( currentStartDate.compareTo( startDate ) >= 0 && currentEndDate.compareTo( endDate ) <= 0 )
{
- relevantDays = getDays( currentEndDate ) - getDays( currentStartDate );
+ relevantDays = getDaysInclusive( currentStartDate, currentEndDate );
}
else if ( currentStartDate.compareTo( startDate ) <= 0 && currentEndDate.compareTo( startDate ) >= 0
&& currentEndDate.compareTo( endDate ) <= 0 )
{
- relevantDays = getDays( currentEndDate ) - getDays( startDate );
+ relevantDays = getDaysInclusive( startDate, currentEndDate );
}
else if ( currentStartDate.compareTo( startDate ) >= 0 && currentStartDate.compareTo( endDate ) <= 0
&& currentEndDate.compareTo( endDate ) >= 0 )
{
- relevantDays = getDays( endDate ) - getDays( currentStartDate );
+ relevantDays = getDaysInclusive( currentStartDate, endDate );
}
else if ( currentStartDate.compareTo( startDate ) <= 0 && currentEndDate.compareTo( endDate ) >= 0 )
{
- relevantDays = getDays( endDate ) - getDays( startDate );
+ relevantDays = getDaysInclusive( startDate, endDate );
}
totalSum += value * relevantDays;
=== modified file 'dhis-2/dhis-services/dhis-service-aggregationengine-default/src/main/java/org/hisp/dhis/aggregation/impl/dataelement/AverageIntSingleValueDataElementAggregation.java'
--- dhis-2/dhis-services/dhis-service-aggregationengine-default/src/main/java/org/hisp/dhis/aggregation/impl/dataelement/AverageIntSingleValueDataElementAggregation.java 2010-07-10 15:19:02 +0000
+++ dhis-2/dhis-services/dhis-service-aggregationengine-default/src/main/java/org/hisp/dhis/aggregation/impl/dataelement/AverageIntSingleValueDataElementAggregation.java 2011-01-06 14:56:17 +0000
@@ -27,7 +27,7 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-import static org.hisp.dhis.system.util.DateUtils.getDays;
+import static org.hisp.dhis.system.util.DateUtils.getDaysInclusive;
import java.util.Collection;
import java.util.Date;
@@ -108,7 +108,7 @@
{
}
- double currentPeriodDuration = ( getDays( currentEndDate ) - getDays( currentStartDate ) );
+ double currentPeriodDuration = getDaysInclusive( currentStartDate, currentEndDate );
if ( currentPeriodDuration > 0 )
{
@@ -116,7 +116,7 @@
if ( currentStartDate.compareTo( endDate ) <= 0 && currentEndDate.compareTo( startDate ) >= 0 ) // Value is intersecting
{
- relevantDays = getDays( endDate ) - getDays( startDate );
+ relevantDays = getDaysInclusive( startDate, endDate );
totalSum += value;
}
=== modified file 'dhis-2/dhis-services/dhis-service-aggregationengine-default/src/main/java/org/hisp/dhis/aggregation/impl/dataelement/SumBoolDataElementAggregation.java'
--- dhis-2/dhis-services/dhis-service-aggregationengine-default/src/main/java/org/hisp/dhis/aggregation/impl/dataelement/SumBoolDataElementAggregation.java 2010-07-10 15:19:02 +0000
+++ dhis-2/dhis-services/dhis-service-aggregationengine-default/src/main/java/org/hisp/dhis/aggregation/impl/dataelement/SumBoolDataElementAggregation.java 2011-01-06 14:56:17 +0000
@@ -27,7 +27,7 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-import static org.hisp.dhis.system.util.DateUtils.getDays;
+import static org.hisp.dhis.system.util.DateUtils.getDaysInclusive;
import static org.hisp.dhis.system.util.MathUtils.getFloor;
import java.util.Collection;
@@ -103,7 +103,7 @@
value = 1;
}
- double currentPeriodDuration = ( getDays( currentEndDate ) - getDays( currentStartDate ) );
+ double currentPeriodDuration = getDaysInclusive( currentStartDate, currentEndDate );
if ( currentPeriodDuration > 0 )
{
@@ -111,26 +111,26 @@
if ( currentStartDate.compareTo( startDate ) >= 0 && currentEndDate.compareTo( endDate ) <= 0 )
{
- relevantDays = ( getDays( endDate ) - getDays( startDate ) );
+ relevantDays = getDaysInclusive( startDate, endDate );
totalSum += value;
}
else if ( currentStartDate.compareTo( startDate ) <= 0 && currentEndDate.compareTo( startDate ) >= 0
&& currentEndDate.compareTo( endDate ) <= 0 )
{
- relevantDays = ( getDays( currentEndDate ) - getDays( startDate ) );
+ relevantDays = getDaysInclusive( startDate, currentEndDate );
double factor = relevantDays / currentPeriodDuration;
totalSum += value * factor;
}
else if ( currentStartDate.compareTo( startDate ) >= 0 && currentStartDate.compareTo( endDate ) <= 0
&& currentEndDate.compareTo( endDate ) >= 0 )
{
- relevantDays = ( getDays( endDate ) - getDays( currentStartDate ) );
+ relevantDays = getDaysInclusive( currentStartDate, endDate );
double factor = relevantDays / currentPeriodDuration;
totalSum += value * factor;
}
else if ( currentStartDate.compareTo( startDate ) <= 0 && currentEndDate.compareTo( endDate ) >= 0 )
{
- relevantDays = ( getDays( endDate ) - getDays( startDate ) );
+ relevantDays = getDaysInclusive( startDate, endDate );
double factor = relevantDays / currentPeriodDuration;
totalSum += value * factor;
}
=== modified file 'dhis-2/dhis-services/dhis-service-aggregationengine-default/src/main/java/org/hisp/dhis/aggregation/impl/dataelement/SumIntDataElementAggregation.java'
--- dhis-2/dhis-services/dhis-service-aggregationengine-default/src/main/java/org/hisp/dhis/aggregation/impl/dataelement/SumIntDataElementAggregation.java 2010-07-10 15:19:02 +0000
+++ dhis-2/dhis-services/dhis-service-aggregationengine-default/src/main/java/org/hisp/dhis/aggregation/impl/dataelement/SumIntDataElementAggregation.java 2011-01-06 14:56:17 +0000
@@ -27,7 +27,7 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-import static org.hisp.dhis.system.util.DateUtils.getDays;
+import static org.hisp.dhis.system.util.DateUtils.getDaysInclusive;
import java.util.Collection;
import java.util.Date;
@@ -115,7 +115,7 @@
{
}
- double currentPeriodDuration = ( getDays( currentEndDate ) - getDays( currentStartDate ) );
+ double currentPeriodDuration = getDaysInclusive( currentStartDate, currentEndDate );
if ( currentPeriodDuration > 0 )
{
@@ -123,26 +123,26 @@
if ( currentStartDate.compareTo( startDate ) >= 0 && currentEndDate.compareTo( endDate ) <= 0 )
{
- relevantDays = getDays( endDate ) - getDays( startDate );
+ relevantDays = getDaysInclusive( startDate, endDate );
totalSum += value;
}
else if ( currentStartDate.compareTo( startDate ) <= 0 && currentEndDate.compareTo( startDate ) >= 0
&& currentEndDate.compareTo( endDate ) <= 0 )
{
- relevantDays = getDays( currentEndDate ) - getDays( startDate );
+ relevantDays = getDaysInclusive( startDate, currentEndDate );
double factor = relevantDays / currentPeriodDuration;
totalSum += value * factor;
}
else if ( currentStartDate.compareTo( startDate ) >= 0 && currentStartDate.compareTo( endDate ) <= 0
&& currentEndDate.compareTo( endDate ) >= 0 )
{
- relevantDays = getDays( endDate ) - getDays( currentStartDate );
+ relevantDays = getDaysInclusive( currentStartDate, endDate );
double factor = relevantDays / currentPeriodDuration;
totalSum += value * factor;
}
else if ( currentStartDate.compareTo( startDate ) <= 0 && currentEndDate.compareTo( endDate ) >= 0 )
{
- relevantDays = getDays( endDate ) - getDays( startDate );
+ relevantDays = getDaysInclusive( startDate, endDate );
double factor = relevantDays / currentPeriodDuration;
totalSum += value * factor;
}
=== 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 2010-10-28 09:17:13 +0000
+++ dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/DateUtils.java 2011-01-06 14:56:17 +0000
@@ -235,7 +235,7 @@
{
return date.getTime() / MS_PER_DAY;
}
-
+
/**
* Returns the number of days between the start date (inclusive) and end
* date (exclusive). The value is rounded off to the floor value and does
@@ -261,11 +261,13 @@
*/
public static long getDaysInclusive( Date startDate, Date endDate )
{
- return (getDays( startDate, endDate ) + 1);
+ return getDays( startDate, endDate ) + 1;
}
/**
- * Calculates the number of days between the start and end-date.
+ * Calculates the number of days between the start and end-date. Note this
+ * method is taking daylight saving time into account and has a performance
+ * overhead.
*
* @param startDate the start date.
* @param endDate the end date.