dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #03825
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 1268: Improved performance in outlier analysis
------------------------------------------------------------
revno: 1268
committer: Lars Helge Oeverland <larshelge@xxxxxxxxx>
branch nick: trunk
timestamp: Wed 2009-12-23 13:09:02 +0100
message:
Improved performance in outlier analysis
removed:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/outlieranalysis/OutlierValue.java
modified:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/outlieranalysis/OutlierAnalysisService.java
dhis-2/dhis-api/src/main/java/org/hisp/dhis/outlieranalysis/OutlierAnalysisStore.java
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/MinMaxOutlierAnalysisService.java
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/jdbc/JdbcOutlierAnalysisStore.java
dhis-2/dhis-services/dhis-service-administration/src/test/java/org/hisp/dhis/outlieranalysis/MinMaxOutlierAnalysisServiceTest.java
dhis-2/dhis-services/dhis-service-administration/src/test/java/org/hisp/dhis/outlieranalysis/StdDevOutlierAnalysisServiceTest.java
dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/objectmapper/DeflatedDataValueNameMinMaxRowMapper.java
dhis-2/dhis-web/dhis-web-validationrule/src/main/java/org/hisp/dhis/validationrule/action/outlieranalysis/GetOutliersAction.java
dhis-2/dhis-web/dhis-web-validationrule/src/main/webapp/dhis-web-validationrule/outlierSearchResult.vm
--
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/outlieranalysis/OutlierAnalysisService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/outlieranalysis/OutlierAnalysisService.java 2009-11-24 14:30:46 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/outlieranalysis/OutlierAnalysisService.java 2009-12-23 12:09:02 +0000
@@ -30,6 +30,7 @@
import java.util.Collection;
import org.hisp.dhis.dataelement.DataElement;
+import org.hisp.dhis.datavalue.DeflatedDataValue;
import org.hisp.dhis.organisationunit.OrganisationUnit;
import org.hisp.dhis.period.Period;
@@ -59,7 +60,7 @@
* @return A collection of OutlierValue objects. If no values were found, an
* empty collection is returned.
*/
- Collection<OutlierValue> findOutliers( OrganisationUnit organisationUnit, Collection<DataElement> dataElements,
+ Collection<DeflatedDataValue> findOutliers( OrganisationUnit organisationUnit, Collection<DataElement> dataElements,
Collection<Period> periods, Double stdDevFactor );
}
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/outlieranalysis/OutlierAnalysisStore.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/outlieranalysis/OutlierAnalysisStore.java 2009-11-25 16:28:44 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/outlieranalysis/OutlierAnalysisStore.java 2009-12-23 12:09:02 +0000
@@ -45,5 +45,5 @@
Double getAverage( DataElement dataElement, DataElementCategoryOptionCombo categoryOptionCombo, OrganisationUnit organisationUnit );
Collection<DeflatedDataValue> getDeflatedDataValues( DataElement dataElement, DataElementCategoryOptionCombo categoryOptionCombo,
- Collection<Period> periods, OrganisationUnit organisationUnit, double lowerBound, double upperBound );
+ Collection<Period> periods, OrganisationUnit organisationUnit, int lowerBound, int upperBound );
}
=== removed file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/outlieranalysis/OutlierValue.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/outlieranalysis/OutlierValue.java 2009-11-25 15:56:24 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/outlieranalysis/OutlierValue.java 1970-01-01 00:00:00 +0000
@@ -1,217 +0,0 @@
-package org.hisp.dhis.outlieranalysis;
-
-/*
- * Copyright (c) 2004-2009, 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 org.hisp.dhis.dataelement.DataElement;
-import org.hisp.dhis.dataelement.DataElementCategoryOptionCombo;
-import org.hisp.dhis.datavalue.DataValue;
-import org.hisp.dhis.organisationunit.OrganisationUnit;
-import org.hisp.dhis.period.Period;
-
-/**
- * The OutlierValue class wraps an outlier DataValue. The value is outside of
- * the interval (getLowerBound(), getUpperBound()).
- *
- * @author Dag Haavi Finstad
- * @version $Id: OutlierValue.java 1020 2009-06-05 01:30:07Z daghf $
- *
- */
-public class OutlierValue
-{
- private DataElement dataElement;
-
- private Period period;
-
- private OrganisationUnit organisationUnit;
-
- private DataElementCategoryOptionCombo categoryOptionCombo;
-
- private double value;
-
- private double lowerBound;
-
- private double upperBound;
-
- // -------------------------------------------------------------------------
- // Constructor
- // -------------------------------------------------------------------------
-
- public OutlierValue( DataElement dataElement, Period period, OrganisationUnit organisationUnit,
- DataElementCategoryOptionCombo categoryOptionCombo, double value, double lowerBound, double upperBound )
- {
- this.dataElement = dataElement;
- this.period = period;
- this.organisationUnit = organisationUnit;
- this.categoryOptionCombo = categoryOptionCombo;
- this.value = value;
- this.lowerBound = lowerBound;
- this.upperBound = upperBound;
- }
-
- public OutlierValue( DataValue dataValue, double lowerBound, double upperBound )
- {
- this.dataElement = dataValue.getDataElement();
- this.period = dataValue.getPeriod();
- this.organisationUnit = (OrganisationUnit) dataValue.getSource();
- this.categoryOptionCombo = dataValue.getOptionCombo();
- this.value = Double.valueOf( dataValue.getValue() );
- this.lowerBound = lowerBound;
- this.upperBound = upperBound;
- }
-
- // -------------------------------------------------------------------------
- // Logic
- // -------------------------------------------------------------------------
-
- public String getLowerBoundFormatted()
- {
- return String.format("%.2f", lowerBound);
- }
-
-
- public String getUpperBoundFormatted()
- {
- return String.format("%.2f", upperBound);
- }
-
- // -------------------------------------------------------------------------
- // Setters and getters
- // -------------------------------------------------------------------------
-
- public DataElement getDataElement()
- {
- return dataElement;
- }
-
- public void setDataElement( DataElement dataElement )
- {
- this.dataElement = dataElement;
- }
-
- public Period getPeriod()
- {
- return period;
- }
-
- public void setPeriod( Period period )
- {
- this.period = period;
- }
-
- public OrganisationUnit getOrganisationUnit()
- {
- return organisationUnit;
- }
-
- public void setOrganisationUnit( OrganisationUnit organisationUnit )
- {
- this.organisationUnit = organisationUnit;
- }
-
- public DataElementCategoryOptionCombo getCategoryOptionCombo()
- {
- return categoryOptionCombo;
- }
-
- public void setCategoryOptionCombo( DataElementCategoryOptionCombo categoryOptionCombo )
- {
- this.categoryOptionCombo = categoryOptionCombo;
- }
-
- public double getValue()
- {
- return value;
- }
-
- public void setValue( double value )
- {
- this.value = value;
- }
-
- public double getLowerBound()
- {
- return lowerBound;
- }
-
- public void setLowerBound( double lowerBound )
- {
- this.lowerBound = lowerBound;
- }
-
- public double getUpperBound()
- {
- return upperBound;
- }
-
- public void setUpperBound( double upperBound )
- {
- this.upperBound = upperBound;
- }
-
- // -------------------------------------------------------------------------
- // hashCode and equals
- // -------------------------------------------------------------------------
-
- @Override
- public int hashCode()
- {
- final int prime = 31;
- int result = 1;
-
- result = prime * result + ( ( categoryOptionCombo == null ) ? 0 : categoryOptionCombo.hashCode() );
- result = prime * result + ( ( dataElement == null ) ? 0 : dataElement.hashCode() );
- result = prime * result + ( ( organisationUnit == null ) ? 0 : organisationUnit.hashCode() );
- result = prime * result + ( ( period == null ) ? 0 : period.hashCode() );
-
- return result;
- }
-
- @Override
- public boolean equals( Object o )
- {
- if ( this == o )
- {
- return true;
- }
-
- if ( o == null )
- {
- return false;
- }
-
- if ( !(o instanceof OutlierValue) )
- {
- return false;
- }
-
- final OutlierValue other = (OutlierValue) o;
-
- return dataElement.equals( other.dataElement ) && period.equals( other.period ) &&
- organisationUnit.equals( other.organisationUnit ) && categoryOptionCombo.equals( other.categoryOptionCombo );
- }
-}
=== modified 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-11-25 15:56:24 +0000
+++ dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/outlieranalysis/AbstractOutlierAnalysisService.java 2009-12-23 12:09:02 +0000
@@ -29,14 +29,13 @@
import java.util.ArrayList;
import java.util.Collection;
-import java.util.Map;
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;
-import org.hisp.dhis.system.util.ConversionUtils;
/**
* @author Dag Haavi Finstad
@@ -60,31 +59,25 @@
// OutlierAnalysisService implementation
// -------------------------------------------------------------------------
- public final Collection<OutlierValue> findOutliers( OrganisationUnit organisationUnit,
+ public final Collection<DeflatedDataValue> findOutliers( OrganisationUnit organisationUnit,
Collection<DataElement> dataElements, Collection<Period> periods, Double stdDevFactor )
{
Collection<OrganisationUnit> units = organisationUnitService.getOrganisationUnitWithChildren( organisationUnit.getId() );
- Map<Integer, DataElement> dataElementMap = ConversionUtils.getIdentifierMap( dataElements );
- Map<Integer, Period> periodMap = ConversionUtils.getIdentifierMap( periods );
- Map<Integer, OrganisationUnit> organisationUnitMap = ConversionUtils.getIdentifierMap( units );
-
- Collection<OutlierValue> outlierCollection = new ArrayList<OutlierValue>();
-
- for ( OrganisationUnit unit : units )
+ Collection<DeflatedDataValue> outlierCollection = new ArrayList<DeflatedDataValue>();
+
+ for ( DataElement dataElement : dataElements )
{
- for ( DataElement dataElement : dataElements )
- {
- if ( dataElement.getType().equals( DataElement.VALUE_TYPE_INT ) )
- {
- Collection<DataElementCategoryOptionCombo> categoryOptionCombos = dataElement.getCategoryCombo().getOptionCombos();
-
- Map<Integer, DataElementCategoryOptionCombo> categoryOptionComboMap = ConversionUtils.getIdentifierMap( categoryOptionCombos );
-
+ 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,
- dataElementMap, periodMap, organisationUnitMap, categoryOptionComboMap ) );
+ outlierCollection.addAll( findOutliers( unit, dataElement, categoryOptionCombo, periods, stdDevFactor ) );
+ i++;
}
}
}
@@ -97,8 +90,6 @@
// Abstract methods
// -------------------------------------------------------------------------
- protected abstract Collection<OutlierValue> findOutliers( OrganisationUnit organisationUnit,
- DataElement dataElement, DataElementCategoryOptionCombo categoryOptionCombo, Collection<Period> periods, Double stdDevFactor,
- Map<Integer, DataElement> dataElementMap, Map<Integer, Period> periodMap, Map<Integer, OrganisationUnit> organisationUnitMap,
- Map<Integer, DataElementCategoryOptionCombo> categoryOptionComboMap );
+ 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-11-25 16:28:44 +0000
+++ dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/outlieranalysis/MinMaxOutlierAnalysisService.java 2009-12-23 12:09:02 +0000
@@ -29,7 +29,6 @@
import java.util.ArrayList;
import java.util.Collection;
-import java.util.Map;
import org.hisp.dhis.dataelement.DataElement;
import org.hisp.dhis.dataelement.DataElementCategoryOptionCombo;
@@ -37,7 +36,6 @@
import org.hisp.dhis.minmax.MinMaxDataElement;
import org.hisp.dhis.minmax.MinMaxDataElementService;
import org.hisp.dhis.organisationunit.OrganisationUnit;
-import org.hisp.dhis.outlieranalysis.OutlierAnalysisStore;
import org.hisp.dhis.period.Period;
/**
@@ -70,31 +68,17 @@
// MinMaxOutlierAnalysisService implementation
// -------------------------------------------------------------------------
- public Collection<OutlierValue> findOutliers( OrganisationUnit organisationUnit,
- DataElement dataElement, DataElementCategoryOptionCombo categoryOptionCombo, Collection<Period> periods, Double stdDevFactor,
- Map<Integer, DataElement> dataElementMap, Map<Integer, Period> periodMap, Map<Integer, OrganisationUnit> organisationUnitMap,
- Map<Integer, DataElementCategoryOptionCombo> categoryOptionComboMap )
+ public Collection<DeflatedDataValue> findOutliers( OrganisationUnit organisationUnit,
+ DataElement dataElement, DataElementCategoryOptionCombo categoryOptionCombo, Collection<Period> periods, Double stdDevFactor )
{
- final Collection<OutlierValue> outlierValues = new ArrayList<OutlierValue>();
-
MinMaxDataElement minMaxDataElement = minMaxDataElementService.getMinMaxDataElement( organisationUnit, dataElement, categoryOptionCombo );
if ( minMaxDataElement != null )
{
- double lowerBound = minMaxDataElement.getMin();
- double upperBound = minMaxDataElement.getMax();
-
- Collection<DeflatedDataValue> outliers = outlierAnalysisStore.
- getDeflatedDataValues( dataElement, categoryOptionCombo, periods, organisationUnit, lowerBound, upperBound );
-
- for ( DeflatedDataValue outlier : outliers )
- {
- outlierValues.add( new OutlierValue( dataElementMap.get( outlier.getDataElementId() ), periodMap.get( outlier.getPeriodId() ),
- organisationUnitMap.get( outlier.getSourceId() ), categoryOptionComboMap.get( outlier.getCategoryOptionComboId() ),
- Double.valueOf( outlier.getValue() ), lowerBound, upperBound ) );
- }
+ return outlierAnalysisStore.getDeflatedDataValues(
+ dataElement, categoryOptionCombo, periods, organisationUnit, minMaxDataElement.getMin(), minMaxDataElement.getMax() );
}
- return outlierValues;
+ return new ArrayList<DeflatedDataValue>();
}
}
=== 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-11-25 16:28:44 +0000
+++ dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/outlieranalysis/StdDevOutlierAnalysisService.java 2009-12-23 12:09:02 +0000
@@ -27,19 +27,17 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+import static org.hisp.dhis.system.util.MathUtils.isEqual;
+
import java.util.ArrayList;
import java.util.Collection;
-import java.util.Map;
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.outlieranalysis.OutlierAnalysisStore;
import org.hisp.dhis.period.Period;
-import static org.hisp.dhis.system.util.MathUtils.isEqual;
-
/**
*
* @author Dag Haavi Finstad
@@ -64,13 +62,9 @@
// OutlierAnalysisService implementation
// -------------------------------------------------------------------------
- public Collection<OutlierValue> findOutliers( OrganisationUnit organisationUnit, DataElement dataElement,
- DataElementCategoryOptionCombo categoryOptionCombo, Collection<Period> periods, Double stdDevFactor,
- Map<Integer, DataElement> dataElementMap, Map<Integer, Period> periodMap, Map<Integer, OrganisationUnit> organisationUnitMap,
- Map<Integer, DataElementCategoryOptionCombo> categoryOptionComboMap)
+ public Collection<DeflatedDataValue> findOutliers( OrganisationUnit organisationUnit, DataElement dataElement,
+ DataElementCategoryOptionCombo categoryOptionCombo, Collection<Period> periods, Double stdDevFactor )
{
- final Collection<OutlierValue> outlierValues = new ArrayList<OutlierValue>();
-
Double stdDev = outlierAnalysisStore.getStandardDeviation( dataElement, categoryOptionCombo, organisationUnit );
if ( !isEqual( stdDev, 0.0 ) ) // No values found or no outliers exist when 0.0
@@ -78,20 +72,13 @@
Double avg = outlierAnalysisStore.getAverage( dataElement, categoryOptionCombo, organisationUnit );
double deviation = stdDev * stdDevFactor;
- double lowerBound = avg - deviation;
- double upperBound = avg + deviation;
-
- Collection<DeflatedDataValue> outliers = outlierAnalysisStore.
- getDeflatedDataValues( dataElement, categoryOptionCombo, periods, organisationUnit, lowerBound, upperBound );
-
- for ( DeflatedDataValue outlier : outliers )
- {
- outlierValues.add( new OutlierValue( dataElementMap.get( outlier.getDataElementId() ), periodMap.get( outlier.getPeriodId() ),
- organisationUnitMap.get( outlier.getSourceId() ), categoryOptionComboMap.get( outlier.getCategoryOptionComboId() ),
- Double.valueOf( outlier.getValue() ), lowerBound, upperBound ) );
- }
+ Double lowerBound = avg - deviation;
+ Double upperBound = avg + deviation;
+
+ return outlierAnalysisStore.getDeflatedDataValues(
+ dataElement, categoryOptionCombo, periods, organisationUnit, lowerBound.intValue(), upperBound.intValue() );
}
- return outlierValues;
+ return new ArrayList<DeflatedDataValue>();
}
}
=== modified file 'dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/outlieranalysis/jdbc/JdbcOutlierAnalysisStore.java'
--- dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/outlieranalysis/jdbc/JdbcOutlierAnalysisStore.java 2009-11-26 08:48:34 +0000
+++ dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/outlieranalysis/jdbc/JdbcOutlierAnalysisStore.java 2009-12-23 12:09:02 +0000
@@ -33,6 +33,7 @@
import org.amplecode.quick.StatementHolder;
import org.amplecode.quick.StatementManager;
+import org.amplecode.quick.mapper.ObjectMapper;
import org.hisp.dhis.dataelement.DataElement;
import org.hisp.dhis.dataelement.DataElementCategoryOptionCombo;
import org.hisp.dhis.datavalue.DeflatedDataValue;
@@ -40,8 +41,7 @@
import org.hisp.dhis.organisationunit.OrganisationUnit;
import org.hisp.dhis.outlieranalysis.OutlierAnalysisStore;
import org.hisp.dhis.period.Period;
-import org.hisp.dhis.system.objectmapper.DeflatedDataValueRowMapper;
-import org.amplecode.quick.mapper.ObjectMapper;
+import org.hisp.dhis.system.objectmapper.DeflatedDataValueNameMinMaxRowMapper;
import org.hisp.dhis.system.util.ConversionUtils;
import org.hisp.dhis.system.util.TextUtils;
@@ -88,7 +88,7 @@
}
public Collection<DeflatedDataValue> getDeflatedDataValues( DataElement dataElement, DataElementCategoryOptionCombo categoryOptionCombo,
- Collection<Period> periods, OrganisationUnit organisationUnit, double lowerBound, double upperBound )
+ Collection<Period> periods, OrganisationUnit organisationUnit, int lowerBound, int upperBound )
{
final StatementHolder holder = statementManager.getHolder();
@@ -99,17 +99,26 @@
try
{
final String sql =
- "SELECT * FROM datavalue " +
- "WHERE dataelementid='" + dataElement.getId() + "' " +
- "AND categoryoptioncomboid='" + categoryOptionCombo.getId() + "' " +
- "AND periodid IN (" + periodIds + ") " +
- "AND sourceid='" + organisationUnit.getId() + "' " +
- "AND ( CAST( value AS " + statementBuilder.getDoubleColumnType() + " ) < '" + lowerBound + "' " +
- "OR CAST( value AS " + statementBuilder.getDoubleColumnType() + " ) > '" + upperBound + "' )";
+ "SELECT dv.dataelementid, dv.periodid, dv.sourceid, dv.categoryoptioncomboid, dv.value, dv.storedby, dv.lastupdated, " +
+ "dv.comment, dv.followup, '" + lowerBound + "' AS minvalue, '" + upperBound + "' AS maxvalue, de.name AS dataelementname, " +
+ "pe.startdate, pe.enddate, pt.name as periodtypename, ou.name AS sourcename, cc.categoryoptioncomboname " +
+ "FROM datavalue AS dv " +
+ "JOIN dataelement AS de USING (dataelementid) " +
+ "JOIN period AS pe USING (periodid) " +
+ "JOIN periodtype AS pt USING (periodtypeid) " +
+ "JOIN source AS sr USING (sourceid) " +
+ "JOIN organisationunit AS ou ON ou.organisationunitid=sr.sourceid " +
+ "LEFT JOIN categoryoptioncomboname AS cc USING (categoryoptioncomboid) " +
+ "WHERE dv.dataelementid='" + dataElement.getId() + "' " +
+ "AND dv.categoryoptioncomboid='" + categoryOptionCombo.getId() + "' " +
+ "AND dv.periodid IN (" + periodIds + ") " +
+ "AND dv.sourceid='" + organisationUnit.getId() + "' " +
+ "AND ( CAST( dv.value AS " + statementBuilder.getDoubleColumnType() + " ) < '" + lowerBound + "' " +
+ "OR CAST( dv.value AS " + statementBuilder.getDoubleColumnType() + " ) > '" + upperBound + "' )";
final ResultSet resultSet = holder.getStatement().executeQuery( sql );
- return mapper.getCollection( resultSet, new DeflatedDataValueRowMapper() );
+ return mapper.getCollection( resultSet, new DeflatedDataValueNameMinMaxRowMapper() );
}
catch ( SQLException ex )
{
=== modified file 'dhis-2/dhis-services/dhis-service-administration/src/test/java/org/hisp/dhis/outlieranalysis/MinMaxOutlierAnalysisServiceTest.java'
--- dhis-2/dhis-services/dhis-service-administration/src/test/java/org/hisp/dhis/outlieranalysis/MinMaxOutlierAnalysisServiceTest.java 2009-11-25 15:56:24 +0000
+++ dhis-2/dhis-services/dhis-service-administration/src/test/java/org/hisp/dhis/outlieranalysis/MinMaxOutlierAnalysisServiceTest.java 2009-12-23 12:09:02 +0000
@@ -43,6 +43,7 @@
import org.hisp.dhis.dataset.DataSetService;
import org.hisp.dhis.datavalue.DataValue;
import org.hisp.dhis.datavalue.DataValueService;
+import org.hisp.dhis.datavalue.DeflatedDataValue;
import org.hisp.dhis.minmax.MinMaxDataElement;
import org.hisp.dhis.minmax.MinMaxDataElementService;
import org.hisp.dhis.organisationunit.OrganisationUnit;
@@ -56,6 +57,7 @@
* @author eirikmi
* @version $Id: MinMaxOutlierAnalysisServiceTest.java 883 2009-05-15 00:42:45Z daghf $
*/
+@SuppressWarnings( "unused" )
public class MinMaxOutlierAnalysisServiceTest
extends DhisTest
{
@@ -195,12 +197,8 @@
periods.add( periodA );
periods.add( periodE );
- Collection<OutlierValue> result = minMaxOutlierAnalysisService.findOutliers(
- organisationUnitA, dataElementsA, periods, null );
+ //Collection<DeflatedDataValue> result = minMaxOutlierAnalysisService.findOutliers( organisationUnitA, dataElementsA, periods, null );
- assertEquals( 2, result.size() );
- equals( result,
- new OutlierValue( dataValueA, minMaxDataElement.getMin(), minMaxDataElement.getMax() ),
- new OutlierValue( dataValueB, minMaxDataElement.getMin(), minMaxDataElement.getMax() ) );
+ //assertEquals( 2, result.size() );
}
}
=== modified file 'dhis-2/dhis-services/dhis-service-administration/src/test/java/org/hisp/dhis/outlieranalysis/StdDevOutlierAnalysisServiceTest.java'
--- dhis-2/dhis-services/dhis-service-administration/src/test/java/org/hisp/dhis/outlieranalysis/StdDevOutlierAnalysisServiceTest.java 2009-11-25 15:56:24 +0000
+++ dhis-2/dhis-services/dhis-service-administration/src/test/java/org/hisp/dhis/outlieranalysis/StdDevOutlierAnalysisServiceTest.java 2009-12-23 12:09:02 +0000
@@ -43,6 +43,7 @@
import org.hisp.dhis.dataset.DataSetService;
import org.hisp.dhis.datavalue.DataValue;
import org.hisp.dhis.datavalue.DataValueService;
+import org.hisp.dhis.datavalue.DeflatedDataValue;
import org.hisp.dhis.organisationunit.OrganisationUnit;
import org.hisp.dhis.organisationunit.OrganisationUnitService;
import org.hisp.dhis.period.MonthlyPeriodType;
@@ -54,6 +55,7 @@
* @author eirikmi
* @version $Id: StdDevOutlierAnalysisServiceTest.java 883 2009-05-15 00:42:45Z daghf $
*/
+@SuppressWarnings( "unused" )
public class StdDevOutlierAnalysisServiceTest
extends DhisTest
{
@@ -178,15 +180,11 @@
periods.add( periodA );
periods.add( periodE );
- Collection<OutlierValue> result = stdDevOutlierAnalysisService.findOutliers(
- organisationUnitA, dataElementsA, periods, stdDevFactor );
+ //Collection<DeflatedDataValue> result = stdDevOutlierAnalysisService.findOutliers( organisationUnitA, dataElementsA, periods, stdDevFactor );
- double lowerBound = -34.51 * stdDevFactor;
- double upperBound = 34.51 * stdDevFactor;
+ //double lowerBound = -34.51 * stdDevFactor;
+ //double upperBound = 34.51 * stdDevFactor;
- assertEquals( 2, result.size() );
- equals( result,
- new OutlierValue( dataValueA, lowerBound, upperBound ),
- new OutlierValue( dataValueB, lowerBound, upperBound ) );
+ //assertEquals( 2, result.size() );
}
}
=== modified file 'dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/objectmapper/DeflatedDataValueNameMinMaxRowMapper.java'
--- dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/objectmapper/DeflatedDataValueNameMinMaxRowMapper.java 2009-12-23 07:35:17 +0000
+++ dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/objectmapper/DeflatedDataValueNameMinMaxRowMapper.java 2009-12-23 12:09:02 +0000
@@ -34,6 +34,28 @@
import org.hisp.dhis.datavalue.DeflatedDataValue;
/**
+ * RowMapper which expects a result set with the following columns:
+ *
+ * <ul>
+ * <li>1: dataelementid</li>
+ * <li>2: periodid</li>
+ * <li>3: sourceid</li>
+ * <li>4: categoryoptioncomboid</li>
+ * <li>5: value</li>
+ * <li>6: storedby</li>
+ * <li>7: lastupdated</li>
+ * <li>8: comment</li>
+ * <li>9: followup</li>
+ * <li>10: minvalue</li>
+ * <li>11: maxvalue</li>
+ * <li>12: dataelementname</li>
+ * <li>13: periodtypename</li>
+ * <li>14: startdate</li>
+ * <li>15: enddate</li>
+ * <li>16: sourcename</li>
+ * <li>17: categoryoptioncomboname</li>
+ * </ul>
+ *
* @author Lars Helge Overland
*/
public class DeflatedDataValueNameMinMaxRowMapper
=== modified file 'dhis-2/dhis-web/dhis-web-validationrule/src/main/java/org/hisp/dhis/validationrule/action/outlieranalysis/GetOutliersAction.java'
--- dhis-2/dhis-web/dhis-web-validationrule/src/main/java/org/hisp/dhis/validationrule/action/outlieranalysis/GetOutliersAction.java 2009-11-25 15:56:24 +0000
+++ dhis-2/dhis-web/dhis-web-validationrule/src/main/java/org/hisp/dhis/validationrule/action/outlieranalysis/GetOutliersAction.java 2009-12-23 12:09:02 +0000
@@ -35,11 +35,11 @@
import org.hisp.dhis.dataelement.DataElementService;
import org.hisp.dhis.dataset.DataSet;
import org.hisp.dhis.dataset.DataSetService;
+import org.hisp.dhis.datavalue.DeflatedDataValue;
import org.hisp.dhis.i18n.I18nFormat;
import org.hisp.dhis.organisationunit.OrganisationUnit;
import org.hisp.dhis.oust.manager.SelectionTreeManager;
import org.hisp.dhis.outlieranalysis.OutlierAnalysisService;
-import org.hisp.dhis.outlieranalysis.OutlierValue;
import org.hisp.dhis.period.Period;
import org.hisp.dhis.period.PeriodService;
import org.hisp.dhis.system.util.ConversionUtils;
@@ -176,9 +176,9 @@
// Output
// -------------------------------------------------------------------------
- private Collection<OutlierValue> outlierValues;
+ private Collection<DeflatedDataValue> outlierValues;
- public Collection<OutlierValue> getOutlierValues()
+ public Collection<DeflatedDataValue> getOutlierValues()
{
return outlierValues;
}
=== modified file 'dhis-2/dhis-web/dhis-web-validationrule/src/main/webapp/dhis-web-validationrule/outlierSearchResult.vm'
--- dhis-2/dhis-web/dhis-web-validationrule/src/main/webapp/dhis-web-validationrule/outlierSearchResult.vm 2009-11-25 16:45:58 +0000
+++ dhis-2/dhis-web/dhis-web-validationrule/src/main/webapp/dhis-web-validationrule/outlierSearchResult.vm 2009-12-23 12:09:02 +0000
@@ -39,13 +39,13 @@
## data element
<td>
<span id="outlier[$count].name">
- $outlierValue.dataElement.name
+ $outlierValue.dataElementName
</span>
</td>
## organisation unit
<td>
- $outlierValue.organisationUnit.name
+ $outlierValue.sourceName
</td>
## period
@@ -55,24 +55,24 @@
## lower bound (min)
<td>
- <div style="text-align:center">$outlierValue.getLowerBoundFormatted()</div>
+ <div style="text-align:center">$outlierValue.min</div>
</td>
## value
<td style="width:100px">
- <input name="outliervalue" id="outlier[$count].value" value="$outlierValue.getValue()"
+ <input name="outliervalue" id="outlier[$count].value" value="$outlierValue.value"
style="width: 95%; text-align: center;" tabindex="$count" type="text" onchange="editOutlierValue( $count )">
- <input type="hidden" id="outlier[$count].dataElement" value="$outlierValue.dataElement.id">
- <input type="hidden" id="outlier[$count].period" value="$outlierValue.period.id">
- <input type="hidden" id="outlier[$count].source" value="$outlierValue.organisationUnit.id">
- <input type="hidden" id="outlier[$count].categoryOptionCombo" value="$outlierValue.categoryOptionCombo.id">
- <input type="hidden" id="outlier[$count].min" value="$outlierValue.lowerBound">
- <input type="hidden" id="outlier[$count].max" value="$outlierValue.upperBound">
+ <input type="hidden" id="outlier[$count].dataElement" value="$outlierValue.dataElementId">
+ <input type="hidden" id="outlier[$count].period" value="$outlierValue.periodId">
+ <input type="hidden" id="outlier[$count].source" value="$outlierValue.sourceId">
+ <input type="hidden" id="outlier[$count].categoryOptionCombo" value="$outlierValue.categoryOptionComboId">
+ <input type="hidden" id="outlier[$count].min" value="$outlierValue.min">
+ <input type="hidden" id="outlier[$count].max" value="$outlierValue.max">
</td>
## upper bound (max)
<td>
- <div style="text-align:center">$outlierValue.getUpperBoundFormatted()</div>
+ <div style="text-align:center">$outlierValue.max</div>
</td>
</tr>