Changeset 2000 for trunk


Ignore:
Timestamp:
Sep 6, 2011, 4:11:10 PM (8 years ago)
Author:
taco@…
Message:

Update for the visualization controller, determining allowed visualization types is now fully implemented

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/grails-app/controllers/dbnp/visualization/VisualizeController.groovy

    r1998 r2000  
    115115        def getVisualizationTypes = {
    116116        def inputData = parseGetDataParams();
    117         println "inputData: "
    118         inputData.each{
    119             println "\t"+it
    120         }
    121117
    122118        if(inputData.columnIds == null || inputData.columnIds == [] || inputData.columnIds[0] == null || inputData.columnIds[0] == ""){
     
    132128        // TODO: handle the case of multiple fields on an axis
    133129        // Determine data types
    134         println "Checking type of row data ("+inputData.rowIds[0]+")"
    135130        def rowType = determineFieldType(inputData.studyIds[0], inputData.rowIds[0])
    136         println "Checking type of column data ("+inputData.columnIds[0]+")"
    137131        def columnType = determineFieldType(inputData.studyIds[0], inputData.columnIds[0])
    138 
    139         println "getVisualizationTypes: row contains data of type "+rowType+" and column contains data of type "+columnType
    140 
    141132
    142133        // Determine possible visualization types
    143134        // TODO: Determine possible visualization types
    144 
    145                 def types = [ [ "id": "barchart", "name": "Barchart"] ];
    146                 return sendResults(types)
     135        def types = []
     136        if(rowType==categoricalData){
     137            if(columnType==categoricalData){
     138                types = [ [ "id": "table", "name": "Table"] ];
     139            }
     140            if(columnType==numericalData){
     141                types = [ [ "id": "horizontal_barchart", "name": "Horizontal barchart"] ];
     142            }
     143        }
     144        if(rowType==numericalData){
     145            if(columnType==categoricalData){
     146                types = [ [ "id": "barchart", "name": "Barchart"], [ "id": "linechart", "name": "Linechart"] ];
     147            }
     148            if(columnType==numericalData){
     149                types = [ [ "id": "scatterplot", "name": "Scatterplot"], [ "id": "linechart", "name": "Linechart"] ];
     150            }
     151        }
     152
     153        return sendResults(types)
    147154        }
    148155
     
    299306                def inputData = parseGetDataParams();
    300307
    301         println "getData's inputData: "+inputData
    302308        if(inputData.columnIds == null || inputData.rowIds == null){
    303309            infoMessage = "Please select row and columndata."
     
    349355                        visualizationType = "barchart"
    350356                } catch(Exception e) {
    351             /* TODO: Find a way to handle exceptions without breaking the user interface.
     357            /* TODO: Find a way to handle these kinds of exceptions without breaking the user interface.
    352358                Doing things in this way results in the user interface getting a 400.
    353359                        returnError(400, "An error occured while retrieving the user input")
     
    478484                        } catch(Exception e){
    479485                log.error("VisualizationController: getFields: "+e)
    480                 send returnError(404, "An error occured while trying to collect data from a module. Most likely, this module is offline.")
     486                return returnError(404, "An error occured while trying to collect data from a module. Most likely, this module is offline.")
    481487                        }
    482488                } else {
     
    779785    }
    780786
    781     protected def determineFieldType(studyId, fieldId){
     787    protected int determineFieldType(studyId, fieldId){
    782788        // Parse the fieldId as given by the user
    783789                def parsedField = parseFieldId( fieldId );
    784790
    785791        def study = Study.get(studyId)
    786         println "study: "+study+", parsedField: "+parsedField
    787792
    788793                def data = []
     
    792797                // Templatefield
    793798                // ask for tf by id, ask for .type
    794                 println "GSCF TF, dunno yet. input: "+studyId+", "+parsedField
    795799                try{
    796800                    TemplateField tf = TemplateField.get(parsedField.id)
    797                     println "tf.type: "+tf.type
    798801                    if(tf.type=="DOUBLE" || tf.type=="LONG" || tf.type=="DATE" || tf.type=="RELTIME"){
    799802                        return numericalData
     
    803806                } catch(Exception e){
    804807                    log.error("VisualizationController: determineFieldType: "+e)
     808                    // If we cannot figure out what kind of a datatype a piece of data is, we treat it as categorical data
     809                    return categoricalData
    805810                }
    806811            } else {
     
    822827                        case "Event":
    823828                        case "events":
    824                             return determineCategoryFromClass(Event.getField(parsedField.name).class)
     829                            return determineCategoryFromClass(Event[parsedField.name].class)
    825830                            break
    826831                        case "SamplingEvent":
     
    834839                    }
    835840                } catch(Exception e){
     841                    log.error("VisualizationController: determineFieldType: "+e)
     842                    // If we cannot figure out what kind of a datatype a piece of data is, we treat it as categorical data
    836843                    return categoricalData
    837844                }
     
    846853    }
    847854
    848     protected String determineCategoryFromClass(inputObject){
    849         println "determineCategoryFromClass: "+inputObject+", class: "+inputObject.class
     855    protected int determineCategoryFromClass(inputObject){
    850856        if(inputObject==java.lang.String){
    851857            return categoricalData
     
    855861    }
    856862
    857     protected String determineCategoryFromData(inputObject){
     863    protected int determineCategoryFromData(inputObject){
    858864        def results = []
    859865        if(inputObject instanceof Collection){
    860             // More complex datatype, call outselves again
     866            // This data is more complex than a single value, so we will call ourselves again so we c
    861867            inputObject.each {
    862868                results << determineCategoryFromData(it)
     
    873879
    874880        if(results.size()>1){
    875             //log.error("VisualizeController: determineCategoryFromData: Category list contains more than one category! List: "+results+", inputObject: "+inputObject)
     881            // If we cannot figure out what kind of a datatype a piece of data is, we treat it as categorical data
    876882            results[0] = categoricalData
    877883        }
     
    887893        }
    888894        results.put("returnData", returnData)
    889         println "Returning "+results
    890895        render results as JSON
    891896    }
     
    895900        results.put("infoMessage", infoMessage)
    896901        infoMessage = ""
    897         println "Returning "+results
    898902        render results as JSON
    899903    }
Note: See TracChangeset for help on using the changeset viewer.