 Timestamp:
 Dec 9, 2011, 6:31:48 PM (11 years ago)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

trunk/grailsapp/controllers/dbnp/visualization/VisualizeController.groovy
r2128 r2129 386 386 data.each { println it } 387 387 388 // Aggregate the data based on the requested aggregation 388 // Aggregate the data based on the requested aggregation 389 389 def aggregatedData = aggregateData( data, fieldInfo, inputData.aggregation ); 390 390 … … 803 803 break; 804 804 case "median": 805 return compute Median( currentData);805 return computePercentile( currentData, 50 ); 806 806 break; 807 807 case "sum": … … 912 912 } 913 913 914 } else { 914 } else if(type=="boxplot") { 915 return_data[ "series" ] = []; 916 HashMap dataMap = new HashMap(); 917 groupedData[ xAxis ].eachWithIndex { category, i > 918 if(!dataMap.containsKey(category)) { 919 dataMap.put(category, []); 920 } 921 dataMap.put(category, dataMap.get(category)+groupedData[ yAxis ][i]); 922 } 923 924 for ( String key : dataMap.keySet() ) { 925 double dblMEAN = computeMean(dataMap.get(key)); 926 double dblSEM = computeSEM(dataMap.get(key),dblMEAN); 927 928 double Q1 = computePercentile(dataMap.get(key),25).get("value"); 929 double Q3 = computePercentile(dataMap.get(key),75).get("value"); 930 931 /* DEBUG 932 println(""); 933 println(" dataMap["+key+"]:: "+dataMap.get(key)); 934 println(" dblMEAN:: "+dblMEAN); 935 println(" dblSEM:: "+dblSEM); 936 println(" Q1:: "+Q1); 937 println(" Q3:: "+Q3); 938 println(""); 939 */ 940 941 return_data[ "series" ] << [ 942 "name": key, 943 "y" : [key, (dblMEANdblSEM), Q1, dblMEAN, Q3, (dblMEAN+dblSEM)] 944 ]; 945 } 946 947 println(return_data); 948 949 950 } else { 915 951 // For a horizontal barchart, the two axes should be swapped 916 952 if( type == "horizontal_barchart" ) { … … 1246 1282 1247 1283 /** 1248 * Computes the medianof the given values. Values that can not be parsed to a number1284 * Computes value of a percentile of the given values. Values that can not be parsed to a number 1249 1285 * are ignored. If no values are given, null is returned. 1250 * @param values List of values to compute the median for 1251 * @return Median of the values 1252 */ 1253 protected def computeMedian( List values ) { 1286 * @param values List of values to compute the percentile for 1287 * @param Percentile Integer that indicates which percentile to calculae 1288 * Example: Percentile=50 calculates the median, 1289 * Percentile=25 calculates Q1 1290 * Percentile=75 calculates Q3 1291 * @return The value at the Percentile of the values 1292 */ 1293 protected def computePercentile( List values, int Percentile ) { 1254 1294 def listOfValues = []; 1255 1295 values.each { value > … … 1266 1306 def objReturn = null; 1267 1307 1308 def dblFactor = Percentile/100; 1309 1268 1310 if( listSize > 0 ) { 1269 def listHalf = (int) Math.abs(listSize /2);1270 if(list Size%2==0) {1271 // If the list is of an even size, take the mean of the middle two value's1311 def listHalf = (int) Math.abs(listSize*dblFactor); 1312 if(listHalf==listSize*dblFactor) { 1313 // If we don't exactly end up at an item, take the mean of the 2 adjecent values 1272 1314 objReturn = (listOfValues.get(listHalf)+listOfValues.get(listHalf1))/2; 1273 1315 } else { 1274 // If the list is of an odd size, take the middle value1316 // If we exactly end up at an item, take this item 1275 1317 objReturn = listOfValues.get(listHalf); 1276 1318 }
Note: See TracChangeset
for help on using the changeset viewer.