Changeset 3328

Show
Ignore:
Timestamp:
05/12/08 03:03:33 (2 months ago)
Author:
travis
Message:

(travis) implementing indicator group functionality

Location:
trunk
Files:
1 added
6 modified

Legend:

Unmodified
Added
Removed
  • trunk/eugene/configs/eugene_gridcell.xml

    r3321 r3328  
    139139  </data_manager> 
    140140  <model_manager> 
    141     <test_model_config type="string"> 
    142     </test_model_config> 
     141    <test_model_config type="string" /> 
    143142  </model_manager> 
    144143  <scenario_manager> 
    145     <Eugene_baseline executable="True" setexpanded="True" type="scenario" copyable="True"> 
     144    <Eugene_baseline copyable="True" executable="True" setexpanded="True" type="scenario"> 
    146145      <parent type="scenario_name">default_scenario</parent> 
    147146      <base_year type="integer">1980</base_year> 
     
    309308      </my_indicators> 
    310309    </Indicator_libraries> 
    311     <Indicator_groups setexpanded="True" type="group"/> 
    312     <Simulation_runs setexpanded="True" type="all_source_data" /> 
    313     <Results setexpanded="True" type="selectable_list" /> 
     310    <Indicator_groups setexpanded="True" type="group"> 
     311      <an_indicator_group type="indicator_group"> 
     312        <industrial_sqft type="indicator_group_member"><visualization_type choices="Map (per indicator per year)|Chart (per indicator, spans years)|Table (per indicator, spans years)|Table (per year, spans indicators)" type="string">Table (per year, spans indicators)</visualization_type> 
     313          <dataset_name choices="gridcell|zone|faz|large_area|city|county|alldata" type="string">gridcell</dataset_name> 
     314        </industrial_sqft> 
     315        <number_of_jobs type="indicator_group_member"> 
     316          <visualization_type choices="Map (per indicator per year)|Chart (per indicator, spans years)|Table (per indicator, spans years)|Table (per year, spans indicators)" type="string">Table (per year, spans indicators)</visualization_type> 
     317          <dataset_name choices="&apos;gridcell|zone|faz|large_area|city|county|alldata&apos;" type="string">zone</dataset_name> 
     318        </number_of_jobs> 
     319      </an_indicator_group> 
     320    </Indicator_groups> 
     321    <Simulation_runs setexpanded="True" type="all_source_data"> 
     322 
     323    </Simulation_runs> 
     324    <Results setexpanded="True" type="selectable_list"> 
     325 
     326    </Results> 
    314327  </results_manager> 
    315328</opus_project> 
  • trunk/opus_gui/config/resultsmanager/opusxmlaction_results.py

    r3327 r3328  
    160160        model = self.currentIndex.model() 
    161161        document = model.domDocument 
    162         name = 'INDICATOR_GROUP_NAME' 
     162        name = 'untitled_indicator_group' 
    163163 
    164164        newNode = model.create_node(document = document,  
     
    211211                                 child_names = ['available_datasets']) 
    212212         
    213         datasets = '|'.join(str(available_datasets['available_datasets'])[1:-1].split("','")) 
     213        datasets = '|'.join(str(available_datasets['available_datasets'])[1:-1].replace("'",'').split(",")) 
    214214 
    215215        visualizations = [ 
  • trunk/opus_gui/results/forms/advanced_visualization_form.py

    r3325 r3328  
    280280    def on_pbn_go_released(self): 
    281281        # Fire up a new thread and run the model 
    282         print 'Generate results button pressed' 
     282        print 'Go button pressed' 
    283283 
    284284        # References to the GUI elements for status for this run... 
  • trunk/opus_gui/results/forms/generate_results_form.py

    r3202 r3328  
    3636         
    3737        self.available_years_for_simulation_runs = {} 
    38  
     38         
    3939        self.result_generator = OpusResultGenerator( 
    4040                                    xml_path = self.toolboxStuff.xml_file, 
    41                                     domDocument = self.domDocument) 
     41                                    domDocument = self.domDocument,  
     42                                    model = self.toolboxStuff.resultsManagerTree.model) 
    4243             
    4344        self.result_generator.guiElement = self 
     
    272273                                   years = years) 
    273274         
    274         self.last_computed_result = { 
    275             'source_data_name': source_text, 
    276             'indicator_name': indicator_text, 
    277             'dataset_name': dataset_name, 
    278             'years': years                            
    279         } 
     275#        self.last_computed_result = { 
     276#            'source_data_name': source_text, 
     277#            'indicator_name': indicator_text, 
     278#            'dataset_name': dataset_name, 
     279#            'years': years                            
     280#        } 
    280281         
    281282        self.runThread = OpusGuiThread( 
     
    307308        print "Results generated met with success = ", success 
    308309         
    309         self.update_results_xml() 
     310        #self.update_results_xml() 
    310311         
    311312        # Get the final logfile update after model finishes... 
     
    313314        self.pbn_generate_results.setEnabled(True) 
    314315     
    315     def update_results_xml(self): 
    316         print "update results" 
    317         xml_tree = self.toolboxStuff.resultsManagerTree 
    318         model = xml_tree.model 
    319         document = self.domDocument 
    320  
    321         name = '%s.%s.%s'%(self.last_computed_result['indicator_name'],  
    322             self.last_computed_result['dataset_name'],  
    323             self.last_computed_result['source_data_name']) 
    324          
    325         newNode = model.create_node(document = document,  
    326                                     name = name,  
    327                                     type = 'indicator_result',  
    328                                     value = '') 
    329         source_data_node = model.create_node(document = document,  
    330                                     name = 'source_data',  
    331                                     type = 'string',  
    332                                     value = self.last_computed_result['source_data_name']) 
    333         indicator_node = model.create_node(document = document,  
    334                                     name = 'indicator_name',  
    335                                     type = 'string',  
    336                                     value = self.last_computed_result['indicator_name'])         
    337         dataset_node = model.create_node(document = document,  
    338                                     name = 'dataset_name',  
    339                                     type = 'string',  
    340                                     value = self.last_computed_result['dataset_name']) 
    341         year_node = model.create_node(document = document,  
    342                                     name = 'available_years',  
    343                                     type = 'string',  
    344                                     value = ', '.join([repr(year) for year in self.last_computed_result['years']]))                 
    345         parent = model.index(0,0,QModelIndex()).parent() 
    346         index = model.findElementIndexByName("Results", parent)[0] 
    347         if index.isValid(): 
    348             model.insertRow(0, 
    349                             index, 
    350                             newNode) 
    351         else: 
    352             print "No valid node was found..." 
    353          
    354         child_index = model.findElementIndexByName(name, parent)[0] 
    355         if child_index.isValid(): 
    356             for node in [dataset_node, indicator_node, source_data_node, year_node]: 
    357                 model.insertRow(0, 
    358                                 child_index, 
    359                                 node) 
    360         else: 
    361             print "No valid node was found..." 
    362          
    363         model.emit(SIGNAL("layoutChanged()")) 
     316#    def update_results_xml(self): 
     317#        print "update results" 
     318#        xml_tree = self.toolboxStuff.resultsManagerTree 
     319#        model = xml_tree.model 
     320#        document = self.domDocument 
     321# 
     322#        name = '%s.%s.%s'%(self.last_computed_result['indicator_name'],  
     323#            self.last_computed_result['dataset_name'],  
     324#            self.last_computed_result['source_data_name']) 
     325#         
     326#        newNode = model.create_node(document = document,  
     327#                                    name = name,  
     328#                                    type = 'indicator_result',  
     329#                                    value = '') 
     330#        source_data_node = model.create_node(document = document,  
     331#                                    name = 'source_data',  
     332#                                    type = 'string',  
     333#                                    value = self.last_computed_result['source_data_name']) 
     334#        indicator_node = model.create_node(document = document,  
     335#                                    name = 'indicator_name',  
     336#                                    type = 'string',  
     337#                                    value = self.last_computed_result['indicator_name'])         
     338#        dataset_node = model.create_node(document = document,  
     339#                                    name = 'dataset_name',  
     340#                                    type = 'string',  
     341#                                    value = self.last_computed_result['dataset_name']) 
     342#        year_node = model.create_node(document = document,  
     343#                                    name = 'available_years',  
     344#                                    type = 'string',  
     345#                                    value = ', '.join([repr(year) for year in self.last_computed_result['years']]))                 
     346#        parent = model.index(0,0,QModelIndex()).parent() 
     347#        index = model.findElementIndexByName("Results", parent)[0] 
     348#        if index.isValid(): 
     349#            model.insertRow(0, 
     350#                            index, 
     351#                            newNode) 
     352#        else: 
     353#            print "No valid node was found..." 
     354#         
     355#        child_index = model.findElementIndexByName(name, parent)[0] 
     356#        if child_index.isValid(): 
     357#            for node in [dataset_node, indicator_node, source_data_node, year_node]: 
     358#                model.insertRow(0, 
     359#                                child_index, 
     360#                                node) 
     361#        else: 
     362#            print "No valid node was found..." 
     363#         
     364#        model.emit(SIGNAL("layoutChanged()")) 
    364365 
    365366    def runErrorFromThread(self,errorMessage): 
  • trunk/opus_gui/results/opus_result_generator.py

    r3194 r3328  
    7474 
    7575 
    76  
     76class OpusIndicatorGroupProcessor(object): 
     77    def __init__(self,  
     78                 xml_path,  
     79                 domDocument, 
     80                 model, 
     81                 kwargs = None): 
     82           
     83        self.generator = OpusResultGenerator( 
     84           xml_path = xml_path, 
     85           domDocument = domDocument, 
     86           model = model                                             
     87        ) 
     88           
     89        self.visualizer = OpusResultVisualizer( 
     90           xml_path = xml_path, 
     91           domDocument = domDocument, 
     92           indicator_type = None, 
     93           indicators = None, 
     94           kwargs = kwargs                      
     95        ) 
     96        self.finishedCallback = None 
     97        self.errorCallback = None 
     98             
     99    def set_data(self,                   
     100                 indicator_defs,  
     101                 source_data_name, 
     102                 years): 
     103         
     104        self.indicator_defs = indicator_defs 
     105        self.years = years 
     106        self.source_data_name = source_data_name         
     107         
     108    def run(self): 
     109        succeeded = False 
     110         
     111        try: 
     112            self.visualizations = [] 
     113            for (visualization_type, dataset_name), indicators in self.indicator_defs.items(): 
     114                indicator_results = [] 
     115                for indicator_name in indicators: 
     116                    try: 
     117                        self.generator.set_data(self.source_data_name,  
     118                                                indicator_name,  
     119                                                dataset_name,  
     120                                                self.years) 
     121                        self.generator.run() 
     122                        indicator = {'indicator_name':indicator_name,#self.generator.last_added_indicator_result_name, 
     123                                     'dataset_name':dataset_name, 
     124                                     'source_data_name':self.source_data_name, 
     125                                     'years':self.years} 
     126                        indicator_results.append(indicator) 
     127                         
     128                    except: 
     129                        print 'could not generate indicator %s'%indicator_name 
     130                self.visualizer.indicator_type = visualization_type 
     131                self.visualizer.indicators = indicator_results 
     132                try: 
     133                    import pydevd;pydevd.settrace() 
     134                except: 
     135                    pass 
     136                self.visualizer.run() 
     137                self.visualizations.append((visualization_type, self.visualizer.get_visualizations())) 
     138             
     139            succeeded = True 
     140        except: 
     141            succeeded = False 
     142            errorInfo = formatExceptionInfo() 
     143            errorString = "Unexpected Error From Model :: " + str(errorInfo) 
     144            print errorInfo 
     145            self.errorCallback(errorString) 
     146 
     147        self.finishedCallback(succeeded) 
     148     
     149    def get_visualizations(self):  
     150        return self.visualizations 
     151     
    77152class OpusResultVisualizer(object): 
    78153    def __init__(self,  
     
    101176            try: 
    102177                # find the directory containing the eugene xml configurations 
    103                 fileNameInfo = QFileInfo(self.xml_path) 
    104                 fileNameAbsolute = fileNameInfo.absoluteFilePath().trimmed() 
    105                 self._visualize(configuration_path = fileNameAbsolute) 
     178                self._visualize() 
    106179                succeeded = True 
    107180            except: 
     
    110183                errorString = "Unexpected Error From Model :: " + str(errorInfo) 
    111184                print errorInfo 
    112                 self.errorCallback(errorString) 
    113  
    114             self.finishedCallback(succeeded) 
     185                if self.errorCallback is not None: 
     186                    self.errorCallback(errorString) 
     187            if self.finishedCallback is not None: 
     188                self.finishedCallback(succeeded) 
    115189        else: 
    116190            pass 
     
    118192 
    119193         
    120     def _visualize(self, configuration_path): 
     194    def _visualize(self): 
    121195        indicators_to_visualize = {} 
    122196        interface = IndicatorFrameworkInterface(domDocument = self.domDocument) 
     
    207281class OpusResultGenerator(object): 
    208282     
    209     def __init__(self, xml_path, domDocument): 
     283    def __init__(self, xml_path, domDocument, model): 
    210284        self.xml_path = xml_path 
    211285        self.finishedCallback = None 
     
    215289        self.firstRead = True 
    216290        self.domDocument = domDocument 
     291        self.model = model 
    217292     
    218293    def set_data(self, 
     
    231306            succeeded = False 
    232307            try: 
    233                 # find the directory containing the eugene xml configurations 
    234                 fileNameInfo = QFileInfo(self.xml_path) 
    235                 fileNameAbsolute = fileNameInfo.absoluteFilePath().trimmed() 
    236                 configuration_path = fileNameAbsolute 
    237308                try: 
    238309                    import pydevd;pydevd.settrace() 
     
    240311                    pass 
    241312                 
    242                 self._generate_results(configuration_path = configuration_path) 
     313                self._generate_results() 
    243314                succeeded = True 
    244315            except Exception, e: 
     
    255326                ) 
    256327                print errorString 
    257                 self.errorCallback(errorString) 
    258  
    259             self.finishedCallback(succeeded) 
     328                if self.errorCallback is not None: 
     329                    self.errorCallback(errorString) 
     330            if self.finishedCallback is not None: 
     331                self.finishedCallback(succeeded) 
    260332        else: 
    261333            pass 
    262334 
    263     def _generate_results(self, configuration_path): 
     335    def _generate_results(self): 
    264336#        try: 
    265337#            import pydevd;pydevd.settrace() 
     
    281353        computed_indicator = maker.create(indicator = indicator,  
    282354                                          source_data = source_data) 
     355        self.update_results_xml() 
     356 
     357    def update_results_xml(self): 
     358        print "update results" 
     359        model = self.model 
     360        document = self.domDocument 
     361         
     362        name = '%s.%s.%s'%(self.indicator_name,  
     363            self.dataset_name,  
     364            self.source_data_name) 
     365         
     366        self.last_added_indicator_result_name = name 
     367         
     368        newNode = model.create_node(document = document,  
     369                                    name = name,  
     370                                    type = 'indicator_result',  
     371                                    value = '') 
     372        source_data_node = model.create_node(document = document,  
     373                                    name = 'source_data',  
     374                                    type = 'string',  
     375                                    value = self.source_data_name) 
     376        indicator_node = model.create_node(document = document,  
     377                                    name = 'indicator_name',  
     378                                    type = 'string',  
     379                                    value = self.indicator_name)         
     380        dataset_node = model.create_node(document = document,  
     381                                    name = 'dataset_name',  
     382                                    type = 'string',  
     383                                    value = self.dataset_name) 
     384        year_node = model.create_node(document = document,  
     385                                    name = 'available_years',  
     386                                    type = 'string',  
     387                                    value = ', '.join([repr(year) for year in self.years]))                 
     388        parent = model.index(0,0,QModelIndex()).parent() 
     389        index = model.findElementIndexByName("Results", parent)[0] 
     390        if index.isValid(): 
     391            model.insertRow(0, 
     392                            index, 
     393                            newNode) 
     394        else: 
     395            print "No valid node was found..." 
     396         
     397        child_index = model.findElementIndexByName(name, parent)[0] 
     398        if child_index.isValid(): 
     399            for node in [dataset_node, indicator_node, source_data_node, year_node]: 
     400                model.insertRow(0, 
     401                                child_index, 
     402                                node) 
     403        else: 
     404            print "No valid node was found..." 
     405         
     406        model.emit(SIGNAL("layoutChanged()")) 
    283407                 
    284408    def _get_current_log(self, key): 
  • trunk/opus_gui/results/resultManagerBase.py

    r3326 r3328  
    255255        self.visualizer = None 
    256256 
    257     def addViewImageIndicator(self, visualization): 
     257    def addViewImageIndicator(self, visualization, indicator_type = None): 
    258258        new_form = ViewImageForm(parent = self.parent, 
    259259                                 visualization = visualization) 
     
    261261        self.updateGuiElements() 
    262262 
    263     def addViewTableIndicator(self, visualization): 
     263    def addViewTableIndicator(self, visualization, indicator_type): 
    264264        new_form = ViewTableForm(parent = self.parent, 
    265265                                 visualization = visualization) 
    266         if self.indicator_type != 'arcgis_map': 
     266        if indicator_type != 'arcgis_map': 
    267267            self.guiElements.insert(0, new_form) 
    268268            self.updateGuiElements()