dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #03827
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 1270: Improved performance in min-max/outlier analysis.
------------------------------------------------------------
revno: 1270
committer: Lars Helge Oeverland <larshelge@xxxxxxxxx>
branch nick: trunk
timestamp: Wed 2009-12-23 13:31:17 +0100
message:
Improved performance in min-max/outlier analysis.
removed:
dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/outlieranalysis/AbstractOutlierAnalysisService.java
added:
dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/outlieranalysis/MinMaxValueMap.java
modified:
dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/outlieranalysis/MinMaxOutlierAnalysisService.java
dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/outlieranalysis/StdDevOutlierAnalysisService.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.
=== removed file 'dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/outlieranalysis/AbstractOutlierAnalysisService.java'
--- dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/outlieranalysis/AbstractOutlierAnalysisService.java 2009-12-23 12:09:47 +0000
+++ dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/outlieranalysis/AbstractOutlierAnalysisService.java 1970-01-01 00:00:00 +0000
@@ -1,94 +0,0 @@
-package org.hisp.dhis.outlieranalysis;
-
-/*
- * Copyright (c) 2004-${year}, University of Oslo
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- * * Redistributions of source code must retain the above copyright notice, this
- * list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- * * Neither the name of the HISP project nor the names of its contributors may
- * be used to endorse or promote products derived from this software without
- * specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-import java.util.ArrayList;
-import java.util.Collection;
-
-import org.hisp.dhis.dataelement.DataElement;
-import org.hisp.dhis.dataelement.DataElementCategoryOptionCombo;
-import org.hisp.dhis.datavalue.DeflatedDataValue;
-import org.hisp.dhis.organisationunit.OrganisationUnit;
-import org.hisp.dhis.organisationunit.OrganisationUnitService;
-import org.hisp.dhis.period.Period;
-
-/**
- * @author Dag Haavi Finstad
- * @version $Id: AbstractStdDevOutlierAnalysisService.java 1020 2009-06-05 01:30:07Z daghf $
- */
-public abstract class AbstractOutlierAnalysisService
- implements OutlierAnalysisService
-{
- // -------------------------------------------------------------------------
- // Dependencies
- // -------------------------------------------------------------------------
-
- private OrganisationUnitService organisationUnitService;
-
- public void setOrganisationUnitService( OrganisationUnitService organisationUnitService )
- {
- this.organisationUnitService = organisationUnitService;
- }
-
- // -------------------------------------------------------------------------
- // OutlierAnalysisService implementation
- // -------------------------------------------------------------------------
-
- public final Collection<DeflatedDataValue> findOutliers( OrganisationUnit organisationUnit,
- Collection<DataElement> dataElements, Collection<Period> periods, Double stdDevFactor )
- {
- Collection<OrganisationUnit> units = organisationUnitService.getOrganisationUnitWithChildren( organisationUnit.getId() );
-
- Collection<DeflatedDataValue> outlierCollection = new ArrayList<DeflatedDataValue>();
-
- for ( DataElement dataElement : dataElements )
- {
- if ( dataElement.getType().equals( DataElement.VALUE_TYPE_INT ) )
- {
- Collection<DataElementCategoryOptionCombo> categoryOptionCombos = dataElement.getCategoryCombo().getOptionCombos();
-
- for ( OrganisationUnit unit : units )
- {
- for ( DataElementCategoryOptionCombo categoryOptionCombo : categoryOptionCombos )
- {
- outlierCollection.addAll( findOutliers( unit, dataElement, categoryOptionCombo, periods, stdDevFactor ) );
- }
- }
- }
- }
-
- return outlierCollection;
- }
-
- // -------------------------------------------------------------------------
- // Abstract methods
- // -------------------------------------------------------------------------
-
- protected abstract Collection<DeflatedDataValue> findOutliers( OrganisationUnit organisationUnit,
- DataElement dataElement, DataElementCategoryOptionCombo categoryOptionCombo, Collection<Period> periods, Double stdDevFactor );
-}
=== modified file 'dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/outlieranalysis/MinMaxOutlierAnalysisService.java'
--- dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/outlieranalysis/MinMaxOutlierAnalysisService.java 2009-12-23 12:09:02 +0000
+++ dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/outlieranalysis/MinMaxOutlierAnalysisService.java 2009-12-23 12:31:17 +0000
@@ -36,15 +36,16 @@
import org.hisp.dhis.minmax.MinMaxDataElement;
import org.hisp.dhis.minmax.MinMaxDataElementService;
import org.hisp.dhis.organisationunit.OrganisationUnit;
+import org.hisp.dhis.organisationunit.OrganisationUnitService;
import org.hisp.dhis.period.Period;
/**
*
* @author Dag Haavi Finstad
- * @version $Id: DefaultMinMaxOutlierAnalysisService.java 1047 2009-06-10 11:01:04Z daghf $
+ * @author Lars Helge Overland
*/
public class MinMaxOutlierAnalysisService
- extends AbstractOutlierAnalysisService
+ implements OutlierAnalysisService
{
// -------------------------------------------------------------------------
// Dependencies
@@ -57,6 +58,13 @@
this.minMaxDataElementService = minMaxDataElementService;
}
+ private OrganisationUnitService organisationUnitService;
+
+ public void setOrganisationUnitService( OrganisationUnitService organisationUnitService )
+ {
+ this.organisationUnitService = organisationUnitService;
+ }
+
private OutlierAnalysisStore outlierAnalysisStore;
public void setOutlierAnalysisStore( OutlierAnalysisStore outlierAnalysisStore )
@@ -68,10 +76,42 @@
// MinMaxOutlierAnalysisService implementation
// -------------------------------------------------------------------------
- public Collection<DeflatedDataValue> findOutliers( OrganisationUnit organisationUnit,
- DataElement dataElement, DataElementCategoryOptionCombo categoryOptionCombo, Collection<Period> periods, Double stdDevFactor )
- {
- MinMaxDataElement minMaxDataElement = minMaxDataElementService.getMinMaxDataElement( organisationUnit, dataElement, categoryOptionCombo );
+ public final Collection<DeflatedDataValue> findOutliers( OrganisationUnit organisationUnit,
+ Collection<DataElement> dataElements, Collection<Period> periods, Double stdDevFactor )
+ {
+ Collection<OrganisationUnit> units = organisationUnitService.getOrganisationUnitWithChildren( organisationUnit.getId() );
+
+ Collection<DeflatedDataValue> outlierCollection = new ArrayList<DeflatedDataValue>();
+
+ MinMaxValueMap map = getMinMaxValueMap( minMaxDataElementService.getMinMaxDataElements( organisationUnit, dataElements ) );
+
+ for ( DataElement dataElement : dataElements )
+ {
+ if ( dataElement.getType().equals( DataElement.VALUE_TYPE_INT ) )
+ {
+ Collection<DataElementCategoryOptionCombo> categoryOptionCombos = dataElement.getCategoryCombo().getOptionCombos();
+
+ for ( DataElementCategoryOptionCombo categoryOptionCombo : categoryOptionCombos )
+ {
+ for ( OrganisationUnit unit : units )
+ {
+ outlierCollection.addAll( findOutliers( unit, dataElement, categoryOptionCombo, periods, map ) );
+ }
+ }
+ }
+ }
+
+ return outlierCollection;
+ }
+
+ // -------------------------------------------------------------------------
+ // Supportive methods
+ // -------------------------------------------------------------------------
+
+ private Collection<DeflatedDataValue> findOutliers( OrganisationUnit organisationUnit, DataElement dataElement,
+ DataElementCategoryOptionCombo categoryOptionCombo, Collection<Period> periods, MinMaxValueMap map )
+ {
+ MinMaxDataElement minMaxDataElement = map.get( organisationUnit, dataElement, categoryOptionCombo );
if ( minMaxDataElement != null )
{
@@ -81,4 +121,16 @@
return new ArrayList<DeflatedDataValue>();
}
+
+ private MinMaxValueMap getMinMaxValueMap( Collection<MinMaxDataElement> minMaxDataElements )
+ {
+ MinMaxValueMap map = new MinMaxValueMap();
+
+ for ( MinMaxDataElement element : minMaxDataElements )
+ {
+ map.put( element );
+ }
+
+ return map;
+ }
}
=== added file 'dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/outlieranalysis/MinMaxValueMap.java'
--- dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/outlieranalysis/MinMaxValueMap.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/outlieranalysis/MinMaxValueMap.java 2009-12-23 12:31:17 +0000
@@ -0,0 +1,56 @@
+package org.hisp.dhis.outlieranalysis;
+
+/*
+ * Copyright (c) 2004-${year}, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * * Neither the name of the HISP project nor the names of its contributors may
+ * be used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+import java.util.HashMap;
+
+import org.hisp.dhis.dataelement.DataElement;
+import org.hisp.dhis.dataelement.DataElementCategoryOptionCombo;
+import org.hisp.dhis.minmax.MinMaxDataElement;
+import org.hisp.dhis.source.Source;
+
+/**
+ * @author Lars Helge Overland
+ */
+public class MinMaxValueMap
+ extends HashMap<String, MinMaxDataElement>
+{
+ private static final String SEP = "-";
+
+ public void put( MinMaxDataElement element )
+ {
+ final String key = element.getSource().getId() + SEP + element.getDataElement().getId() + SEP + element.getOptionCombo().getId();
+
+ super.put( key, element );
+ }
+
+ public MinMaxDataElement get( Source source, DataElement dataElement, DataElementCategoryOptionCombo categoryOptionCombo )
+ {
+ return super.get( source.getId() + SEP + dataElement.getId() + SEP + categoryOptionCombo.getId() );
+ }
+}
=== modified file 'dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/outlieranalysis/StdDevOutlierAnalysisService.java'
--- dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/outlieranalysis/StdDevOutlierAnalysisService.java 2009-12-23 12:09:02 +0000
+++ dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/outlieranalysis/StdDevOutlierAnalysisService.java 2009-12-23 12:31:17 +0000
@@ -36,16 +36,16 @@
import org.hisp.dhis.dataelement.DataElementCategoryOptionCombo;
import org.hisp.dhis.datavalue.DeflatedDataValue;
import org.hisp.dhis.organisationunit.OrganisationUnit;
+import org.hisp.dhis.organisationunit.OrganisationUnitService;
import org.hisp.dhis.period.Period;
/**
*
* @author Dag Haavi Finstad
* @author Lars Helge Overland
- * @version $Id: DefaultStdDevOutlierAnalysisService.java 1020 2009-06-05 01:30:07Z daghf $
*/
public class StdDevOutlierAnalysisService
- extends AbstractOutlierAnalysisService
+ implements OutlierAnalysisService
{
// -------------------------------------------------------------------------
// Dependencies
@@ -58,11 +58,48 @@
this.outlierAnalysisStore = outlierAnalysisStore;
}
+ private OrganisationUnitService organisationUnitService;
+
+ public void setOrganisationUnitService( OrganisationUnitService organisationUnitService )
+ {
+ this.organisationUnitService = organisationUnitService;
+ }
+
// -------------------------------------------------------------------------
// OutlierAnalysisService implementation
// -------------------------------------------------------------------------
- public Collection<DeflatedDataValue> findOutliers( OrganisationUnit organisationUnit, DataElement dataElement,
+ public final Collection<DeflatedDataValue> findOutliers( OrganisationUnit organisationUnit,
+ Collection<DataElement> dataElements, Collection<Period> periods, Double stdDevFactor )
+ {
+ Collection<OrganisationUnit> units = organisationUnitService.getOrganisationUnitWithChildren( organisationUnit.getId() );
+
+ Collection<DeflatedDataValue> outlierCollection = new ArrayList<DeflatedDataValue>();
+
+ for ( DataElement dataElement : dataElements )
+ {
+ if ( dataElement.getType().equals( DataElement.VALUE_TYPE_INT ) )
+ {
+ Collection<DataElementCategoryOptionCombo> categoryOptionCombos = dataElement.getCategoryCombo().getOptionCombos();
+
+ for ( OrganisationUnit unit : units )
+ {
+ for ( DataElementCategoryOptionCombo categoryOptionCombo : categoryOptionCombos )
+ {
+ outlierCollection.addAll( findOutliers( unit, dataElement, categoryOptionCombo, periods, stdDevFactor ) );
+ }
+ }
+ }
+ }
+
+ return outlierCollection;
+ }
+
+ // -------------------------------------------------------------------------
+ // Supportive methods
+ // -------------------------------------------------------------------------
+
+ private Collection<DeflatedDataValue> findOutliers( OrganisationUnit organisationUnit, DataElement dataElement,
DataElementCategoryOptionCombo categoryOptionCombo, Collection<Period> periods, Double stdDevFactor )
{
Double stdDev = outlierAnalysisStore.getStandardDeviation( dataElement, categoryOptionCombo, organisationUnit );