 Timestamp:
 Oct 10, 2011, 6:09:59 PM (7 years ago)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

trunk/grailsapp/controllers/dbnp/visualization/VisualizeController.groovy
r2054 r2055 405 405 // Retrieve data from GSCF itself 406 406 def closure = valueCallback( parsedField.type ) 407 407 408 408 if( closure ) { 409 409 samples.each { sample > … … 606 606 // The computation for mean and error will return null if no (numerical) values are found 607 607 // In that case, the user won't see this category 608 def dataForGroup = computeMeanAndError( values ); 608 def dataForGroup = null; 609 switch( params.get( 'aggregation') ) { 610 case "average": 611 dataForGroup = computeMeanAndError( values ); 612 break; 613 case "count": 614 dataForGroup = computeCount( values ); 615 break; 616 case "median": 617 dataForGroup = computeMedian( values ); 618 break; 619 case "none": 620 // Currently disabled, create another function 621 dataForGroup = computeMeanAndError( values ); 622 break; 623 case "sum": 624 dataForGroup = computeSum( values ); 625 break; 626 default: 627 // Default is "average" 628 dataForGroup = computeMeanAndError( values ); 629 } 630 609 631 610 632 if( showEmptyCategories  dataForGroup.value != null ) { … … 742 764 if(it instanceof Number) { 743 765 try{ 744 tmpDateContainer << new java.util.Date( it ).toString()766 tmpDateContainer << new java.util.Date( (Long) it ).toString() 745 767 } catch(IllegalArgumentException e){ 746 768 tmpDateContainer << it … … 878 900 /** 879 901 * Computes the mean of the given values. Values that can not be parsed to a number 880 * are ignored. If no values are given, the mean of 0is returned.902 * are ignored. If no values are given, null is returned. 881 903 * @param values List of values to compute the mean for 882 904 * @return Arithmetic mean of the values … … 890 912 sumOfValues += num; 891 913 sizeOfValues++ 892 } 914 } 893 915 } 894 916 … … 896 918 return sumOfValues / sizeOfValues; 897 919 else 898 return null; 920 return null; 899 921 } 900 922 … … 902 924 * Computes the standard error of mean of the given values. 903 925 * Values that can not be parsed to a number are ignored. 904 * If no values are given, the standard deviation of 0is returned.926 * If no values are given, null is returned. 905 927 * @param values List of values to compute the standard deviation for 906 928 * @param mean Mean of the list (if already computed). If not given, the mean … … 929 951 } 930 952 } 953 954 /** 955 * Computes the median of the given values. Values that can not be parsed to a number 956 * are ignored. If no values are given, null is returned. 957 * @param values List of values to compute the median for 958 * @return Median of the values 959 */ 960 protected def computeMedian( List values ) { 961 def listOfValues = []; 962 values.each { value > 963 def num = getNumericValue( value ); 964 if( num != null ) { 965 listOfValues << num; 966 } 967 } 968 969 listOfValues.sort(); 970 971 def listSize = listOfValues.size(); 972 973 if( listSize > 0 ) { 974 def listHalf = (int) Math.abs(listSize/2); 975 if(listSize%2==0) { 976 // If the list is of an even size, take the mean of the middle two value's 977 return ["value": (listOfValues.get(listHalf)+listOfValues.get(listHalf1))/2]; 978 } else { 979 // If the list is of an odd size, take the middle value 980 return ["value": listOfValues.get(listHalf1)]; 981 } 982 } else 983 return ["value": null]; 984 } 985 986 /** 987 * Computes the count of the given values. Values that can not be parsed to a number 988 * are ignored. If no values are given, null is returned. 989 * @param values List of values to compute the count for 990 * @return Count of the values 991 */ 992 protected def computeCount( List values ) { 993 def sumOfValues = 0; 994 def sizeOfValues = 0; 995 values.each { value > 996 def num = getNumericValue( value ); 997 if( num != null ) { 998 sumOfValues += num; 999 sizeOfValues++ 1000 } 1001 } 1002 1003 if( sizeOfValues > 0 ) 1004 return ["value": sizeOfValues]; 1005 else 1006 return ["value": null]; 1007 } 1008 1009 /** 1010 * Computes the sum of the given values. Values that can not be parsed to a number 1011 * are ignored. If no values are given, null is returned. 1012 * @param values List of values to compute the sum for 1013 * @return Arithmetic sum of the values 1014 */ 1015 protected def computeSum( List values ) { 1016 def sumOfValues = 0; 1017 def sizeOfValues = 0; 1018 values.each { value > 1019 def num = getNumericValue( value ); 1020 if( num != null ) { 1021 sumOfValues += num; 1022 sizeOfValues++ 1023 } 1024 } 1025 1026 if( sizeOfValues > 0 ) 1027 return ["value": sumOfValues]; 1028 else 1029 return ["value": null]; 1030 } 931 1031 932 1032 /**
Note: See TracChangeset
for help on using the changeset viewer.