Changeset 2015
- Timestamp:
- Sep 12, 2011, 2:35:43 PM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/grails-app/controllers/dbnp/visualization/VisualizeController.groovy
r2013 r2015 23 23 def authenticationService 24 24 def moduleCommunicationService 25 def infoMessage = "" 25 def infoMessage = [] 26 def infoMessageOfflineModules = [] 26 27 final int CATEGORICALDATA = 0 27 28 final int NUMERICALDATA = 1 … … 58 59 // Check to see if we have enough information 59 60 if(input_object==null || input_object?.studyIds==null){ 60 infoMessage = "Please select a study."61 setInfoMessage("Please select a study.") 61 62 return sendInfoMessage() 62 63 } else { … … 108 109 } 109 110 111 // Make sure any informational messages regarding offline modules are submitted to the client 112 setInfoMessageOfflineModules() 113 110 114 111 115 // TODO: Maybe we should add study's own fields … … 132 136 133 137 if(inputData.columnIds == null || inputData.columnIds == [] || inputData.columnIds[0] == null || inputData.columnIds[0] == ""){ 134 infoMessage = "Please select a data source for the x-axis."138 setInfoMessage("Please select a data source for the x-axis.") 135 139 return sendInfoMessage() 136 140 } 137 141 if(inputData.rowIds == null || inputData.rowIds == [] || inputData.rowIds[0] == null || inputData.rowIds[0] == ""){ 138 infoMessage = "Please select a data source for the y-axis."142 setInfoMessage("Please select a data source for the y-axis.") 139 143 return sendInfoMessage() 140 144 } … … 184 188 } catch(Exception e){ 185 189 //returnError(404, "An error occured while trying to collect field data from a module. Most likely, this module is offline.") 186 infoMessage = "Unfortunately, "+assay.module.name+" could not be reached. As a result, we cannot at this time visualize data contained in this module."190 infoMessageOfflineModules.add(assay.module.name) 187 191 log.error("VisualizationController: getFields: "+e) 188 192 } … … 620 624 } 621 625 622 /**623 * Returns the objects within the given study that should be used with the given entity string624 *625 * For example:626 * What object should be consulted if the user asks for "samples"627 * Response: study.samples628 * @return List of domain objects that should be used with the given entity string629 */630 protected def templateObjectCallback( String entity, Study study ) {631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 }626 /** 627 * Returns the objects within the given study that should be used with the given entity string 628 * 629 * For example: 630 * What object should be consulted if the user asks for "samples" 631 * Response: study.samples 632 * @return List of domain objects that should be used with the given entity string 633 */ 634 protected def templateObjectCallback( String entity, Study study ) { 635 switch( entity ) { 636 case "Study": 637 case "studies": 638 return study 639 case "Subject": 640 case "subjects": 641 return study?.samples?.parentSubject 642 case "Sample": 643 case "samples": 644 return study?.samples 645 case "Event": 646 case "events": 647 return study?.samples?.parentEventGroup?.events?.flatten() 648 case "SamplingEvent": 649 case "samplingEvents": 650 return study?.samples?.parentEvent 651 case "Assay": 652 case "assays": 653 return study?.assays 654 } 655 } 652 656 653 657 /** … … 701 705 * @return Standard error of the mean of the values or 0 if no values can be used. 702 706 */ 703 protected def computeSEM( List values, def mean = null ) {704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 }724 Exception e707 protected def computeSEM( List values, def mean = null ) { 708 if( mean == null ) 709 mean = computeMean( values ) 710 711 def sumOfDifferences = 0; 712 def sizeOfValues = 0; 713 values.each { value -> 714 def num = getNumericValue( value ); 715 if( num != null ) { 716 sumOfDifferences += Math.pow( num - mean, 2 ); 717 sizeOfValues++ 718 } 719 } 720 721 if( sizeOfValues > 0 ) { 722 def std = Math.sqrt( sumOfDifferences / sizeOfValues ); 723 return std / Math.sqrt( sizeOfValues ); 724 } else { 725 return 0; 726 } 727 } 728 Exception e 725 729 /** 726 730 * Return the numeric value of the given object, or null if no numeric value could be returned … … 902 906 protected void sendResults(returnData){ 903 907 def results = [:] 904 if(infoMessage !=""){908 if(infoMessage.size()!=0){ 905 909 results.put("infoMessage", infoMessage) 906 infoMessage = ""910 infoMessage = [] 907 911 } 908 912 results.put("returnData", returnData) … … 918 922 def results = [:] 919 923 results.put("infoMessage", infoMessage) 920 infoMessage = ""924 infoMessage = [] 921 925 render results as JSON 926 } 927 928 /** 929 * Adds a new message to the infoMessage 930 * @param message The information that needs to be added to the infoMessage 931 */ 932 protected void setInfoMessage(message){ 933 infoMessage.add([message]) 934 println "setInfoMessage: "+infoMessage 935 } 936 937 /** 938 * Adds a message to the infoMessage that gives the client information about offline modules 939 */ 940 protected void setInfoMessageOfflineModules(){ 941 if(infoMessageOfflineModules.size()>0){ 942 String message = "Unfortunately" 943 infoMessageOfflineModules.eachWithIndex{ it, index -> 944 if(index==(infoMessageOfflineModules.size()-2)){ 945 message += ', the '+it+' and ' 946 } else { 947 if(index==(infoMessageOfflineModules.size()-1)){ 948 message += 'the '+it 949 } else { 950 message += ', the '+it 951 } 952 } 953 } 954 message += " could not be reached. As a result, we cannot at this time visualize data contained in " 955 if(infoMessageOfflineModules.size()>1){ 956 message += "these modules." 957 } else { 958 message += "this module." 959 } 960 setInfoMessage(message) 961 } 962 infoMessageOfflineModules = [] 922 963 } 923 964
Note: See TracChangeset
for help on using the changeset viewer.