← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 7261: regression rendering bugfix

 

------------------------------------------------------------
revno: 7261
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Sun 2012-06-10 18:48:16 +0300
message:
  regression rendering bugfix
modified:
  dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/grid/ListGrid.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-support/dhis-support-system/src/main/java/org/hisp/dhis/system/grid/ListGrid.java'
--- dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/grid/ListGrid.java	2012-05-26 12:39:39 +0000
+++ dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/grid/ListGrid.java	2012-06-10 15:48:16 +0000
@@ -27,21 +27,11 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-import static org.hisp.dhis.system.util.MathUtils.getRounded;
-
-import java.sql.ResultSet;
-import java.sql.ResultSetMetaData;
-import java.sql.SQLException;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Comparator;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.fasterxml.jackson.annotation.JsonView;
+import com.fasterxml.jackson.databind.annotation.JsonSerialize;
 import net.sf.jasperreports.engine.JRException;
 import net.sf.jasperreports.engine.JRField;
-
 import org.apache.commons.math.stat.regression.SimpleRegression;
 import org.hisp.dhis.common.Grid;
 import org.hisp.dhis.common.GridHeader;
@@ -49,9 +39,12 @@
 import org.hisp.dhis.common.view.DetailedView;
 import org.hisp.dhis.system.util.MathUtils;
 
-import com.fasterxml.jackson.annotation.JsonProperty;
-import com.fasterxml.jackson.annotation.JsonView;
-import com.fasterxml.jackson.databind.annotation.JsonSerialize;
+import java.sql.ResultSet;
+import java.sql.ResultSetMetaData;
+import java.sql.SQLException;
+import java.util.*;
+
+import static org.hisp.dhis.system.util.MathUtils.getRounded;
 
 /**
  * @author Lars Helge Overland
@@ -118,7 +111,7 @@
     // ---------------------------------------------------------------------
 
     @JsonProperty
-    @JsonView( {DetailedView.class} )
+    @JsonView( { DetailedView.class } )
     public String getTitle()
     {
         return title;
@@ -132,7 +125,7 @@
     }
 
     @JsonProperty
-    @JsonView( {DetailedView.class} )
+    @JsonView( { DetailedView.class } )
     public String getSubtitle()
     {
         return subtitle;
@@ -146,7 +139,7 @@
     }
 
     @JsonProperty
-    @JsonView( {DetailedView.class} )
+    @JsonView( { DetailedView.class } )
     public String getTable()
     {
         return table;
@@ -169,7 +162,7 @@
     }
 
     @JsonProperty
-    @JsonView( {DetailedView.class} )
+    @JsonView( { DetailedView.class } )
     public List<GridHeader> getHeaders()
     {
         return headers;
@@ -191,14 +184,14 @@
     }
 
     @JsonProperty
-    @JsonView( {DetailedView.class} )
+    @JsonView( { DetailedView.class } )
     public int getHeight()
     {
         return (grid != null && grid.size() > 0) ? grid.size() : 0;
     }
 
     @JsonProperty
-    @JsonView( {DetailedView.class} )
+    @JsonView( { DetailedView.class } )
     public int getWidth()
     {
         verifyGridState();
@@ -236,7 +229,7 @@
 
     @JsonProperty
     @JsonSerialize( using = JacksonRowDataSerializer.class )
-    @JsonView( {DetailedView.class} )
+    @JsonView( { DetailedView.class } )
     public List<List<Object>> getRows()
     {
         return grid;
@@ -375,7 +368,7 @@
         {
             return this; // No sorting
         }
-        
+
         columnIndex = columnIndex - 1;
 
         if ( columnIndex < 0 || columnIndex >= getWidth() )
@@ -401,8 +394,8 @@
         for ( Object value : column )
         {
             // 0 omitted from regression
-            
-            if ( !MathUtils.isEqual( Double.parseDouble( String.valueOf( value ) ), 0d ) ) 
+
+            if ( value != null && !MathUtils.isEqual( Double.parseDouble( String.valueOf( value ) ), 0d ) )
             {
                 regression.addData( index++, Double.parseDouble( String.valueOf( value ) ) );
             }
@@ -415,8 +408,8 @@
             final double predicted = regression.predict( i );
 
             // Enough values must exist for regression
-            
-            if ( !Double.isNaN( predicted ) ) 
+
+            if ( !Double.isNaN( predicted ) )
             {
                 regressionColumn.add( getRounded( predicted, 1 ) );
             }
@@ -522,12 +515,11 @@
             {
                 addHeader( new GridHeader( rsmd.getColumnLabel( i ), false, false ) );
             }
-        } 
-        catch ( SQLException ex )
+        } catch ( SQLException ex )
         {
             throw new RuntimeException( ex );
         }
-        
+
         return this;
     }
 
@@ -546,15 +538,14 @@
                     addValue( rs.getObject( i ) );
                 }
             }
-        } 
-        catch ( SQLException ex )
+        } catch ( SQLException ex )
         {
             throw new RuntimeException( ex );
         }
-        
+
         return this;
     }
-    
+
     // -------------------------------------------------------------------------
     // Supportive methods
     // -------------------------------------------------------------------------
@@ -643,7 +634,7 @@
         {
             boolean list1Invalid = list1 == null || list1.get( columnIndex ) == null || !(list1.get( columnIndex ) instanceof Comparable<?>);
             boolean list2Invalid = list2 == null || list2.get( columnIndex ) == null || !(list2.get( columnIndex ) instanceof Comparable<?>);
-            
+
             if ( list1Invalid && list2Invalid )
             {
                 return 0;
@@ -654,7 +645,7 @@
             }
             else if ( list2Invalid )
             {
-                return order > 0 ? -1 : 1; 
+                return order > 0 ? -1 : 1;
             }
 
             final Comparable<Object> value1 = (Comparable<Object>) list1.get( columnIndex );