dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #23344
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 11353: PNG maps, performance improvement
------------------------------------------------------------
revno: 11353
committer: Lars Helge Øverland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Sat 2013-07-06 18:06:50 +0200
message:
PNG maps, performance improvement
modified:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/mapping/MapView.java
dhis-2/dhis-services/dhis-service-mapgeneration/src/main/java/org/hisp/dhis/mapgeneration/GeoToolsMapGenerationService.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/mapping/MapView.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/mapping/MapView.java 2013-05-24 15:23:08 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/mapping/MapView.java 2013-07-06 16:06:50 +0000
@@ -27,6 +27,9 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+import java.util.ArrayList;
+import java.util.List;
+
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonView;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
@@ -120,6 +123,8 @@
private transient int parentLevel;
+ private transient List<OrganisationUnit> organisationUnitsAtLevel = new ArrayList<OrganisationUnit>();
+
public MapView()
{
}
@@ -491,6 +496,16 @@
this.parentLevel = parentLevel;
}
+ public List<OrganisationUnit> getOrganisationUnitsAtLevel()
+ {
+ return organisationUnitsAtLevel;
+ }
+
+ public void setOrganisationUnitsAtLevel( List<OrganisationUnit> organisationUnitsAtLevel )
+ {
+ this.organisationUnitsAtLevel = organisationUnitsAtLevel;
+ }
+
@Override
public String toString()
{
=== modified file 'dhis-2/dhis-services/dhis-service-mapgeneration/src/main/java/org/hisp/dhis/mapgeneration/GeoToolsMapGenerationService.java'
--- dhis-2/dhis-services/dhis-service-mapgeneration/src/main/java/org/hisp/dhis/mapgeneration/GeoToolsMapGenerationService.java 2013-06-08 21:51:15 +0000
+++ dhis-2/dhis-services/dhis-service-mapgeneration/src/main/java/org/hisp/dhis/mapgeneration/GeoToolsMapGenerationService.java 2013-07-06 16:06:50 +0000
@@ -34,7 +34,9 @@
import java.awt.image.BufferedImage;
import java.util.ArrayList;
import java.util.Collection;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
import org.apache.commons.lang.StringUtils;
import org.hisp.dhis.analytics.AnalyticsService;
@@ -137,36 +139,18 @@
List<OrganisationUnit> organisationUnits = new ArrayList<OrganisationUnit>( organisationUnitService.
getOrganisationUnitsAtLevel( mapView.getOrganisationUnitLevel().getLevel(), mapView.getParentOrganisationUnit() ) );
- DataQueryParams params = new DataQueryParams();
-
- if ( mapView.getIndicator() != null )
- {
- params.setIndicators( getList( mapView.getIndicator() ) );
- }
- else if ( mapView.getDataElement() != null )
- {
- params.setDataElements( getList( mapView.getDataElement() ) );
- }
-
- //TODO operands
-
- params.setOrganisationUnits( organisationUnits );
- params.setFilterPeriods( getList( mapView.getPeriod() ) );
-
- Grid grid = analyticsService.getAggregatedDataValues( params );
-
- Collection<MapValue> mapValues = new ArrayList<MapValue>();
-
- for ( List<Object> row : grid.getRows() )
- {
- if ( row != null && row.size() >= 3 )
- {
- String ou = (String) row.get( 1 );
- Double value = (Double) row.get( 2 );
-
- mapValues.add( new MapValue( ou, value ) );
- }
- }
+ Map<String, OrganisationUnit> uidOuMap = new HashMap<String, OrganisationUnit>();
+
+ for ( OrganisationUnit ou : organisationUnits )
+ {
+ uidOuMap.put( ou.getUid(), ou );
+ }
+
+ mapView.setOrganisationUnitsAtLevel( organisationUnits );
+
+ Grid grid = getDataGrid( mapView );
+
+ Collection<MapValue> mapValues = getMapValues( grid );
if ( mapValues.isEmpty() )
{
@@ -216,7 +200,7 @@
for ( MapValue mapValue : mapValues )
{
// Get the org unit for this map value
- OrganisationUnit orgUnit = organisationUnitService.getOrganisationUnit( mapValue.getOu() );
+ OrganisationUnit orgUnit = uidOuMap.get( mapValue.getOu() );
if ( orgUnit != null && orgUnit.hasCoordinates() && orgUnit.hasFeatureType() )
{
@@ -239,6 +223,51 @@
return mapLayer;
}
+ /**
+ * Creates a Grid with aggregated data.
+ */
+ private Grid getDataGrid( MapView mapView )
+ {
+ DataQueryParams params = new DataQueryParams();
+
+ if ( mapView.getIndicator() != null )
+ {
+ params.setIndicators( getList( mapView.getIndicator() ) );
+ }
+ else if ( mapView.getDataElement() != null )
+ {
+ params.setDataElements( getList( mapView.getDataElement() ) );
+ }
+
+ //TODO operands
+
+ params.setOrganisationUnits( mapView.getOrganisationUnitsAtLevel() );
+ params.setFilterPeriods( getList( mapView.getPeriod() ) );
+
+ return analyticsService.getAggregatedDataValues( params );
+ }
+
+ /**
+ * Creates a list of aggregated map values.
+ */
+ private List<MapValue> getMapValues( Grid grid )
+ {
+ List<MapValue> mapValues = new ArrayList<MapValue>();
+
+ for ( List<Object> row : grid.getRows() )
+ {
+ if ( row != null && row.size() >= 3 )
+ {
+ String ou = (String) row.get( 1 );
+ Double value = (Double) row.get( 2 );
+
+ mapValues.add( new MapValue( ou, value ) );
+ }
+ }
+
+ return mapValues;
+ }
+
private GeoToolsMapObject buildSingleGeoToolsMapObjectForMapLayer( InternalMapLayer mapLayer,
double mapValue, OrganisationUnit orgUnit )
{