Changeset 2036
- Timestamp:
- Sep 27, 2011, 10:43:14 AM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/grails-app/controllers/dbnp/visualization/VisualizeController.groovy
r2035 r2036 288 288 } 289 289 290 // Handle the case that we are gathering data for a horizontal barchart291 if(inputData.visualizationType=='horizontal_barchart'){292 def tmp = inputData.columnIds293 inputData.columnIds = inputData.rowIds294 inputData.rowIds = tmp295 }296 297 290 // TODO: handle the case that we have multiple studies 298 291 def studyId = inputData.studyIds[ 0 ]; … … 308 301 309 302 // Group data based on the y-axis if categorical axis is selected 310 def groupedData = groupFieldData( data ); 303 def groupedData 304 if(inputData.visualizationType=='horizontal_barchart'){ 305 groupedData = groupFieldData( data, "y", "x" ); // Indicate non-standard axis ordering 306 } else { 307 groupedData = groupFieldData( data ); // Don't indicate axis ordering, standard <"x", "y"> will be used 308 } 311 309 312 310 // Format data so it can be rendered as JSON 313 def returnData = formatData( inputData.visualizationType, groupedData, fields ); 311 def returnData 312 if(inputData.visualizationType=='horizontal_barchart'){ 313 returnData = formatData( inputData.visualizationType, groupedData, fields, "y", "x" ); // Indicate non-standard axis ordering 314 } else { 315 returnData = formatData( inputData.visualizationType, groupedData, fields); // Don't indicate axis ordering, standard <"x", "y"> will be used 316 } 314 317 return sendResults(returnData) 315 318 } … … 549 552 // TODO: Handle name and unit of fields correctly 550 553 if(type=="table"){ 554 // TODO: implement this 551 555 def xAxis = groupedData[ groupAxis ].collect { it.toString() }; 552 556 def yName = parseFieldId( fields[ valueAxis ] ).name; … … 843 847 */ 844 848 protected int determineFieldType(studyId, fieldId){ 845 // Parse the fieldId as given by the user846 849 def parsedField = parseFieldId( fieldId ); 847 848 850 def study = Study.get(studyId) 849 850 851 def data = [] 851 852 852 if( parsedField.source == "GSCF" ) { 853 if(parsedField.id.isNumber()){ 854 // Templatefield 855 // ask for tf by id, ask for .type 856 try{ 857 TemplateField tf = TemplateField.get(parsedField.id) 858 if(tf.type==TemplateFieldType.DOUBLE || tf.type==TemplateFieldType.LONG || tf.type==TemplateFieldType.DATE || tf.type==TemplateFieldType.RELTIME){ 859 println "GSCF templatefield: NUMERICALDATA ("+NUMERICALDATA+") (based on "+tf.type+")" 860 return NUMERICALDATA 853 try{ 854 if( parsedField.source == "GSCF" ) { 855 if(parsedField.id.isNumber()){ 856 return determineCategoryFromTemplateField(parsedField.id) 857 } else { // Domainfield or memberclass 858 def field = domainObjectCallback( parsedField.type )?.declaredFields.find { it.name == parsedField.name }; 859 if( field ) { 860 return determineCategoryFromClass( field.getType() ) 861 861 } else { 862 println "GSCF templatefield: CATEGORICALDATA ("+CATEGORICALDATA+") (based on "+tf.type+")"863 return CATEGORICALDATA862 // TODO: how do we communicate this to the user? Do we allow the process to proceed? 863 log.error( "The user asked for field " + parsedField.type + " - " + parsedField.name + ", but it doesn't exist." ); 864 864 } 865 } catch(Exception e){866 log.error("VisualizationController: determineFieldType: "+e)867 // If we cannot figure out what kind of a datatype a piece of data is, we treat it as categorical data868 return CATEGORICALDATA869 865 } 870 866 } else { 871 // Domainfield or memberclass 872 try{ 873 def field = domainObjectCallback( parsedField.type )?.declaredFields.find { it.name == parsedField.name }; 874 if( field ) { 875 return determineCategoryFromClass( field.getType() ) 876 } else { 877 log.error( "The user asked for field " + parsedField.type + " - " + parsedField.name + ", but it doesn't exist." ); 878 } 879 } catch(Exception e){ 880 log.error("VisualizationController: determineFieldType: "+e) 881 e.printStackTrace() 882 // If we cannot figure out what kind of a datatype a piece of data is, we treat it as categorical data 883 return CATEGORICALDATA 884 } 885 } 886 } else { 887 data = getModuleData( study, study.getSamples(), parsedField.source, parsedField.name ); 888 println "Data: " + data 889 def cat = determineCategoryFromData(data) 890 return cat 891 } 867 data = getModuleData( study, study.getSamples(), parsedField.source, parsedField.name ); 868 println "Data: " + data 869 def cat = determineCategoryFromData(data) 870 return cat 871 } 872 } catch(Exception e){ 873 log.error("VisualizationController: determineFieldType: "+e) 874 e.printStackTrace() 875 // If we cannot figure out what kind of a datatype a piece of data is, we treat it as categorical data 876 return CATEGORICALDATA 877 } 892 878 } 893 879 … … 937 923 } 938 924 925 /** 926 * Determines a field category, based on the TemplateFieldType of a Templatefield 927 * @param id A database ID for a TemplateField 928 * @return Either CATEGORICALDATA of NUMERICALDATA 929 */ 930 protected int determineCategoryFromTemplateField(id){ 931 TemplateField tf = TemplateField.get(id) 932 if(tf.type==TemplateFieldType.DOUBLE || tf.type==TemplateFieldType.LONG || tf.type==TemplateFieldType.DATE || tf.type==TemplateFieldType.RELTIME){ 933 println "GSCF templatefield: NUMERICALDATA ("+NUMERICALDATA+") (based on "+tf.type+")" 934 return NUMERICALDATA 935 } else { 936 println "GSCF templatefield: CATEGORICALDATA ("+CATEGORICALDATA+") (based on "+tf.type+")" 937 return CATEGORICALDATA 938 } 939 } 939 940 /** 940 941 * Properly formats the object that will be returned to the client. Also adds an informational message, if that message has been set by a function. Resets the informational message to the empty String.
Note: See TracChangeset
for help on using the changeset viewer.